use of org.apache.ratis.server.simulation.MiniRaftClusterWithSimulatedRpc in project incubator-ratis by apache.
the class TestStateMachine method runTestTransactionContextIsPassedBack.
void runTestTransactionContextIsPassedBack(boolean useMemory) throws Throwable {
final RaftProperties properties = new RaftProperties();
properties.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SMTransactionContext.class, StateMachine.class);
RaftServerConfigKeys.Log.setUseMemory(properties, useMemory);
try (MiniRaftClusterWithSimulatedRpc cluster = getFactory().newCluster(NUM_SERVERS, properties)) {
cluster.start();
runTestTransactionContextIsPassedBack(cluster);
}
}
use of org.apache.ratis.server.simulation.MiniRaftClusterWithSimulatedRpc in project incubator-ratis by apache.
the class TestRaftServerJmx method testJmxBeans.
@Test(timeout = 30000)
public void testJmxBeans() throws Exception {
final int NUM_SERVERS = 3;
final MiniRaftClusterWithSimulatedRpc cluster = MiniRaftClusterWithSimulatedRpc.FACTORY.newCluster(3, new RaftProperties());
cluster.start();
waitForLeader(cluster);
MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectInstance> objectInstances = platformMBeanServer.queryMBeans(new ObjectName("Ratis:*"), null);
Assert.assertEquals(NUM_SERVERS, objectInstances.size());
for (ObjectInstance instance : objectInstances) {
Object groupId = platformMBeanServer.getAttribute(instance.getObjectName(), "GroupId");
Assert.assertEquals(cluster.getGroupId().toString(), groupId);
}
cluster.shutdown();
}
use of org.apache.ratis.server.simulation.MiniRaftClusterWithSimulatedRpc in project incubator-ratis by apache.
the class TestStateMachine method testStateMachineRegistry.
@Test
public void testStateMachineRegistry() throws Throwable {
final Map<RaftGroupId, StateMachine> registry = new ConcurrentHashMap<>();
registry.put(RaftGroupId.randomId(), new SimpleStateMachine4Testing());
registry.put(RaftGroupId.randomId(), new SMTransactionContext());
try (MiniRaftClusterWithSimulatedRpc cluster = newCluster(0)) {
cluster.setStateMachineRegistry(registry::get);
final RaftPeerId id = RaftPeerId.valueOf("s0");
cluster.putNewServer(id, null, true);
cluster.start();
for (RaftGroupId gid : registry.keySet()) {
final RaftGroup newGroup = RaftGroup.valueOf(gid, cluster.getPeers());
LOG.info("add new group: " + newGroup);
try (final RaftClient client = cluster.createClient(newGroup)) {
for (RaftPeer p : newGroup.getPeers()) {
client.getGroupManagementApi(p.getId()).add(newGroup);
}
}
}
final RaftServer server = cluster.getServer(id);
for (Map.Entry<RaftGroupId, StateMachine> e : registry.entrySet()) {
Assert.assertSame(e.getValue(), server.getDivision(e.getKey()).getStateMachine());
}
}
}
Aggregations