use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class IndexSamplingIntegrationTest method fetchIndexSamplingValues.
private DoubleLongRegister fetchIndexSamplingValues(GraphDatabaseService db) throws IndexNotFoundKernelException {
try {
// Then
db = new TestGraphDatabaseFactory().newEmbeddedDatabase(testDirectory.graphDbDir());
@SuppressWarnings("deprecation") GraphDatabaseAPI api = (GraphDatabaseAPI) db;
CountsTracker countsTracker = api.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores().getCounts();
IndexSampleKey key = CountsKeyFactory.indexSampleKey(indexId(api));
return countsTracker.get(key, Registers.newDoubleLongRegister());
} finally {
if (db != null) {
db.shutdown();
}
}
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class IndexSamplingIntegrationTest method shouldSampleNotUniqueIndex.
@Test
public void shouldSampleNotUniqueIndex() throws Throwable {
GraphDatabaseService db = null;
long deletedNodes = 0;
try {
// Given
db = new TestGraphDatabaseFactory().newEmbeddedDatabase(testDirectory.graphDbDir());
IndexDefinition indexDefinition;
try (Transaction tx = db.beginTx()) {
indexDefinition = db.schema().indexFor(label).on(property).create();
tx.success();
}
try (Transaction tx = db.beginTx()) {
db.schema().awaitIndexOnline(indexDefinition, 10, TimeUnit.SECONDS);
tx.success();
}
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < nodes; i++) {
db.createNode(label).setProperty(property, names[i % names.length]);
tx.success();
}
}
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < (nodes / 10); i++) {
db.findNodes(label, property, names[i % names.length]).next().delete();
deletedNodes++;
tx.success();
}
}
} finally {
if (db != null) {
db.shutdown();
}
}
// When
triggerIndexResamplingOnNextStartup();
// Then
// sampling will consider also the delete nodes till the next lucene compaction
DoubleLongRegister register = fetchIndexSamplingValues(db);
assertEquals(names.length, register.readFirst());
assertEquals(nodes, register.readSecond());
// but the deleted nodes should not be considered in the index size value
DoubleLongRegister indexSizeRegister = fetchIndexSizeValues(db);
assertEquals(0, indexSizeRegister.readFirst());
assertEquals(nodes - deletedNodes, indexSizeRegister.readSecond());
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class DynamicIndexStoreViewIT method populateDbWithConcurrentUpdates.
@Test
public void populateDbWithConcurrentUpdates() throws Exception {
GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabase(testDirectory.graphDbDir());
try {
int counter = 1;
for (int j = 0; j < 100; j++) {
try (Transaction transaction = database.beginTx()) {
for (int i = 0; i < 5; i++) {
Node node = database.createNode(Label.label("label" + counter));
node.setProperty("property", ThreadLocalRandom.current().nextInt());
}
transaction.success();
}
counter++;
}
int populatorCount = 5;
ExecutorService executor = Executors.newFixedThreadPool(populatorCount);
CountDownLatch startSignal = new CountDownLatch(1);
AtomicBoolean endSignal = new AtomicBoolean();
for (int i = 0; i < populatorCount; i++) {
executor.submit(new Populator(database, counter, startSignal, endSignal));
}
try {
try (Transaction transaction = database.beginTx()) {
database.schema().indexFor(Label.label("label10")).on("property").create();
transaction.success();
}
startSignal.countDown();
try (Transaction transaction = database.beginTx()) {
database.schema().awaitIndexesOnline(populatorCount, TimeUnit.MINUTES);
transaction.success();
}
} finally {
endSignal.set(true);
executor.shutdown();
// Basically we don't care to await their completion because they've done their job
}
} finally {
database.shutdown();
ConsistencyCheckService consistencyCheckService = new ConsistencyCheckService();
Config config = Config.defaults();
config = config.with(stringMap(GraphDatabaseSettings.pagecache_memory.name(), "8m"));
consistencyCheckService.runFullConsistencyCheck(testDirectory.graphDbDir(), config, ProgressMonitorFactory.NONE, FormattedLogProvider.toOutputStream(System.out), false);
}
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class FileWatchIT method setUp.
@Before
public void setUp() {
storeDir = testDirectory.graphDbDir();
logProvider = new AssertableLogProvider();
database = new TestGraphDatabaseFactory().setInternalLogProvider(logProvider).newEmbeddedDatabase(storeDir);
}
use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.
the class TestRecoveryMultipleDataSources method main.
public static void main(String[] args) throws IOException {
if (args.length != 1) {
exit(1);
}
File storeDir = new File(args[0]);
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try (Transaction tx = db.beginTx()) {
db.createNode().createRelationshipTo(db.createNode(), MyRelTypes.TEST);
tx.success();
}
((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
try (Transaction tx = db.beginTx()) {
db.index().forNodes("index").add(db.createNode(), storeDir.getAbsolutePath(), db.createNode());
tx.success();
}
exit(0);
}
Aggregations