//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPopulateAndUpdate() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldPopulateAndUpdate() { // GIVEN WithPopulator(IndexProvider.getPopulator(Descriptor, IndexSamplingConfig, heapBufferFactory(1024)), p => p.add(Updates(ValueSet1))); using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, IndexSamplingConfig)) { // WHEN using (IndexUpdater updater = accessor.NewUpdater(IndexUpdateMode.ONLINE)) { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.List<IndexEntryUpdate<?>> updates = updates(valueSet2); IList <IndexEntryUpdate <object> > updates = updates(ValueSet2); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (IndexEntryUpdate<?> update : updates) foreach (IndexEntryUpdate <object> update in updates) { updater.Process(update); } } // THEN using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader())) { int propertyKeyId = Descriptor.schema().PropertyId; foreach (NodeAndValue entry in Iterables.concat(ValueSet1, ValueSet2)) { NodeValueIterator nodes = new NodeValueIterator(); reader.Query(nodes, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId, entry.Value)); assertEquals(entry.NodeId, nodes.Next()); assertFalse(nodes.HasNext()); } } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void updateAndCommit(org.neo4j.kernel.api.index.IndexAccessor accessor, Iterable<org.neo4j.kernel.api.index.IndexEntryUpdate<?>> updates) throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException private void UpdateAndCommit <T1>(IndexAccessor accessor, IEnumerable <T1> updates) { using (IndexUpdater updater = accessor.NewUpdater(IndexUpdateMode.ONLINE)) { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (org.neo4j.kernel.api.index.IndexEntryUpdate<?> update : updates) foreach (IndexEntryUpdate <object> update in updates) { updater.Process(update); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void addUpdates(SpatialIndexProvider provider, org.neo4j.storageengine.api.schema.StoreIndexDescriptor schemaIndexDescriptor, ValueCreatorUtil<SpatialIndexKey,NativeIndexValue> layoutUtil) throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException private void AddUpdates(SpatialIndexProvider provider, StoreIndexDescriptor schemaIndexDescriptor, ValueCreatorUtil <SpatialIndexKey, NativeIndexValue> layoutUtil) { IndexAccessor accessor = provider.GetOnlineAccessor(schemaIndexDescriptor, SamplingConfig()); using (IndexUpdater updater = accessor.NewUpdater(ONLINE)) { // when foreach (IndexEntryUpdate <IndexDescriptor> update in layoutUtil.SomeUpdates(_randomRule)) { updater.Process(update); } } accessor.Force(Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited); accessor.Dispose(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToRecoverAndUpdateOnlineIndex() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToRecoverAndUpdateOnlineIndex() { // Given StartDb(); IndexPopulator populator = mock(typeof(IndexPopulator)); when(_mockedIndexProvider.getPopulator(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)), any())).thenReturn(populator); when(populator.SampleResult()).thenReturn(new IndexSample()); IndexAccessor mockedAccessor = mock(typeof(IndexAccessor)); when(mockedAccessor.NewUpdater(any(typeof(IndexUpdateMode)))).thenReturn(SwallowingIndexUpdater.INSTANCE); when(_mockedIndexProvider.getOnlineAccessor(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)))).thenReturn(mockedAccessor); CreateIndexAndAwaitPopulation(_myLabel); // rotate logs RotateLogsAndCheckPoint(); // make updates //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.Set<org.neo4j.kernel.api.index.IndexEntryUpdate<?>> expectedUpdates = createSomeBananas(myLabel); ISet <IndexEntryUpdate <object> > expectedUpdates = CreateSomeBananas(_myLabel); // And Given KillDb(); when(_mockedIndexProvider.getInitialState(any(typeof(StoreIndexDescriptor)))).thenReturn(InternalIndexState.ONLINE); GatheringIndexWriter writer = new GatheringIndexWriter(); when(_mockedIndexProvider.getOnlineAccessor(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)))).thenReturn(writer); // When StartDb(); // Then assertThat(getIndexes(_db, _myLabel), inTx(_db, hasSize(1))); assertThat(getIndexes(_db, _myLabel), inTx(_db, haveState(_db, Org.Neo4j.Graphdb.schema.Schema_IndexState.Online))); verify(_mockedIndexProvider, times(1)).getPopulator(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig)), any()); int onlineAccessorInvocationCount = 2; // once when we create the index, and once when we restart the db verify(_mockedIndexProvider, times(onlineAccessorInvocationCount)).getOnlineAccessor(any(typeof(StoreIndexDescriptor)), any(typeof(IndexSamplingConfig))); assertEquals(expectedUpdates, writer.BatchedUpdates); }
/// <summary> /// This test target a bug around minimal splitter in gbpTree and unique index populator. It goes like this: /// Given a set of updates (value,entityId): /// - ("A01",1), ("A90",3), ("A9",2) /// If ("A01",1) and ("A90",3) would cause a split to occur they would produce a minimal splitter ("A9",3). /// Note that the value in this minimal splitter is equal to our last update ("A9",2). /// When making insertions with the unique populator we don't compare entityId which would means ("A9",2) /// ends up to the right of ("A9",3), even though it belongs to the left because of entityId being smaller. /// At this point the tree is in an inconsistent (key on wrong side of splitter). /// /// To work around this problem the entityId is only kept in minimal splitter if strictly necessary to divide /// left from right. This means the minimal splitter between ("A01",1) and ("A90",3) is ("A9",-1) and ("A9",2) /// will correctly be placed on the right side of this splitter. /// /// To trigger this scenario this test first insert a bunch of values that are all unique and that will cause a /// split to happen. This is the firstBatch. /// The second batch are constructed so that at least one of them will have a value equal to the splitter key /// constructed during the firstBatch. /// It's important that the secondBatch has ids that are lower than the first batch to align with example described above. /// </summary> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPopulateAndRemoveEntriesWithSimilarMinimalSplitter() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldPopulateAndRemoveEntriesWithSimilarMinimalSplitter() { string prefix = "Work out your own salvation. Do not depend on others. "; int nbrOfNodes = 200; long nodeId = 0; // Second batch has lower ids IList <NodeAndValue> secondBatch = new List <NodeAndValue>(); for (int i = 0; i < nbrOfNodes; i++) { secondBatch.Add(new NodeAndValue(nodeId++, stringValue(prefix + i))); } // First batch has higher ids and minimal splitter among values in first batch will be found among second batch IList <NodeAndValue> firstBatch = new List <NodeAndValue>(); for (int i = 0; i < nbrOfNodes; i++) { firstBatch.Add(new NodeAndValue(nodeId++, stringValue(prefix + i + " " + i))); } WithPopulator(IndexProvider.getPopulator(Descriptor, IndexSamplingConfig, heapBufferFactory(1024)), p => { p.add(Updates(firstBatch)); p.add(Updates(secondBatch)); // Index should be consistent }); IList <NodeAndValue> toRemove = new List <NodeAndValue>(); ((IList <NodeAndValue>)toRemove).AddRange(firstBatch); ((IList <NodeAndValue>)toRemove).AddRange(secondBatch); Collections.shuffle(toRemove); // And we should be able to remove the entries in any order using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, IndexSamplingConfig)) { // WHEN using (IndexUpdater updater = accessor.NewUpdater(IndexUpdateMode.ONLINE)) { foreach (NodeAndValue nodeAndValue in toRemove) { updater.Process(IndexEntryUpdate.Remove(nodeAndValue.NodeId, Descriptor, nodeAndValue.Value)); } } // THEN using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader())) { int propertyKeyId = Descriptor.schema().PropertyId; foreach (NodeAndValue nodeAndValue in toRemove) { NodeValueIterator nodes = new NodeValueIterator(); reader.Query(nodes, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId, nodeAndValue.Value)); bool anyHits = false; StringJoiner nodesStillLeft = new StringJoiner(", ", "[", "]"); while (nodes.HasNext()) { anyHits = true; nodesStillLeft.add(Convert.ToString(nodes.Next())); } assertFalse("Expected this query to have zero hits but found " + nodesStillLeft.ToString(), anyHits); } } } }
/* getOnlineAccessor */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotCheckConflictsWhenApplyingUpdatesInOnlineAccessor() throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotCheckConflictsWhenApplyingUpdatesInOnlineAccessor() { // given _provider = NewProvider(); // when StoreIndexDescriptor descriptor = DescriptorUnique(); using (IndexAccessor accessor = _provider.getOnlineAccessor(descriptor, SamplingConfig()), IndexUpdater indexUpdater = accessor.NewUpdater(IndexUpdateMode.ONLINE)) { Value value = SomeValue(); indexUpdater.Process(IndexEntryUpdate.add(1, descriptor.Schema(), value)); // then // ... expect no failure on duplicate value indexUpdater.Process(IndexEntryUpdate.add(2, descriptor.Schema(), value)); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void makeSureIndexHasSomeData(org.neo4j.kernel.api.index.IndexProvider provider) throws java.io.IOException, org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException private void MakeSureIndexHasSomeData(IndexProvider provider) { using (IndexAccessor accessor = provider.GetOnlineAccessor(_storeIndexDescriptor, _samplingConfig), IndexUpdater updater = accessor.NewUpdater(IndexUpdateMode.ONLINE)) { updater.Process(IndexEntryUpdate.add(1, _storeIndexDescriptor, Values.of("some string"))); } }