//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 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 shouldFailReleaseThreadLocalBufferIfNotAcquired() internal virtual void ShouldFailReleaseThreadLocalBufferIfNotAcquired() { // given ByteBufferFactory factory = new ByteBufferFactory(() => HEAP_ALLOCATOR, 1024); factory.AcquireThreadLocalBuffer(); factory.ReleaseThreadLocalBuffer(); // when/then assertThrows(typeof(System.InvalidOperationException), factory.releaseThreadLocalBuffer); factory.Close(); }