//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldFreeOnClose() internal virtual void ShouldFreeOnClose() { // given MemoryAllocationTracker tracker = new LocalMemoryTracker(); using (UnsafeDirectByteBufferAllocator factory = new UnsafeDirectByteBufferAllocator(tracker)) { // when factory.Allocate(256); } // then assertEquals(0, tracker.UsedDirectMemory()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldHandleMultipleClose() internal virtual void ShouldHandleMultipleClose() { // given MemoryAllocationTracker tracker = new LocalMemoryTracker(); UnsafeDirectByteBufferAllocator factory = new UnsafeDirectByteBufferAllocator(tracker); // when factory.Allocate(256); factory.Close(); // then assertEquals(0, tracker.UsedDirectMemory()); factory.Close(); assertEquals(0, tracker.UsedDirectMemory()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldAllocateBuffer() internal virtual void ShouldAllocateBuffer() { // given MemoryAllocationTracker tracker = new LocalMemoryTracker(); using (UnsafeDirectByteBufferAllocator factory = new UnsafeDirectByteBufferAllocator(tracker)) { // when int bufferSize = 128; factory.Allocate(bufferSize); // then assertEquals(bufferSize, tracker.UsedDirectMemory()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void mustAllocateResourcesLazilyAndCleanUpOnClose() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void MustAllocateResourcesLazilyAndCleanUpOnClose() { FileSystemAbstraction fs = Directory.FileSystem; LocalMemoryTracker allocationTracker = new LocalMemoryTracker(); File file = Directory.file("file"); using (UnsafeDirectByteBufferAllocator bufferFactory = new UnsafeDirectByteBufferAllocator(allocationTracker), IndexKeyStorage <GenericKey> keyStorage = keyStorage(file, bufferFactory)) { assertEquals(0, allocationTracker.UsedDirectMemory(), "Expected to not have any buffers allocated yet"); assertFalse(fs.FileExists(file), "Expected file to be created lazily"); keyStorage.add(RandomKey(1)); assertEquals(BLOCK_SIZE, allocationTracker.UsedDirectMemory(), "Expected to have exactly one buffer allocated by now"); assertTrue(fs.FileExists(file), "Expected file to be created by now"); } assertFalse(fs.FileExists(file), "Expected file to be deleted on close"); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldNotAllocateAfterClosed() internal virtual void ShouldNotAllocateAfterClosed() { // given UnsafeDirectByteBufferAllocator factory = new UnsafeDirectByteBufferAllocator(new LocalMemoryTracker()); factory.Close(); // when try { factory.Allocate(8); } catch (System.InvalidOperationException) { // then good } }