Search in sources :

Example 1 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class MonitoredBoltWorkerFactoryTest method shouldReportStartedSessions.

@Test
public void shouldReportStartedSessions() {
    int workersCount = 42;
    Monitors monitors = new Monitors();
    CountingSessionMonitor monitor = new CountingSessionMonitor();
    monitors.addMonitorListener(monitor);
    WorkerFactory mockWorkers = mock(WorkerFactory.class);
    when(mockWorkers.newWorker(anyObject(), any())).thenReturn(mock(BoltWorker.class));
    MonitoredWorkerFactory workerFactory = new MonitoredWorkerFactory(monitors, mockWorkers, systemClock());
    for (int i = 0; i < workersCount; i++) {
        workerFactory.newWorker(CONNECTION_DESCRIPTOR);
    }
    assertEquals(workersCount, monitor.sessionsStarted);
}
Also used : MonitoredBoltWorker(org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory.MonitoredBoltWorker) Monitors(org.neo4j.kernel.monitoring.Monitors) Test(org.junit.Test)

Example 2 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class MonitoredBoltWorkerFactoryTest method shouldNotWrapWithMonitoredSessionIfNobodyIsListening.

@Test
public void shouldNotWrapWithMonitoredSessionIfNobodyIsListening() throws Throwable {
    // Given
    // Monitoring adds GC overhead, so we only want to do the work involved
    // if someone has actually registered a listener. We still allow plugging
    // monitoring in at runtime, but it will only apply to sessions started
    // after monitor listeners are added
    WorkerFactory workerFactory = mock(WorkerFactory.class);
    BoltWorker innerSession = mock(BoltWorker.class);
    when(workerFactory.newWorker(anyObject(), anyObject())).thenReturn(innerSession);
    Monitors monitors = new Monitors();
    MonitoredWorkerFactory monitoredWorkerFactory = new MonitoredWorkerFactory(monitors, workerFactory, Clocks.fakeClock());
    // When
    BoltWorker worker = monitoredWorkerFactory.newWorker(CONNECTION_DESCRIPTOR);
    // Then
    assertEquals(innerSession, worker);
    // But when I register a listener
    monitors.addMonitorListener(new CountingSessionMonitor());
    // Then new sessions should be monitored
    assertThat(monitoredWorkerFactory.newWorker(CONNECTION_DESCRIPTOR), instanceOf(MonitoredBoltWorker.class));
}
Also used : MonitoredBoltWorker(org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory.MonitoredBoltWorker) Monitors(org.neo4j.kernel.monitoring.Monitors) MonitoredBoltWorker(org.neo4j.bolt.v1.runtime.MonitoredWorkerFactory.MonitoredBoltWorker) Test(org.junit.Test)

Example 3 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class CommunityCypherEngineProvider method createEngine.

@Override
protected QueryExecutionEngine createEngine(Dependencies deps, GraphDatabaseAPI graphAPI) {
    GraphDatabaseCypherService queryService = new GraphDatabaseCypherService(graphAPI);
    deps.satisfyDependency(queryService);
    DependencyResolver resolver = graphAPI.getDependencyResolver();
    LogService logService = resolver.resolveDependency(LogService.class);
    KernelAPI kernelAPI = resolver.resolveDependency(KernelAPI.class);
    Monitors monitors = resolver.resolveDependency(Monitors.class);
    LogProvider logProvider = logService.getInternalLogProvider();
    CommunityCompatibilityFactory compatibilityFactory = new CommunityCompatibilityFactory(queryService, kernelAPI, monitors, logProvider);
    deps.satisfyDependencies(compatibilityFactory);
    return new ExecutionEngine(queryService, logProvider, compatibilityFactory);
}
Also used : LogProvider(org.neo4j.logging.LogProvider) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) Monitors(org.neo4j.kernel.monitoring.Monitors) CommunityCompatibilityFactory(org.neo4j.cypher.internal.CommunityCompatibilityFactory) GraphDatabaseCypherService(org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService) KernelAPI(org.neo4j.kernel.api.KernelAPI) LogService(org.neo4j.kernel.impl.logging.LogService) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 4 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class ExecutionEngineTests method shouldConvertListsAndMapsWhenPassingFromScalaToJava.

@Test
public void shouldConvertListsAndMapsWhenPassingFromScalaToJava() throws Exception {
    GraphDatabaseQueryService graph = new GraphDatabaseCypherService(this.database.getGraphDatabaseAPI());
    KernelAPI kernelAPI = graph.getDependencyResolver().resolveDependency(KernelAPI.class);
    Monitors monitors = graph.getDependencyResolver().resolveDependency(Monitors.class);
    NullLogProvider nullLogProvider = NullLogProvider.getInstance();
    CommunityCompatibilityFactory compatibilityFactory = new CommunityCompatibilityFactory(graph, kernelAPI, monitors, nullLogProvider);
    ExecutionEngine executionEngine = new ExecutionEngine(graph, nullLogProvider, compatibilityFactory);
    Result result;
    try (InternalTransaction tx = graph.beginTransaction(KernelTransaction.Type.implicit, SecurityContext.AUTH_DISABLED)) {
        String query = "RETURN { key : 'Value' , collectionKey: [{ inner: 'Map1' }, { inner: 'Map2' }]}";
        TransactionalContext tc = createTransactionContext(graph, tx, query);
        result = executionEngine.executeQuery(query, NO_PARAMS, tc);
        tx.success();
    }
    Map firstRowValue = (Map) result.next().values().iterator().next();
    assertThat(firstRowValue.get("key"), is("Value"));
    List theList = (List) firstRowValue.get("collectionKey");
    assertThat(((Map) theList.get(0)).get("inner"), is("Map1"));
    assertThat(((Map) theList.get(1)).get("inner"), is("Map2"));
}
Also used : GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) GraphDatabaseCypherService(org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Monitors(org.neo4j.kernel.monitoring.Monitors) NullLogProvider(org.neo4j.logging.NullLogProvider) CommunityCompatibilityFactory(org.neo4j.cypher.internal.CommunityCompatibilityFactory) List(java.util.List) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) KernelAPI(org.neo4j.kernel.api.KernelAPI) Map(java.util.Map) Test(org.junit.Test)

Example 5 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class PhysicalLogicalTransactionStoreTest method shouldOpenCleanStore.

@Test
public void shouldOpenCleanStore() throws Exception {
    // GIVEN
    TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
    TransactionMetadataCache positionCache = new TransactionMetadataCache(1000);
    LogHeaderCache logHeaderCache = new LogHeaderCache(10);
    LifeSupport life = new LifeSupport();
    PhysicalLogFiles logFiles = new PhysicalLogFiles(testDir, DEFAULT_NAME, fileSystemRule.get());
    Monitor monitor = new Monitors().newMonitor(PhysicalLogFile.Monitor.class);
    LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
    life.add(new BatchingTransactionAppender(logFile, NO_ROTATION, positionCache, transactionIdStore, BYPASS, DATABASE_HEALTH));
    try {
        // WHEN
        life.start();
    } finally {
        life.shutdown();
    }
}
Also used : DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) Monitor(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor) Monitors(org.neo4j.kernel.monitoring.Monitors) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Test(org.junit.Test)

Aggregations

Monitors (org.neo4j.kernel.monitoring.Monitors)79 Test (org.junit.Test)53 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)12 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)11 File (java.io.File)10 ByteBuffer (java.nio.ByteBuffer)9 StoreId (org.neo4j.causalclustering.identity.StoreId)9 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)9 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)9 ByteCounterMonitor (org.neo4j.kernel.monitoring.ByteCounterMonitor)9 IOException (java.io.IOException)8 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)8 BlockLogBuffer (org.neo4j.com.BlockLogBuffer)8 Config (org.neo4j.kernel.configuration.Config)8 PageCache (org.neo4j.io.pagecache.PageCache)7 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)7 DependencyResolver (org.neo4j.graphdb.DependencyResolver)6 URI (java.net.URI)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)5