Flush() public method

Flushes any changes to current chunk to the database. It can be called in client code at any time or it will automatically be called on Close() and when the stream position moves off the bounds of the current chunk.
public Flush ( ) : void
return void
Esempio n. 1
0
        public void TestWriteWithMultipleFlushes()
        {
            string         filename = "multiflush.txt";
            GridFileStream gfs      = fs.Create(filename);
            Object         id       = gfs.GridFileInfo.Id;
            int            size     = gfs.GridFileInfo.ChunkSize * 2;

            byte[] buff;

            int x = 0;

            for (int i = 0; i < size; i += 4)
            {
                buff = BitConverter.GetBytes(x);
                gfs.Write(buff, 0, buff.Length);
                x++;
                if (i % size / 4 == 0)
                {
                    gfs.Flush();
                }
            }
            gfs.Close();

            gfs = fs.OpenRead(filename);
            int read;
            int val;

            buff = new byte[4];
            for (int i = 0; i < size / 4; i++)
            {
                read = gfs.Read(buff, 0, 4);
                val  = BitConverter.ToInt32(buff, 0);
                Assert.AreEqual(4, read, "Not enough bytes were read. Pos: " + gfs.Position);
                Assert.AreEqual(i, val, "value read back was not the same as written. Pos: " + gfs.Position);
            }
        }