Search in sources :

Example 66 with TestGraphDatabaseFactory

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

the class GraphDatabaseInternalLogIT method shouldNotWriteDebugToInternalDiagnosticsLogByDefault.

@Test
public void shouldNotWriteDebugToInternalDiagnosticsLogByDefault() throws Exception {
    // Given
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(testDir.graphDbDir()).setConfig(GraphDatabaseSettings.logs_directory, testDir.directory("logs").getAbsolutePath()).newGraphDatabase();
    // When
    LogService logService = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(LogService.class);
    logService.getInternalLog(getClass()).debug("A debug entry");
    db.shutdown();
    File internalLog = new File(testDir.directory("logs"), StoreLogService.INTERNAL_LOG_NAME);
    // Then
    assertThat(internalLog.isFile(), is(true));
    assertThat(internalLog.length(), greaterThan(0L));
    assertEquals(0, countOccurrences(internalLog, "A debug entry"));
}
Also used : TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) LogService(org.neo4j.kernel.impl.logging.LogService) StoreLogService(org.neo4j.kernel.impl.logging.StoreLogService) Test(org.junit.Test)

Example 67 with TestGraphDatabaseFactory

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

the class GraphDatabaseInternalLogIT method shouldWriteToInternalDiagnosticsLog.

@Test
public void shouldWriteToInternalDiagnosticsLog() throws Exception {
    // Given
    new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(testDir.graphDbDir()).setConfig(GraphDatabaseSettings.logs_directory, testDir.directory("logs").getAbsolutePath()).newGraphDatabase().shutdown();
    File internalLog = new File(testDir.directory("logs"), StoreLogService.INTERNAL_LOG_NAME);
    // Then
    assertThat(internalLog.isFile(), is(true));
    assertThat(internalLog.length(), greaterThan(0L));
    assertEquals(1, countOccurrences(internalLog, "Database is now ready"));
    assertEquals(1, countOccurrences(internalLog, "Database is now unavailable"));
}
Also used : TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) Test(org.junit.Test)

Example 68 with TestGraphDatabaseFactory

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

the class GraphDatabaseInternalLogIT method shouldWriteDebugToInternalDiagnosticsLogForEnabledContexts.

@Test
public void shouldWriteDebugToInternalDiagnosticsLogForEnabledContexts() throws Exception {
    // Given
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(testDir.graphDbDir()).setConfig(GraphDatabaseSettings.store_internal_debug_contexts, getClass().getName() + ",java.io").setConfig(GraphDatabaseSettings.logs_directory, testDir.directory("logs").getAbsolutePath()).newGraphDatabase();
    // When
    LogService logService = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(LogService.class);
    logService.getInternalLog(getClass()).debug("A debug entry");
    logService.getInternalLog(GraphDatabaseService.class).debug("A GDS debug entry");
    logService.getInternalLog(StringWriter.class).debug("A SW debug entry");
    db.shutdown();
    File internalLog = new File(testDir.directory("logs"), StoreLogService.INTERNAL_LOG_NAME);
    // Then
    assertThat(internalLog.isFile(), is(true));
    assertThat(internalLog.length(), greaterThan(0L));
    assertEquals(1, countOccurrences(internalLog, "A debug entry"));
    assertEquals(0, countOccurrences(internalLog, "A GDS debug entry"));
    assertEquals(1, countOccurrences(internalLog, "A SW debug entry"));
}
Also used : StringWriter(java.io.StringWriter) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) LogService(org.neo4j.kernel.impl.logging.LogService) StoreLogService(org.neo4j.kernel.impl.logging.StoreLogService) Test(org.junit.Test)

Example 69 with TestGraphDatabaseFactory

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

the class GraphDatabaseServiceTest method terminateNestedTransactionThrowsExceptionOnNextNestedOperationMultiThreadedVersionWithNestedTx.

@Test
public void terminateNestedTransactionThrowsExceptionOnNextNestedOperationMultiThreadedVersionWithNestedTx() 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(() -> {
            Transaction transaction = db.beginTx();
            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;
            } finally {
                transaction.close();
            }
        });
        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 70 with TestGraphDatabaseFactory

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

the class ManyPropertyKeysIT method concurrently_creating_same_property_key_in_different_transactions_should_end_up_with_same_key_id.

@Test
public void concurrently_creating_same_property_key_in_different_transactions_should_end_up_with_same_key_id() throws Exception {
    // GIVEN
    GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
    OtherThreadExecutor<WorkerState> worker1 = new OtherThreadExecutor<>("w1", new WorkerState(db));
    OtherThreadExecutor<WorkerState> worker2 = new OtherThreadExecutor<>("w2", new WorkerState(db));
    worker1.execute(new BeginTx());
    worker2.execute(new BeginTx());
    // WHEN
    String key = "mykey";
    worker1.execute(new CreateNodeAndSetProperty(key));
    worker2.execute(new CreateNodeAndSetProperty(key));
    worker1.execute(new FinishTx());
    worker2.execute(new FinishTx());
    worker1.close();
    worker2.close();
    // THEN
    assertEquals(1, propertyKeyCount(db));
    db.shutdown();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) OtherThreadExecutor(org.neo4j.test.OtherThreadExecutor) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) 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