use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class FullCheckIntegrationTest method createIndexRule.
private void createIndexRule(final int labelId, final int... propertyKeyIds) throws Exception {
AtomicReference<String> indexName = new AtomicReference<>();
fixture.apply(new GraphStoreFixture.Transaction() {
@Override
protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) throws KernelException {
int id = (int) next.schema();
String name = "index_" + id;
IndexDescriptor index = forSchema(forLabel(labelId, propertyKeyIds), DESCRIPTOR).withName(name).materialise(id);
indexName.set(name);
index = tx.completeConfiguration(index);
SchemaRecord before = new SchemaRecord(id);
SchemaRecord after = cloneRecord(before);
serializeRule(index, after, tx, next);
tx.createSchema(before, after, index);
}
});
fixture.apply(tx -> {
try {
tx.schema().awaitIndexOnline(indexName.get(), 1, TimeUnit.MINUTES);
} catch (RuntimeException e) {
if (e.getCause() instanceof KernelException) {
// this is OK since many createIndex calls will create invalid indexes
} else {
throw e;
}
}
});
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class RecordStorageEngineTest method databasePanicIsRaisedWhenTxApplicationFails.
@Test
void databasePanicIsRaisedWhenTxApplicationFails() throws Throwable {
RecordStorageEngine engine = buildRecordStorageEngine();
Exception applicationError = executeFailingTransaction(engine);
ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
verify(databaseHealth).panic(captor.capture());
Throwable exception = captor.getValue();
if (exception instanceof KernelException) {
assertThat(((KernelException) exception).status()).isEqualTo(Status.General.UnknownError);
exception = exception.getCause();
}
assertThat(exception).isEqualTo(applicationError);
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class EntityTest method mockedTransactionWithDepletedTokens.
InternalTransaction mockedTransactionWithDepletedTokens() throws KernelException {
var internalTransaction = mock(InternalTransaction.class);
var ktx = mock(KernelTransaction.class);
var tokenWrite = mock(TokenWrite.class);
when(ktx.tokenWrite()).thenReturn(tokenWrite);
when(tokenWrite.labelGetOrCreateForName(any())).thenThrow(new TokenCapacityExceededKernelException(new Exception("Just some cause"), TokenHolder.TYPE_LABEL));
when(tokenWrite.propertyKeyGetOrCreateForName(any())).thenThrow(new TokenCapacityExceededKernelException(new Exception("Just some cause"), TokenHolder.TYPE_PROPERTY_KEY));
when(tokenWrite.relationshipTypeGetOrCreateForName(any())).thenThrow(new TokenCapacityExceededKernelException(new Exception("Just some cause"), TokenHolder.TYPE_RELATIONSHIP_TYPE));
when(internalTransaction.kernelTransaction()).thenReturn(ktx);
return internalTransaction;
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class AllStoreHolder method countsForRelationshipWithoutTxState.
@Override
public long countsForRelationshipWithoutTxState(int startLabelId, int typeId, int endLabelId) {
AccessMode mode = ktx.securityContext().mode();
CursorContext cursorContext = ktx.cursorContext();
if (mode.allowsTraverseRelType(typeId) && mode.allowsTraverseNode(startLabelId) && mode.allowsTraverseNode(endLabelId)) {
return storageReader.countsForRelationship(startLabelId, typeId, endLabelId, cursorContext);
}
if (mode.disallowsTraverseRelType(typeId) || mode.disallowsTraverseLabel(startLabelId) || mode.disallowsTraverseLabel(endLabelId)) {
// so the count will be 0.
return 0;
}
// token index scan can only scan for single relationship type
if (typeId != TokenRead.ANY_RELATIONSHIP_TYPE) {
try {
var index = findUsableTokenIndex(EntityType.RELATIONSHIP);
if (index != IndexDescriptor.NO_INDEX) {
long count = 0;
try (DefaultRelationshipTypeIndexCursor relationshipsWithType = cursors.allocateRelationshipTypeIndexCursor(cursorContext);
DefaultRelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(cursorContext);
DefaultNodeCursor sourceNode = cursors.allocateNodeCursor(cursorContext);
DefaultNodeCursor targetNode = cursors.allocateNodeCursor(cursorContext)) {
var session = tokenReadSession(index);
this.relationshipTypeScan(session, relationshipsWithType, unconstrained(), new TokenPredicate(typeId));
while (relationshipsWithType.next()) {
relationshipsWithType.relationship(relationship);
count += countRelationshipsWithEndLabels(relationship, sourceNode, targetNode, startLabelId, endLabelId);
}
}
return count - countsForRelationshipInTxState(startLabelId, typeId, endLabelId);
}
} catch (KernelException ignored) {
// ignore, fallback to allRelationshipsScan
}
}
long count;
try (DefaultRelationshipScanCursor rels = cursors.allocateRelationshipScanCursor(cursorContext);
DefaultNodeCursor sourceNode = cursors.allocateFullAccessNodeCursor(cursorContext);
DefaultNodeCursor targetNode = cursors.allocateFullAccessNodeCursor(cursorContext)) {
this.allRelationshipsScan(rels);
Predicate<RelationshipScanCursor> predicate = typeId == TokenRead.ANY_RELATIONSHIP_TYPE ? alwaysTrue() : CursorPredicates.hasType(typeId);
var filteredCursor = new FilteringRelationshipScanCursorWrapper(rels, predicate);
count = countRelationshipsWithEndLabels(filteredCursor, sourceNode, targetNode, startLabelId, endLabelId);
}
return count - countsForRelationshipInTxState(startLabelId, typeId, endLabelId);
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class TokenTestBase method assertIllegalToken.
private void assertIllegalToken(ThrowingConsumer<Token, KernelException> f) {
try (KernelTransaction tx = beginTransaction()) {
f.accept(tx.token());
fail("Expected IllegalTokenNameException");
} catch (IllegalTokenNameException e) {
// wanted
} catch (KernelException e) {
fail("Unwanted exception: " + e.getMessage());
}
}
Aggregations