use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.
the class BuiltInProceduresTest method setup.
@BeforeEach
void setup() throws Exception {
procs.registerComponent(KernelTransaction.class, ctx -> ctx.internalTransaction().kernelTransaction(), false);
procs.registerComponent(DependencyResolver.class, Context::dependencyResolver, false);
procs.registerComponent(GraphDatabaseAPI.class, Context::graphDatabaseAPI, false);
procs.registerComponent(Transaction.class, Context::internalTransaction, true);
procs.registerComponent(SecurityContext.class, Context::securityContext, true);
procs.registerComponent(ProcedureCallContext.class, Context::procedureCallContext, true);
procs.registerComponent(SystemGraphComponents.class, ctx -> systemGraphComponents, false);
procs.registerComponent(Log.class, ctx -> log, false);
procs.registerType(Node.class, NTNode);
procs.registerType(Relationship.class, NTRelationship);
procs.registerType(Path.class, NTPath);
new SpecialBuiltInProcedures("1.3.37", Edition.COMMUNITY.toString()).accept(procs);
procs.registerProcedure(BuiltInProcedures.class);
procs.registerProcedure(BuiltInDbmsProcedures.class);
when(transaction.kernelTransaction()).thenReturn(tx);
when(tx.tokenRead()).thenReturn(tokens);
when(tx.dataRead()).thenReturn(read);
when(tx.schemaRead()).thenReturn(schemaRead);
when(tx.securityContext()).thenReturn(SecurityContext.AUTH_DISABLED);
when(callContext.isCalledFromCypher()).thenReturn(false);
when(schemaRead.snapshot()).thenReturn(schemaReadCore);
when(tokens.propertyKeyGetAllTokens()).thenAnswer(asTokens(propKeys));
when(tokens.labelsGetAllTokens()).thenAnswer(asTokens(labels));
when(tokens.relationshipTypesGetAllTokens()).thenAnswer(asTokens(relTypes));
when(schemaReadCore.indexesGetAll()).thenAnswer(i -> Iterators.concat(indexes.iterator(), uniqueIndexes.iterator()));
when(schemaReadCore.index(any(SchemaDescriptor.class))).thenAnswer((Answer<IndexDescriptor>) invocationOnMock -> {
SchemaDescriptor schema = invocationOnMock.getArgument(0);
return getIndexReference(schema);
});
when(schemaReadCore.constraintsGetAll()).thenAnswer(i -> constraints.iterator());
when(tokens.propertyKeyName(anyInt())).thenAnswer(invocation -> propKeys.get(invocation.getArgument(0)));
when(tokens.nodeLabelName(anyInt())).thenAnswer(invocation -> labels.get(invocation.getArgument(0)));
when(tokens.relationshipTypeName(anyInt())).thenAnswer(invocation -> relTypes.get(invocation.getArgument(0)));
when(tokens.propertyKeyGetName(anyInt())).thenAnswer(invocation -> propKeys.get(invocation.getArgument(0)));
when(tokens.labelGetName(anyInt())).thenAnswer(invocation -> labels.get(invocation.getArgument(0)));
when(tokens.relationshipTypeGetName(anyInt())).thenAnswer(invocation -> relTypes.get(invocation.getArgument(0)));
when(tokens.entityTokensGetNames(any(), any())).then(invocation -> {
EntityType type = invocation.getArgument(0);
int[] ids = invocation.getArgument(1);
Map<Integer, String> mapping = type == EntityType.NODE ? labels : relTypes;
return Arrays.stream(ids).mapToObj(mapping::get).toArray(String[]::new);
});
when(schemaReadCore.constraintsGetForRelationshipType(anyInt())).thenReturn(emptyIterator());
when(schemaReadCore.indexesGetForLabel(anyInt())).thenReturn(emptyIterator());
when(schemaReadCore.indexesGetForRelationshipType(anyInt())).thenReturn(emptyIterator());
when(schemaReadCore.constraintsGetForLabel(anyInt())).thenReturn(emptyIterator());
when(read.countsForNode(anyInt())).thenReturn(1L);
when(read.countsForRelationship(anyInt(), anyInt(), anyInt())).thenReturn(1L);
when(schemaReadCore.indexGetState(any(IndexDescriptor.class))).thenReturn(InternalIndexState.ONLINE);
}
use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsMustNotIncludeIndexBackedConstraintsWithFailedIndexIndex.
@Test
void schemaStatementsMustNotIncludeIndexBackedConstraintsWithFailedIndexIndex() throws IndexNotFoundKernelException, ProcedureException {
IndexDescriptor index = someOrphanedIndex();
ConstraintDescriptor constraint = indexBackedConstraint(index);
index = indexBoundToConstraint(index, constraint);
InternalIndexState internalIndexState = InternalIndexState.FAILED;
SchemaReadCore schemaReadCore = getSchemaReadCore(constraint, index, internalIndexState);
TokenRead tokenRead = mock(TokenRead.class);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
assertEquals(0, result.size());
}
use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsMustNotIncludeOrphanedIndexes.
@Test
void schemaStatementsMustNotIncludeOrphanedIndexes() throws IndexNotFoundKernelException, ProcedureException {
IndexDescriptor index = someOrphanedIndex();
InternalIndexState indexState = InternalIndexState.ONLINE;
SchemaReadCore schemaReadCore = getSchemaReadCore(index, indexState);
TokenRead tokenRead = mock(TokenRead.class);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
assertEquals(0, result.size());
}
use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsShouldHandleIndexWithBackticks.
@Test
void schemaStatementsShouldHandleIndexWithBackticks() throws IndexNotFoundKernelException, ProcedureException, LabelNotFoundKernelException, PropertyKeyIdNotFoundKernelException {
IndexDescriptor index = forSchema(forLabel(1, 1)).withName(NAME_WITH_BACKTICKS).materialise(1);
InternalIndexState internalIndexState = InternalIndexState.ONLINE;
SchemaReadCore schemaReadCore = getSchemaReadCore(index, internalIndexState);
TokenRead tokenRead = mock(TokenRead.class);
when(tokenRead.nodeLabelName(1)).thenReturn(LABEL_WITH_BACKTICKS);
when(tokenRead.propertyKeyName(1)).thenReturn(PROPERTY_KEY_WITH_BACKTICKS);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
Iterator<BuiltInProcedures.SchemaStatementResult> iter = result.iterator();
assertTrue(iter.hasNext());
BuiltInProcedures.SchemaStatementResult next = iter.next();
assertEquals(NAME_WITH_BACKTICKS, next.name);
assertEquals(format("CALL db.createIndex('%s', ['%s'], ['%s'], 'Undecided-0', {})", NAME_WITH_BACKTICKS, LABEL_WITH_BACKTICKS, PROPERTY_KEY_WITH_BACKTICKS), next.createStatement);
assertEquals(format("DROP INDEX %s", ESCAPED_NAME_WITH_BACKTICKS), next.dropStatement);
assertFalse(iter.hasNext());
}
use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsMustNotIncludeFailedIndexes.
@Test
void schemaStatementsMustNotIncludeFailedIndexes() throws IndexNotFoundKernelException, ProcedureException {
IndexDescriptor index = someIndex();
InternalIndexState indexState = InternalIndexState.FAILED;
SchemaReadCore schemaReadCore = getSchemaReadCore(index, indexState);
TokenRead tokenRead = mock(TokenRead.class);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
assertEquals(0, result.size());
}
Aggregations