Search in sources :

Example 16 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class IndexEntryConflictExceptionTest method shouldMakeEntryConflicts.

@Test
public void shouldMakeEntryConflicts() {
    LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel(labelId, 2);
    IndexEntryConflictException e = new IndexEntryConflictException(0L, 1L, "hi");
    assertThat(e.evidenceMessage(SchemaUtil.idTokenNameLookup, schema), equalTo("Both Node(0) and Node(1) have the label `label[1]` and property `property[2]` = 'hi'"));
}
Also used : LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 17 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class IndexEntryConflictExceptionTest method shouldMakeCompositeEntryConflicts.

@Test
public void shouldMakeCompositeEntryConflicts() {
    LabelSchemaDescriptor schema = SchemaDescriptorFactory.forLabel(labelId, 2, 3, 4);
    OrderedPropertyValues values = OrderedPropertyValues.ofUndefined(true, "hi", new long[] { 6L, 4L });
    IndexEntryConflictException e = new IndexEntryConflictException(0L, 1L, values);
    assertThat(e.evidenceMessage(SchemaUtil.idTokenNameLookup, schema), equalTo("Both Node(0) and Node(1) have the label `label[1]` " + "and properties `property[2]` = true, `property[3]` = 'hi', `property[4]` = [6, 4]"));
}
Also used : OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 18 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class LockingStatementOperationsTest method shouldAcquireSchemaWriteLockBeforeAddingIndexRule.

@Test
public void shouldAcquireSchemaWriteLockBeforeAddingIndexRule() throws Exception {
    // given
    LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(123, 456);
    NewIndexDescriptor index = NewIndexDescriptorFactory.forLabel(123, 456);
    when(schemaWriteOps.indexCreate(state, descriptor)).thenReturn(index);
    // when
    NewIndexDescriptor result = lockingOps.indexCreate(state, descriptor);
    // then
    assertSame(index, result);
    order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.SCHEMA, schemaResource());
    order.verify(schemaWriteOps).indexCreate(state, descriptor);
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 19 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class IndexPopulationJobTest method shouldPopulateIndexWithOneNode.

@Test
public void shouldPopulateIndexWithOneNode() throws Exception {
    // GIVEN
    String value = "Taylor";
    long nodeId = createNode(map(name, value), FIRST);
    IndexPopulator populator = spy(inMemoryPopulator(false));
    IndexPopulationJob job = newIndexPopulationJob(populator, new FlippableIndexProxy(), false);
    LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(0, 0);
    // WHEN
    job.run();
    // THEN
    IndexEntryUpdate update = IndexEntryUpdate.add(nodeId, descriptor, value);
    verify(populator).create();
    verify(populator).configureSampling(true);
    verify(populator).includeSample(update);
    verify(populator).add(anyListOf(IndexEntryUpdate.class));
    verify(populator).sampleResult();
    verify(populator).close(true);
    verifyNoMoreInteractions(populator);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 20 with LabelSchemaDescriptor

use of org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor in project neo4j by neo4j.

the class IndexCRUDIT method addingANodeWithPropertyShouldGetIndexed.

@Test
public void addingANodeWithPropertyShouldGetIndexed() throws Exception {
    // Given
    String indexProperty = "indexProperty";
    GatheringIndexWriter writer = newWriter();
    createIndex(db, myLabel, indexProperty);
    // When
    int value1 = 12;
    String otherProperty = "otherProperty";
    int otherValue = 17;
    Node node = createNode(map(indexProperty, value1, otherProperty, otherValue), myLabel);
    // Then, for now, this should trigger two NodePropertyUpdates
    try (Transaction tx = db.beginTx()) {
        ReadOperations readOperations = ctxSupplier.get().readOperations();
        int propertyKey1 = readOperations.propertyKeyGetForName(indexProperty);
        int label = readOperations.labelGetForName(myLabel.name());
        LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(label, propertyKey1);
        assertThat(writer.updatesCommitted, equalTo(asSet(IndexEntryUpdate.add(node.getId(), descriptor, value1))));
        tx.success();
    }
// We get two updates because we both add a label and a property to be indexed
// in the same transaction, in the future, we should optimize this down to
// one NodePropertyUpdate.
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Aggregations

LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)23 Test (org.junit.Test)12 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)5 Transaction (org.neo4j.graphdb.Transaction)4 Statement (org.neo4j.kernel.api.Statement)4 IndexEntryUpdate (org.neo4j.kernel.api.index.IndexEntryUpdate)4 Node (org.neo4j.graphdb.Node)3 Pair (org.neo4j.helpers.collection.Pair)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 PrimitiveIntSet (org.neo4j.collection.primitive.PrimitiveIntSet)2 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)2 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)2 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)2 NodeItem (org.neo4j.storageengine.api.NodeItem)2 IOException (java.io.IOException)1 Map (java.util.Map)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)1