use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class LabelsAcceptanceTest method beansAPIWithNoMoreLabelIds.
@SuppressWarnings("deprecation")
private GraphDatabaseService beansAPIWithNoMoreLabelIds() {
final EphemeralIdGenerator.Factory idFactory = new EphemeralIdGenerator.Factory() {
private IdTypeConfigurationProvider idTypeConfigurationProvider = new CommunityIdTypeConfigurationProvider();
@Override
public IdGenerator open(File fileName, int grabSize, IdType idType, long highId, long maxId) {
if (idType == IdType.LABEL_TOKEN) {
IdGenerator generator = generators.get(idType);
if (generator == null) {
IdTypeConfiguration idTypeConfiguration = idTypeConfigurationProvider.getIdTypeConfiguration(idType);
generator = new EphemeralIdGenerator(idType, idTypeConfiguration) {
@Override
public long nextId() {
// Same exception as the one thrown by IdGeneratorImpl
throw new UnderlyingStorageException("Id capacity exceeded");
}
};
generators.put(idType, generator);
}
return generator;
}
return super.open(fileName, grabSize, idType, Long.MAX_VALUE, Long.MAX_VALUE);
}
};
TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory() {
@Override
protected GraphDatabaseBuilder.DatabaseCreator createImpermanentDatabaseCreator(final File storeDir, final TestGraphDatabaseFactoryState state) {
return new GraphDatabaseBuilder.DatabaseCreator() {
@Override
public GraphDatabaseService newDatabase(Map<String, String> config) {
return newDatabase(Config.embeddedDefaults(config));
}
@Override
public GraphDatabaseService newDatabase(@Nonnull Config config) {
return new ImpermanentGraphDatabase(storeDir, config, GraphDatabaseDependencies.newDependencies(state.databaseDependencies())) {
@Override
protected void create(File storeDir, Config config, GraphDatabaseFacadeFactory.Dependencies dependencies) {
Function<PlatformModule, EditionModule> factory = (platformModule) -> new CommunityEditionModule(platformModule) {
@Override
protected IdGeneratorFactory createIdGeneratorFactory(FileSystemAbstraction fs, IdTypeConfigurationProvider idTypeConfigurationProvider) {
return idFactory;
}
};
new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, factory) {
@Override
protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
return new ImpermanentPlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade);
}
}.initFacade(storeDir, config, dependencies, this);
}
};
}
};
}
};
return dbFactory.newImpermanentDatabase();
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class GraphDatabaseServiceTest method givenShutdownDatabaseWhenBeginTxThenExceptionIsThrown.
@Test
public void givenShutdownDatabaseWhenBeginTxThenExceptionIsThrown() throws Exception {
// Given
GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
db.shutdown();
// Expect
exception.expect(DatabaseShutdownException.class);
// When
db.beginTx();
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class TestKernelEvents method testShutdownEvents.
@Test
public void testShutdownEvents() {
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
DummyKernelEventHandler handler1 = new DummyKernelEventHandler(RESOURCE1) {
@Override
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
if (((DummyKernelEventHandler) other).resource == RESOURCE2) {
return ExecutionOrder.AFTER;
}
return ExecutionOrder.DOESNT_MATTER;
}
};
DummyKernelEventHandler handler2 = new DummyKernelEventHandler(RESOURCE1) {
@Override
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
if (((DummyKernelEventHandler) other).resource == RESOURCE1) {
return ExecutionOrder.BEFORE;
}
return ExecutionOrder.DOESNT_MATTER;
}
};
graphDb.registerKernelEventHandler(handler1);
graphDb.registerKernelEventHandler(handler2);
graphDb.shutdown();
assertEquals(Integer.valueOf(0), handler2.beforeShutdown);
assertEquals(Integer.valueOf(1), handler1.beforeShutdown);
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class TransactionMonitorTest method shouldCountTerminatedTransactions.
@Test
public void shouldCountTerminatedTransactions() throws Exception {
GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
try {
TransactionCounters counts = db.getDependencyResolver().resolveDependency(TransactionCounters.class);
TransactionCountersChecker checker = new TransactionCountersChecker(counts);
try (Transaction tx = db.beginTx()) {
dbConsumer.accept(db);
tx.terminate();
}
checker.verifyTerminated(isWriteTx, counts);
} finally {
db.shutdown();
}
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class TransactionMonitorTest method shoulCountRolledBackTransactions.
@Test
public void shoulCountRolledBackTransactions() throws Exception {
GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
try {
TransactionCounters counts = db.getDependencyResolver().resolveDependency(TransactionCounters.class);
TransactionCountersChecker checker = new TransactionCountersChecker(counts);
try (Transaction tx = db.beginTx()) {
dbConsumer.accept(db);
tx.failure();
}
checker.verifyRolledBacked(isWriteTx, counts);
} finally {
db.shutdown();
}
}
Aggregations