use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class TransactionMonitorTest method shouldCountCommittedTransactions.
@Test
public void shouldCountCommittedTransactions() 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.success();
}
checker.verifyCommitted(isWriteTx, counts);
} finally {
db.shutdown();
}
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class DuplicatePropertyRemoverTest method setUp.
@BeforeClass
public static void setUp() {
GraphDatabaseFactory factory = new TestGraphDatabaseFactory();
GraphDatabaseService db = factory.newEmbeddedDatabase(storePath.absolutePath());
api = (GraphDatabaseAPI) db;
Label nodeLabel = Label.label("Label");
propertyNames = new ArrayList<>();
try (Transaction transaction = db.beginTx()) {
node = db.createNode(nodeLabel);
nodeId = node.getId();
for (int i = 0; i < PROPERTY_COUNT; i++) {
String propKey = "key" + i;
propertyNames.add(propKey);
String propValue = "value" + i;
boolean isBigProp = ThreadLocalRandom.current().nextBoolean();
if (isBigProp) {
propValue += propValue;
propValue += propValue;
propValue += propValue;
propValue += propValue;
propValue += propValue;
}
node.setProperty(propKey, propValue);
}
transaction.success();
}
Collections.shuffle(propertyNames);
DependencyResolver resolver = api.getDependencyResolver();
NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
nodeStore = neoStores.getNodeStore();
PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
indexedPropertyKeys = PropertyDeduplicatorTestUtil.indexPropertyKeys(propertyKeyTokenStore);
propertyStore = neoStores.getPropertyStore();
remover = new DuplicatePropertyRemover(nodeStore, propertyStore);
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class StoreMigrationTest method storeMigrationToolShouldBeAbleToMigrateOldStore.
@Test
public void storeMigrationToolShouldBeAbleToMigrateOldStore() throws IOException {
StoreMigration.main(new String[] { testDir.graphDbDir().getAbsolutePath() });
// after migration we can open store and do something
GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabase(testDir.graphDbDir());
try (Transaction transaction = database.beginTx()) {
Node node = database.createNode();
node.setProperty("key", "value");
transaction.success();
} finally {
database.shutdown();
}
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class LucenePartitionedIndexStressTesting method setUp.
@Before
public void setUp() throws IOException {
storeDir = prepareStoreDir();
System.out.println(String.format("Starting database at: %s", storeDir));
populators = Executors.newFixedThreadPool(NUMBER_OF_POPULATORS);
db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).newGraphDatabase();
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class ConstraintRecoveryIT method shouldNotHaveAnIndexIfUniqueConstraintCreationOnRecoveryFails.
@Test
public void shouldNotHaveAnIndexIfUniqueConstraintCreationOnRecoveryFails() throws IOException {
// given
final EphemeralFileSystemAbstraction fs = fileSystemRule.get();
fs.mkdir(new File("/tmp"));
File pathToDb = new File("/tmp/bar2");
TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory();
dbFactory.setFileSystem(fs);
final EphemeralFileSystemAbstraction[] storeInNeedOfRecovery = new EphemeralFileSystemAbstraction[1];
final AtomicBoolean monitorCalled = new AtomicBoolean(false);
Monitors monitors = new Monitors();
monitors.addMonitorListener(new IndexingService.MonitorAdapter() {
@Override
public void indexPopulationScanComplete() {
monitorCalled.set(true);
db.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getSchemaStore().flush();
storeInNeedOfRecovery[0] = fs.snapshot();
}
});
dbFactory.setMonitors(monitors);
db = (GraphDatabaseAPI) dbFactory.newImpermanentDatabase(pathToDb);
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < 2; i++) {
Node node1 = db.createNode(LABEL);
node1.setProperty("prop", true);
}
tx.success();
}
try (Transaction tx = db.beginTx()) {
db.schema().constraintFor(LABEL).assertPropertyIsUnique("prop").create();
fail("Should have failed with ConstraintViolationException");
tx.success();
} catch (ConstraintViolationException ignored) {
}
db.shutdown();
assertTrue(monitorCalled.get());
// when
dbFactory = new TestGraphDatabaseFactory();
dbFactory.setFileSystem(storeInNeedOfRecovery[0]);
db = (GraphDatabaseAPI) dbFactory.newImpermanentDatabase(pathToDb);
// then
try (Transaction tx = db.beginTx()) {
db.schema().awaitIndexesOnline(5000, TimeUnit.MILLISECONDS);
}
try (Transaction tx = db.beginTx()) {
assertEquals(2, Iterables.count(db.getAllNodes()));
}
try (Transaction tx = db.beginTx()) {
assertEquals(0, Iterables.count(Iterables.asList(db.schema().getConstraints())));
}
try (Transaction tx = db.beginTx()) {
assertEquals(0, Iterables.count(Iterables.asList(db.schema().getIndexes())));
}
db.shutdown();
}
Aggregations