Search in sources :

Example 76 with TestGraphDatabaseFactory

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

the class ProcedureIT method setUp.

@Before
public void setUp() throws IOException {
    exceptionsInProcedure.clear();
    new JarBuilder().createJarFor(plugins.newFile("myProcedures.jar"), ClassWithProcedures.class);
    new JarBuilder().createJarFor(plugins.newFile("myFunctions.jar"), ClassWithFunctions.class);
    db = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(plugin_dir, plugins.getRoot().getAbsolutePath()).newGraphDatabase();
}
Also used : TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) JarBuilder(org.neo4j.kernel.impl.proc.JarBuilder) Before(org.junit.Before)

Example 77 with TestGraphDatabaseFactory

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

the class SessionRule method apply.

@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            Map<Setting<?>, String> config = new HashMap<>();
            config.put(GraphDatabaseSettings.auth_enabled, Boolean.toString(authEnabled));
            gdb = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase(config);
            DependencyResolver resolver = gdb.getDependencyResolver();
            Authentication authentication = authentication(resolver.resolveDependency(AuthManager.class), resolver.resolveDependency(UserManagerSupplier.class));
            boltFactory = new BoltFactoryImpl(gdb, new UsageData(null), NullLogService.getInstance(), resolver.resolveDependency(ThreadToStatementContextBridge.class), authentication, BoltConnectionTracker.NOOP, Config.defaults());
            boltFactory.start();
            try {
                base.evaluate();
            } finally {
                try {
                    if (runningMachines != null) {
                        runningMachines.forEach(BoltStateMachine::close);
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                gdb.shutdown();
            }
        }
    };
}
Also used : UsageData(org.neo4j.udc.UsageData) HashMap(java.util.HashMap) AuthManager(org.neo4j.kernel.api.security.AuthManager) Statement(org.junit.runners.model.Statement) Setting(org.neo4j.graphdb.config.Setting) UserManagerSupplier(org.neo4j.kernel.api.security.UserManagerSupplier) DependencyResolver(org.neo4j.graphdb.DependencyResolver) BoltFactoryImpl(org.neo4j.bolt.v1.runtime.BoltFactoryImpl) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) Authentication(org.neo4j.bolt.security.auth.Authentication) BasicAuthentication(org.neo4j.bolt.security.auth.BasicAuthentication) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory)

Example 78 with TestGraphDatabaseFactory

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

the class LabelScanStoreHaIT method setUp.

@Before
public void setUp() {
    KernelExtensionFactory<?> testExtension = labelScanStoreExtension(monitor);
    TestHighlyAvailableGraphDatabaseFactory factory = new TestHighlyAvailableGraphDatabaseFactory();
    factory.removeKernelExtensions(extension -> extension.getClass().getName().contains("LabelScan"));
    factory.addKernelExtension(testExtension);
    ClusterManager clusterManager = new ClusterManager.Builder(testDirectory.directory("root")).withDbFactory(factory).withSharedSetting(GraphDatabaseSettings.label_index, labelIndexSettingName()).withStoreDirInitializer((serverId, storeDir) -> {
        if (serverId == 1) {
            GraphDatabaseService db = new TestGraphDatabaseFactory().addKernelExtension(testExtension).newEmbeddedDatabaseBuilder(storeDir.getAbsoluteFile()).setConfig(GraphDatabaseSettings.label_index, labelIndexSettingName()).newGraphDatabase();
            try {
                createSomeLabeledNodes(db, new Label[] { Labels.First }, new Label[] { Labels.First, Labels.Second }, new Label[] { Labels.Second });
            } finally {
                db.shutdown();
            }
        }
    }).build();
    life.add(clusterManager);
    life.start();
    cluster = clusterManager.getCluster();
    cluster.await(allSeesAllAsAvailable());
    cluster.await(allAvailabilityGuardsReleased());
}
Also used : Label(org.neo4j.graphdb.Label) TestDirectory(org.neo4j.test.rule.TestDirectory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Iterators.count(org.neo4j.helpers.collection.Iterators.count) TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory) Rule(org.junit.Rule) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) ClusterManager.allSeesAllAsAvailable(org.neo4j.kernel.impl.ha.ClusterManager.allSeesAllAsAvailable) After(org.junit.After) KernelExtensionFactory(org.neo4j.kernel.extension.KernelExtensionFactory) ClusterManager.allAvailabilityGuardsReleased(org.neo4j.kernel.impl.ha.ClusterManager.allAvailabilityGuardsReleased) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) Transaction(org.neo4j.graphdb.Transaction) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Label(org.neo4j.graphdb.Label) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Before(org.junit.Before)

Example 79 with TestGraphDatabaseFactory

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

the class CheckPointingLogRotationStressTesting method shouldBehaveCorrectlyUnderStress.

@Test
public void shouldBehaveCorrectlyUnderStress() throws Throwable {
    long durationInMinutes = parseLong(fromEnv("CHECK_POINT_LOG_ROTATION_STRESS_DURATION", DEFAULT_DURATION_IN_MINUTES));
    File storeDir = new File(fromEnv("CHECK_POINT_LOG_ROTATION_STORE_DIRECTORY", DEFAULT_STORE_DIR));
    long nodeCount = parseLong(fromEnv("CHECK_POINT_LOG_ROTATION_NODE_COUNT", DEFAULT_NODE_COUNT));
    int threads = parseInt(fromEnv("CHECK_POINT_LOG_ROTATION_WORKER_THREADS", DEFAULT_WORKER_THREADS));
    String pageCacheMemory = fromEnv("CHECK_POINT_LOG_ROTATION_PAGE_CACHE_MEMORY", DEFAULT_PAGE_CACHE_MEMORY);
    System.out.println("1/6\tBuilding initial store...");
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        new ParallelBatchImporter(ensureExistsAndEmpty(storeDir), fileSystem, DEFAULT, NullLogService.getInstance(), ExecutionMonitors.defaultVisible(), Config.defaults()).doImport(new NodeCountInputs(nodeCount));
    }
    System.out.println("2/6\tStarting database...");
    GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir);
    GraphDatabaseService db = builder.setConfig(GraphDatabaseSettings.pagecache_memory, pageCacheMemory).setConfig(GraphDatabaseSettings.keep_logical_logs, Settings.FALSE).setConfig(GraphDatabaseSettings.check_point_interval_time, CHECK_POINT_INTERVAL_MINUTES + "m").setConfig(GraphDatabaseFacadeFactory.Configuration.tracer, "timer").newGraphDatabase();
    System.out.println("3/6\tWarm up db...");
    try (Workload workload = new Workload(db, defaultRandomMutation(nodeCount, db), threads)) {
        // make sure to run at least one checkpoint during warmup
        long warmUpTimeMillis = TimeUnit.SECONDS.toMillis(CHECK_POINT_INTERVAL_MINUTES * 2);
        workload.run(warmUpTimeMillis, Workload.TransactionThroughput.NONE);
    }
    System.out.println("4/6\tStarting workload...");
    TransactionThroughputChecker throughput = new TransactionThroughputChecker();
    try (Workload workload = new Workload(db, defaultRandomMutation(nodeCount, db), threads)) {
        workload.run(TimeUnit.MINUTES.toMillis(durationInMinutes), throughput);
    }
    System.out.println("5/6\tShutting down...");
    db.shutdown();
    try {
        System.out.println("6/6\tPrinting stats and recorded timings...");
        TimerTransactionTracer.printStats(System.out);
        throughput.assertThroughput(System.out);
    } finally {
        System.out.println("Done.");
    }
    // let's cleanup disk space when everything went well
    FileUtils.deleteRecursively(storeDir);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Workload(org.neo4j.kernel.stresstests.transaction.checkpoint.workload.Workload) ParallelBatchImporter(org.neo4j.unsafe.impl.batchimport.ParallelBatchImporter) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Test(org.junit.Test)

Example 80 with TestGraphDatabaseFactory

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

the class DatabaseRebuildToolTest method databaseWithSomeTransactions.

private void databaseWithSomeTransactions(File dir) {
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(dir);
    Node[] nodes = new Node[10];
    for (int i = 0; i < nodes.length; i++) {
        try (Transaction tx = db.beginTx()) {
            Node node = db.createNode(label("Label_" + (i % 2)));
            setProperties(node, i);
            nodes[i] = node;
            tx.success();
        }
    }
    for (int i = 0; i < 40; i++) {
        try (Transaction tx = db.beginTx()) {
            Relationship relationship = nodes[i % nodes.length].createRelationshipTo(nodes[(i + 1) % nodes.length], withName("TYPE_" + (i % 3)));
            setProperties(relationship, i);
            tx.success();
        }
    }
    try (Transaction tx = db.beginTx()) {
        Node node = nodes[nodes.length - 1];
        for (Relationship relationship : node.getRelationships()) {
            relationship.delete();
        }
        node.delete();
        tx.success();
    }
    db.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory)

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