use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class NeoStoreDataSourceRule method getDataSource.
public NeoStoreDataSource getDataSource(File storeDir, FileSystemAbstraction fs, IdGeneratorFactory idGeneratorFactory, IdTypeConfigurationProvider idConfigurationProvider, PageCache pageCache, Config config, DatabaseHealth databaseHealth, LogService logService) {
if (dataSource != null) {
dataSource.stop();
dataSource.shutdown();
}
StatementLocksFactory locksFactory = mock(StatementLocksFactory.class);
StatementLocks statementLocks = mock(StatementLocks.class);
Locks.Client locks = mock(Locks.Client.class);
when(statementLocks.optimistic()).thenReturn(locks);
when(statementLocks.pessimistic()).thenReturn(locks);
when(locksFactory.newInstance()).thenReturn(statementLocks);
JobScheduler jobScheduler = mock(JobScheduler.class, RETURNS_MOCKS);
Monitors monitors = new Monitors();
LabelScanStoreProvider labelScanStoreProvider = nativeLabelScanStoreProvider(storeDir, fs, pageCache, config, logService);
SystemNanoClock clock = Clocks.nanoClock();
dataSource = new NeoStoreDataSource(storeDir, config, idGeneratorFactory, IdReuseEligibility.ALWAYS, idConfigurationProvider, logService, mock(JobScheduler.class, RETURNS_MOCKS), mock(TokenNameLookup.class), dependencyResolverForNoIndexProvider(labelScanStoreProvider), mock(PropertyKeyTokenHolder.class), mock(LabelTokenHolder.class), mock(RelationshipTypeTokenHolder.class), locksFactory, mock(SchemaWriteGuard.class), mock(TransactionEventHandlers.class), IndexingService.NO_MONITOR, fs, mock(TransactionMonitor.class), databaseHealth, mock(PhysicalLogFile.Monitor.class), TransactionHeaderInformationFactory.DEFAULT, new StartupStatisticsProvider(), null, new CommunityCommitProcessFactory(), mock(InternalAutoIndexing.class), pageCache, new StandardConstraintSemantics(), monitors, new Tracers("null", NullLog.getInstance(), monitors, jobScheduler), mock(Procedures.class), IOLimiter.unlimited(), new AvailabilityGuard(clock, NullLog.getInstance()), clock, new CanWrite(), new StoreCopyCheckPointMutex());
return dataSource;
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class MonitoredTermStateStorageTest method shouldMonitorTerm.
@Test
public void shouldMonitorTerm() throws Exception {
// given
Monitors monitors = new Monitors();
StubRaftTermMonitor raftTermMonitor = new StubRaftTermMonitor();
monitors.addMonitorListener(raftTermMonitor);
TermState state = new TermState();
MonitoredTermStateStorage monitoredTermStateStorage = new MonitoredTermStateStorage(new InMemoryStateStorage<>(new TermState()), monitors);
// when
state.update(7);
monitoredTermStateStorage.persistStoreData(state);
// then
assertEquals(7, raftTermMonitor.term());
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class TestBlockLogBuffer method canWriteLargestAtomAfterFillingBuffer.
@Test
public void canWriteLargestAtomAfterFillingBuffer() throws Exception {
byte[] bytes = new byte[300];
ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
wrappedBuffer.resetWriterIndex();
BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, new Monitors().newMonitor(ByteCounterMonitor.class));
byte[] bytesValue = new byte[255];
bytesValue[0] = 1;
bytesValue[254] = -1;
long longValue = 123456;
buffer.put(bytesValue, bytesValue.length);
buffer.putLong(longValue);
buffer.close();
ByteBuffer verificationBuffer = ByteBuffer.wrap(bytes);
assertEquals((byte) 0, verificationBuffer.get());
byte[] actualBytes = new byte[bytesValue.length];
verificationBuffer.get(actualBytes);
assertThat(actualBytes, new ArrayMatches<byte[]>(bytesValue));
assertEquals((byte) 8, verificationBuffer.get());
assertEquals(longValue, verificationBuffer.getLong());
}
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());
}
Aggregations