Search in sources :

Example 46 with TestGraphDatabaseFactory

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();
        }
    }
}
Also used : IndexSampleKey(org.neo4j.kernel.impl.store.counts.keys.IndexSampleKey) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker)

Example 47 with TestGraphDatabaseFactory

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());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Transaction(org.neo4j.graphdb.Transaction) DoubleLongRegister(org.neo4j.register.Register.DoubleLongRegister) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 48 with TestGraphDatabaseFactory

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);
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(org.neo4j.graphdb.Transaction) Config(org.neo4j.kernel.configuration.Config) Node(org.neo4j.graphdb.Node) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) ExecutorService(java.util.concurrent.ExecutorService) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 49 with TestGraphDatabaseFactory

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);
}
Also used : TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Before(org.junit.Before)

Example 50 with TestGraphDatabaseFactory

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);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) File(java.io.File)

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