Search in sources :

Example 71 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class LuceneIndexRecoveryIT method createIndex.

private IndexDefinition createIndex(Label label) {
    try (Transaction tx = db.beginTx()) {
        IndexDefinition definition = db.schema().indexFor(label).on(NUM_BANANAS_KEY).create();
        tx.success();
        return definition;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition)

Example 72 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class LuceneIndexRecoveryIT method changeShouldBeIdempotentWhenDoingRecovery.

@Test
public void changeShouldBeIdempotentWhenDoingRecovery() throws Exception {
    // Given
    startDb(createLuceneIndexFactory());
    IndexDefinition indexDefinition = createIndex(myLabel);
    waitForIndex(indexDefinition);
    long node = createNode(myLabel, 12);
    rotateLogsAndCheckPoint();
    updateNode(node, 13);
    // And Given
    killDb();
    // When
    startDb(createLuceneIndexFactory());
    // Then
    assertEquals(0, doIndexLookup(myLabel, 12).size());
    assertEquals(1, doIndexLookup(myLabel, 13).size());
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Test(org.junit.Test)

Example 73 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class LuceneIndexRecoveryIT method shouldNotUpdateTwiceDuringRecovery.

@Test
public void shouldNotUpdateTwiceDuringRecovery() throws Exception {
    // Given
    startDb(createLuceneIndexFactory());
    IndexDefinition indexDefinition = createIndex(myLabel);
    waitForIndex(indexDefinition);
    long nodeId = createNode(myLabel, 12);
    updateNode(nodeId, 14);
    // And Given
    killDb();
    // When
    startDb(createLuceneIndexFactory());
    // Then
    assertEquals(0, doIndexLookup(myLabel, 12).size());
    assertEquals(1, doIndexLookup(myLabel, 14).size());
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Test(org.junit.Test)

Example 74 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class IndexValuesValidationTest method validateNodePropertiesOnPopulation.

@Test
public void validateNodePropertiesOnPopulation() {
    Label label = Label.label("populationTestNodeLabel");
    String propertyName = "populationTestPropertyName";
    try (Transaction transaction = database.beginTx()) {
        Node node = database.createNode(label);
        node.setProperty(propertyName, StringUtils.repeat("a", IndexWriter.MAX_TERM_LENGTH + 1));
        transaction.success();
    }
    IndexDefinition indexDefinition = createIndex(label, propertyName);
    try {
        try (Transaction ignored = database.beginTx()) {
            database.schema().awaitIndexesOnline(5, TimeUnit.MINUTES);
        }
    } catch (IllegalStateException e) {
        try (Transaction ignored = database.beginTx()) {
            String indexFailure = database.schema().getIndexFailure(indexDefinition);
            assertThat("", indexFailure, Matchers.startsWith("java.lang.IllegalArgumentException: " + "Property value bytes length: 32767 is longer then 32766, " + "which is maximum supported length of indexed property value."));
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) Test(org.junit.Test)

Example 75 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class DatabaseContentVerifier method verifyIndex.

public void verifyIndex() {
    try (Transaction tx = database.beginTx()) {
        List<IndexDefinition> indexDefinitions = Iterables.asList(database.schema().getIndexes());
        assertEquals(1, indexDefinitions.size());
        IndexDefinition indexDefinition = indexDefinitions.get(0);
        assertEquals("Label", indexDefinition.getLabel().name());
        List<String> propKeys = Iterables.asList(indexDefinition.getPropertyKeys());
        assertEquals(1, propKeys.size());
        String propKey = propKeys.get(0);
        assertEquals("prop", propKey);
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) MigrationTestUtils.makeLongString(org.neo4j.kernel.impl.storemigration.MigrationTestUtils.makeLongString)

Aggregations

IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)84 Test (org.junit.Test)56 Transaction (org.neo4j.graphdb.Transaction)32 StringContains.containsString (org.hamcrest.core.StringContains.containsString)11 Node (org.neo4j.graphdb.Node)9 Statement (org.neo4j.kernel.api.Statement)7 ArrayList (java.util.ArrayList)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Label (org.neo4j.graphdb.Label)4 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)4 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)4 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)3 Iterator (java.util.Iterator)2 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)2 TransactionData (org.neo4j.graphdb.event.TransactionData)2 TransactionEventHandler (org.neo4j.graphdb.event.TransactionEventHandler)2 ConstraintDefinition (org.neo4j.graphdb.schema.ConstraintDefinition)2