use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class FullCheckIntegrationTest method createFixture.
private GraphStoreFixture createFixture() {
return new GraphStoreFixture(getRecordFormatName(), testDirectory) {
@Override
protected void generateInitialData(GraphDatabaseService db) {
// because many tests rely on sort order for those token ids.
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
TokenWrite tokenWrite = ktx.tokenWrite();
label1 = tokenWrite.labelGetOrCreateForName("label1");
label2 = tokenWrite.labelGetOrCreateForName("label2");
label3 = tokenWrite.labelGetOrCreateForName("label3");
tokenWrite.labelGetOrCreateForName("label4");
draconian = tokenWrite.labelGetOrCreateForName("draconian");
key1 = tokenWrite.propertyKeyGetOrCreateForName(PROP1);
mandatory = tokenWrite.propertyKeyGetOrCreateForName("mandatory");
C = tokenWrite.relationshipTypeGetOrCreateForName("C");
T = tokenWrite.relationshipTypeGetOrCreateForName("T");
M = tokenWrite.relationshipTypeGetOrCreateForName("M");
tx.commit();
} catch (KernelException e) {
throw new RuntimeException(e);
}
// Create indexes
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
tx.schema().indexFor(label("label3")).on(PROP1).create();
tx.schema().indexFor(label("label3")).on(PROP1).on(PROP2).create();
tx.schema().constraintFor(label("label4")).assertPropertyIsUnique(PROP1).create();
tx.commit();
}
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
}
// Create initial data
try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
Node node1 = set(tx.createNode(label("label1")));
Node node2 = set(tx.createNode(label("label2")), property(PROP1, VALUE1));
node1.createRelationshipTo(node2, withName("C"));
// Just to create one more rel type
tx.createNode().createRelationshipTo(tx.createNode(), withName("T"));
indexedNodes.add(set(tx.createNode(label("label3")), property(PROP1, VALUE1)).getId());
indexedNodes.add(set(tx.createNode(label("label3")), property(PROP1, VALUE1), property(PROP2, VALUE2)).getId());
set(tx.createNode(label("label4")), property(PROP1, VALUE1));
tx.commit();
}
}
@Override
protected Map<Setting<?>, Object> getConfig() {
return getSettings();
}
};
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportInvalidConstraintBackReferences.
@Test
void shouldReportInvalidConstraintBackReferences() throws Exception {
// given
AtomicReference<IndexDescriptor> descriptor = new AtomicReference<>();
fixture.apply(new GraphStoreFixture.Transaction() {
@Override
protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) throws KernelException {
int ruleId1 = (int) next.schema();
int ruleId2 = (int) next.schema();
int labelId = next.label();
int propertyKeyId = next.propertyKey();
SchemaRecord before1 = new SchemaRecord(ruleId1);
SchemaRecord before2 = new SchemaRecord(ruleId2);
SchemaRecord after1 = cloneRecord(before1).initialize(true, 0);
SchemaRecord after2 = cloneRecord(before2).initialize(true, 0);
IndexDescriptor rule1 = constraintIndexRule(ruleId1, labelId, propertyKeyId, DESCRIPTOR, ruleId2);
rule1 = tx.completeConfiguration(rule1);
ConstraintDescriptor rule2 = uniquenessConstraintRule(ruleId2, labelId, propertyKeyId, ruleId2);
serializeRule(rule1, after1, tx, next);
serializeRule(rule2, after2, tx, next);
tx.nodeLabel(labelId, "label", false);
tx.propertyKey(propertyKeyId, "property", false);
tx.createSchema(before1, after1, rule1);
tx.createSchema(before2, after2, rule2);
descriptor.set(rule1);
}
});
fixture.indexingService().activateIndex(descriptor.get());
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.SCHEMA, 2).andThatsAllFolks();
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class NodeGetUniqueFromIndexSeekIT method shouldBlockUniqueIndexSeekFromCompetingTransaction.
// ( timeout = 10_000 )
@Test
void shouldBlockUniqueIndexSeekFromCompetingTransaction() throws Exception {
// This is the interleaving that we are trying to verify works correctly:
// ----------------------------------------------------------------------
// Thread1 (main) : Thread2
// create unique node :
// lookup(node) :
// open start latch ----->
// | : lookup(node)
// wait for T2 to block : |
// : *block*
// commit ---------------> *unblock*
// wait for T2 end latch : |
// : finish transaction
// : open end latch
// *unblock* <-------------‘
// assert that we complete before timeout
final DoubleLatch latch = new DoubleLatch();
IndexDescriptor index = createUniquenessConstraint(labelId, propertyId1);
Value value = Values.of("value");
Write write = dataWriteInNewTransaction();
long nodeId = write.nodeCreate();
write.nodeAddLabel(nodeId, labelId);
// This adds the node to the unique index and should take an index write lock
write.nodeSetProperty(nodeId, propertyId1, value);
Runnable runnableForThread2 = () -> {
latch.waitForAllToStart();
try (KernelTransaction tx = kernel.beginTransaction(KernelTransaction.Type.IMPLICIT, LoginContext.AUTH_DISABLED)) {
try (NodeValueIndexCursor cursor = tx.cursors().allocateNodeValueIndexCursor(tx.cursorContext(), tx.memoryTracker())) {
tx.dataRead().lockingNodeUniqueIndexSeek(index, cursor, exact(propertyId1, value));
}
tx.commit();
} catch (KernelException e) {
throw new RuntimeException(e);
} finally {
latch.finish();
}
};
Thread thread2 = new Thread(runnableForThread2, "Transaction Thread 2");
thread2.start();
latch.startAndWaitForAllToStart();
while ((thread2.getState() != Thread.State.TIMED_WAITING) && (thread2.getState() != Thread.State.WAITING)) {
Thread.yield();
}
commit();
latch.waitForAllToFinish();
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class IndexIT method createIndexForAnotherLabelWhileHoldingSharedLockOnOtherLabel.
@Test
void createIndexForAnotherLabelWhileHoldingSharedLockOnOtherLabel() throws KernelException, ExecutionException, InterruptedException {
TokenWrite tokenWrite = tokenWriteInNewTransaction();
int label2 = tokenWrite.labelGetOrCreateForName("Label2");
commit();
Write write = dataWriteInNewTransaction();
long nodeId = write.nodeCreate();
write.nodeAddLabel(nodeId, label2);
try (var ignored = captureTransaction()) {
executorService.submit(() -> {
try {
schemaWriteInNewTransaction().indexCreate(schema, null);
commit();
} catch (Exception e) {
throw new RuntimeException(e);
}
}).get();
}
}
use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.
the class ExceptionRepresentationTest method shouldExcludeLegacyFormatIfAsked.
@Test
void shouldExcludeLegacyFormatIfAsked() throws Exception {
// Given
ExceptionRepresentation rep = new ExceptionRepresentation(new KernelException(UnknownError, "Hello") {
}, /*legacy*/
false);
// When
JsonNode out = serialize(rep);
// Then
assertThat(out.get("errors").get(0).get("code").asText()).isEqualTo("Neo.DatabaseError.General.UnknownError");
assertThat(out.get("errors").get(0).get("message").asText()).isEqualTo("Hello");
assertThat(out.has("message")).isEqualTo(false);
}
Aggregations