Search in sources :

Example 56 with Monitors

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

the class BoltFailuresIT method throwsWhenMonitoredWorkerCreationFails.

@Test(timeout = TEST_TIMEOUT)
public void throwsWhenMonitoredWorkerCreationFails() {
    ThrowingSessionMonitor sessionMonitor = new ThrowingSessionMonitor();
    sessionMonitor.throwInSessionStarted();
    Monitors monitors = newMonitorsSpy(sessionMonitor);
    db = startDbWithBolt(new GraphDatabaseFactory().setMonitors(monitors));
    driver = createDriver();
    try {
        driver.session();
        fail("Exception expected");
    } catch (Exception e) {
        assertThat(e, instanceOf(ConnectionFailureException.class));
    }
}
Also used : GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) Monitors(org.neo4j.kernel.monitoring.Monitors) ConnectionFailureException(org.neo4j.driver.v1.exceptions.ConnectionFailureException) Test(org.junit.Test)

Example 57 with Monitors

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

the class BoltFailuresIT method newMonitorsSpy.

private static Monitors newMonitorsSpy(ThrowingSessionMonitor sessionMonitor) {
    Monitors monitors = spy(new Monitors());
    // it is not allowed to throw exceptions from monitors
    // make the given sessionMonitor be returned as is, without any proxying
    when(monitors.newMonitor(SessionMonitor.class)).thenReturn(sessionMonitor);
    when(monitors.hasListeners(SessionMonitor.class)).thenReturn(true);
    return monitors;
}
Also used : Monitors(org.neo4j.kernel.monitoring.Monitors)

Example 58 with Monitors

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

the class BoltFailuresIT method throwsWhenRunMessageFails.

private void throwsWhenRunMessageFails(Consumer<ThrowingSessionMonitor> monitorSetup) {
    ThrowingSessionMonitor sessionMonitor = new ThrowingSessionMonitor();
    Monitors monitors = newMonitorsSpy(sessionMonitor);
    db = startTestDb(monitors);
    driver = createDriver();
    Session session = driver.session();
    // setup monitor to throw before running the query to make processing of the RUN message fail
    monitorSetup.accept(sessionMonitor);
    session.run("CREATE ()");
    try {
        session.close();
        fail("Exception expected");
    } catch (Exception e) {
        assertThat(e, instanceOf(ConnectionFailureException.class));
    }
}
Also used : Monitors(org.neo4j.kernel.monitoring.Monitors) ConnectionFailureException(org.neo4j.driver.v1.exceptions.ConnectionFailureException) Session(org.neo4j.driver.v1.Session)

Example 59 with Monitors

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

the class BoltFailuresIT method throwsWhenInitMessageFails.

private void throwsWhenInitMessageFails(Consumer<ThrowingSessionMonitor> monitorSetup, boolean shouldBeAbleToGetSession) {
    ThrowingSessionMonitor sessionMonitor = new ThrowingSessionMonitor();
    monitorSetup.accept(sessionMonitor);
    Monitors monitors = newMonitorsSpy(sessionMonitor);
    db = startTestDb(monitors);
    driver = createDriver();
    try (Session session = driver.session()) {
        if (shouldBeAbleToGetSession) {
            session.run("CREATE ()").consume();
        } else {
            fail("Exception expected");
        }
    } catch (Exception e) {
        assertThat(e, instanceOf(ConnectionFailureException.class));
    }
}
Also used : Monitors(org.neo4j.kernel.monitoring.Monitors) ConnectionFailureException(org.neo4j.driver.v1.exceptions.ConnectionFailureException) Session(org.neo4j.driver.v1.Session)

Example 60 with Monitors

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

the class CoreBootstrapper method appendNullTransactionLogEntryToSetRaftIndexToMinusOne.

private void appendNullTransactionLogEntryToSetRaftIndexToMinusOne() throws IOException {
    PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fs);
    ReadOnlyLogVersionRepository logVersionRepository = new ReadOnlyLogVersionRepository(pageCache, storeDir);
    ReadOnlyTransactionIdStore readOnlyTransactionIdStore = new ReadOnlyTransactionIdStore(pageCache, storeDir);
    PhysicalLogFile logFile = new PhysicalLogFile(fs, logFiles, Long.MAX_VALUE, /*don't rotate*/
    () -> readOnlyTransactionIdStore.getLastClosedTransactionId() - 1, logVersionRepository, new Monitors().newMonitor(PhysicalLogFile.Monitor.class), new LogHeaderCache(10));
    long dummyTransactionId;
    try (Lifespan lifespan = new Lifespan(logFile)) {
        FlushableChannel channel = logFile.getWriter();
        TransactionLogWriter writer = new TransactionLogWriter(new LogEntryWriter(channel));
        long lastCommittedTransactionId = readOnlyTransactionIdStore.getLastCommittedTransactionId();
        PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(Collections.emptyList());
        byte[] txHeaderBytes = LogIndexTxHeaderEncoding.encodeLogIndexAsTxHeader(-1);
        tx.setHeader(txHeaderBytes, -1, -1, -1, lastCommittedTransactionId, -1, -1);
        dummyTransactionId = lastCommittedTransactionId + 1;
        writer.append(tx, dummyTransactionId);
        channel.prepareForFlush().flush();
    }
    File neoStoreFile = new File(storeDir, MetaDataStore.DEFAULT_NAME);
    MetaDataStore.setRecord(pageCache, neoStoreFile, LAST_TRANSACTION_ID, dummyTransactionId);
}
Also used : PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) ReadOnlyTransactionIdStore(org.neo4j.kernel.impl.transaction.log.ReadOnlyTransactionIdStore) FlushableChannel(org.neo4j.kernel.impl.transaction.log.FlushableChannel) Monitors(org.neo4j.kernel.monitoring.Monitors) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) ReadOnlyLogVersionRepository(org.neo4j.kernel.impl.transaction.log.ReadOnlyLogVersionRepository) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation)

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