Exemple #1
0
//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();
        }