//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldShareThreadLocalBuffersStressfully() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldShareThreadLocalBuffersStressfully() { // given ByteBufferFactory factory = new ByteBufferFactory(() => HEAP_ALLOCATOR, 1024); Race race = new Race(); int threads = 10; IList <ISet <ByteBuffer> > seenBuffers = new List <ISet <ByteBuffer> >(); for (int i = 0; i < threads; i++) { HashSet <ByteBuffer> seen = new HashSet <ByteBuffer>(); seenBuffers.Add(seen); race.AddContestant(() => { for (int j = 0; j < 1000; j++) { ByteBuffer buffer = factory.AcquireThreadLocalBuffer(); assertNotNull(buffer); seen.Add(buffer); factory.ReleaseThreadLocalBuffer(); } }, 1); } // when race.Go(); // then for (int i = 0; i < threads; i++) { assertEquals(1, seenBuffers[i].Count); } factory.Close(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldCloseGlobalAllocationsOnClose() internal virtual void ShouldCloseGlobalAllocationsOnClose() { // given ByteBufferFactory.Allocator allocator = mock(typeof(ByteBufferFactory.Allocator)); when(allocator.Allocate(anyInt())).thenAnswer(invocationOnMock => ByteBuffer.allocate(invocationOnMock.getArgument(0))); ByteBufferFactory factory = new ByteBufferFactory(() => allocator, 100); // when doing some allocations that are counted as global factory.AcquireThreadLocalBuffer(); factory.ReleaseThreadLocalBuffer(); factory.AcquireThreadLocalBuffer(); factory.ReleaseThreadLocalBuffer(); factory.GlobalAllocator().allocate(123); factory.GlobalAllocator().allocate(456); // and closing it factory.Close(); // then InOrder inOrder = inOrder(allocator); inOrder.verify(allocator, times(1)).allocate(100); inOrder.verify(allocator, times(1)).allocate(123); inOrder.verify(allocator, times(1)).allocate(456); inOrder.verify(allocator, times(1)).close(); inOrder.verifyNoMoreInteractions(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldFailAcquireThreadLocalBufferIfAlreadyAcquired() internal virtual void ShouldFailAcquireThreadLocalBufferIfAlreadyAcquired() { // given ByteBufferFactory factory = new ByteBufferFactory(() => HEAP_ALLOCATOR, 1024); factory.AcquireThreadLocalBuffer(); // when/then assertThrows(typeof(System.InvalidOperationException), factory.acquireThreadLocalBuffer); factory.Close(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDeallocateAllAllocatedMemoryOnDrop() throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDeallocateAllAllocatedMemoryOnDrop() { // given ThreadSafePeakMemoryAllocationTracker memoryTracker = new ThreadSafePeakMemoryAllocationTracker(new LocalMemoryTracker()); ByteBufferFactory bufferFactory = new ByteBufferFactory(() => new UnsafeDirectByteBufferAllocator(memoryTracker), 100); BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(NO_MONITOR, bufferFactory); bool closed = false; try { // when //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.Collection<org.neo4j.kernel.api.index.IndexEntryUpdate<?>> updates = batchOfUpdates(); ICollection <IndexEntryUpdate <object> > updates = BatchOfUpdates(); populator.Add(updates); int nextId = updates.Count; ExternalUpdates(populator, nextId, nextId + 10); nextId = nextId + 10; long memoryBeforeScanCompleted = memoryTracker.UsedDirectMemory(); populator.ScanCompleted(nullInstance); ExternalUpdates(populator, nextId, nextId + 10); // then assertTrue("expected some memory to have been temporarily allocated in scanCompleted", memoryTracker.PeakMemoryUsage() > memoryBeforeScanCompleted); populator.Drop(); closed = true; assertEquals("expected all allocated memory to have been freed on drop", memoryBeforeScanCompleted, memoryTracker.UsedDirectMemory()); bufferFactory.Close(); assertEquals(0, memoryTracker.UsedDirectMemory()); } finally { if (!closed) { populator.Close(true); } } }