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));
}
}
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;
}
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));
}
}
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));
}
}
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);
}
Aggregations