use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class DynamicIndexStoreViewTest method shouldVisitRelationshipsUsingTokenIndex.
@Test
void shouldVisitRelationshipsUsingTokenIndex() throws Throwable {
// Given
StubTokenIndexReader tokenReader = new StubTokenIndexReader();
StubStorageCursors cursors = new StubStorageCursors().withTokenIndexes();
IndexProxy indexProxy = mock(IndexProxy.class);
IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
IndexDescriptor descriptor = forSchema(forAnyEntityTokens(RELATIONSHIP), DESCRIPTOR).withName("index").materialise(0);
when(indexProxy.getState()).thenReturn(InternalIndexState.ONLINE);
when(indexProxy.getDescriptor()).thenReturn(descriptor);
when(indexProxy.newTokenReader()).thenReturn(tokenReader);
when(indexProxies.getIndexProxy(any())).thenReturn(indexProxy);
int targetType = 1;
int notTargetType = 2;
int[] indexedTypes = { targetType };
String targetPropertyKey = "key";
String notTargetPropertyKey = "not-key";
Value propertyValue = Values.stringValue("value");
MutableLongList relationshipsWithTargetType = LongLists.mutable.empty();
long id = 0;
int wantedPropertyUpdates = 5;
for (int i = 0; i < wantedPropertyUpdates; i++) {
// Relationships that are indexed
cursors.withRelationship(id, 1, targetType, 3).properties(targetPropertyKey, propertyValue);
tokenReader.index(indexedTypes, id);
relationshipsWithTargetType.add(id++);
// Relationship with wrong property
cursors.withRelationship(id++, 1, targetType, 3).properties(notTargetPropertyKey, propertyValue);
// Relationship with wrong type
cursors.withRelationship(id++, 1, notTargetType, 3).properties(targetPropertyKey, propertyValue);
}
// When
DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
TestTokenScanConsumer tokenConsumer = new TestTokenScanConsumer();
TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
StoreScan storeScan = storeView.visitRelationships(indexedTypes, relationType -> true, propertyScanConsumer, tokenConsumer, false, true, NULL, INSTANCE);
storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
// Then make sure all the fitting relationships where included
assertThat(propertyScanConsumer.batches.size()).isEqualTo(1);
assertThat(propertyScanConsumer.batches.get(0).size()).isEqualTo(wantedPropertyUpdates);
// and that we didn't visit any more relationships than what we would get from scan store
assertThat(tokenConsumer.batches.size()).isEqualTo(1);
assertThat(tokenConsumer.batches.get(0).size()).isEqualTo(relationshipsWithTargetType.size());
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class DefaultSchemaIndexConfigTest method validateIndexConfig.
private void validateIndexConfig(GraphDatabaseService db) throws IndexNotFoundKernelException {
try (Transaction tx = db.beginTx()) {
GraphDatabaseAPI api = (GraphDatabaseAPI) db;
IndexingService indexingService = getIndexingService(api);
IndexProxy indexProxy = indexingService.getIndexProxy(index);
Map<String, Value> indexConfig = indexProxy.indexConfig();
// Expected default values for schema index
assertEquals(Values.doubleArray(new double[] { -1000000.0, -1000000.0 }), indexConfig.get("spatial.cartesian.min"));
assertEquals(Values.doubleArray(new double[] { 1000000.0, 1000000.0 }), indexConfig.get("spatial.cartesian.max"));
assertEquals(Values.doubleArray(new double[] { -1000000.0, -1000000.0, -1000000.0 }), indexConfig.get("spatial.cartesian-3d.min"));
assertEquals(Values.doubleArray(new double[] { 1000000.0, 1000000.0, 1000000.0 }), indexConfig.get("spatial.cartesian-3d.max"));
assertEquals(Values.doubleArray(new double[] { -180.0, -90.0 }), indexConfig.get("spatial.wgs-84.min"));
assertEquals(Values.doubleArray(new double[] { 180.0, 90.0 }), indexConfig.get("spatial.wgs-84.max"));
assertEquals(Values.doubleArray(new double[] { -180.0, -90.0, -1000000.0 }), indexConfig.get("spatial.wgs-84-3d.min"));
assertEquals(Values.doubleArray(new double[] { 180.0, 90.0, 1000000.0 }), indexConfig.get("spatial.wgs-84-3d.max"));
tx.commit();
}
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class FulltextIndexConsistencyCheckIT method mustDiscoverRelationshipInStoreMissingFromIndex.
@Test
void mustDiscoverRelationshipInStoreMissingFromIndex() throws Exception {
GraphDatabaseService db = createDatabase();
try (Transaction tx = db.beginTx()) {
tx.execute(format(RELATIONSHIP_CREATE, "rels", asStrList("REL"), asStrList("prop"))).close();
tx.commit();
}
IndexDescriptor indexDescriptor;
long relId;
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
indexDescriptor = getFulltextIndexDescriptor(tx.schema().getIndexes());
Node node = tx.createNode();
Relationship rel = node.createRelationshipTo(node, RelationshipType.withName("REL"));
rel.setProperty("prop", "value");
relId = rel.getId();
tx.commit();
}
IndexingService indexes = getIndexingService(db);
IndexProxy indexProxy = indexes.getIndexProxy(indexDescriptor);
try (IndexUpdater updater = indexProxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
updater.process(IndexEntryUpdate.remove(relId, indexDescriptor, Values.stringValue("value")));
}
managementService.shutdown();
ConsistencyCheckService.Result result = checkConsistency();
assertFalse(result.isSuccessful());
}
Aggregations