Search in sources :

Example 11 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class TransactionMonitorTest method shouldCountCommittedTransactions.

@Test
public void shouldCountCommittedTransactions() throws Exception {
    GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
    try {
        TransactionCounters counts = db.getDependencyResolver().resolveDependency(TransactionCounters.class);
        TransactionCountersChecker checker = new TransactionCountersChecker(counts);
        try (Transaction tx = db.beginTx()) {
            dbConsumer.accept(db);
            tx.success();
        }
        checker.verifyCommitted(isWriteTx, counts);
    } finally {
        db.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 12 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class DuplicatePropertyRemoverTest method setUp.

@BeforeClass
public static void setUp() {
    GraphDatabaseFactory factory = new TestGraphDatabaseFactory();
    GraphDatabaseService db = factory.newEmbeddedDatabase(storePath.absolutePath());
    api = (GraphDatabaseAPI) db;
    Label nodeLabel = Label.label("Label");
    propertyNames = new ArrayList<>();
    try (Transaction transaction = db.beginTx()) {
        node = db.createNode(nodeLabel);
        nodeId = node.getId();
        for (int i = 0; i < PROPERTY_COUNT; i++) {
            String propKey = "key" + i;
            propertyNames.add(propKey);
            String propValue = "value" + i;
            boolean isBigProp = ThreadLocalRandom.current().nextBoolean();
            if (isBigProp) {
                propValue += propValue;
                propValue += propValue;
                propValue += propValue;
                propValue += propValue;
                propValue += propValue;
            }
            node.setProperty(propKey, propValue);
        }
        transaction.success();
    }
    Collections.shuffle(propertyNames);
    DependencyResolver resolver = api.getDependencyResolver();
    NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    nodeStore = neoStores.getNodeStore();
    PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
    indexedPropertyKeys = PropertyDeduplicatorTestUtil.indexPropertyKeys(propertyKeyTokenStore);
    propertyStore = neoStores.getPropertyStore();
    remover = new DuplicatePropertyRemover(nodeStore, propertyStore);
}
Also used : PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) BeforeClass(org.junit.BeforeClass)

Example 13 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory 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 14 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class LucenePartitionedIndexStressTesting method setUp.

@Before
public void setUp() throws IOException {
    storeDir = prepareStoreDir();
    System.out.println(String.format("Starting database at: %s", storeDir));
    populators = Executors.newFixedThreadPool(NUMBER_OF_POPULATORS);
    db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).newGraphDatabase();
}
Also used : TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Before(org.junit.Before)

Example 15 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory 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)

Aggregations

TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)156 Test (org.junit.Test)70 Transaction (org.neo4j.graphdb.Transaction)62 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)61 File (java.io.File)34 Node (org.neo4j.graphdb.Node)28 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)26 BeforeClass (org.junit.BeforeClass)25 Before (org.junit.Before)22 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)9 Relationship (org.neo4j.graphdb.Relationship)8 Result (org.neo4j.graphdb.Result)6 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)6 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)6 GraphDatabaseShellServer (org.neo4j.shell.kernel.GraphDatabaseShellServer)6 HashMap (java.util.HashMap)5 DependencyResolver (org.neo4j.graphdb.DependencyResolver)5 PageCache (org.neo4j.io.pagecache.PageCache)5 WrappedDatabase (org.neo4j.server.database.WrappedDatabase)5 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4