Search in sources :

Example 1 with TestDatabaseIdRepository

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();
}
Also used : BoltResponseMessageWriter(org.neo4j.bolt.messaging.BoltResponseMessageWriter) BoltConnectionFactory(org.neo4j.bolt.runtime.BoltConnectionFactory) BoltStateMachineFactory(org.neo4j.bolt.runtime.statemachine.BoltStateMachineFactory) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) BoltProtocol(org.neo4j.bolt.BoltProtocol) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion) BoltChannel(org.neo4j.bolt.BoltChannel) BoltTestUtil.newTestBoltChannel(org.neo4j.bolt.testing.BoltTestUtil.newTestBoltChannel) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TestDatabaseIdRepository

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);
}
Also used : ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) BoltConnectionFactory(org.neo4j.bolt.runtime.BoltConnectionFactory) BoltProtocol(org.neo4j.bolt.BoltProtocol) BoltStateMachineFactory(org.neo4j.bolt.runtime.statemachine.BoltStateMachineFactory) BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion) BoltChannel(org.neo4j.bolt.BoltChannel) BoltTestUtil.newTestBoltChannel(org.neo4j.bolt.testing.BoltTestUtil.newTestBoltChannel) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) MemoryTracker(org.neo4j.memory.MemoryTracker) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with TestDatabaseIdRepository

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);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) DatabaseTracers(org.neo4j.kernel.database.DatabaseTracers) DbmsRuntimeRepository(org.neo4j.dbms.database.DbmsRuntimeRepository) StorageEngine(org.neo4j.storageengine.api.StorageEngine) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) SchemaState(org.neo4j.internal.schema.SchemaState) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) DatabaseTransactionEventListeners(org.neo4j.kernel.internal.event.DatabaseTransactionEventListeners) Pool(org.neo4j.collection.pool.Pool) Dependencies(org.neo4j.collection.Dependencies) InternalTransactionCommitProcess(org.neo4j.kernel.impl.api.InternalTransactionCommitProcess) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) TransactionMonitor(org.neo4j.kernel.impl.transaction.TransactionMonitor) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics)

Example 4 with TestDatabaseIdRepository

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);
    }
}
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 5 with TestDatabaseIdRepository

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);
}
Also used : SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TestDatabaseIdRepository (org.neo4j.kernel.database.TestDatabaseIdRepository)5 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 BoltChannel (org.neo4j.bolt.BoltChannel)2 BoltProtocol (org.neo4j.bolt.BoltProtocol)2 BoltProtocolVersion (org.neo4j.bolt.BoltProtocolVersion)2 BoltConnectionFactory (org.neo4j.bolt.runtime.BoltConnectionFactory)2 BoltStateMachineFactory (org.neo4j.bolt.runtime.statemachine.BoltStateMachineFactory)2 BoltTestUtil.newTestBoltChannel (org.neo4j.bolt.testing.BoltTestUtil.newTestBoltChannel)2 NoOpClient (org.neo4j.kernel.impl.locking.NoOpClient)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1 BoltResponseMessageWriter (org.neo4j.bolt.messaging.BoltResponseMessageWriter)1 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)1 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)1 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)1 Dependencies (org.neo4j.collection.Dependencies)1 Pool (org.neo4j.collection.pool.Pool)1 SettingChangeListener (org.neo4j.configuration.SettingChangeListener)1 DbmsRuntimeRepository (org.neo4j.dbms.database.DbmsRuntimeRepository)1