use of org.neo4j.cluster.TestProtocolServer in project neo4j by neo4j.
the class ClusterMockTest method verifyConfigurations.
public void verifyConfigurations(VerifyInstanceConfiguration[] toCheckAgainst) {
logger.getLogger().fine("Verify configurations against given");
List<URI> members;
Map<String, InstanceId> roles;
Set<InstanceId> failed;
List<AssertionError> errors = new LinkedList<AssertionError>();
List<TestProtocolServer> protocolServers = network.getServers();
assertEquals("You must provide a configuration for all instances", protocolServers.size(), toCheckAgainst.length);
for (int j = 0; j < protocolServers.size(); j++) {
members = toCheckAgainst[j].members;
roles = toCheckAgainst[j].roles;
failed = toCheckAgainst[j].failed;
StateMachines stateMachines = protocolServers.get(j).getServer().getStateMachines();
State<?, ?> clusterState = stateMachines.getStateMachine(ClusterMessage.class).getState();
if (!clusterState.equals(ClusterState.entered)) {
logger.getLogger().warning("Instance " + (j + 1) + " is not in the cluster (" + clusterState + ")");
continue;
}
ClusterContext context = (ClusterContext) stateMachines.getStateMachine(ClusterMessage.class).getContext();
HeartbeatContext heartbeatContext = (HeartbeatContext) stateMachines.getStateMachine(HeartbeatMessage.class).getContext();
ClusterConfiguration clusterConfiguration = context.getConfiguration();
if (!clusterConfiguration.getMemberURIs().isEmpty()) {
logger.getLogger().fine(" Server " + (j + 1) + ": Cluster:" + clusterConfiguration.getMemberURIs() + ", Roles:" + clusterConfiguration.getRoles() + ", Failed:" + heartbeatContext.getFailed());
verifyConfigurations(stateMachines, members, roles, failed, errors);
}
}
if (!errors.isEmpty()) {
for (AssertionError error : errors) {
logger.getLogger().severe(error.toString());
}
throw errors.get(0);
}
}
use of org.neo4j.cluster.TestProtocolServer in project neo4j by neo4j.
the class ClusterMockTest method testCluster.
protected void testCluster(int[] serverIds, VerifyInstanceConfiguration[] finalConfig, NetworkMock mock, ClusterTestScript script) throws ExecutionException, InterruptedException, URISyntaxException, TimeoutException {
this.script = script;
network = mock;
servers.clear();
out.clear();
in.clear();
for (int i = 0; i < serverIds.length; i++) {
final URI uri = new URI("server" + (i + 1));
members.put(serverIds[i], uri);
TestProtocolServer server = network.addServer(serverIds[i], uri);
final Cluster cluster = server.newClient(Cluster.class);
clusterStateListener(uri, cluster);
server.newClient(Heartbeat.class).addHeartbeatListener(new HeartbeatListener() {
@Override
public void failed(InstanceId server) {
logger.getLogger().warning(uri + ": Failed:" + server);
}
@Override
public void alive(InstanceId server) {
logger.getLogger().fine(uri + ": Alive:" + server);
}
});
server.newClient(AtomicBroadcast.class).addAtomicBroadcastListener(new AtomicBroadcastListener() {
AtomicBroadcastSerializer serializer = new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory());
@Override
public void receive(Payload value) {
try {
logger.getLogger().fine(uri + " received: " + serializer.receive(value));
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
});
servers.add(server);
out.add(cluster);
}
// Run test
for (int i = 0; i < script.rounds(); i++) {
logger.getLogger().fine("Round " + i + ", time:" + network.getTime());
script.tick(network.getTime());
network.tick();
}
// Let messages settle
network.tick(100);
if (finalConfig == null) {
verifyConfigurations("final config");
} else {
verifyConfigurations(finalConfig);
}
logger.getLogger().fine("All nodes leave");
// All leave
for (Cluster cluster : new ArrayList<Cluster>(in)) {
logger.getLogger().fine("Leaving:" + cluster);
cluster.leave();
in.remove(cluster);
network.tick(400);
}
if (finalConfig != null) {
verifyConfigurations(finalConfig);
} else {
verifyConfigurations("test over");
}
}
use of org.neo4j.cluster.TestProtocolServer in project neo4j by neo4j.
the class MultiPaxosTest method testFailure.
@Test
public void testFailure() throws Exception {
ScriptableNetworkFailureLatencyStrategy networkLatency = new ScriptableNetworkFailureLatencyStrategy();
NetworkMock network = new NetworkMock(NullLogService.getInstance(), new Monitors(), 50, new MultipleFailureLatencyStrategy(networkLatency), new MessageTimeoutStrategy(new FixedTimeoutStrategy(1000)));
List<TestProtocolServer> nodes = new ArrayList<TestProtocolServer>();
TestProtocolServer server = network.addServer(1, URI.create("cluster://server1"));
server.newClient(Cluster.class).create("default");
network.tickUntilDone();
nodes.add(server);
for (int i = 1; i < 3; i++) {
TestProtocolServer protocolServer = network.addServer(i + 1, new URI("cluster://server" + (i + 1)));
protocolServer.newClient(Cluster.class).join("default", new URI("cluster://server1"));
network.tick(10);
nodes.add(protocolServer);
}
final AtomicBroadcast atomicBroadcast = nodes.get(0).newClient(AtomicBroadcast.class);
ObjectStreamFactory objectStreamFactory = new ObjectStreamFactory();
final AtomicBroadcastSerializer serializer = new AtomicBroadcastSerializer(objectStreamFactory, objectStreamFactory);
atomicBroadcast.broadcast(serializer.broadcast(new DaPayload()));
networkLatency.nodeIsDown("cluster://server2");
networkLatency.nodeIsDown("cluster://server3");
atomicBroadcast.broadcast(serializer.broadcast(new DaPayload()));
network.tick(100);
networkLatency.nodeIsUp("cluster://server3");
network.tick(1000);
for (TestProtocolServer node : nodes) {
node.newClient(Cluster.class).leave();
network.tick(10);
}
}
use of org.neo4j.cluster.TestProtocolServer in project neo4j by neo4j.
the class ClusterMockTest method verifyConfigurations.
public void verifyConfigurations(String description) {
logger.getLogger().fine("Verify configurations");
List<URI> members = null;
Map<String, InstanceId> roles = null;
Set<InstanceId> failed = null;
List<AssertionError> errors = new LinkedList<AssertionError>();
List<TestProtocolServer> protocolServers = network.getServers();
for (int j = 0; j < protocolServers.size(); j++) {
StateMachines stateMachines = protocolServers.get(j).getServer().getStateMachines();
State<?, ?> clusterState = stateMachines.getStateMachine(ClusterMessage.class).getState();
if (!clusterState.equals(ClusterState.entered)) {
logger.getLogger().fine("Instance " + (j + 1) + " is not in the cluster (" + clusterState + ")");
continue;
}
ClusterContext context = (ClusterContext) stateMachines.getStateMachine(ClusterMessage.class).getContext();
HeartbeatContext heartbeatContext = (HeartbeatContext) stateMachines.getStateMachine(HeartbeatMessage.class).getContext();
ClusterConfiguration clusterConfiguration = context.getConfiguration();
if (!clusterConfiguration.getMemberURIs().isEmpty()) {
logger.getLogger().fine(" Server " + (j + 1) + ": Cluster:" + clusterConfiguration.getMemberURIs() + ", Roles:" + clusterConfiguration.getRoles() + ", Failed:" + heartbeatContext.getFailed());
if (members == null) {
members = clusterConfiguration.getMemberURIs();
roles = clusterConfiguration.getRoles();
failed = heartbeatContext.getFailed();
} else {
verifyConfigurations(stateMachines, members, roles, failed, errors);
}
}
}
assertEquals(description + ": In:" + in + ", Out:" + out, protocolServers.size(), Iterables.count(Iterables.<Cluster, List<Cluster>>flatten(in, out)));
if (!errors.isEmpty()) {
for (AssertionError error : errors) {
logger.getLogger().severe(error.toString());
}
throw errors.get(0);
}
}
use of org.neo4j.cluster.TestProtocolServer in project neo4j by neo4j.
the class ClusterMockTest method getRoles.
private void getRoles(Map<String, InstanceId> roles) {
List<TestProtocolServer> protocolServers = network.getServers();
for (int j = 0; j < protocolServers.size(); j++) {
StateMachines stateMachines = protocolServers.get(j).getServer().getStateMachines();
State<?, ?> clusterState = stateMachines.getStateMachine(ClusterMessage.class).getState();
if (!clusterState.equals(ClusterState.entered)) {
logger.getLogger().warning("Instance " + (j + 1) + " is not in the cluster (" + clusterState + ")");
continue;
}
ClusterContext context = (ClusterContext) stateMachines.getStateMachine(ClusterMessage.class).getContext();
ClusterConfiguration clusterConfiguration = context.getConfiguration();
roles.putAll(clusterConfiguration.getRoles());
}
}
Aggregations