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); } }
public void TestOpenReadOnly() { string filename = "gfi-open.txt"; GridFile gf = new GridFile(DB, "gfopen"); GridFileStream gfs = gf.Create(filename); gfs.Close(); gfs = gf.OpenRead(filename); Assert.IsNotNull(gfs); bool thrown = false; try{ gfs.Write(new byte[] { 0 }, 0, 1); }catch (System.NotSupportedException) { thrown = true; }catch (Exception ex) { Assert.Fail("Wrong exception thrown " + ex.GetType().Name); } Assert.IsTrue(thrown, "NotSupportedException not thrown"); }
public void TestOpenReadOnly() { string filename = "gfi-open.txt"; GridFile gf = new GridFile(db["tests"], "gfopen"); GridFileStream gfs = gf.Create(filename); gfs.Close(); gfs = gf.OpenRead(filename); Assert.IsNotNull(gfs); bool thrown = false; try{ gfs.Write(new byte[]{0},0,1); }catch(System.NotSupportedException){ thrown = true; }catch(Exception ex){ Assert.Fail("Wrong exception thrown " + ex.GetType().Name); } Assert.IsTrue(thrown, "NotSupportedException not thrown"); }