use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class IndexPopulationJobTest method shouldPopulateRelationshipIndexWithASmallDataset.
@Test
void shouldPopulateRelationshipIndexWithASmallDataset() {
// GIVEN
String value = "Philip J.Fry";
long node1 = createNode(map(name, value), FIRST);
long node2 = createNode(map(name, value), SECOND);
long node3 = createNode(map(age, 31), FIRST);
long node4 = createNode(map(age, 35, name, value), FIRST);
long rel1 = createRelationship(map(name, value), likes, node1, node3);
createRelationship(map(name, value), knows, node3, node1);
createRelationship(map(age, 31), likes, node2, node1);
long rel4 = createRelationship(map(age, 35, name, value), likes, node4, node4);
int rel = tokenHolders.relationshipTypeTokens().getIdByName(likes.name());
int prop = tokenHolders.propertyKeyTokens().getIdByName(name);
IndexPrototype descriptor = IndexPrototype.forSchema(SchemaDescriptor.forRelType(rel, prop));
IndexPopulator actualPopulator = indexPopulator(descriptor);
TrackingIndexPopulator populator = new TrackingIndexPopulator(actualPopulator);
IndexPopulationJob job = newIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.RELATIONSHIP, descriptor);
// WHEN
job.run();
// THEN
IndexEntryUpdate<?> update1 = add(rel1, descriptor, Values.of(value));
IndexEntryUpdate<?> update2 = add(rel4, descriptor, Values.of(value));
assertTrue(populator.created);
assertEquals(Arrays.asList(update1, update2), populator.includedSamples);
assertEquals(1, populator.adds.size());
assertTrue(populator.resultSampled);
assertTrue(populator.closeCall);
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class IndexPopulationJobTest method indexPrototype.
private IndexPrototype indexPrototype(Label label, String propertyKey, boolean constraint) throws KernelException {
try (KernelTransaction tx = kernel.beginTransaction(IMPLICIT, LoginContext.AUTH_DISABLED)) {
int labelId = tx.tokenWrite().labelGetOrCreateForName(label.name());
int propertyKeyId = tx.tokenWrite().propertyKeyGetOrCreateForName(propertyKey);
SchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, propertyKeyId);
IndexPrototype descriptor = constraint ? IndexPrototype.uniqueForSchema(schema, PROVIDER_DESCRIPTOR) : IndexPrototype.forSchema(schema, PROVIDER_DESCRIPTOR);
tx.commit();
return descriptor;
}
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class StubStorageCursors method indexDescriptor.
private IndexDescriptor indexDescriptor(EntityType entityType, long id) {
IndexPrototype indexPrototype = IndexPrototype.forSchema(forAnyEntityTokens(entityType)).withIndexType(LOOKUP).withIndexProvider(new IndexProviderDescriptor("token-lookup", "1.0"));
indexPrototype = indexPrototype.withName(SchemaRule.generateName(indexPrototype, new String[] {}, new String[] {}));
return indexPrototype.materialise(id);
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method createTransaction.
private KernelTransactionImplementation createTransaction() {
KernelTransactionImplementation transaction = mock(KernelTransactionImplementation.class);
try {
StorageEngine storageEngine = mock(StorageEngine.class);
StorageReader storageReader = mock(StorageReader.class);
when(storageEngine.newReader()).thenReturn(storageReader);
Locks.Client locks = mock(Locks.Client.class);
when(transaction.lockClient()).thenReturn(locks);
when(transaction.tokenRead()).thenReturn(tokenRead);
when(transaction.schemaRead()).thenReturn(schemaRead);
when(transaction.schemaWrite()).thenReturn(schemaWrite);
TransactionState transactionState = mock(TransactionState.class);
when(transaction.txState()).thenReturn(transactionState);
when(transaction.indexUniqueCreate(any(IndexPrototype.class))).thenAnswer(i -> i.<IndexPrototype>getArgument(0).materialise(INDEX_ID));
when(transaction.newStorageReader()).thenReturn(mock(StorageReader.class));
} catch (InvalidTransactionTypeKernelException e) {
fail("Expected write transaction");
}
return transaction;
}
use of org.neo4j.internal.schema.IndexPrototype in project neo4j by neo4j.
the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnFulltextSchemas.
@Test
void indexedBackedConstraintCreateMustThrowOnFulltextSchemas() throws Exception {
// given
when(tokenHolders.labelTokens().getTokenById(anyInt())).thenReturn(new NamedToken("Label", 123));
when(tokenHolders.propertyKeyTokens().getTokenById(anyInt())).thenReturn(new NamedToken("prop", 456));
SchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, this.schema.getEntityTokenIds(), this.schema.getPropertyIds());
IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema).withName("constraint name").withIndexProvider(GenericNativeIndexProvider.DESCRIPTOR);
IndexDescriptor constraintIndex = prototype.materialise(42);
when(constraintIndexCreator.createUniquenessConstraintIndex(any(), any(), eq(prototype))).thenReturn(constraintIndex);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexProxy.getDescriptor()).thenReturn(constraintIndex);
when(indexingService.getIndexProxy(constraintIndex)).thenReturn(indexProxy);
when(storageReader.constraintsGetForSchema(schema)).thenReturn(Collections.emptyIterator());
when(storageReader.indexGetForSchema(schema)).thenReturn(Collections.emptyIterator());
// when
var e = assertThrows(KernelException.class, () -> operations.uniquePropertyConstraintCreate(prototype));
assertThat(e.getUserMessage(tokenHolders)).contains("full-text schema");
}
Aggregations