Search in sources :

Example 21 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 22 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)

Example 23 with Monitors

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

the class TxPullRequestHandlerTest method shouldRespondWithCompleteStreamOfTransactions.

@Test
public void shouldRespondWithCompleteStreamOfTransactions() throws Exception {
    // given
    StoreId storeId = new StoreId(1, 2, 3, 4);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
    LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
    when(logicalTransactionStore.getTransactions(14L)).thenReturn(txCursor(cursor(tx(14), tx(15))));
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), NullLogProvider.getInstance());
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(13, storeId));
    // then
    verify(context, times(2)).write(ResponseMessageType.TX);
    verify(context).write(new TxPullResponse(storeId, tx(14)));
    verify(context).write(new TxPullResponse(storeId, tx(15)));
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(SUCCESS_END_OF_STREAM, 15L));
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreId(org.neo4j.causalclustering.identity.StoreId) Monitors(org.neo4j.kernel.monitoring.Monitors) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) CatchupServerProtocol(org.neo4j.causalclustering.catchup.CatchupServerProtocol) Test(org.junit.Test)

Example 24 with Monitors

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

the class TxPullRequestHandlerTest method shouldRespondWithEndOfStreamIfThereAreNoTransactions.

@Test
public void shouldRespondWithEndOfStreamIfThereAreNoTransactions() throws Exception {
    // given
    StoreId storeId = new StoreId(1, 2, 3, 4);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(14L);
    LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> storeId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), NullLogProvider.getInstance());
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(14, storeId));
    // then
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(SUCCESS_END_OF_STREAM, 14L));
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreId(org.neo4j.causalclustering.identity.StoreId) Monitors(org.neo4j.kernel.monitoring.Monitors) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) CatchupServerProtocol(org.neo4j.causalclustering.catchup.CatchupServerProtocol) Test(org.junit.Test)

Example 25 with Monitors

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

the class TxPullRequestHandlerTest method shouldNotStreamTxEntriesIfStoreIdMismatches.

@Test
public void shouldNotStreamTxEntriesIfStoreIdMismatches() throws Exception {
    // given
    StoreId serverStoreId = new StoreId(1, 2, 3, 4);
    StoreId clientStoreId = new StoreId(5, 6, 7, 8);
    TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
    when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(15L);
    LogicalTransactionStore logicalTransactionStore = mock(LogicalTransactionStore.class);
    TxPullRequestHandler txPullRequestHandler = new TxPullRequestHandler(new CatchupServerProtocol(), () -> serverStoreId, () -> true, () -> transactionIdStore, () -> logicalTransactionStore, BATCH_SIZE, new Monitors(), logProvider);
    // when
    txPullRequestHandler.channelRead0(context, new TxPullRequest(1, clientStoreId));
    // then
    verify(context, never()).write(ResponseMessageType.TX);
    verify(context).write(ResponseMessageType.TX_STREAM_FINISHED);
    verify(context).write(new TxStreamFinishedResponse(E_STORE_ID_MISMATCH, 15L));
    logProvider.assertAtLeastOnce(inLog(TxPullRequestHandler.class).info("Failed to serve TxPullRequest for tx %d and storeId %s because that storeId is different " + "from this machine with %s", 2L, clientStoreId, serverStoreId));
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreId(org.neo4j.causalclustering.identity.StoreId) Monitors(org.neo4j.kernel.monitoring.Monitors) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) CatchupServerProtocol(org.neo4j.causalclustering.catchup.CatchupServerProtocol) 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