//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 TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldProvidePopulatorThatAcceptsDuplicateEntries() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldProvidePopulatorThatAcceptsDuplicateEntries() { // when long offset = ValueSet1.Count; WithPopulator(IndexProvider.getPopulator(Descriptor, IndexSamplingConfig, heapBufferFactory(1024)), p => { p.add(Updates(ValueSet1, 0)); p.add(Updates(ValueSet1, offset)); }); // then using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, IndexSamplingConfig)) { using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader())) { int propertyKeyId = Descriptor.schema().PropertyId; foreach (NodeAndValue entry in ValueSet1) { NodeValueIterator nodes = new NodeValueIterator(); reader.Query(nodes, IndexOrder.NONE, false, IndexQuery.exact(propertyKeyId, entry.Value)); assertEquals(entry.Value.ToString(), asSet(entry.NodeId, entry.NodeId + offset), PrimitiveLongCollections.toSet(nodes)); } } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldApplyUpdatesIdempotently() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldApplyUpdatesIdempotently() { // GIVEN IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig(Config.defaults()); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.values.storable.Value propertyValue = org.neo4j.values.storable.Values.of("value1"); Value propertyValue = Values.of("value1"); WithPopulator(IndexProvider.getPopulator(Descriptor, indexSamplingConfig, heapBufferFactory(1024)), p => { long nodeId = 1; // update using populator... IndexEntryUpdate <SchemaDescriptor> update = add(nodeId, Descriptor.schema(), propertyValue); p.add(singletonList(update)); // ...is the same as update using updater using (IndexUpdater updater = p.newPopulatingUpdater((node, propertyId) => propertyValue)) { updater.Process(update); } }); // THEN using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, indexSamplingConfig)) { using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader())) { int propertyKeyId = Descriptor.schema().PropertyId; LongIterator nodes = reader.Query(IndexQuery.exact(propertyKeyId, propertyValue)); assertEquals(asSet(1L), PrimitiveLongCollections.toSet(nodes)); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void before() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void Before() { IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig(Config.defaults()); IndexPopulator populator = IndexProvider.getPopulator(Descriptor, indexSamplingConfig, heapBufferFactory(1024)); populator.Create(); populator.Close(true); Accessor = IndexProvider.getOnlineAccessor(Descriptor, indexSamplingConfig); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void assertHasAllValues(java.util.List<NodeAndValue> values) throws java.io.IOException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException private void AssertHasAllValues(IList <NodeAndValue> values) { using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, IndexSamplingConfig)) { using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader())) { int propertyKeyId = Descriptor.schema().PropertyId; foreach (NodeAndValue entry in values) { 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 TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldProvidePopulatorThatAcceptsDuplicateEntries() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldProvidePopulatorThatAcceptsDuplicateEntries() { // when IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig(Config.defaults()); WithPopulator(IndexProvider.getPopulator(Descriptor, indexSamplingConfig, heapBufferFactory(1024)), p => p.add(Arrays.asList(add(1, Descriptor.schema(), "v1", "v2"), add(2, Descriptor.schema(), "v1", "v2")))); // then using (IndexAccessor accessor = IndexProvider.getOnlineAccessor(Descriptor, indexSamplingConfig)) { using (IndexReader reader = new QueryResultComparingIndexReader(accessor.NewReader())) { LongIterator nodes = reader.Query(IndexQuery.exact(1, "v1"), IndexQuery.exact(1, "v2")); assertEquals(asSet(1L, 2L), PrimitiveLongCollections.toSet(nodes)); } } }
/// <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); } } } }