//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldRegisterPeakMemoryUsage() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldRegisterPeakMemoryUsage()
        {
            // given
            ThreadSafePeakMemoryAllocationTracker tracker = new ThreadSafePeakMemoryAllocationTracker(GlobalMemoryTracker.Instance);
            int threads = 200;

            long[]            allocations = new long[threads];
            ThreadLocalRandom random      = ThreadLocalRandom.current();
            long sum = 0;

            for (int i = 0; i < allocations.Length; i++)
            {
                allocations[i] = random.Next(1, 10_000);
                sum           += allocations[i];
            }

            // when
            Race race = new Race();

            for (int i = 0; i < threads; i++)
            {
                int id = i;
                race.AddContestant(() => tracker.allocated(allocations[id]));
            }
            race.Go();
            long peakAfterAllocation = tracker.PeakMemoryUsage();

            LongStream.of(allocations).forEach(tracker.deallocated);
            long peakAfterDeallocation = tracker.PeakMemoryUsage();

            LongStream.of(allocations).forEach(tracker.allocated);
            tracker.Allocated(10);                 // <-- 10 more than previous peak
            long peakAfterHigherReallocation = tracker.PeakMemoryUsage();

            LongStream.of(allocations).forEach(tracker.deallocated);
            tracker.Deallocated(10);
            long peakAfterFinalDeallocation = tracker.PeakMemoryUsage();

            // then
            assertEquals(sum, peakAfterAllocation);
            assertEquals(sum, peakAfterDeallocation);
            assertEquals(sum + 10, peakAfterHigherReallocation);
            assertEquals(sum + 10, peakAfterFinalDeallocation);
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") public static java.util.stream.LongStream toLongStream(Object list)
        public static LongStream ToLongStream(object list)
        {
            if (list == null)
            {
                return(LongStream.empty());
            }
            else if (list is SequenceValue)
            {
                throw new System.ArgumentException("Need to implement support for SequenceValue in CompiledConversionUtils.toLongStream");
            }
            else if (list is System.Collections.IList)
            {
                return(((System.Collections.IList)list).Select(n => (( Number )n).longValue()));
            }
            else if (list.GetType().IsAssignableFrom(typeof(object[])))
            {
                return(java.util.( object[] )list.Select(n => (( Number )n).longValue()));
            }
            else if (list is sbyte[])
            {
                sbyte[] array = ( sbyte[] )list;
                return(IntStream.range(0, array.Length).mapToLong(i => array[i]));
            }
            else if (list is short[])
            {
                short[] array = ( short[] )list;
                return(IntStream.range(0, array.Length).mapToLong(i => array[i]));
            }
            else if (list is int[])
            {
                return(IntStream.of(( int[] )list).mapToLong(i => i));
            }
            else if (list is long[])
            {
                return(LongStream.of(( long[] )list));
            }
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            throw new System.ArgumentException(format("Can not be converted to stream: %s", list.GetType().FullName));
        }
예제 #3
0
 public static PrimitiveNodeStream Of(long[] array)
 {
     return(new PrimitiveNodeStream(LongStream.of(array)));
 }
 public static PrimitiveRelationshipStream Of(long[] array)
 {
     return(new PrimitiveRelationshipStream(LongStream.of(array)));
 }
예제 #5
0
        private StorageRelationshipTraversalCursor StoreCursor(params long[] ids)
        {
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            return(StoreCursor(LongStream.of(ids).mapToObj(id => Rel(id, -1L, -1L, -1)).toArray(Rel[] ::new)));
        }
예제 #6
0
        private Read TxState(params long[] ids)
        {
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
            return(TxState(LongStream.of(ids).mapToObj(id => Rel(id, _node, _node, _type)).toArray(Rel[] ::new)));
        }