use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class Prover method bootstrapCluster.
private void bootstrapCluster() throws Exception {
String instance1 = "cluster://localhost:5001";
String instance2 = "cluster://localhost:5002";
String instance3 = "cluster://localhost:5003";
ClusterConfiguration config = new ClusterConfiguration("default", NullLogProvider.getInstance(), instance1, instance2, instance3);
ClusterState state = new ClusterState(asList(newClusterInstance(new InstanceId(1), new URI(instance1), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(2), new URI(instance2), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(3), new URI(instance3), new Monitors(), config, 10, NullLogProvider.getInstance())), emptySetOf(ClusterAction.class));
state = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.create, new URI(instance3), "defaultcluster").setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, instance3)));
state = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI(instance2), new Object[] { "defaultcluster", new URI[] { new URI(instance3) } }).setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, instance2)));
state = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI(instance1), new Object[] { "defaultcluster", new URI[] { new URI(instance3) } }).setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, instance1)));
state.addPendingActions(new InstanceCrashedAction(instance3));
unexploredKnownStates.add(state);
db.newState(state);
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class TestProver method aClusterSnapshotShouldEqualItsOrigin.
@Test
public void aClusterSnapshotShouldEqualItsOrigin() throws Exception {
// Given
ClusterConfiguration config = new ClusterConfiguration("default", NullLogProvider.getInstance(), "cluster://localhost:5001", "cluster://localhost:5002", "cluster://localhost:5003");
ClusterState state = new ClusterState(asList(newClusterInstance(new InstanceId(1), new URI("cluster://localhost:5001"), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(2), new URI("cluster://localhost:5002"), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(3), new URI("cluster://localhost:5003"), new Monitors(), config, 10, NullLogProvider.getInstance())), emptySetOf(ClusterAction.class));
// When
ClusterState snapshot = state.snapshot();
// Then
assertEquals(state, snapshot);
assertEquals(state.hashCode(), snapshot.hashCode());
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class TestProver method twoStatesWithSameSetupAndPendingMessagesShouldBeEqual.
@Test
public void twoStatesWithSameSetupAndPendingMessagesShouldBeEqual() throws Exception {
// Given
ClusterConfiguration config = new ClusterConfiguration("default", NullLogProvider.getInstance(), "cluster://localhost:5001", "cluster://localhost:5002", "cluster://localhost:5003");
ClusterState state = new ClusterState(asList(newClusterInstance(new InstanceId(1), new URI("cluster://localhost:5001"), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(2), new URI("cluster://localhost:5002"), new Monitors(), config, 10, NullLogProvider.getInstance()), newClusterInstance(new InstanceId(3), new URI("cluster://localhost:5003"), new Monitors(), config, 10, NullLogProvider.getInstance())), emptySetOf(ClusterAction.class));
// When
ClusterState firstState = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI("cluster://localhost:5002"), new Object[] { "defaultcluster", new URI[] { new URI("cluster://localhost:5003") } }).setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, "cluster://localhost:5002")));
ClusterState secondState = state.performAction(new MessageDeliveryAction(Message.to(ClusterMessage.join, new URI("cluster://localhost:5002"), new Object[] { "defaultcluster", new URI[] { new URI("cluster://localhost:5003") } }).setHeader(Message.CONVERSATION_ID, "-1").setHeader(Message.FROM, "cluster://localhost:5002")));
// Then
assertEquals(firstState, secondState);
assertEquals(firstState.hashCode(), secondState.hashCode());
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class TestBlockLogBuffer method readOnlyOneFullBlock.
@Test
public void readOnlyOneFullBlock() throws Exception {
byte[] bytes = new byte[256];
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;
buffer.put(bytesValue, bytesValue.length);
buffer.close();
ReadableByteChannel reader = new BlockLogReader(wrappedBuffer);
ByteBuffer verificationBuffer = ByteBuffer.wrap(new byte[1000]);
reader.read(verificationBuffer);
verificationBuffer.flip();
byte[] actualBytes = new byte[bytesValue.length];
verificationBuffer.get(actualBytes);
assertThat(actualBytes, new ArrayMatches<byte[]>(bytesValue));
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class TestBlockLogBuffer method canReaderReallyLargeByteArray.
@Test
public void canReaderReallyLargeByteArray() 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;
BlockLogReader reader = new BlockLogReader(wrappedBuffer);
ByteBuffer verificationBuffer = ByteBuffer.wrap(new byte[1000]);
reader.read(verificationBuffer);
verificationBuffer.flip();
actual = new byte[255];
verificationBuffer.get(actual);
assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 0, 255)));
actual = new byte[255];
verificationBuffer.get(actual);
assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 255, 510)));
actual = new byte[90];
verificationBuffer.get(actual);
assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 510, 600)));
}
Aggregations