Search in sources :

Example 66 with DatabaseManagementService

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

the class DatabaseRecoveryIT method shouldRecoverIdsCorrectlyWhenWeCreateAndDeleteANodeInTheSameRecoveryRun.

@Test
void shouldRecoverIdsCorrectlyWhenWeCreateAndDeleteANodeInTheSameRecoveryRun() throws IOException {
    GraphDatabaseService database = startDatabase(directory.homePath());
    Label testLabel = Label.label("testLabel");
    final String propertyToDelete = "propertyToDelete";
    final String validPropertyName = "validProperty";
    try (Transaction transaction = database.beginTx()) {
        Node node = transaction.createNode();
        node.addLabel(testLabel);
        transaction.commit();
    }
    try (Transaction transaction = database.beginTx()) {
        Node node = findNodeByLabel(transaction, testLabel);
        node.setProperty(propertyToDelete, createLongString());
        node.setProperty(validPropertyName, createLongString());
        transaction.commit();
    }
    try (Transaction transaction = database.beginTx()) {
        Node node = findNodeByLabel(transaction, testLabel);
        node.removeProperty(propertyToDelete);
        transaction.commit();
    }
    // copying only transaction log simulate non clean shutdown db that should be able to recover just from logs
    var restoreDbLayout = copyStore();
    // database should be restored and node should have expected properties
    DatabaseManagementService recoveredService = getManagementService(restoreDbLayout.getNeo4jLayout().homeDirectory());
    GraphDatabaseService recoveredDatabase = recoveredService.database(DEFAULT_DATABASE_NAME);
    try (Transaction transaction = recoveredDatabase.beginTx()) {
        Node node = findNodeByLabel(transaction, testLabel);
        assertFalse(node.hasProperty(propertyToDelete));
        assertTrue(node.hasProperty(validPropertyName));
    }
    recoveredService.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 67 with DatabaseManagementService

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

the class TransactionStateMachineSPIProviderV4Test method shouldReturnTransactionStateMachineSPIIfDatabaseExists.

@Test
void shouldReturnTransactionStateMachineSPIIfDatabaseExists() throws Throwable {
    String databaseName = "database";
    DatabaseManagementService managementService = managementService(databaseName);
    TransactionStateMachineSPIProvider spiProvider = newSpiProvider(managementService);
    TransactionStateMachineSPI spi = spiProvider.getTransactionStateMachineSPI(databaseName, mock(StatementProcessorReleaseManager.class));
    assertThat(spi).isInstanceOf(TransactionStateMachineV4SPI.class);
}
Also used : StatementProcessorReleaseManager(org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) TransactionStateMachineSPIProvider(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPIProvider) Test(org.junit.jupiter.api.Test)

Example 68 with DatabaseManagementService

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

the class TransactionStateMachineSPIProviderV4Test method shouldAllocateMemoryForTransactionStateMachineSPI.

@Test
void shouldAllocateMemoryForTransactionStateMachineSPI() throws BoltProtocolBreachFatality, BoltIOException {
    String databaseName = "neo4j";
    var clock = mock(SystemNanoClock.class);
    DatabaseManagementService managementService = managementService(databaseName);
    var memoryTracker = mock(MemoryTracker.class);
    var scopedMemoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
    when(mockBoltChannel.defaultDatabase()).thenReturn("neo4j");
    when(memoryTracker.getScopedMemoryTracker()).thenReturn(scopedMemoryTracker);
    var dbProvider = new BoltKernelDatabaseManagementServiceProvider(managementService, new Monitors(), clock, Duration.ZERO);
    var spiProvider = new TransactionStateMachineSPIProviderV4(dbProvider, mockBoltChannel, clock, memoryTracker);
    spiProvider.getTransactionStateMachineSPI("", mock(StatementProcessorReleaseManager.class));
    verify(memoryTracker).getScopedMemoryTracker();
    verify(scopedMemoryTracker).allocateHeap(TransactionStateMachineV4SPI.SHALLOW_SIZE);
    verify(scopedMemoryTracker).allocateHeap(BoltKernelGraphDatabaseServiceProvider.SHALLOW_SIZE);
    verify(scopedMemoryTracker).getScopedMemoryTracker();
    verifyNoMoreInteractions(memoryTracker);
    verifyNoMoreInteractions(scopedMemoryTracker);
}
Also used : StatementProcessorReleaseManager(org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager) BoltKernelDatabaseManagementServiceProvider(org.neo4j.bolt.dbapi.impl.BoltKernelDatabaseManagementServiceProvider) Monitors(org.neo4j.monitoring.Monitors) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 69 with DatabaseManagementService

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

the class ManyPropertyKeysIT method concurrently_creating_same_property_key_in_different_transactions_should_end_up_with_same_key_id.

@Test
void concurrently_creating_same_property_key_in_different_transactions_should_end_up_with_same_key_id() throws Exception {
    // GIVEN
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
    GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    Worker worker1 = new Worker("w1", db);
    Worker worker2 = new Worker("w2", db);
    worker1.beginTx();
    worker2.beginTx();
    // WHEN
    String key = "mykey";
    worker1.setProperty(key);
    worker2.setProperty(key);
    worker1.commit();
    worker2.commit();
    worker1.close();
    worker2.close();
    // THEN
    assertEquals(1, propertyKeyCount(db));
    managementService.shutdown();
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 70 with DatabaseManagementService

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

the class TestConcurrentRelationshipChainLoadingIssue method tryToTriggerRelationshipLoadingStoppingMidWay.

private void tryToTriggerRelationshipLoadingStoppingMidWay(int denseNodeThreshold) throws Throwable {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder().impermanent().setConfig(dense_node_threshold, denseNodeThreshold).build();
    GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    Node node = createNodeWithRelationships(db);
    checkStateToHelpDiagnoseFlakyTest(db, node);
    long end = currentTimeMillis() + SECONDS.toMillis(5);
    int iterations = 0;
    while (currentTimeMillis() < end && iterations < 100) {
        tryOnce(db, node);
        iterations++;
    }
    managementService.shutdown();
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Node(org.neo4j.graphdb.Node) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

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