use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class UniquenessConstraintValidationIT method addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup.
@Test
public void addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup() throws Exception {
// given
createConstraint("Person", "id");
long ourNode;
{
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
ourNode = createLabeledNode(statement, "Person", "id", 1);
commit();
}
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
ReadOperations readOps = statement.readOperations();
int person = readOps.labelGetForName("Person");
int propId = readOps.propertyKeyGetForName("id");
NewIndexDescriptor idx = readOps.uniqueIndexGetForLabelAndPropertyKey(new NodePropertyDescriptor(person, propId));
// when
createLabeledNode(statement, "Person", "id", 2);
// then I should find the original node
assertThat(readOps.nodeGetFromUniqueIndexSeek(idx, exact(propId, 1)), equalTo(ourNode));
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class UniquenessConstraintValidationIT method unrelatedNodesWithSamePropertyShouldNotInterfereWithUniquenessCheck.
@Test
public void unrelatedNodesWithSamePropertyShouldNotInterfereWithUniquenessCheck() throws Exception {
// given
createConstraint("Person", "id");
long ourNode;
{
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
ourNode = createLabeledNode(statement, "Person", "id", 1);
createLabeledNode(statement, "Item", "id", 2);
commit();
}
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
ReadOperations readOps = statement.readOperations();
int person = readOps.labelGetForName("Person");
int propId = readOps.propertyKeyGetForName("id");
NewIndexDescriptor idx = readOps.uniqueIndexGetForLabelAndPropertyKey(new NodePropertyDescriptor(person, propId));
// when
createLabeledNode(statement, "Item", "id", 2);
// then I should find the original node
assertThat(readOps.nodeGetFromUniqueIndexSeek(idx, exact(propId, 1)), equalTo(ourNode));
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class KernelIT method schemaStateShouldBeEvictedOnIndexDropped.
@Test
public void schemaStateShouldBeEvictedOnIndexDropped() throws Exception {
// GIVEN
NewIndexDescriptor idx = createIndex(statementInNewTransaction(SecurityContext.AUTH_DISABLED));
commit();
try (Transaction tx = db.beginTx()) {
db.schema().awaitIndexOnline(db.schema().getIndexes().iterator().next(), 20, SECONDS);
getOrCreateSchemaState("my key", "some state");
tx.success();
}
// WHEN
schemaWriteOperationsInNewTransaction().indexDrop(idx);
commit();
// THEN
assertFalse(schemaStateContains("my key"));
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class NodeGetUniqueFromIndexSeekIT method shouldCompositeFindMatchingNode.
@Test
public void shouldCompositeFindMatchingNode() throws Exception {
// given
NewIndexDescriptor index = createUniquenessConstraint(labelId, propertyId1, propertyId2);
String value1 = "value1";
String value2 = "value2";
long nodeId = createNodeWithValues(value1, value2);
// when looking for it
ReadOperations readOperations = readOperationsInNewTransaction();
long foundId = readOperations.nodeGetFromUniqueIndexSeek(index, exact(propertyId1, value1), exact(propertyId2, value2));
commit();
// then
assertTrue("Created node was not found", nodeId == foundId);
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class NodeGetUniqueFromIndexSeekIT method shouldBlockUniqueIndexSeekFromCompetingTransaction.
@Test(timeout = 1000)
public 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();
final NewIndexDescriptor index = createUniquenessConstraint(labelId, propertyId1);
final String value = "value";
DataWriteOperations dataStatement = dataWriteOperationsInNewTransaction();
long nodeId = dataStatement.nodeCreate();
dataStatement.nodeAddLabel(nodeId, labelId);
// This adds the node to the unique index and should take an index write lock
dataStatement.nodeSetProperty(nodeId, Property.stringProperty(propertyId1, value));
Runnable runnableForThread2 = () -> {
latch.waitForAllToStart();
try (Transaction tx = db.beginTx()) {
try (Statement statement1 = statementContextSupplier.get()) {
statement1.readOperations().nodeGetFromUniqueIndexSeek(index, exact(propertyId1, value));
}
tx.success();
} catch (IndexNotFoundKernelException | IndexNotApplicableKernelException | IndexBrokenKernelException e) {
throw new RuntimeException(e);
} finally {
latch.finish();
}
};
Thread thread2 = new Thread(runnableForThread2, "Transaction Thread 2");
thread2.start();
latch.startAndWaitForAllToStart();
//noinspection UnusedLabel
spinUntilBlocking: for (; ; ) {
if (thread2.getState() == Thread.State.TIMED_WAITING || thread2.getState() == Thread.State.WAITING) {
break;
}
Thread.yield();
}
commit();
latch.waitForAllToFinish();
}
Aggregations