Search in sources :

Example 91 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class ConsistencyCheckServiceIntegrationTest method shouldNotReportDuplicateForHugeLongValues.

@Test
public void shouldNotReportDuplicateForHugeLongValues() throws Exception {
    // given
    ConsistencyCheckService service = new ConsistencyCheckService();
    Config configuration = Config.embeddedDefaults(settings());
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(testDirectory.graphDbDir()).setConfig(GraphDatabaseSettings.record_format, getRecordFormatName()).newGraphDatabase();
    String propertyKey = "itemId";
    Label label = Label.label("Item");
    try (Transaction tx = db.beginTx()) {
        db.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).create();
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        set(db.createNode(label), property(propertyKey, 973305894188596880L));
        set(db.createNode(label), property(propertyKey, 973305894188596864L));
        tx.success();
    }
    db.shutdown();
    // when
    Result result = runFullConsistencyCheck(service, configuration);
    // then
    assertTrue(result.isSuccessful());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Config(org.neo4j.kernel.configuration.Config) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Label(org.neo4j.graphdb.Label) Matchers.containsString(org.hamcrest.Matchers.containsString) Result(org.neo4j.consistency.ConsistencyCheckService.Result) Test(org.junit.Test)

Example 92 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class ConsistencyCheckServiceIntegrationTest method getGraphDatabaseService.

private GraphDatabaseService getGraphDatabaseService() {
    GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(testDirectory.absolutePath());
    builder.setConfig(settings());
    return builder.newGraphDatabase();
}
Also used : TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder)

Example 93 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class ConsistencyCheckToolTest method createGraphDbAndKillIt.

private void createGraphDbAndKillIt() throws Exception {
    final GraphDatabaseService db = new TestGraphDatabaseFactory().setFileSystem(fs.get()).newImpermanentDatabaseBuilder(storeDirectory.graphDbDir()).newGraphDatabase();
    try (Transaction tx = db.beginTx()) {
        db.createNode(label("FOO"));
        db.createNode(label("BAR"));
        tx.success();
    }
    fs.snapshot(() -> db.shutdown());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory)

Example 94 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class GraphStoreFixture method generateInitialData.

private void generateInitialData() {
    GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(directory);
    GraphDatabaseAPI graphDb = (GraphDatabaseAPI) builder.setConfig(GraphDatabaseSettings.record_format, formatName).setConfig(GraphDatabaseSettings.label_block_size, "60").newGraphDatabase();
    try {
        generateInitialData(graphDb);
        StoreAccess stores = new StoreAccess(graphDb.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores()).initialize();
        schemaId = stores.getSchemaStore().getHighId();
        nodeId = stores.getNodeStore().getHighId();
        labelId = (int) stores.getLabelTokenStore().getHighId();
        nodeLabelsId = stores.getNodeDynamicLabelStore().getHighId();
        relId = stores.getRelationshipStore().getHighId();
        relGroupId = stores.getRelationshipGroupStore().getHighId();
        propId = (int) stores.getPropertyStore().getHighId();
        stringPropId = stores.getStringStore().getHighId();
        arrayPropId = stores.getArrayStore().getHighId();
        relTypeId = (int) stores.getRelationshipTypeTokenStore().getHighId();
        propKeyId = (int) stores.getPropertyKeyNameStore().getHighId();
    } finally {
        graphDb.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AccessStatsKeepingStoreAccess(org.neo4j.consistency.statistics.AccessStatsKeepingStoreAccess) DirectStoreAccess(org.neo4j.kernel.api.direct.DirectStoreAccess) StoreAccess(org.neo4j.kernel.impl.store.StoreAccess) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder)

Example 95 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class ParallelBatchImporterTest method shouldImportCsvData.

@Test
public void shouldImportCsvData() throws Exception {
    // GIVEN
    ExecutionMonitor processorAssigner = eagerRandomSaturation(config.maxNumberOfProcessors());
    final BatchImporter inserter = new ParallelBatchImporter(directory.graphDbDir(), fileSystemRule.get(), config, NullLogService.getInstance(), processorAssigner, EMPTY, Config.empty(), getFormat());
    boolean successful = false;
    IdGroupDistribution groups = new IdGroupDistribution(NODE_COUNT, 5, random.random());
    long nodeRandomSeed = random.nextLong(), relationshipRandomSeed = random.nextLong();
    try {
        // WHEN
        inserter.doImport(Inputs.input(nodes(nodeRandomSeed, NODE_COUNT, inputIdGenerator, groups), relationships(relationshipRandomSeed, RELATIONSHIP_COUNT, inputIdGenerator, groups), idMapper, idGenerator, /*insanely high bad tolerance, but it will actually never be that many*/
        silentBadCollector(RELATIONSHIP_COUNT)));
        // THEN
        GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(directory.graphDbDir()).newGraphDatabase();
        try (Transaction tx = db.beginTx()) {
            inputIdGenerator.reset();
            verifyData(NODE_COUNT, RELATIONSHIP_COUNT, db, groups, nodeRandomSeed, relationshipRandomSeed);
            tx.success();
        } finally {
            db.shutdown();
        }
        assertConsistent(directory.graphDbDir());
        successful = true;
    } finally {
        if (!successful) {
            File failureFile = directory.file("input");
            try (PrintStream out = new PrintStream(failureFile)) {
                out.println("Seed used in this failing run: " + random.seed());
                out.println(inputIdGenerator);
                inputIdGenerator.reset();
                for (InputNode node : nodes(nodeRandomSeed, NODE_COUNT, inputIdGenerator, groups)) {
                    out.println(node);
                }
                for (InputRelationship relationship : relationships(relationshipRandomSeed, RELATIONSHIP_COUNT, inputIdGenerator, groups)) {
                    out.println(relationship);
                }
                out.println();
                out.println("Processor assignments");
                out.println(processorAssigner.toString());
            }
            System.err.println("Additional debug information stored in " + failureFile);
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) PrintStream(java.io.PrintStream) InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) ExecutionMonitor(org.neo4j.unsafe.impl.batchimport.staging.ExecutionMonitor) File(java.io.File) Test(org.junit.Test)

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