Exemple #1
0
//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);
            }
        }
Exemple #2
0
//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);
                }
            }
        }
Exemple #3
0
//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);
            }
        }
Exemple #4
0
//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);
                }
            }
        }
Exemple #5
0
//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);
                }
            }
        }
Exemple #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: ThreadLocalBlockStorage(int id) throws java.io.IOException
            internal ThreadLocalBlockStorage(BlockBasedIndexPopulator <KEY, VALUE> outerInstance, int id) : base(outerInstance.blockStorageMonitor)
            {
                this._outerInstance = outerInstance;
                File blockFile = new File(storeFile.ParentFile, storeFile.Name + ".scan-" + id);

                this.BlockStorage = new BlockStorage <KEY, VALUE>(layout, outerInstance.bufferFactory, fileSystem, blockFile, this);
            }
Exemple #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void externalUpdate(BlockBasedIndexPopulator<GenericKey,NativeIndexValue> populator, org.neo4j.values.storable.TextValue matata, int matataId) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        private void ExternalUpdate(BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator, TextValue matata, int matataId)
        {
            using (IndexUpdater indexUpdater = populator.NewPopulatingUpdater())
            {
                // After scanCompleted
                indexUpdater.Process(add(matataId, _indexDescriptor, matata));
            }
        }
Exemple #8
0
 private void AssertHasEntry(BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator, Value duplicate, int expectedId)
 {
     using (NativeIndexReader <GenericKey, NativeIndexValue> reader = populator.newReader())
     {
         PrimitiveLongResourceIterator query = reader.Query(IndexQuery.exact(_indexDescriptor.properties()[0], duplicate));
         assertTrue(query.hasNext());
         long id = query.next();
         assertEquals(expectedId, id);
     }
 }
Exemple #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void externalUpdates(BlockBasedIndexPopulator<GenericKey,NativeIndexValue> populator, int firstId, int lastId) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        private void ExternalUpdates(BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator, int firstId, int lastId)
        {
            using (IndexUpdater updater = populator.NewPopulatingUpdater())
            {
                for (int i = firstId; i < lastId; i++)
                {
                    updater.Process(Add(i));
                }
            }
        }
Exemple #10
0
 private void AssertMatch(BlockBasedIndexPopulator <GenericKey, NativeIndexValue> populator, Value value, long id)
 {
     using (NativeIndexReader <GenericKey, NativeIndexValue> reader = populator.newReader())
     {
         SimpleNodeValueClient cursor = new SimpleNodeValueClient();
         reader.Query(cursor, IndexOrder.NONE, true, IndexQuery.exact(_indexDescriptor.properties()[0], value));
         assertTrue(cursor.Next());
         assertEquals(id, cursor.Reference);
         assertEquals(value, cursor.Values[0]);
         assertFalse(cursor.Next());
     }
 }
Exemple #11
0
//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);
                }
            }
        }
Exemple #12
0
//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);
                }
            }
        }
Exemple #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDeallocateAllAllocatedMemoryOnDrop() throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDeallocateAllAllocatedMemoryOnDrop()
        {
            // 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.Drop();
                closed = true;
                assertEquals("expected all allocated memory to have been freed on drop", memoryBeforeScanCompleted, memoryTracker.UsedDirectMemory());

                bufferFactory.Close();
                assertEquals(0, memoryTracker.UsedDirectMemory());
            }
            finally
            {
                if (!closed)
                {
                    populator.Close(true);
                }
            }
        }
Exemple #14
0
//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);
                }
            }
        }
Exemple #15
0
 public IndexUpdaterAnonymousInnerClass(BlockBasedIndexPopulator <KEY, VALUE> outerInstance)
 {
     this.outerInstance = outerInstance;
 }