Search in sources :

Example 1 with GraphDatabaseFacade

use of org.neo4j.kernel.impl.factory.GraphDatabaseFacade in project neo4j by neo4j.

the class ProcedureGDSFactory method apply.

@Override
public GraphDatabaseService apply(Context context) throws ProcedureException {
    SecurityContext securityContext = context.getOrElse(Context.SECURITY_CONTEXT, SecurityContext.AUTH_DISABLED);
    GraphDatabaseFacade facade = new GraphDatabaseFacade();
    facade.init(new ProcedureGDBFacadeSPI(platform, dataSource, resolver, availability, urlValidator, securityContext), dataSource.guard, dataSource.threadToTransactionBridge, platform.config);
    return facade;
}
Also used : SecurityContext(org.neo4j.kernel.api.security.SecurityContext) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade)

Example 2 with GraphDatabaseFacade

use of org.neo4j.kernel.impl.factory.GraphDatabaseFacade 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();
}
Also used : EphemeralIdGenerator(org.neo4j.test.impl.EphemeralIdGenerator) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) Matchers.not(org.hamcrest.Matchers.not) Statement(org.neo4j.kernel.api.Statement) IdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.IdTypeConfigurationProvider) Matchers.hasItems(org.hamcrest.Matchers.hasItems) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Cursor(org.neo4j.cursor.Cursor) GraphDatabaseDependencies(org.neo4j.kernel.GraphDatabaseDependencies) Assert.assertThat(org.junit.Assert.assertThat) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Iterables.map(org.neo4j.helpers.collection.Iterables.map) EditionModule(org.neo4j.kernel.impl.factory.EditionModule) Map(java.util.Map) CommunityIdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider) Assert.fail(org.junit.Assert.fail) Neo4jMatchers.inTx(org.neo4j.test.mockito.matcher.Neo4jMatchers.inTx) Collectors.toSet(java.util.stream.Collectors.toSet) UnderlyingStorageException(org.neo4j.kernel.impl.store.UnderlyingStorageException) PrimitiveIntCollections.consume(org.neo4j.collection.primitive.PrimitiveIntCollections.consume) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) Set(java.util.Set) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) IdType(org.neo4j.kernel.impl.store.id.IdType) List(java.util.List) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) TestGraphDatabaseFactoryState(org.neo4j.test.TestGraphDatabaseFactoryState) PropertyItem(org.neo4j.storageengine.api.PropertyItem) ImpermanentGraphDatabase(org.neo4j.test.ImpermanentGraphDatabase) IdTypeConfiguration(org.neo4j.kernel.impl.store.id.configuration.IdTypeConfiguration) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) Neo4jMatchers.hasNoLabels(org.neo4j.test.mockito.matcher.Neo4jMatchers.hasNoLabels) CommunityEditionModule(org.neo4j.kernel.impl.factory.CommunityEditionModule) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Neo4jMatchers.hasLabel(org.neo4j.test.mockito.matcher.Neo4jMatchers.hasLabel) Neo4jMatchers.hasNoNodes(org.neo4j.test.mockito.matcher.Neo4jMatchers.hasNoNodes) Neo4jMatchers.hasLabels(org.neo4j.test.mockito.matcher.Neo4jMatchers.hasLabels) Nonnull(javax.annotation.Nonnull) ImpermanentDatabaseRule(org.neo4j.test.rule.ImpermanentDatabaseRule) Config(org.neo4j.kernel.configuration.Config) Iterator(java.util.Iterator) DatabaseInfo(org.neo4j.kernel.impl.factory.DatabaseInfo) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Label.label(org.neo4j.graphdb.Label.label) Iterables.asList(org.neo4j.helpers.collection.Iterables.asList) File(java.io.File) Rule(org.junit.Rule) Iterables(org.neo4j.helpers.collection.Iterables) Neo4jMatchers.hasNodes(org.neo4j.test.mockito.matcher.Neo4jMatchers.hasNodes) NodeItem(org.neo4j.storageengine.api.NodeItem) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) PlatformModule(org.neo4j.kernel.impl.factory.PlatformModule) Assert.assertEquals(org.junit.Assert.assertEquals) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) EphemeralIdGenerator(org.neo4j.test.impl.EphemeralIdGenerator) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) GraphDatabaseDependencies(org.neo4j.kernel.GraphDatabaseDependencies) IdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.IdTypeConfigurationProvider) CommunityIdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) CommunityEditionModule(org.neo4j.kernel.impl.factory.CommunityEditionModule) TestGraphDatabaseFactoryState(org.neo4j.test.TestGraphDatabaseFactoryState) Nonnull(javax.annotation.Nonnull) EphemeralIdGenerator(org.neo4j.test.impl.EphemeralIdGenerator) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) UnderlyingStorageException(org.neo4j.kernel.impl.store.UnderlyingStorageException) PlatformModule(org.neo4j.kernel.impl.factory.PlatformModule) IdType(org.neo4j.kernel.impl.store.id.IdType) EditionModule(org.neo4j.kernel.impl.factory.EditionModule) CommunityEditionModule(org.neo4j.kernel.impl.factory.CommunityEditionModule) IdTypeConfiguration(org.neo4j.kernel.impl.store.id.configuration.IdTypeConfiguration) CommunityIdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider) ImpermanentGraphDatabase(org.neo4j.test.ImpermanentGraphDatabase) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) File(java.io.File) Map(java.util.Map)

Example 3 with GraphDatabaseFacade

use of org.neo4j.kernel.impl.factory.GraphDatabaseFacade in project neo4j by neo4j.

the class GraphDatabaseFacadeFactoryTest method newFaultyGraphDatabaseFacadeFactory.

private GraphDatabaseFacadeFactory newFaultyGraphDatabaseFacadeFactory(final RuntimeException startupError) {
    return new GraphDatabaseFacadeFactory(DatabaseInfo.UNKNOWN, (p) -> Mockito.mock(EditionModule.class, Mockito.RETURNS_DEEP_STUBS)) {

        @Override
        protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
            final LifeSupport lifeMock = mock(LifeSupport.class);
            doThrow(startupError).when(lifeMock).start();
            doAnswer(invocation -> invocation.getArguments()[0]).when(lifeMock).add(any(Lifecycle.class));
            return new PlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade) {

                @Override
                public LifeSupport createLife() {
                    return lifeMock;
                }
            };
        }

        @Override
        protected DataSourceModule createDataSource(PlatformModule platformModule, EditionModule editionModule, Supplier<QueryExecutionEngine> queryExecutionEngineSupplier) {
            return mock(DataSourceModule.class);
        }
    };
}
Also used : EditionModule(org.neo4j.kernel.impl.factory.EditionModule) Config(org.neo4j.kernel.configuration.Config) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Supplier(java.util.function.Supplier) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) PlatformModule(org.neo4j.kernel.impl.factory.PlatformModule) File(java.io.File)

Example 4 with GraphDatabaseFacade

use of org.neo4j.kernel.impl.factory.GraphDatabaseFacade in project neo4j by neo4j.

the class PartialTransactionFailureIT method concurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction.

@Test
public void concurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction() throws Exception {
    final ClassGuardedAdversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, false), Command.RelationshipCommand.class);
    adversary.disable();
    File storeDir = dir.graphDbDir();
    final Map<String, String> params = stringMap(GraphDatabaseSettings.pagecache_memory.name(), "8m");
    final EmbeddedGraphDatabase db = new TestEmbeddedGraphDatabase(storeDir, params) {

        @Override
        protected void create(File storeDir, Map<String, String> params, GraphDatabaseFacadeFactory.Dependencies dependencies) {
            new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, CommunityEditionModule::new) {

                @Override
                protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
                    return new PlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade) {

                        @Override
                        protected FileSystemAbstraction createFileSystemAbstraction() {
                            return new AdversarialFileSystemAbstraction(adversary);
                        }
                    };
                }
            }.initFacade(storeDir, params, dependencies, this);
        }
    };
    Node a, b, c, d;
    try (Transaction tx = db.beginTx()) {
        a = db.createNode();
        b = db.createNode();
        c = db.createNode();
        d = db.createNode();
        tx.success();
    }
    adversary.enable();
    CountDownLatch latch = new CountDownLatch(1);
    Thread t1 = new Thread(createRelationship(db, a, b, latch), "T1");
    Thread t2 = new Thread(createRelationship(db, c, d, latch), "T2");
    t1.start();
    t2.start();
    // Wait for both threads to get going
    t1.join(10);
    t2.join(10);
    latch.countDown();
    // Wait for the transactions to finish
    t1.join(25000);
    t2.join(25000);
    db.shutdown();
    // We should observe the store in a consistent state
    EmbeddedGraphDatabase db2 = new TestEmbeddedGraphDatabase(storeDir, params);
    try (Transaction tx = db2.beginTx()) {
        Node x = db2.getNodeById(a.getId());
        Node y = db2.getNodeById(b.getId());
        Node z = db2.getNodeById(c.getId());
        Node w = db2.getNodeById(d.getId());
        Iterator<Relationship> itrRelX = x.getRelationships().iterator();
        Iterator<Relationship> itrRelY = y.getRelationships().iterator();
        Iterator<Relationship> itrRelZ = z.getRelationships().iterator();
        Iterator<Relationship> itrRelW = w.getRelationships().iterator();
        if (itrRelX.hasNext() != itrRelY.hasNext()) {
            fail("Node x and y have inconsistent relationship counts");
        } else if (itrRelX.hasNext()) {
            Relationship rel = itrRelX.next();
            assertEquals(rel, itrRelY.next());
            assertFalse(itrRelX.hasNext());
            assertFalse(itrRelY.hasNext());
        }
        if (itrRelZ.hasNext() != itrRelW.hasNext()) {
            fail("Node z and w have inconsistent relationship counts");
        } else if (itrRelZ.hasNext()) {
            Relationship rel = itrRelZ.next();
            assertEquals(rel, itrRelW.next());
            assertFalse(itrRelZ.hasNext());
            assertFalse(itrRelW.hasNext());
        }
    } finally {
        db2.shutdown();
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.internal.EmbeddedGraphDatabase) CountingAdversary(org.neo4j.adversaries.CountingAdversary) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ClassGuardedAdversary(org.neo4j.adversaries.ClassGuardedAdversary) Config(org.neo4j.kernel.configuration.Config) Node(org.neo4j.graphdb.Node) PlatformModule(org.neo4j.kernel.impl.factory.PlatformModule) CountDownLatch(java.util.concurrent.CountDownLatch) Transaction(org.neo4j.graphdb.Transaction) Command(org.neo4j.kernel.impl.transaction.command.Command) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) Relationship(org.neo4j.graphdb.Relationship) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) File(java.io.File) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) Test(org.junit.Test)

Example 5 with GraphDatabaseFacade

use of org.neo4j.kernel.impl.factory.GraphDatabaseFacade in project neo4j by neo4j.

the class NonUniqueIndexTests method newEmbeddedGraphDatabaseWithSlowJobScheduler.

private GraphDatabaseService newEmbeddedGraphDatabaseWithSlowJobScheduler() {
    GraphDatabaseFactoryState graphDatabaseFactoryState = new GraphDatabaseFactoryState();
    graphDatabaseFactoryState.setUserLogProvider(NullLogService.getInstance().getUserLogProvider());
    return new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, CommunityEditionModule::new) {

        @Override
        protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
            return new PlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade) {

                @Override
                protected Neo4jJobScheduler createJobScheduler() {
                    return newSlowJobScheduler();
                }

                @Override
                protected LogService createLogService(LogProvider userLogProvider) {
                    return NullLogService.getInstance();
                }
            };
        }
    }.newFacade(directory.graphDbDir(), Config.embeddedDefaults(), graphDatabaseFactoryState.databaseDependencies());
}
Also used : Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) Config(org.neo4j.kernel.configuration.Config) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) GraphDatabaseFactoryState(org.neo4j.graphdb.factory.GraphDatabaseFactoryState) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) PlatformModule(org.neo4j.kernel.impl.factory.PlatformModule) File(java.io.File) LogService(org.neo4j.kernel.impl.logging.LogService) NullLogService(org.neo4j.kernel.impl.logging.NullLogService)

Aggregations

GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)16 Test (org.junit.Test)11 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 Config (org.neo4j.kernel.configuration.Config)5 GraphDatabaseFacadeFactory (org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory)5 File (java.io.File)4 Result (org.neo4j.graphdb.Result)4 PlatformModule (org.neo4j.kernel.impl.factory.PlatformModule)4 EnterpriseSecurityContext (org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext)3 Map (java.util.Map)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Transaction (org.neo4j.graphdb.Transaction)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)2 EditionModule (org.neo4j.kernel.impl.factory.EditionModule)2 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1