public void restart(boolean format) throws IOException { shutdown(); List<RaftPeerId> idList = new ArrayList<>(servers.keySet()); servers.clear(); putNewServers(idList, format); start(); }
public void restart(boolean format) throws IOException { shutdown(); List<RaftPeerId> idList = new ArrayList<>(servers.keySet()); servers.clear(); putNewServers(idList, format); start(); }
/** Set {@link #currentCluster} to the given cluster and start it if {@link #currentCluster} is changed. */ public static void setAndStart(MiniRaftCluster cluster) throws InterruptedException { final MiniRaftCluster previous = currentCluster.getAndSet(cluster); if (previous != cluster) { if (previous != null) { previous.shutdown(); } cluster.start(); RaftTestUtil.waitForLeader(cluster); } }
/** Set {@link #currentCluster} to the given cluster and start it if {@link #currentCluster} is changed. */ public static void setAndStart(MiniRaftCluster cluster) throws InterruptedException, IOException { final MiniRaftCluster previous = currentCluster.getAndSet(cluster); if (previous != cluster) { if (previous != null) { previous.shutdown(); } cluster.start(); RaftTestUtil.waitForLeader(cluster); } }
@Test public void testEnforceLeader() throws Exception { final int numServer = 3; LOG.info("Running testEnforceLeader"); final String leader = "s" + ThreadLocalRandom.current().nextInt(numServer); LOG.info("enforce leader to " + leader); final MiniRaftCluster cluster = newCluster(numServer); cluster.start(); waitForLeader(cluster); waitForLeader(cluster, leader); cluster.shutdown(); }
@Test public void testAsyncDelayRequestIfLeaderStepDown() throws Exception { final CLUSTER cluster = newCluster(5); cluster.start(); runTestDelayRequestIfLeaderStepDown(true, cluster, LOG); } }
@Test public void testFlushMetric() throws Exception { try(final MiniRaftCluster cluster = newCluster(NUM_SERVERS)) { cluster.start(); runTestFlushMetric(cluster); } }
@Before public void setUpCluster() throws IOException, InterruptedException { cluster = newCluster(NUM_PEERS); cluster.start(); RaftTestUtil.waitForLeader(cluster); }
void runTestBasicAppendEntriesAsync(ReplicationLevel replication, boolean killLeader) throws Exception { final CLUSTER cluster = newCluster(killLeader? 5: 3); try { cluster.start(); waitForLeader(cluster); RaftBasicTests.runTestBasicAppendEntries(true, replication, killLeader, 1000, cluster, LOG); } finally { cluster.shutdown(); } }
@Test public void testWithLoadAsync() throws Exception { LOG.info("Running testWithLoadAsync"); final CLUSTER cluster = newCluster(NUM_SERVERS); cluster.start(); waitForLeader(cluster); RaftBasicTests.testWithLoad(10, 500, true, cluster, LOG); cluster.shutdown(); }
@Before public void setup() throws IOException { Assert.assertNull(getCluster().getLeader()); getCluster().start(); }
@Before public void setup() throws IOException { final RaftProperties prop = getProperties(); RaftServerConfigKeys.Log.Appender .setBufferCapacity(prop, SizeInBytes.valueOf("4KB")); cluster = newCluster(NUM_PEERS); cluster.start(); }
@Before public void setup() throws IOException { Assert.assertNull(getCluster().getLeader()); getCluster().start(); }
@Test public void testBasicLeaderElection() throws Exception { LOG.info("Running testBasicLeaderElection"); final MiniRaftCluster cluster = newCluster(5); cluster.start(); waitAndKillLeader(cluster, true); waitAndKillLeader(cluster, true); waitAndKillLeader(cluster, true); waitAndKillLeader(cluster, false); cluster.shutdown(); }
@Test public void testFileStoreAsync() throws Exception { final CLUSTER cluster = newCluster(NUM_PEERS); cluster.start(); RaftTestUtil.waitForLeader(cluster); final FileStoreClient client = new FileStoreClient(cluster.getGroup(), getProperties()); final ExecutorService executor = Executors.newFixedThreadPool(20); testSingleFile("foo", SizeInBytes.valueOf("10M"), executor, client); testMultipleFiles("file", 100, SizeInBytes.valueOf("1M"), executor, client); executor.shutdown(); client.close(); cluster.shutdown(); }
@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(); }
@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(); }
@Test public void testFileStore() throws Exception { final CLUSTER cluster = newCluster(NUM_PEERS); cluster.start(); RaftTestUtil.waitForLeader(cluster); final CheckedSupplier<FileStoreClient, IOException> newClient = () -> new FileStoreClient(cluster.getGroup(), getProperties()); testSingleFile("foo", SizeInBytes.valueOf("10M"), newClient); testMultipleFiles("file", 100, SizeInBytes.valueOf("1M"), newClient); cluster.shutdown(); }
@Test public void testFileStore() throws Exception { final CLUSTER cluster = newCluster(NUM_PEERS); cluster.start(); RaftTestUtil.waitForLeader(cluster); final CheckedSupplier<FileStoreClient, IOException> newClient = () -> new FileStoreClient(cluster.getGroup(), getProperties()); testSingleFile("foo", SizeInBytes.valueOf("10M"), newClient); testMultipleFiles("file", 100, SizeInBytes.valueOf("1M"), newClient); cluster.shutdown(); }
@Test public void testRequestTimeout() throws Exception { final TimeDuration oldExpiryTime = RaftServerConfigKeys.RetryCache.expiryTime(getProperties()); RaftServerConfigKeys.RetryCache.setExpiryTime(getProperties(), TimeDuration.valueOf(5, TimeUnit.SECONDS)); final CLUSTER cluster = newCluster(NUM_SERVERS); cluster.start(); RaftBasicTests.testRequestTimeout(true, cluster, LOG); cluster.shutdown(); //reset for the other tests RaftServerConfigKeys.RetryCache.setExpiryTime(getProperties(), oldExpiryTime); }