Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCatchArithmeticExceptionsAndTryNext()
        public virtual void ShouldCatchArithmeticExceptionsAndTryNext()
        {
            // GIVEN
            NumberArrayFactory  throwingMemoryFactory = mock(typeof(NumberArrayFactory));
            ArithmeticException failure = new ArithmeticException("This is an artificial failure");

            doThrow(failure).when(throwingMemoryFactory).newByteArray(anyLong(), any(typeof(sbyte[])), anyLong());
            FailureMonitor     monitor = new FailureMonitor();
            NumberArrayFactory factory = new NumberArrayFactory_Auto(monitor, throwingMemoryFactory, NumberArrayFactory.HEAP);
            int itemSize = 4;

            // WHEN
            ByteArray array = factory.NewByteArray(KILO, new sbyte[itemSize], 0);

            array.SetInt(KILO - 10, 0, 12345);

            // THEN
            verify(throwingMemoryFactory, times(1)).newByteArray(eq(KILO), any(typeof(sbyte[])), eq(0L));
            assertTrue(array is HeapByteArray);
            assertEquals(12345, array.GetInt(KILO - 10, 0));
            assertEquals(KILO * itemSize, monitor.Memory);
            assertEquals(NumberArrayFactory.HEAP, monitor.SuccessfulFactory);
            assertEquals(throwingMemoryFactory, single(monitor.AttemptedAllocationFailures).Factory);
            assertThat(single(monitor.AttemptedAllocationFailures).Failure.Message, containsString(failure.Message));
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPickFirstAvailableCandidateLongArray()
        public virtual void ShouldPickFirstAvailableCandidateLongArray()
        {
            // GIVEN
            NumberArrayFactory factory = new NumberArrayFactory_Auto(NO_MONITOR, NumberArrayFactory.HEAP);

            // WHEN
            LongArray array = factory.NewLongArray(KILO, -1);

            array.Set(KILO - 10, 12345);

            // THEN
            assertTrue(array is HeapLongArray);
            assertEquals(12345, array.Get(KILO - 10));
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPickFirstAvailableCandidateIntArray()
        public virtual void ShouldPickFirstAvailableCandidateIntArray()
        {
            // GIVEN
            FailureMonitor     monitor = new FailureMonitor();
            NumberArrayFactory factory = new NumberArrayFactory_Auto(monitor, NumberArrayFactory.HEAP);

            // WHEN
            IntArray array = factory.NewIntArray(KILO, -1);

            array.Set(KILO - 10, 12345);

            // THEN
            assertTrue(array is HeapIntArray);
            assertEquals(12345, array.Get(KILO - 10));
            assertEquals(NumberArrayFactory.HEAP, monitor.SuccessfulFactory);
            assertFalse(monitor.AttemptedAllocationFailures.GetEnumerator().hasNext());
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPickFirstAvailableCandidateLongArrayWhenSomeDontHaveEnoughMemory()
        public virtual void ShouldPickFirstAvailableCandidateLongArrayWhenSomeDontHaveEnoughMemory()
        {
            // GIVEN
            NumberArrayFactory lowMemoryFactory = mock(typeof(NumberArrayFactory));

            doThrow(typeof(System.OutOfMemoryException)).when(lowMemoryFactory).newLongArray(anyLong(), anyLong(), anyLong());
            NumberArrayFactory factory = new NumberArrayFactory_Auto(NO_MONITOR, lowMemoryFactory, NumberArrayFactory.HEAP);

            // WHEN
            LongArray array = factory.NewLongArray(KILO, -1);

            array.Set(KILO - 10, 12345);

            // THEN
            verify(lowMemoryFactory, times(1)).newLongArray(KILO, -1, 0);
            assertTrue(array is HeapLongArray);
            assertEquals(12345, array.Get(KILO - 10));
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPickFirstAvailableCandidateIntArrayWhenSomeThrowNativeMemoryAllocationRefusedError()
        public virtual void ShouldPickFirstAvailableCandidateIntArrayWhenSomeThrowNativeMemoryAllocationRefusedError()
        {
            // GIVEN
            NumberArrayFactory lowMemoryFactory = mock(typeof(NumberArrayFactory));

            doThrow(typeof(NativeMemoryAllocationRefusedError)).when(lowMemoryFactory).newIntArray(anyLong(), anyInt(), anyLong());
            NumberArrayFactory factory = new NumberArrayFactory_Auto(NO_MONITOR, lowMemoryFactory, NumberArrayFactory.HEAP);

            // WHEN
            IntArray array = factory.NewIntArray(KILO, -1);

            array.Set(KILO - 10, 12345);

            // THEN
            verify(lowMemoryFactory, times(1)).newIntArray(KILO, -1, 0);
            assertTrue(array is HeapIntArray);
            assertEquals(12345, array.Get(KILO - 10));
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowOomOnNotEnoughMemory()
        public virtual void ShouldThrowOomOnNotEnoughMemory()
        {
            // GIVEN
            FailureMonitor     monitor          = new FailureMonitor();
            NumberArrayFactory lowMemoryFactory = mock(typeof(NumberArrayFactory));

            doThrow(typeof(System.OutOfMemoryException)).when(lowMemoryFactory).newLongArray(anyLong(), anyLong(), anyLong());
            NumberArrayFactory factory = new NumberArrayFactory_Auto(monitor, lowMemoryFactory);

            // WHEN
            try
            {
                factory.NewLongArray(KILO, -1);
                fail("Should have thrown");
            }
            catch (System.OutOfMemoryException)
            {
                // THEN OK
                assertFalse(monitor.Called);
            }
        }
Esempio n. 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void offHeapArrayShouldAllowVeryLargeBases()
        public virtual void OffHeapArrayShouldAllowVeryLargeBases()
        {
            NumberArrayFactory factory = new NumberArrayFactory_Auto(NO_MONITOR, NumberArrayFactory.OFF_HEAP);

            VerifyVeryLargeBaseSupport(factory);
        }