Search in sources :

Example 41 with Transaction

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

the class StoreMigrationTest method storeMigrationToolShouldBeAbleToMigrateOldStore.

@Test
public void storeMigrationToolShouldBeAbleToMigrateOldStore() throws IOException {
    StoreMigration.main(new String[] { testDir.graphDbDir().getAbsolutePath() });
    // after migration we can open store and do something
    GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabase(testDir.graphDbDir());
    try (Transaction transaction = database.beginTx()) {
        Node node = database.createNode();
        node.setProperty("key", "value");
        transaction.success();
    } finally {
        database.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 42 with Transaction

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

the class LucenePartitionedIndexStressTesting method dropAllIndexes.

private void dropAllIndexes() {
    try (Transaction transaction = db.beginTx()) {
        Schema schema = db.schema();
        schema.getConstraints().forEach(ConstraintDefinition::drop);
        schema.getIndexes().forEach(IndexDefinition::drop);
        transaction.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Schema(org.neo4j.graphdb.schema.Schema) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 43 with Transaction

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

the class LucenePartitionedIndexStressTesting method awaitIndexesOnline.

private void awaitIndexesOnline(GraphDatabaseService db) {
    try (Transaction ignored = db.beginTx()) {
        Schema schema = db.schema();
        schema.awaitIndexesOnline(WAIT_DURATION_MINUTES, TimeUnit.MINUTES);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Schema(org.neo4j.graphdb.schema.Schema)

Example 44 with Transaction

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

the class ConstraintRecoveryIT method shouldNotHaveAnIndexIfUniqueConstraintCreationOnRecoveryFails.

@Test
public void shouldNotHaveAnIndexIfUniqueConstraintCreationOnRecoveryFails() throws IOException {
    // given
    final EphemeralFileSystemAbstraction fs = fileSystemRule.get();
    fs.mkdir(new File("/tmp"));
    File pathToDb = new File("/tmp/bar2");
    TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory();
    dbFactory.setFileSystem(fs);
    final EphemeralFileSystemAbstraction[] storeInNeedOfRecovery = new EphemeralFileSystemAbstraction[1];
    final AtomicBoolean monitorCalled = new AtomicBoolean(false);
    Monitors monitors = new Monitors();
    monitors.addMonitorListener(new IndexingService.MonitorAdapter() {

        @Override
        public void indexPopulationScanComplete() {
            monitorCalled.set(true);
            db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getSchemaStore().flush();
            storeInNeedOfRecovery[0] = fs.snapshot();
        }
    });
    dbFactory.setMonitors(monitors);
    db = (GraphDatabaseAPI) dbFactory.newImpermanentDatabase(pathToDb);
    try (Transaction tx = db.beginTx()) {
        for (int i = 0; i < 2; i++) {
            Node node1 = db.createNode(LABEL);
            node1.setProperty("prop", true);
        }
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        db.schema().constraintFor(LABEL).assertPropertyIsUnique("prop").create();
        fail("Should have failed with ConstraintViolationException");
        tx.success();
    } catch (ConstraintViolationException ignored) {
    }
    db.shutdown();
    assertTrue(monitorCalled.get());
    // when
    dbFactory = new TestGraphDatabaseFactory();
    dbFactory.setFileSystem(storeInNeedOfRecovery[0]);
    db = (GraphDatabaseAPI) dbFactory.newImpermanentDatabase(pathToDb);
    // then
    try (Transaction tx = db.beginTx()) {
        db.schema().awaitIndexesOnline(5000, TimeUnit.MILLISECONDS);
    }
    try (Transaction tx = db.beginTx()) {
        assertEquals(2, Iterables.count(db.getAllNodes()));
    }
    try (Transaction tx = db.beginTx()) {
        assertEquals(0, Iterables.count(Iterables.asList(db.schema().getConstraints())));
    }
    try (Transaction tx = db.beginTx()) {
        assertEquals(0, Iterables.count(Iterables.asList(db.schema().getIndexes())));
    }
    db.shutdown();
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) Node(org.neo4j.graphdb.Node) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(org.neo4j.graphdb.Transaction) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Monitors(org.neo4j.kernel.monitoring.Monitors) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) File(java.io.File) Test(org.junit.Test)

Example 45 with Transaction

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

the class IndexingServiceIntegrationTest method testSchemaIndexMatchIndexingService.

@Test
public void testSchemaIndexMatchIndexingService() throws IndexNotFoundKernelException {
    try (Transaction transaction = database.beginTx()) {
        database.schema().constraintFor(Label.label(CLOTHES_LABEL)).assertPropertyIsUnique(PROPERTY_NAME).create();
        database.schema().indexFor(Label.label(WEATHER_LABEL)).on(PROPERTY_NAME).create();
        transaction.success();
    }
    try (Transaction transaction = database.beginTx()) {
        database.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
    }
    IndexingService indexingService = getIndexingService(database);
    LabelTokenHolder labelTokenHolder = getLabelTokenHolder(database);
    PropertyKeyTokenHolder propertyKeyTokenHolder = getPropertyKeyTokenHolder(database);
    int clothedLabelId = labelTokenHolder.getIdByName(CLOTHES_LABEL);
    int weatherLabelId = labelTokenHolder.getIdByName(WEATHER_LABEL);
    int propertyId = propertyKeyTokenHolder.getIdByName(PROPERTY_NAME);
    IndexProxy clothesIndex = indexingService.getIndexProxy(SchemaDescriptorFactory.forLabel(clothedLabelId, propertyId));
    IndexProxy weatherIndex = indexingService.getIndexProxy(SchemaDescriptorFactory.forLabel(weatherLabelId, propertyId));
    assertEquals(InternalIndexState.ONLINE, clothesIndex.getState());
    assertEquals(InternalIndexState.ONLINE, weatherIndex.getState());
}
Also used : Transaction(org.neo4j.graphdb.Transaction) PropertyKeyTokenHolder(org.neo4j.kernel.impl.core.PropertyKeyTokenHolder) LabelTokenHolder(org.neo4j.kernel.impl.core.LabelTokenHolder) Test(org.junit.Test)

Aggregations

Transaction (org.neo4j.graphdb.Transaction)2409 Node (org.neo4j.graphdb.Node)1086 Test (org.junit.jupiter.api.Test)751 Test (org.junit.Test)607 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)352 Relationship (org.neo4j.graphdb.Relationship)307 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)302 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)241 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)177 Label (org.neo4j.graphdb.Label)154 Result (org.neo4j.graphdb.Result)142 HashMap (java.util.HashMap)105 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)104 MethodSource (org.junit.jupiter.params.provider.MethodSource)103 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)86 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)77 File (java.io.File)74 ArrayList (java.util.ArrayList)73 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)67 Path (java.nio.file.Path)64