Search in sources :

Example 46 with IndexDefinition

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

the class AppsIT method failSamplingWhenProvidingOnlyLabel.

@Test
public void failSamplingWhenProvidingOnlyLabel() throws Exception {
    // GIVEN
    Label label = label("Person");
    String property = "name";
    beginTx();
    IndexDefinition index = db.schema().indexFor(label).on(property).create();
    finishTx();
    waitForIndex(db, index);
    // WHEN / THEN
    try {
        executeCommand("schema sample -l Person");
        fail("This should fail");
    } catch (ShellException e) {
        assertThat(e.getMessage(), containsString("Provide both the property and the label, or run with -a to sample all indexes"));
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 47 with IndexDefinition

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

the class AppsIT method failSamplingWhenProvidingBadLabel.

@Test
public void failSamplingWhenProvidingBadLabel() throws Exception {
    // GIVEN
    Label label = label("Person");
    String property = "name";
    beginTx();
    IndexDefinition index = db.schema().indexFor(label).on(property).create();
    finishTx();
    waitForIndex(db, index);
    // WHEN / THEN
    try {
        executeCommand("schema sample -l People -p name");
        fail("This should fail");
    } catch (ShellException e) {
        assertThat(e.getMessage(), containsString("No label associated with 'People' was found"));
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 48 with IndexDefinition

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

the class AppsIT method canAwaitIndexesToComeOnline.

@Test
public void canAwaitIndexesToComeOnline() throws Exception {
    // GIVEN
    Label label = label("Person");
    beginTx();
    IndexDefinition index = db.schema().indexFor(label).on("name").create();
    finishTx();
    // WHEN / THEN
    executeCommand("schema await -l " + label.name());
    beginTx();
    assertEquals(IndexState.ONLINE, db.schema().getIndexState(index));
    finishTx();
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Test(org.junit.Test)

Example 49 with IndexDefinition

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

the class AppsIT method failSamplingWhenProvidingMultipleLabels.

@Test
public void failSamplingWhenProvidingMultipleLabels() throws Exception {
    // GIVEN
    Label label = label("Person");
    Label otherLabel = label("Dog");
    String property = "name";
    beginTx();
    IndexDefinition index1 = db.schema().indexFor(label).on(property).create();
    IndexDefinition index2 = db.schema().indexFor(otherLabel).on(property).create();
    finishTx();
    waitForIndex(db, index1);
    waitForIndex(db, index2);
    // WHEN / THEN
    try {
        executeCommand("schema sample -p name -l [Person,Dog]");
        fail("This should fail");
    } catch (ShellException e) {
        assertThat(e.getMessage(), containsString("Only one label must be provided"));
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 50 with IndexDefinition

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

the class AppsIT method canListIndexesForGivenPropertyAndLabel.

@Test
public void canListIndexesForGivenPropertyAndLabel() throws Exception {
    // GIVEN
    Label label1 = label("Person");
    Label label2 = label("Thing");
    String property1 = "name";
    String property2 = "age";
    beginTx();
    IndexDefinition index1 = db.schema().indexFor(label1).on(property1).create();
    IndexDefinition index2 = db.schema().indexFor(label1).on(property2).create();
    IndexDefinition index3 = db.schema().indexFor(label2).on(property1).create();
    IndexDefinition index4 = db.schema().indexFor(label2).on(property2).create();
    finishTx();
    waitForIndex(db, index1);
    waitForIndex(db, index2);
    waitForIndex(db, index3);
    waitForIndex(db, index4);
    // WHEN / THEN
    executeCommand("schema ls" + " -l :" + label2.name() + " -p " + property1, label2.name(), property1, "!" + label1.name(), "!" + property2);
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

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