private CLUSTER reuseCluster(int numServers, RaftProperties prop) throws IOException { for(;;) { final CLUSTER cluster = reusableCluster.get(); if (cluster != null) { return cluster; } final CLUSTER newCluster = newCluster(numServers, prop); if (reusableCluster.compareAndSet(null, newCluster)) { newCluster.start(); Runtime.getRuntime().addShutdownHook(new Thread(newCluster::shutdown)); return newCluster; } } }
private static void add( Collection<Object[]> clusters, MiniRaftCluster.Factory factory, String[] ids, RaftProperties properties) throws IOException { clusters.add(new Object[]{factory.newCluster(ids, properties)}); }
private static void add( Collection<Object[]> clusters, MiniRaftCluster.Factory factory, String[] ids, RaftProperties properties) throws IOException { clusters.add(new Object[]{factory.newCluster(ids, properties)}); }
public MiniRaftCluster getCluster(int peerNum) throws IOException { return getClusterFactory().newCluster(peerNum, prop); }
@Test(timeout = 10000) 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(); }
public CLUSTER newCluster(int numServer, RaftProperties prop) { return newCluster(generateIds(numServer, 0), prop); } }
default CLUSTER newCluster(int numPeers) { return getFactory().newCluster(numPeers, getProperties()); }
default CLUSTER newCluster(int numPeers) throws IOException { return getFactory().newCluster(numPeers, getProperties()); } }
@Before public void setup() throws IOException { final RaftProperties prop = new RaftProperties(); prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class); RaftServerConfigKeys.Snapshot.setAutoTriggerThreshold( prop, SNAPSHOT_TRIGGER_THRESHOLD); RaftServerConfigKeys.Snapshot.setAutoTriggerEnabled(prop, true); this.cluster = getFactory().newCluster(1, prop); cluster.start(); }
public MiniRaftCluster getCluster(int peerNum) throws IOException { return getClusterFactory().newCluster(peerNum, prop); }
public TestRetryCacheWithGrpc() throws IOException { cluster = MiniRaftClusterWithGRpc.FACTORY.newCluster( NUM_SERVERS, properties); Assert.assertNull(cluster.getLeader()); }
@Override public MiniRaftClusterWithGRpc getCluster(int peerNum) throws IOException { return MiniRaftClusterWithGRpc.FACTORY.newCluster(peerNum, prop); } }
@Before public void setup() { final RaftProperties prop = new RaftProperties(); prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class); RaftServerConfigKeys.Snapshot.setAutoTriggerThreshold( prop, SNAPSHOT_TRIGGER_THRESHOLD); RaftServerConfigKeys.Snapshot.setAutoTriggerEnabled(prop, true); this.cluster = getFactory().newCluster(1, prop); cluster.start(); }
public TestRetryCacheWithSimulatedRpc() throws IOException { cluster = MiniRaftClusterWithSimulatedRpc.FACTORY.newCluster( NUM_SERVERS, getProperties()); }
public CLUSTER newCluster(int numServer, RaftProperties prop) { return newCluster(generateIds(numServer, 0), prop); } }
public TestRaftWithSimulatedRpc() throws IOException { cluster = MiniRaftClusterWithSimulatedRpc.FACTORY.newCluster( NUM_SERVERS, getProperties()); }
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); } }
public TestRaftWithGrpc() throws IOException { properties.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class); cluster = MiniRaftClusterWithGRpc.FACTORY.newCluster( NUM_SERVERS, properties); Assert.assertNull(cluster.getLeader()); }
@Override public MiniRaftCluster getCluster(int peerNum) throws IOException { return MiniRaftClusterWithSimulatedRpc.FACTORY.newCluster(peerNum, prop); } }
private void startCluster() { cluster = MiniRaftClusterWithSimulatedRpc.FACTORY.newCluster( NUM_SERVERS, properties); Assert.assertNull(getCluster().getLeader()); getCluster().start(); }