Search in sources :

Example 86 with TestGraphDatabaseFactory

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

the class UserFunctionIT method setUp.

@Before
public void setUp() throws IOException {
    exceptionsInFunction.clear();
    new JarBuilder().createJarFor(plugins.newFile("myFunctions.jar"), ClassWithFunctions.class);
    db = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(GraphDatabaseSettings.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 87 with TestGraphDatabaseFactory

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

the class DiagnosticsLoggingTest method shouldSeeExpectedDiagnostics.

@Test
public void shouldSeeExpectedDiagnostics() {
    AssertableLogProvider logProvider = new AssertableLogProvider();
    GraphDatabaseService db = new TestGraphDatabaseFactory().setInternalLogProvider(logProvider).newImpermanentDatabaseBuilder().setConfig(GraphDatabaseSettings.dump_configuration, Settings.TRUE).setConfig(GraphDatabaseSettings.pagecache_memory, "4M").newGraphDatabase();
    // THEN we should have logged
    logProvider.assertContainsMessageContaining("Network information");
    logProvider.assertContainsMessageContaining("Disk space on partition");
    logProvider.assertContainsMessageContaining("Local timezone");
    // page cache info
    logProvider.assertContainsMessageContaining("Page cache size: 4 MiB");
    // neostore records
    for (MetaDataStore.Position position : MetaDataStore.Position.values()) {
        logProvider.assertContainsMessageContaining(position.name());
    }
    // transaction log info
    logProvider.assertContainsMessageContaining("Transaction log");
    db.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 88 with TestGraphDatabaseFactory

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

the class GraphDatabaseServiceTest method givenDatabaseAndStartedTxWhenShutdownThenWaitForTxToFinish.

@Test
public void givenDatabaseAndStartedTxWhenShutdownThenWaitForTxToFinish() throws Exception {
    // Given
    final GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
    // When
    Barrier.Control barrier = new Barrier.Control();
    Future<Object> txFuture = t2.execute(state -> {
        try (Transaction tx = db.beginTx()) {
            barrier.reached();
            db.createNode();
            tx.success();
        }
        return null;
    });
    // i.e. wait for transaction to start
    barrier.await();
    // now there's a transaction open, blocked on continueTxSignal
    Future<Object> shutdownFuture = t3.execute(state -> {
        db.shutdown();
        return null;
    });
    t3.get().waitUntilWaiting(location -> location.isAt(DatabaseAvailability.class, "stop"));
    barrier.release();
    try {
        txFuture.get();
    } catch (ExecutionException e) {
    // expected
    }
    shutdownFuture.get();
}
Also used : TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Barrier(org.neo4j.test.Barrier) DatabaseAvailability(org.neo4j.kernel.DatabaseAvailability) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 89 with TestGraphDatabaseFactory

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

the class GraphDatabaseServiceTest method terminateNestedTransactionThrowsExceptionOnNextNestedOperationMultiThreadedVersion.

@Test
public void terminateNestedTransactionThrowsExceptionOnNextNestedOperationMultiThreadedVersion() throws Exception {
    // Given
    final GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
    try {
        // When
        final CountDownLatch txSet = new CountDownLatch(1);
        final CountDownLatch terminated = new CountDownLatch(1);
        final Transaction[] outer = { null };
        final Exception[] threadFail = { null };
        Thread worker = new Thread(() -> {
            try (Transaction inner = db.beginTx()) {
                outer[0] = inner;
                txSet.countDown();
                terminated.await();
                db.createNode();
                fail("should have failed earlier");
            } catch (Exception e) {
                threadFail[0] = e;
            }
        });
        worker.start();
        txSet.await();
        outer[0].terminate();
        terminated.countDown();
        worker.join();
        assertThat(threadFail[0], instanceOf(TransactionTerminatedException.class));
    } finally {
        db.shutdown();
    }
}
Also used : TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) ExpectedException(org.junit.rules.ExpectedException) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) Test(org.junit.Test)

Example 90 with TestGraphDatabaseFactory

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

the class GraphDatabaseServiceTest method givenDatabaseAndStartedTxWhenShutdownAndStartNewTxThenBeginTxTimesOut.

@Test
public void givenDatabaseAndStartedTxWhenShutdownAndStartNewTxThenBeginTxTimesOut() throws Exception {
    // Given
    GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
    // When
    Barrier.Control barrier = new Barrier.Control();
    t2.execute(state -> {
        try (Transaction tx = db.beginTx()) {
            barrier.reached();
        }
        return null;
    });
    barrier.await();
    Future<Object> shutdownFuture = t3.execute(state -> {
        db.shutdown();
        return null;
    });
    t3.get().waitUntilWaiting(location -> location.isAt(DatabaseAvailability.class, "stop"));
    // <-- this triggers t2 to continue its transaction
    barrier.release();
    shutdownFuture.get();
    try {
        db.beginTx();
        fail("Should fail");
    } catch (DatabaseShutdownException e) {
    //THEN good
    }
}
Also used : TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Barrier(org.neo4j.test.Barrier) DatabaseAvailability(org.neo4j.kernel.DatabaseAvailability) Test(org.junit.Test)

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