use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class TestBlockLogBuffer method canWriteReallyLargeByteArray.
@Test
public void canWriteReallyLargeByteArray() throws Exception {
byte[] bytes = new byte[650];
ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
wrappedBuffer.resetWriterIndex();
BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, new Monitors().newMonitor(ByteCounterMonitor.class));
byte[] bytesValue = new byte[600];
bytesValue[1] = 1;
bytesValue[99] = 2;
bytesValue[199] = 3;
bytesValue[299] = 4;
bytesValue[399] = 5;
bytesValue[499] = 6;
bytesValue[599] = 7;
buffer.put(bytesValue, bytesValue.length);
buffer.close();
byte[] actual;
ByteBuffer verificationBuffer = ByteBuffer.wrap(bytes);
assertEquals((byte) 0, verificationBuffer.get());
actual = new byte[255];
verificationBuffer.get(actual);
assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 0, 255)));
assertEquals((byte) 0, verificationBuffer.get());
actual = new byte[255];
verificationBuffer.get(actual);
assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 255, 510)));
assertEquals((byte) 90, verificationBuffer.get());
actual = new byte[90];
verificationBuffer.get(actual);
assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 510, 600)));
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class TestBlockLogBuffer method readSmallPortions.
@Test
public void readSmallPortions() throws IOException {
byte[] bytes = new byte[255];
ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
wrappedBuffer.resetWriterIndex();
BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, new Monitors().newMonitor(ByteCounterMonitor.class));
byte byteValue = 5;
int intValue = 1234;
long longValue = 574853;
buffer.put(byteValue);
buffer.putInt(intValue);
buffer.putLong(longValue);
buffer.close();
ReadableByteChannel reader = new BlockLogReader(wrappedBuffer);
ByteBuffer verificationBuffer = ByteBuffer.wrap(new byte[1]);
reader.read(verificationBuffer);
verificationBuffer.flip();
assertEquals(byteValue, verificationBuffer.get());
verificationBuffer = ByteBuffer.wrap(new byte[4]);
reader.read(verificationBuffer);
verificationBuffer.flip();
assertEquals(intValue, verificationBuffer.getInt());
verificationBuffer = ByteBuffer.wrap(new byte[8]);
reader.read(verificationBuffer);
verificationBuffer.flip();
assertEquals(longValue, verificationBuffer.getLong());
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class QueryLoggerKernelExtension method newInstance.
@Override
public Lifecycle newInstance(@SuppressWarnings("unused") KernelContext context, final Dependencies dependencies) throws Throwable {
final Config config = dependencies.config();
boolean queryLogEnabled = config.get(GraphDatabaseSettings.log_queries);
final File queryLogFile = config.get(GraphDatabaseSettings.log_queries_filename);
final FileSystemAbstraction fileSystem = dependencies.fileSystem();
final JobScheduler jobScheduler = dependencies.jobScheduler();
final Monitors monitoring = dependencies.monitoring();
if (!queryLogEnabled) {
return createEmptyAdapter();
}
return new LifecycleAdapter() {
Closeable closable;
@Override
public void init() throws Throwable {
Long thresholdMillis = config.get(GraphDatabaseSettings.log_queries_threshold);
Long rotationThreshold = config.get(GraphDatabaseSettings.log_queries_rotation_threshold);
int maxArchives = config.get(GraphDatabaseSettings.log_queries_max_archives);
boolean logQueryParameters = config.get(GraphDatabaseSettings.log_queries_parameter_logging_enabled);
FormattedLog.Builder logBuilder = FormattedLog.withUTCTimeZone();
Log log;
if (rotationThreshold == 0) {
OutputStream logOutputStream = createOrOpenAsOuputStream(fileSystem, queryLogFile, true);
log = logBuilder.toOutputStream(logOutputStream);
closable = logOutputStream;
} else {
RotatingFileOutputStreamSupplier rotatingSupplier = new RotatingFileOutputStreamSupplier(fileSystem, queryLogFile, rotationThreshold, 0, maxArchives, jobScheduler.executor(JobScheduler.Groups.queryLogRotation));
log = logBuilder.toOutputStream(rotatingSupplier);
closable = rotatingSupplier;
}
QueryLogger logger = new QueryLogger(Clocks.systemClock(), log, thresholdMillis, logQueryParameters);
monitoring.addMonitorListener(logger);
}
@Override
public void shutdown() throws Throwable {
closable.close();
}
};
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class TestStartTransactionDuringLogRotation method setUp.
@Before
public void setUp() throws InterruptedException {
executor = Executors.newCachedThreadPool();
startLogRotationLatch = new CountDownLatch(1);
completeLogRotationLatch = new CountDownLatch(1);
writerStopped = new AtomicBoolean();
monitors = db.getDependencyResolver().resolveDependency(Monitors.class);
rotationListener = new LogRotation.Monitor() {
@Override
public void startedRotating(long currentVersion) {
startLogRotationLatch.countDown();
try {
completeLogRotationLatch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
@Override
public void finishedRotating(long currentVersion) {
}
};
monitors.addMonitorListener(rotationListener);
label = Label.label("Label");
rotationFuture = t2.execute(forceLogRotation(db));
// Waiting for the writer task to start a log rotation
startLogRotationLatch.await();
// Then we should be able to start a transaction, though perhaps not be able to finish it.
// This is what the individual test methods will be doing.
// The test passes when transaction.close completes within the test timeout, that is, it didn't deadlock.
}
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);
}
Aggregations