Search in sources :

Example 51 with TestGraphDatabaseFactory

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

the class RebuildCountsTest method restart.

private void restart(FileSystemAbstraction fs) throws IOException {
    if (db != null) {
        db.shutdown();
    }
    fs.mkdirs(storeDir);
    TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory();
    db = dbFactory.setUserLogProvider(userLogProvider).setInternalLogProvider(internalLogProvider).setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fs)).addKernelExtension(new InMemoryIndexProviderFactory(indexProvider)).newImpermanentDatabaseBuilder(storeDir).setConfig(index_background_sampling_enabled, "false").newGraphDatabase();
}
Also used : InMemoryIndexProviderFactory(org.neo4j.kernel.impl.api.index.inmemory.InMemoryIndexProviderFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) UncloseableDelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)

Example 52 with TestGraphDatabaseFactory

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

the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed.

@Test
public void startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed() throws Throwable {
    // given
    // create a store
    File storeDir = testDirectory.graphDbDir();
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
    try (Transaction tx = db.beginTx()) {
        db.createNode();
        tx.success();
    }
    db.shutdown();
    // mess up the version in the metadatastore
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
        MetaDataStore.setRecord(pageCache, new File(storeDir, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong("bad"));
    }
    // when
    try {
        new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
        fail("It should have failed.");
    } catch (RuntimeException ex) {
        // then
        assertTrue(ex.getCause() instanceof LifecycleException);
        assertTrue(ex.getCause().getCause() instanceof UpgradeNotAllowedByConfigurationException);
        assertEquals("Failed to start Neo4j with an older data store version. To enable automatic upgrade, " + "please set configuration parameter \"dbms.allow_format_migration=true\"", ex.getCause().getCause().getMessage());
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) UpgradeNotAllowedByConfigurationException(org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 53 with TestGraphDatabaseFactory

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

the class MultipleIndexPopulationStressIT method populateDbAndIndexes.

private void populateDbAndIndexes(int nodeCount, boolean multiThreaded) throws InterruptedException {
    final GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(directory.graphDbDir()).setConfig(GraphDatabaseSettings.multi_threaded_schema_index_population_enabled, multiThreaded + "").newGraphDatabase();
    try {
        createIndexes(db);
        final AtomicBoolean end = new AtomicBoolean();
        ExecutorService executor = cleanup.add(Executors.newCachedThreadPool());
        for (int i = 0; i < 10; i++) {
            executor.submit(() -> {
                Randoms random = new Randoms();
                while (!end.get()) {
                    changeRandomNode(db, nodeCount, random);
                }
            });
        }
        while (!indexesAreOnline(db)) {
            Thread.sleep(100);
        }
        end.set(true);
        executor.shutdown();
        executor.awaitTermination(10, SECONDS);
    } finally {
        db.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Randoms(org.neo4j.test.Randoms) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) ExecutorService(java.util.concurrent.ExecutorService)

Example 54 with TestGraphDatabaseFactory

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

the class PagingTraversalTest method startDatabase.

@Before
public void startDatabase() throws IOException {
    graph = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase();
    database = new WrappedDatabase(graph);
    helper = new GraphDbHelper(database);
    EntityOutputFormat output = new EntityOutputFormat(new JsonFormat(), URI.create(BASE_URI), null);
    leaseManager = new LeaseManager(Clocks.fakeClock());
    service = new RestfulGraphDatabase(new JsonFormat(), output, new DatabaseActions(leaseManager, true, database.getGraph()), null);
    service = new TransactionWrappingRestfulGraphDatabase(graph, service);
}
Also used : GraphDbHelper(org.neo4j.server.rest.domain.GraphDbHelper) JsonFormat(org.neo4j.server.rest.repr.formats.JsonFormat) LeaseManager(org.neo4j.server.rest.paging.LeaseManager) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) WrappedDatabase(org.neo4j.server.database.WrappedDatabase) EntityOutputFormat(org.neo4j.test.server.EntityOutputFormat) Before(org.junit.Before)

Example 55 with TestGraphDatabaseFactory

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

the class DatabaseActionsTest method createDb.

@BeforeClass
public static void createDb() throws IOException {
    graph = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase();
    database = new WrappedDatabase(graph);
    graphdbHelper = new GraphDbHelper(database);
    actions = new TransactionWrappedDatabaseActions(new LeaseManager(Clocks.fakeClock()), database.getGraph());
}
Also used : GraphDbHelper(org.neo4j.server.rest.domain.GraphDbHelper) LeaseManager(org.neo4j.server.rest.paging.LeaseManager) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) WrappedDatabase(org.neo4j.server.database.WrappedDatabase) BeforeClass(org.junit.BeforeClass)

Aggregations

TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)154 Test (org.junit.Test)83 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)77 Transaction (org.neo4j.graphdb.Transaction)56 File (java.io.File)40 Node (org.neo4j.graphdb.Node)32 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)25 Before (org.junit.Before)23 Result (org.neo4j.graphdb.Result)13 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)11 Relationship (org.neo4j.graphdb.Relationship)9 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)9 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)9 BeforeClass (org.junit.BeforeClass)8 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)8 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)8 HashMap (java.util.HashMap)7 Point (org.neo4j.graphdb.spatial.Point)7 DependencyResolver (org.neo4j.graphdb.DependencyResolver)6 PageCache (org.neo4j.io.pagecache.PageCache)6