public void TestDiskFull() { byte[] bytes = new byte[] { 1, 2 }; // test writeBytes using (MockDirectoryWrapper dir = NewMockDirectory()) { dir.MaxSizeInBytes = 3; using (IndexOutput @out = dir.CreateOutput("foo", IOContext.DEFAULT)) { @out.WriteBytes(bytes, bytes.Length); // first write should succeed // close() to ensure the written bytes are not buffered and counted // against the directory size } // @out.close(); using (IndexOutput @out = dir.CreateOutput("bar", IOContext.DEFAULT)) { try { @out.WriteBytes(bytes, bytes.Length); fail("should have failed on disk full"); } #pragma warning disable 168 catch (Exception e) #pragma warning restore 168 { // expected } } // @out.close(); } // dir.close(); // test copyBytes using (MockDirectoryWrapper dir = NewMockDirectory()) { dir.MaxSizeInBytes = 3; using (IndexOutput @out = dir.CreateOutput("foo", IOContext.DEFAULT)) { @out.CopyBytes(new ByteArrayDataInput(bytes), bytes.Length); // first copy should succeed // close() to ensure the written bytes are not buffered and counted // against the directory size } // @out.close(); using (IndexOutput @out = dir.CreateOutput("bar", IOContext.DEFAULT)) { try { @out.CopyBytes(new ByteArrayDataInput(bytes), bytes.Length); fail("should have failed on disk full"); } #pragma warning disable 168 catch (Exception e) #pragma warning restore 168 { // expected } } // @out.close(); } // dir.close(); }
public virtual void TestDiskFull() { // test writeBytes MockDirectoryWrapper dir = NewMockDirectory(); dir.MaxSizeInBytes = 3; sbyte[] bytes = new sbyte[] { 1, 2 }; IndexOutput @out = dir.CreateOutput("foo", IOContext.DEFAULT); @out.WriteBytes(bytes, bytes.Length); // first write should succeed // flush() to ensure the written bytes are not buffered and counted // against the directory size @out.Flush(); try { @out.WriteBytes(bytes, bytes.Length); Assert.Fail("should have failed on disk full"); } catch (IOException e) { // expected } @out.Dispose(); dir.Dispose(); // test copyBytes dir = NewMockDirectory(); dir.MaxSizeInBytes = 3; @out = dir.CreateOutput("foo", IOContext.DEFAULT); @out.CopyBytes(new ByteArrayDataInput((byte[])(Array)bytes), bytes.Length); // first copy should succeed // flush() to ensure the written bytes are not buffered and counted // against the directory size @out.Flush(); try { @out.CopyBytes(new ByteArrayDataInput((byte[])(Array)bytes), bytes.Length); Assert.Fail("should have failed on disk full"); } catch (IOException e) { // expected } @out.Dispose(); dir.Dispose(); }
public void TestAbuseClosedIndexInput() { using MockDirectoryWrapper dir = NewMockDirectory(); using (IndexOutput @out = dir.CreateOutput("foo", IOContext.DEFAULT)) { @out.WriteByte((byte)42); } // @out.close(); IndexInput @in = dir.OpenInput("foo", IOContext.DEFAULT); @in.Dispose(); Assert.Throws <LuceneSystemException>(() => @in.ReadByte()); }
public virtual void TestDummy() { MockDirectoryWrapper dir = NewMockDirectory(); dir.AssertNoUnrefencedFilesOnClose = true; IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(LuceneTestCase.TEST_VERSION_CURRENT, null)); iw.AddDocument(new Document()); iw.Dispose(); IndexOutput output = dir.CreateOutput("_hello.world", IOContext.DEFAULT); output.writeString("i am unreferenced!"); output.Dispose(); dir.Sync(CollectionsHelper.Singleton("_hello.world")); dir.Dispose(); }