Search in sources :

Example 71 with Label

use of org.neo4j.graphdb.Label in project neo4j by neo4j.

the class IndexValuesValidationTest method validateLegacyIndexedRelationshipProperties.

@Test
public void validateLegacyIndexedRelationshipProperties() {
    Label label = Label.label("legacyIndexedRelationshipPropertiesTestLabel");
    String propertyName = "legacyIndexedRelationshipProperties";
    String legacyIndexedRelationshipIndex = "legacyIndexedRelationshipIndex";
    RelationshipType indexType = RelationshipType.withName("legacyIndexType");
    try (Transaction transaction = database.beginTx()) {
        Node source = database.createNode(label);
        Node destination = database.createNode(label);
        Relationship relationship = source.createRelationshipTo(destination, indexType);
        database.index().forRelationships(legacyIndexedRelationshipIndex).add(relationship, propertyName, "shortString");
        transaction.success();
    }
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Property value bytes length: 32767 is longer then 32766, " + "which is maximum supported length of indexed property value.");
    try (Transaction transaction = database.beginTx()) {
        Node source = database.createNode(label);
        Node destination = database.createNode(label);
        Relationship relationship = source.createRelationshipTo(destination, indexType);
        String longValue = StringUtils.repeat("a", IndexWriter.MAX_TERM_LENGTH + 1);
        database.index().forRelationships(legacyIndexedRelationshipIndex).add(relationship, propertyName, longValue);
        transaction.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 72 with Label

use of org.neo4j.graphdb.Label in project neo4j by neo4j.

the class IndexValuesValidationTest method validateIndexedNodeProperties.

@Test
public void validateIndexedNodeProperties() throws Exception {
    Label label = Label.label("indexedNodePropertiesTestLabel");
    String propertyName = "indexedNodePropertyName";
    createIndex(label, propertyName);
    try (Transaction ignored = database.beginTx()) {
        database.schema().awaitIndexesOnline(5, TimeUnit.MINUTES);
    }
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Property value bytes length: 32767 is longer then 32766, " + "which is maximum supported length of indexed property value.");
    try (Transaction transaction = database.beginTx()) {
        Node node = database.createNode(label);
        node.setProperty(propertyName, StringUtils.repeat("a", IndexWriter.MAX_TERM_LENGTH + 1));
        transaction.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) Test(org.junit.Test)

Example 73 with Label

use of org.neo4j.graphdb.Label 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 74 with Label

use of org.neo4j.graphdb.Label in project neo4j by neo4j.

the class MultiIndexPopulationConcurrentUpdatesIT method prepareDb.

private void prepareDb() {
    Label countryLabel = Label.label(COUNTRY_LABEL);
    Label color = Label.label(COLOR_LABEL);
    Label car = Label.label(CAR_LABEL);
    try (Transaction transaction = embeddedDatabase.beginTx()) {
        createNamedLabeledNode(countryLabel, "Sweden");
        createNamedLabeledNode(countryLabel, "USA");
        createNamedLabeledNode(color, "red");
        createNamedLabeledNode(color, "green");
        createNamedLabeledNode(car, "Volvo");
        createNamedLabeledNode(car, "Ford");
        for (int i = 0; i < 250; i++) {
            embeddedDatabase.createNode();
        }
        transaction.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Label(org.neo4j.graphdb.Label)

Example 75 with Label

use of org.neo4j.graphdb.Label in project neo4j by neo4j.

the class DatabaseContentVerifier method verifyJohnnyLabels.

public void verifyJohnnyLabels() {
    // Johnny labels has got a bunch of alter egos
    try (Transaction tx = database.beginTx()) {
        Node johhnyLabels = database.getNodeById(1);
        Set<String> expectedLabels = new HashSet<>();
        for (int i = 0; i < 30; i++) {
            expectedLabels.add("AlterEgo" + i);
        }
        for (Label label : johhnyLabels.getLabels()) {
            assertTrue(expectedLabels.remove(label.name()));
        }
        assertTrue(expectedLabels.isEmpty());
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) MigrationTestUtils.makeLongString(org.neo4j.kernel.impl.storemigration.MigrationTestUtils.makeLongString) HashSet(java.util.HashSet)

Aggregations

Label (org.neo4j.graphdb.Label)82 Test (org.junit.Test)55 Node (org.neo4j.graphdb.Node)48 Transaction (org.neo4j.graphdb.Transaction)44 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)12 RelationshipType (org.neo4j.graphdb.RelationshipType)8 DependencyResolver (org.neo4j.graphdb.DependencyResolver)6 DynamicLabel (org.neo4j.graphdb.DynamicLabel)6 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)6 Statement (org.neo4j.kernel.api.Statement)6 ArrayList (java.util.ArrayList)5 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)5 Relationship (org.neo4j.graphdb.Relationship)5 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)5 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)5 File (java.io.File)4 HashSet (java.util.HashSet)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)4