//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldRegisterConcurrentAllocationsAndDeallocations() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldRegisterConcurrentAllocationsAndDeallocations() { // given ThreadSafePeakMemoryAllocationTracker tracker = new ThreadSafePeakMemoryAllocationTracker(GlobalMemoryTracker.Instance); Race race = new Race(); race.AddContestants(10, () => { for (int i = 1; i < 100; i++) { tracker.Allocated(i); assertThat(tracker.UsedDirectMemory(), greaterThan(0L)); } for (int i = 1; i < 100; i++) { assertThat(tracker.UsedDirectMemory(), greaterThan(0L)); tracker.Deallocated(i); } }, 1); // when race.Go(); // then assertEquals(0, tracker.UsedDirectMemory()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void tryOnce(final org.neo4j.kernel.internal.GraphDatabaseAPI db, final org.neo4j.graphdb.Node node) throws Throwable //JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: private void TryOnce(GraphDatabaseAPI db, Node node) { Race race = (new Race()).withRandomStartDelays(); race.AddContestants(Runtime.Runtime.availableProcessors(), () => { using (Transaction ignored = Db.beginTx()) { assertEquals(_relCount, count(node.Relationships)); } }); race.Go(); }
//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); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReadConsistentPropertyValues() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReadConsistentPropertyValues() { // GIVEN //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final Node[] nodes = new Node[10]; Node[] nodes = new Node[10]; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String[] keys = new String[] {"1", "2", "3"}; string[] keys = new string[] { "1", "2", "3" }; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final String[] values = new String[] { longString('a'), longString('b'), longString('c')}; string[] values = new string[] { LongString('a'), LongString('b'), LongString('c') }; using (Transaction tx = Db.beginTx()) { for (int i = 0; i < nodes.Length; i++) { nodes[i] = Db.createNode(); foreach (string key in keys) { nodes[i].SetProperty(key, values[0]); } } tx.Success(); } int updaters = 10; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicLong updatersDone = new java.util.concurrent.atomic.AtomicLong(updaters); AtomicLong updatersDone = new AtomicLong(updaters); Race race = new Race(); for (int i = 0; i < updaters; i++) { // Changers race.AddContestant(() => { try { ThreadLocalRandom random = ThreadLocalRandom.current(); for (int j = 0; j < 100; j++) { Node node = nodes[random.Next(nodes.Length)]; string key = keys[random.Next(keys.Length)]; using (Transaction tx = Db.beginTx()) { node.RemoveProperty(key); tx.Success(); } using (Transaction tx = Db.beginTx()) { node.SetProperty(key, values[random.Next(values.Length)]); tx.Success(); } } } finally { updatersDone.decrementAndGet(); } }); } for (int i = 0; i < 100; i++) { // Readers race.AddContestant(() => { ThreadLocalRandom random = ThreadLocalRandom.current(); while (updatersDone.get() > 0) { using (Transaction tx = Db.beginTx()) { string value = ( string )nodes[random.Next(nodes.Length)].getProperty(keys[random.Next(keys.Length)], null); assertTrue(value, string.ReferenceEquals(value, null) || ArrayUtil.contains(values, value)); tx.Success(); } } }); } // WHEN race.Go(); }