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);
}
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.");
}
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();
}
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);
}
}
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)));
}
Aggregations