Search in sources :

Example 16 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class HttpTransactionManagerTest method shouldGetEmptyTransactionFacadeForUnknownDatabase.

@Test
void shouldGetEmptyTransactionFacadeForUnknownDatabase() {
    DatabaseManagementService managementService = mock(DatabaseManagementService.class);
    var memoryPool = mock(MemoryPool.class);
    var manager = newTransactionManager(managementService, memoryPool);
    var transactionFacade = manager.getGraphDatabaseAPI("foo");
    assertFalse(transactionFacade.isPresent());
    verify(managementService).database("foo");
}
Also used : DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 17 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class BoltStateMachineFactoryImplTest method newDbMock.

private static DatabaseManagementService newDbMock() {
    GraphDatabaseFacade db = mock(GraphDatabaseFacade.class);
    DependencyResolver dependencyResolver = mock(DependencyResolver.class);
    when(db.getDependencyResolver()).thenReturn(dependencyResolver);
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    when(queryService.getDependencyResolver()).thenReturn(dependencyResolver);
    when(dependencyResolver.resolveDependency(GraphDatabaseQueryService.class)).thenReturn(queryService);
    DatabaseManagementService managementService = mock(DatabaseManagementService.class);
    when(managementService.database(CUSTOM_DB_NAME)).thenReturn(db);
    return managementService;
}
Also used : GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) DependencyResolver(org.neo4j.common.DependencyResolver)

Example 18 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class DefaultDatabaseTransactionStateMachineSPIProviderTest method shouldErrorIfDatabaseNotFound.

@Test
void shouldErrorIfDatabaseNotFound() {
    DatabaseManagementService managementService = managementServiceWithDatabase("database");
    TransactionStateMachineSPIProvider spiProvider = newSpiProvider(managementService);
    BoltProtocolBreachFatality error = assertThrows(BoltProtocolBreachFatality.class, () -> spiProvider.getTransactionStateMachineSPI("database", mock(StatementProcessorReleaseManager.class)));
    assertThat(error.getMessage()).contains("Database selection by name not supported by Bolt protocol version lower than BoltV4.");
}
Also used : DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) TransactionStateMachineSPIProvider(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPIProvider) BoltProtocolBreachFatality(org.neo4j.bolt.runtime.BoltProtocolBreachFatality) Test(org.junit.jupiter.api.Test)

Example 19 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class DefaultDatabaseTransactionStateMachineSPIProviderTest method managementServiceWithDatabase.

private DatabaseManagementService managementServiceWithDatabase(String databaseName) {
    DatabaseManagementService managementService = mock(DatabaseManagementService.class);
    GraphDatabaseFacade databaseFacade = mock(GraphDatabaseFacade.class);
    when(databaseFacade.isAvailable(anyLong())).thenReturn(true);
    when(managementService.database(databaseName)).thenReturn(databaseFacade);
    DependencyResolver dependencyResolver = mock(DependencyResolver.class);
    when(databaseFacade.getDependencyResolver()).thenReturn(dependencyResolver);
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    when(dependencyResolver.resolveDependency(GraphDatabaseQueryService.class)).thenReturn(queryService);
    when(queryService.getDependencyResolver()).thenReturn(dependencyResolver);
    when(dependencyResolver.resolveDependency(Database.class)).thenReturn(mock(Database.class));
    when(mockBoltChannel.defaultDatabase()).thenReturn("neo4j");
    return managementService;
}
Also used : GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Database(org.neo4j.kernel.database.Database) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) DependencyResolver(org.neo4j.common.DependencyResolver)

Example 20 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class FulltextIndexConsistencyCheckIT method mustDiscoverNodeInIndexMissingFromStore.

@Disabled("Turns out that this is not something that the consistency checker actually looks for, currently. " + "The test is disabled until the consistency checker is extended with checks that will discover this sort of inconsistency.")
@Test
void mustDiscoverNodeInIndexMissingFromStore() throws Exception {
    GraphDatabaseService db = createDatabase();
    try (Transaction tx = db.beginTx()) {
        tx.execute(format(NODE_CREATE, "nodes", asStrList("Label"), asStrList("prop"))).close();
        tx.commit();
    }
    long nodeId;
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
        Node node = tx.createNode(Label.label("Label"));
        nodeId = node.getId();
        node.setProperty("prop", "value");
        tx.commit();
    }
    // Remove the property without updating the index
    managementService.shutdown();
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setFileSystem(fs).removeExtensions(INDEX_PROVIDERS_FILTER).addExtension(new FailingGenericNativeIndexProviderFactory(SKIP_ONLINE_UPDATES)).addExtension(new TokenIndexProviderFactory()).build();
    db = managementService.database(DEFAULT_DATABASE_NAME);
    try (Transaction tx = db.beginTx()) {
        tx.getNodeById(nodeId).removeProperty("prop");
        tx.commit();
    }
    managementService.shutdown();
    ConsistencyCheckService.Result result = checkConsistency();
    assertFalse(result.isSuccessful());
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) TokenIndexProviderFactory(org.neo4j.kernel.impl.index.schema.TokenIndexProviderFactory) FailingGenericNativeIndexProviderFactory(org.neo4j.kernel.impl.index.schema.FailingGenericNativeIndexProviderFactory) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)155 Test (org.junit.jupiter.api.Test)100 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)79 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)61 Transaction (org.neo4j.graphdb.Transaction)60 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)56 Path (java.nio.file.Path)37 Node (org.neo4j.graphdb.Node)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Label (org.neo4j.graphdb.Label)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)9 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)9 DatabaseStateService (org.neo4j.dbms.DatabaseStateService)8 Config (org.neo4j.configuration.Config)7 DatabaseManagementServiceBuilder (org.neo4j.dbms.api.DatabaseManagementServiceBuilder)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 GBPTreeCountsStore (org.neo4j.internal.counts.GBPTreeCountsStore)6 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)6