Search in sources :

Example 6 with NamedDatabaseId

use of org.neo4j.kernel.database.NamedDatabaseId in project neo4j by neo4j.

the class DatabaseTransactionEventListenersTest method shouldUnregisterRemainingListenerOnShutdown.

@Test
void shouldUnregisterRemainingListenerOnShutdown() {
    // Given
    GlobalTransactionEventListeners globalListeners = mock(GlobalTransactionEventListeners.class);
    NamedDatabaseId databaseId = DatabaseIdFactory.from("foo", UUID.randomUUID());
    DatabaseTransactionEventListeners listeners = new DatabaseTransactionEventListeners(mock(GraphDatabaseFacade.class), globalListeners, databaseId);
    TransactionEventListener<?> firstListener = mock(TransactionEventListener.class);
    TransactionEventListener<?> secondListener = mock(TransactionEventListener.class);
    // When
    listeners.registerTransactionEventListener(firstListener);
    listeners.registerTransactionEventListener(secondListener);
    // Then
    verify(globalListeners).registerTransactionEventListener(databaseId.name(), firstListener);
    verify(globalListeners).registerTransactionEventListener(databaseId.name(), secondListener);
    verifyNoMoreInteractions(globalListeners);
    // When
    listeners.unregisterTransactionEventListener(firstListener);
    // Then
    verify(globalListeners).unregisterTransactionEventListener(databaseId.name(), firstListener);
    verifyNoMoreInteractions(globalListeners);
    // When
    listeners.shutdown();
    // Then
    verify(globalListeners).unregisterTransactionEventListener(databaseId.name(), secondListener);
    verifyNoMoreInteractions(globalListeners);
}
Also used : NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) Test(org.junit.jupiter.api.Test)

Example 7 with NamedDatabaseId

use of org.neo4j.kernel.database.NamedDatabaseId in project neo4j by neo4j.

the class DefaultDatabaseManagerUpgradeIT method upgradeDatabaseMustThrowOnFailure.

@Test
void upgradeDatabaseMustThrowOnFailure() {
    // Given
    RuntimeException expectedException = new RuntimeException("Dammit Leroy!");
    useThrowingMigrationLogProvider(expectedException);
    createDbms();
    GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
    DefaultDatabaseManager databaseManager = getDatabaseManager(db);
    RecordStoreVersionCheck check = new RecordStoreVersionCheck(fs, getPageCache(db), databaseLayout, NullLogProvider.getInstance(), Config.defaults(), NULL);
    assertFalse(db.isAvailable(100), "Expected database to have failed during startup because we don't allow upgrade.");
    // When
    NamedDatabaseId namedDatabaseId = db.databaseId();
    DatabaseManagementException e = assertThrows(DatabaseManagementException.class, () -> databaseManager.upgradeDatabase(namedDatabaseId));
    // Then
    assertThat(e).hasMessage("Failed to upgrade " + namedDatabaseId);
    assertThat(e).hasRootCause(expectedException);
    assertFalse(db.isAvailable(100), "Expected database to be available after upgrade");
    assertTrue(MigrationTestUtils.checkNeoStoreHasFormatVersion(check, StandardV3_4.RECORD_FORMATS), "Expected store not upgraded.");
}
Also used : DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) RecordStoreVersionCheck(org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) Test(org.junit.jupiter.api.Test)

Example 8 with NamedDatabaseId

use of org.neo4j.kernel.database.NamedDatabaseId in project neo4j by neo4j.

the class LocalGraphTransactionIdTracker method getNamedDatabaseId.

private NamedDatabaseId getNamedDatabaseId(Location.Local location) {
    DatabaseId databaseId = DatabaseIdFactory.from(location.getUuid());
    var namedDatabaseId = databaseIdRepository.getById(databaseId);
    if (namedDatabaseId.isEmpty()) {
        // this can only happen when the database has just been deleted or someone tempered with a bookmark
        throw new IllegalArgumentException("A local graph could not be mapped to a database");
    }
    return namedDatabaseId.get();
}
Also used : NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) DatabaseId(org.neo4j.kernel.database.DatabaseId)

Example 9 with NamedDatabaseId

use of org.neo4j.kernel.database.NamedDatabaseId in project neo4j by neo4j.

the class DatabaseConfigTest method shouldHandleRegisterDynamicUpdateListenersConcurrently.

@Test
void shouldHandleRegisterDynamicUpdateListenersConcurrently() throws Throwable {
    // given
    NamedDatabaseId namedDatabaseId = new TestDatabaseIdRepository().defaultDatabase();
    DatabaseConfig dbConfig = new DatabaseConfig(Collections.emptyMap(), Config.defaults(), namedDatabaseId);
    Setting<GraphDatabaseSettings.TransactionTracingLevel> setting = GraphDatabaseSettings.transaction_tracing_level;
    // big because we want to exercise what happens when the potentially backing List wants to grow
    int threads = 100;
    Listener[] listeners = new Listener[threads];
    for (int i = 0; i < threads; i++) {
        listeners[i] = new Listener();
    }
    // when
    Race race = new Race();
    for (int i = 0; i < threads; i++) {
        int slot = i;
        race.addContestant(() -> dbConfig.addListener(setting, listeners[slot]), 1);
    }
    race.go();
    // then
    dbConfig.setDynamic(setting, GraphDatabaseSettings.TransactionTracingLevel.DISABLED, getClass().getSimpleName());
    for (int i = 0; i < threads; i++) {
        assertEquals(1, listeners[i].callCount);
    }
}
Also used : SettingChangeListener(org.neo4j.configuration.SettingChangeListener) Race(org.neo4j.test.Race) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) Test(org.junit.jupiter.api.Test)

Example 10 with NamedDatabaseId

use of org.neo4j.kernel.database.NamedDatabaseId in project neo4j by neo4j.

the class CommunityDatabaseStateProcedureTest method shouldThrowWhenDatabaseNotFound.

@Test
void shouldThrowWhenDatabaseNotFound() throws ProcedureException {
    // given
    var existing = idRepository.getRaw("existing");
    var nonExisting = idRepository.getRaw("nonExisting");
    idRepository.filter(nonExisting.name());
    Map<NamedDatabaseId, DatabaseState> states = Map.of(existing, new CommunityDatabaseState(existing, true, false, null));
    var stateService = new StubDatabaseStateService(states, CommunityDatabaseState::unknown);
    var procedure = procedure(stateService);
    // when/then
    // Should not throw
    procedure.apply(mock(Context.class), new AnyValue[] { stringValue(existing.name()) }, mock(ResourceTracker.class));
    // Should throw
    assertThrows(ProcedureException.class, () -> procedure.apply(mock(Context.class), new AnyValue[] { stringValue(nonExisting.name()) }, mock(ResourceTracker.class)));
}
Also used : Context(org.neo4j.kernel.api.procedure.Context) DatabaseState(org.neo4j.dbms.DatabaseState) CommunityDatabaseState(org.neo4j.dbms.CommunityDatabaseState) CommunityDatabaseState(org.neo4j.dbms.CommunityDatabaseState) ResourceTracker(org.neo4j.kernel.api.ResourceTracker) StubDatabaseStateService(org.neo4j.dbms.StubDatabaseStateService) AnyValue(org.neo4j.values.AnyValue) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) Test(org.junit.jupiter.api.Test)

Aggregations

NamedDatabaseId (org.neo4j.kernel.database.NamedDatabaseId)13 Test (org.junit.jupiter.api.Test)7 HashMap (java.util.HashMap)3 DatabaseManagementException (org.neo4j.dbms.api.DatabaseManagementException)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 CommunityDatabaseState (org.neo4j.dbms.CommunityDatabaseState)2 DatabaseState (org.neo4j.dbms.DatabaseState)2 StubDatabaseStateService (org.neo4j.dbms.StubDatabaseStateService)2 DatabaseContext (org.neo4j.dbms.database.DatabaseContext)2 KernelTransactionHandle (org.neo4j.kernel.api.KernelTransactionHandle)2 ResourceTracker (org.neo4j.kernel.api.ResourceTracker)2 Context (org.neo4j.kernel.api.procedure.Context)2 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)2 DatabaseIdRepository (org.neo4j.kernel.database.DatabaseIdRepository)2 Description (org.neo4j.procedure.Description)2 Procedure (org.neo4j.procedure.Procedure)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 BoltIOException (org.neo4j.bolt.messaging.BoltIOException)1