use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class IndexingServiceTest method shouldCreateMultipleIndexesInOneCall.
@Test
void shouldCreateMultipleIndexesInOneCall() throws Exception {
// GIVEN
IndexingService.Monitor monitor = IndexingService.NO_MONITOR;
IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData(addNodeUpdate(0, "value", 1)), monitor);
life.start();
// WHEN
IndexDescriptor index1 = storeIndex(0, 0, 0, PROVIDER_DESCRIPTOR);
IndexDescriptor index2 = storeIndex(1, 0, 1, PROVIDER_DESCRIPTOR);
IndexDescriptor index3 = storeIndex(2, 1, 0, PROVIDER_DESCRIPTOR);
indexing.createIndexes(AUTH_DISABLED, index1, index2, index3);
// THEN
IndexPrototype prototype = forSchema(forLabel(0, 0)).withIndexProvider(PROVIDER_DESCRIPTOR);
verify(indexProvider).getPopulator(eq(prototype.withName("index_0").materialise(0)), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class));
verify(indexProvider).getPopulator(eq(prototype.withSchemaDescriptor(forLabel(0, 1)).withName("index_1").materialise(1)), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class));
verify(indexProvider).getPopulator(eq(prototype.withSchemaDescriptor(forLabel(1, 0)).withName("index_2").materialise(2)), any(IndexSamplingConfig.class), any(), any(), any(TokenNameLookup.class));
waitForIndexesToComeOnline(indexing, index1, index2, index3);
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class IndexingServiceTest method shouldLogTriggerSamplingOnAnIndexes.
@Test
void shouldLogTriggerSamplingOnAnIndexes() throws Exception {
// given
long indexId = 0;
IndexSamplingMode mode = backgroundRebuildAll();
IndexPrototype prototype = forSchema(forLabel(0, 1)).withIndexProvider(PROVIDER_DESCRIPTOR).withName("index");
IndexDescriptor index = prototype.materialise(indexId);
when(accessor.newValueReader()).thenReturn(ValueIndexReader.EMPTY);
IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData(), index);
life.init();
life.start();
// when
indexingService.triggerIndexSampling(index, mode);
// then
String userDescription = index.userDescription(nameLookup);
assertThat(internalLogProvider).forLevel(INFO).containsMessages("Manual trigger for sampling index " + userDescription + " [" + mode + "]");
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldCreateConstraintIndexForSpecifiedProvider.
@Test
void shouldCreateConstraintIndexForSpecifiedProvider() throws Exception {
// given
IndexingService indexingService = mock(IndexingService.class);
IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("Groovy", "1.2");
IndexPrototype prototype = this.prototype.withIndexProvider(providerDescriptor);
IndexDescriptor index = prototype.materialise(this.index.getId());
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
// when
KernelTransactionImplementation transaction = createTransaction();
creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
// then
assertEquals(1, kernel.transactions.size());
KernelTransactionImplementation transactionInstance = kernel.transactions.get(0);
verify(transactionInstance).indexUniqueCreate(prototype);
verify(schemaRead).indexGetForName(constraint.getName());
verifyNoMoreInteractions(schemaRead);
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class SchemaRuleSerialization35 method readIndexRule.
// PRIVATE
// READ INDEX
private static IndexDescriptor readIndexRule(long id, ByteBuffer source) throws MalformedSchemaRuleException {
String providerKey = getDecodedStringFrom(source);
String providerVersion = getDecodedStringFrom(source);
IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor(providerKey, providerVersion);
byte indexRuleType = source.get();
Optional<String> name;
switch(indexRuleType) {
case GENERAL_INDEX:
{
SchemaDescriptor schema = readSchema(source);
name = readRuleName(source);
IndexPrototype prototype = IndexPrototype.forSchema(schema, providerDescriptor);
if (schema.isFulltextSchemaDescriptor()) {
prototype = prototype.withIndexType(IndexType.FULLTEXT);
}
if (name.isPresent()) {
prototype = prototype.withName(name.get());
} else {
prototype = prototype.withName(defaultIndexName(id));
}
return prototype.materialise(id);
}
case UNIQUE_INDEX:
{
long readOwningConstraint = source.getLong();
SchemaDescriptor schema = readSchema(source);
name = readRuleName(source);
IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema, providerDescriptor);
if (name.isPresent()) {
prototype = prototype.withName(name.get());
} else {
prototype = prototype.withName(defaultIndexName(id));
}
IndexDescriptor index = prototype.materialise(id);
if (readOwningConstraint != NO_OWNING_CONSTRAINT_YET) {
index = index.withOwningConstraintId(readOwningConstraint);
}
return index;
}
default:
throw new MalformedSchemaRuleException(format("Got unknown index rule type '%d'.", indexRuleType));
}
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseRelationshipIndexCursors.
@Test
void shouldReuseRelationshipIndexCursors() throws Exception {
// given
int connection;
int name;
String indexName = "myIndex";
IndexDescriptor index;
try (KernelTransaction tx = beginTransaction()) {
connection = tx.tokenWrite().relationshipTypeGetOrCreateForName("Connection");
name = tx.tokenWrite().propertyKeyGetOrCreateForName("name");
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, array(connection), array(name));
IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withName(indexName).withIndexType(IndexType.FULLTEXT);
index = tx.schemaWrite().indexCreate(prototype);
tx.commit();
}
Predicates.awaitEx(() -> tx.schemaRead().indexGetState(index) == ONLINE, 1, MINUTES);
RelationshipValueIndexCursor c1 = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
IndexReadSession indexSession = tx.dataRead().indexReadSession(index);
read.relationshipIndexSeek(indexSession, c1, IndexQueryConstraints.unconstrained(), PropertyIndexQuery.fulltextSearch("hello"));
c1.close();
RelationshipValueIndexCursor c2 = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
assertThat(c1).isSameAs(c2);
c2.close();
}
Aggregations