use of org.neo4j.kernel.database.TestDatabaseIdRepository in project neo4j by neo4j.
the class DefaultBoltProtocolFactoryTest method shouldCreateBoltProtocol.
@ParameterizedTest(name = "V{0}.{1}")
@CsvSource({ "3, 0", "4, 0", "4, 1", "4, 2", "4, 3" })
void shouldCreateBoltProtocol(int majorVersion, int minorVersion) throws Throwable {
EmbeddedChannel channel = new EmbeddedChannel();
BoltChannel boltChannel = newTestBoltChannel(channel);
BoltProtocolVersion boltProtocolVersion = new BoltProtocolVersion(majorVersion, minorVersion);
BoltStateMachineFactory stateMachineFactory = mock(BoltStateMachineFactory.class);
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
var channelProtector = mock(ChannelProtector.class);
var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
when(stateMachineFactory.newStateMachine(boltProtocolVersion, boltChannel, MapValue.EMPTY, memoryTracker)).thenReturn(stateMachine);
BoltConnectionFactory connectionFactory = mock(BoltConnectionFactory.class);
BoltConnection connection = mock(BoltConnection.class);
when(connectionFactory.newConnection(eq(boltChannel), eq(stateMachine), any())).thenReturn(connection);
BoltProtocolFactory factory = new DefaultBoltProtocolFactory(connectionFactory, stateMachineFactory, Config.defaults(), NullLogService.getInstance(), new TestDatabaseIdRepository(), CustomBookmarkFormatParser.DEFAULT, mock(TransportThrottleGroup.class), Clocks.fakeClock(), Duration.ZERO);
BoltProtocol protocol = factory.create(boltProtocolVersion, boltChannel, channelProtector, memoryTracker);
protocol.install();
// handler with correct version is created
assertEquals(boltProtocolVersion, protocol.version());
// it uses the expected worker
verify(connectionFactory).newConnection(eq(boltChannel), any(BoltStateMachine.class), any(BoltResponseMessageWriter.class));
verify(memoryTracker, times(5)).allocateHeap(anyLong());
// and halts this same worker when closed
verify(connection, never()).stop();
channel.close();
verify(connection).stop();
channel.finishAndReleaseAll();
}
use of org.neo4j.kernel.database.TestDatabaseIdRepository in project neo4j by neo4j.
the class DefaultBoltProtocolFactoryTest method shouldCreateNothingForUnknownProtocolVersion.
@Test
void shouldCreateNothingForUnknownProtocolVersion() {
int protocolVersion = 42;
BoltChannel channel = newTestBoltChannel();
BoltProtocolFactory factory = new DefaultBoltProtocolFactory(mock(BoltConnectionFactory.class), mock(BoltStateMachineFactory.class), Config.defaults(), NullLogService.getInstance(), new TestDatabaseIdRepository(), CustomBookmarkFormatParser.DEFAULT, mock(TransportThrottleGroup.class), Clocks.fakeClock(), Duration.ZERO);
BoltProtocol protocol = factory.create(new BoltProtocolVersion(protocolVersion, 0), channel, mock(ChannelProtector.class), mock(MemoryTracker.class));
// handler is not created
assertNull(protocol);
}
use of org.neo4j.kernel.database.TestDatabaseIdRepository in project neo4j by neo4j.
the class KernelTransactionFactory method kernelTransactionWithInternals.
private static Instances kernelTransactionWithInternals(LoginContext loginContext) {
StorageEngine storageEngine = mock(StorageEngine.class);
StorageReader storageReader = mock(StorageReader.class);
when(storageEngine.newReader()).thenReturn(storageReader);
when(storageEngine.newCommandCreationContext(any())).thenReturn(mock(CommandCreationContext.class));
Dependencies dependencies = new Dependencies();
dependencies.satisfyDependency(mock(GraphDatabaseFacade.class));
KernelTransactionImplementation transaction = new KernelTransactionImplementation(Config.defaults(), mock(DatabaseTransactionEventListeners.class), mock(ConstraintIndexCreator.class), mock(GlobalProcedures.class), mock(InternalTransactionCommitProcess.class), mock(TransactionMonitor.class), mock(Pool.class), Clocks.nanoClock(), new AtomicReference<>(CpuClock.NOT_AVAILABLE), mock(DatabaseTracers.class, RETURNS_MOCKS), storageEngine, any -> CanWrite.INSTANCE, EmptyVersionContextSupplier.EMPTY, ON_HEAP, new StandardConstraintSemantics(), mock(SchemaState.class), mockedTokenHolders(), mock(IndexingService.class), mock(IndexStatisticsStore.class), dependencies, new TestDatabaseIdRepository().defaultDatabase(), LeaseService.NO_LEASES, MemoryPools.NO_TRACKING, DatabaseReadOnlyChecker.writable(), TransactionExecutionMonitor.NO_OP, CommunitySecurityLog.NULL_LOG, () -> KernelVersion.LATEST, mock(DbmsRuntimeRepository.class));
transaction.initialize(0, 0, new NoOpClient(), KernelTransaction.Type.IMPLICIT, loginContext.authorize(LoginContext.IdLookup.EMPTY, DEFAULT_DATABASE_NAME, CommunitySecurityLog.NULL_LOG), 0L, 1L, EMBEDDED_CONNECTION);
return new Instances(transaction);
}
use of org.neo4j.kernel.database.TestDatabaseIdRepository 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.TestDatabaseIdRepository in project neo4j by neo4j.
the class KernelTransactionImplementationTest method shouldThrowWhenCreatingTxStateWithReadOnlyDatabase.
@Test
void shouldThrowWhenCreatingTxStateWithReadOnlyDatabase() {
// given
var fooName = "foo";
var fooDb = new TestDatabaseIdRepository().getRaw(fooName);
var configValues = Map.of(read_only_database_default, false, read_only_databases, Set.of(fooName));
var config = Config.defaults(configValues);
var transaction = newNotInitializedTransaction(config, fooDb);
transaction.initialize(0, BASE_TX_COMMIT_TIMESTAMP, mock(Locks.Client.class), KernelTransaction.Type.IMPLICIT, mock(SecurityContext.class), 0, 1L, EMBEDDED_CONNECTION);
// when / then
var rte = assertThrows(RuntimeException.class, transaction::txState);
assertThat(rte).hasCauseInstanceOf(ReadOnlyDbException.class);
}
Aggregations