//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCorrectlyDecideToAwaitMergeDependingOnProgress() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCorrectlyDecideToAwaitMergeDependingOnProgress() { // given BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(NO_MONITOR); bool closed = false; try { populator.Add(BatchOfUpdates()); // when Race race = new Race(); race.AddContestant(throwing(() => populator.scanCompleted(nullInstance))); race.AddContestant(throwing(() => populator.close(false))); race.Go(); closed = true; // then regardless of who wins (close/merge) after close call returns no files should still be mapped EphemeralFileSystemAbstraction ephemeralFileSystem = ( EphemeralFileSystemAbstraction )_fs; ephemeralFileSystem.AssertNoOpenFiles(); } finally { if (!closed) { populator.Close(true); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSeeExternalUpdateBothBeforeAndAfterScanCompleted() throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSeeExternalUpdateBothBeforeAndAfterScanCompleted() { // given BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(_indexDescriptor); try { // when TextValue hakuna = stringValue("hakuna"); TextValue matata = stringValue("matata"); int hakunaId = 1; int matataId = 2; ExternalUpdate(populator, hakuna, hakunaId); populator.ScanCompleted(nullInstance); ExternalUpdate(populator, matata, matataId); // then AssertMatch(populator, hakuna, hakunaId); AssertMatch(populator, matata, matataId); } finally { populator.Close(true); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReportAccurateProgressThroughoutThePhases() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReportAccurateProgressThroughoutThePhases() { // given TrappingMonitor monitor = new TrappingMonitor(numberOfBlocks => numberOfBlocks == 1); BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(monitor); try { populator.Add(BatchOfUpdates()); // when starting to merge (in a separate thread) Future <object> mergeFuture = T2.execute(command(() => populator.scanCompleted(nullInstance))); // and waiting for merge to get going monitor.Barrier.awaitUninterruptibly(); // this is a bit fuzzy, but what we want is to assert that the scan doesn't represent 100% of the work assertEquals(0.5f, populator.Progress(Org.Neo4j.Storageengine.Api.schema.PopulationProgress_Fields.Done).Progress, 0.1f); monitor.Barrier.release(); monitor.MergeFinishedBarrier.awaitUninterruptibly(); assertEquals(0.7f, populator.Progress(Org.Neo4j.Storageengine.Api.schema.PopulationProgress_Fields.Done).Progress, 0.1f); monitor.MergeFinishedBarrier.release(); mergeFuture.get(); assertEquals(1f, populator.Progress(Org.Neo4j.Storageengine.Api.schema.PopulationProgress_Fields.Done).Progress, 0f); } finally { populator.Close(true); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleBeingAbortedWhileMerging() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleBeingAbortedWhileMerging() { // given TrappingMonitor monitor = new TrappingMonitor(numberOfBlocks => numberOfBlocks == 2); BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(monitor); bool closed = false; try { populator.Add(BatchOfUpdates()); // when starting to merge (in a separate thread) Future <object> mergeFuture = T2.execute(command(() => populator.scanCompleted(nullInstance))); // and waiting for merge to get going monitor.Barrier.await(); monitor.Barrier.release(); monitor.MergeFinishedBarrier.awaitUninterruptibly(); // calling close here should wait for the merge future, so that checking the merge future for "done" immediately afterwards must say true Future <object> closeFuture = T3.execute(command(() => populator.close(false))); T3.get().waitUntilWaiting(); monitor.MergeFinishedBarrier.release(); closeFuture.get(); closed = true; // then let's make sure scanComplete was cancelled, not throwing exception or anything. mergeFuture.get(); } finally { if (!closed) { populator.Close(false); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAwaitMergeToBeFullyAbortedBeforeLeavingCloseMethod() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAwaitMergeToBeFullyAbortedBeforeLeavingCloseMethod() { // given TrappingMonitor monitor = new TrappingMonitor(ignore => false); BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(monitor); bool closed = false; try { populator.Add(BatchOfUpdates()); // when starting to merge (in a separate thread) Future <object> mergeFuture = T2.execute(command(() => populator.scanCompleted(nullInstance))); // and waiting for merge to get going monitor.Barrier.awaitUninterruptibly(); // calling close here should wait for the merge future, so that checking the merge future for "done" immediately afterwards must say true Future <object> closeFuture = T3.execute(command(() => populator.close(false))); T3.get().waitUntilWaiting(); monitor.Barrier.release(); closeFuture.get(); closed = true; // then assertTrue(mergeFuture.Done); } finally { if (!closed) { populator.Close(true); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDeallocateAllAllocatedMemoryOnClose() throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDeallocateAllAllocatedMemoryOnClose() { // given ThreadSafePeakMemoryAllocationTracker memoryTracker = new ThreadSafePeakMemoryAllocationTracker(new LocalMemoryTracker()); ByteBufferFactory bufferFactory = new ByteBufferFactory(() => new UnsafeDirectByteBufferAllocator(memoryTracker), 100); BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(NO_MONITOR, bufferFactory); bool closed = false; try { // when //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.Collection<org.neo4j.kernel.api.index.IndexEntryUpdate<?>> updates = batchOfUpdates(); ICollection <IndexEntryUpdate <object> > updates = BatchOfUpdates(); populator.Add(updates); int nextId = updates.Count; ExternalUpdates(populator, nextId, nextId + 10); nextId = nextId + 10; long memoryBeforeScanCompleted = memoryTracker.UsedDirectMemory(); populator.ScanCompleted(nullInstance); ExternalUpdates(populator, nextId, nextId + 10); // then assertTrue("expected some memory to have been temporarily allocated in scanCompleted", memoryTracker.PeakMemoryUsage() > memoryBeforeScanCompleted); populator.Close(true); assertEquals("expected all allocated memory to have been freed on close", memoryBeforeScanCompleted, memoryTracker.UsedDirectMemory()); closed = true; bufferFactory.Close(); assertEquals(0, memoryTracker.UsedDirectMemory()); } finally { if (!closed) { populator.Close(true); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotThrowOnDuplicationsLaterFixedByExternalUpdates() throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotThrowOnDuplicationsLaterFixedByExternalUpdates() { // given BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(_uniqueIndexDescriptor); bool closed = false; try { // when Value duplicate = Values.of("duplicate"); Value unique = Values.of("unique"); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> firstScanUpdate = org.neo4j.kernel.api.index.IndexEntryUpdate.add(1, INDEX_DESCRIPTOR, duplicate); IndexEntryUpdate <object> firstScanUpdate = IndexEntryUpdate.add(1, _indexDescriptor, duplicate); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> secondScanUpdate = org.neo4j.kernel.api.index.IndexEntryUpdate.add(2, INDEX_DESCRIPTOR, duplicate); IndexEntryUpdate <object> secondScanUpdate = IndexEntryUpdate.add(2, _indexDescriptor, duplicate); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> externalUpdate = org.neo4j.kernel.api.index.IndexEntryUpdate.change(1, INDEX_DESCRIPTOR, duplicate, unique); IndexEntryUpdate <object> externalUpdate = IndexEntryUpdate.change(1, _indexDescriptor, duplicate, unique); populator.Add(singleton(firstScanUpdate)); using (IndexUpdater updater = populator.NewPopulatingUpdater()) { updater.Process(externalUpdate); } populator.Add(singleton(secondScanUpdate)); populator.ScanCompleted(nullInstance); // then AssertHasEntry(populator, unique, 1); AssertHasEntry(populator, duplicate, 2); } finally { if (!closed) { populator.Close(true); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldThrowOnDuplicatedValuesFromScanAndExternalUpdates() public virtual void ShouldThrowOnDuplicatedValuesFromScanAndExternalUpdates() { // given BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(_uniqueIndexDescriptor); bool closed = false; try { // when Value duplicate = Values.of("duplicate"); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> externalUpdate = org.neo4j.kernel.api.index.IndexEntryUpdate.add(1, INDEX_DESCRIPTOR, duplicate); IndexEntryUpdate <object> externalUpdate = IndexEntryUpdate.add(1, _indexDescriptor, duplicate); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> scanUpdate = org.neo4j.kernel.api.index.IndexEntryUpdate.add(2, INDEX_DESCRIPTOR, duplicate); IndexEntryUpdate <object> scanUpdate = IndexEntryUpdate.add(2, _indexDescriptor, duplicate); try { using (IndexUpdater updater = populator.NewPopulatingUpdater()) { updater.Process(externalUpdate); } populator.Add(singleton(scanUpdate)); populator.ScanCompleted(nullInstance); fail("Expected to throw"); } catch (IndexEntryConflictException) { // then } } finally { if (!closed) { populator.Close(true); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDeleteDirectoryOnDrop() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDeleteDirectoryOnDrop() { // given TrappingMonitor monitor = new TrappingMonitor(ignore => false); BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator = InstantiatePopulator(monitor); bool closed = false; try { populator.Add(BatchOfUpdates()); // when starting to merge (in a separate thread) Future <object> mergeFuture = T2.execute(command(() => populator.scanCompleted(nullInstance))); // and waiting for merge to get going monitor.Barrier.awaitUninterruptibly(); // calling drop here should wait for the merge future and then delete index directory assertTrue(_fs.fileExists(_indexDir)); assertTrue(_fs.isDirectory(_indexDir)); assertTrue(_fs.listFiles(_indexDir).Length > 0); Future <object> dropFuture = T3.execute(command(populator.drop)); T3.get().waitUntilWaiting(); monitor.Barrier.release(); dropFuture.get(); closed = true; // then assertTrue(mergeFuture.Done); assertFalse(_fs.fileExists(_indexDir)); } finally { if (!closed) { populator.Close(true); } } }