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"));
}
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"));
}
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"));
}
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();
}
}
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();
}
Aggregations