Search in sources :

Example 1 with MiniRaftClusterWithSimulatedRpc

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);
    }
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) MiniRaftClusterWithSimulatedRpc(org.apache.ratis.server.simulation.MiniRaftClusterWithSimulatedRpc)

Example 2 with MiniRaftClusterWithSimulatedRpc

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();
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) ObjectInstance(javax.management.ObjectInstance) MiniRaftClusterWithSimulatedRpc(org.apache.ratis.server.simulation.MiniRaftClusterWithSimulatedRpc) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

Example 3 with MiniRaftClusterWithSimulatedRpc

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());
        }
    }
}
Also used : RaftServer(org.apache.ratis.server.RaftServer) RaftGroupId(org.apache.ratis.protocol.RaftGroupId) MiniRaftClusterWithSimulatedRpc(org.apache.ratis.server.simulation.MiniRaftClusterWithSimulatedRpc) RaftGroup(org.apache.ratis.protocol.RaftGroup) RaftPeer(org.apache.ratis.protocol.RaftPeer) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RaftClient(org.apache.ratis.client.RaftClient) BaseTest(org.apache.ratis.BaseTest)

Aggregations

MiniRaftClusterWithSimulatedRpc (org.apache.ratis.server.simulation.MiniRaftClusterWithSimulatedRpc)3 BaseTest (org.apache.ratis.BaseTest)2 RaftProperties (org.apache.ratis.conf.RaftProperties)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 MBeanServer (javax.management.MBeanServer)1 ObjectInstance (javax.management.ObjectInstance)1 ObjectName (javax.management.ObjectName)1 RaftClient (org.apache.ratis.client.RaftClient)1 RaftGroup (org.apache.ratis.protocol.RaftGroup)1 RaftGroupId (org.apache.ratis.protocol.RaftGroupId)1 RaftPeer (org.apache.ratis.protocol.RaftPeer)1 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)1 RaftServer (org.apache.ratis.server.RaftServer)1 Test (org.junit.Test)1