use of com.alipay.sofa.jraft.rhea.client.RheaKVCliService in project sofa-jraft by sofastack.
the class AbstractChaosTest method chaosSplittingTest.
@Test
public void chaosSplittingTest() {
final List<PeerId> peerIds = TestUtil.generatePeers(INITIAL_PEER_COUNT);
final CliOptions opts = new CliOptions();
opts.setTimeoutMs(30000);
final RheaKVCliService cliService = RheaKVServiceFactory.createAndInitRheaKVCliService(opts);
final long regionId = Constants.DEFAULT_REGION_ID;
final long newRegionId = 2;
final String groupId = JRaftHelper.getJRaftGroupId(ChaosTestCluster.CLUSTER_NAME, regionId);
final Configuration conf = new Configuration(peerIds);
ChaosTestCluster cluster = null;
for (int l = 0; l < RETRIES; l++) {
final ExecutorService executor = Executors.newCachedThreadPool(new NamedThreadFactory("chaos-splitting-test", true));
final List<Future<?>> allFutures = new CopyOnWriteArrayList<>();
try {
cluster = new ChaosTestCluster(peerIds, getStorageType(), isAllowBatching(), isOnlyLeaderRead());
cluster.start();
final RheaKVStore store = cluster.getLeaderStore();
// for least keys on split
for (int j = 0; j < LOOP_2; j++) {
store.bPut(j + "_split_", VALUE);
}
for (int i = 0; i < LOOP_1; i++) {
final int index = i;
final Future<?> f = executor.submit(() -> {
for (int j = 0; j < LOOP_2; j++) {
store.bPut(index + "_split_test_" + j, VALUE);
}
});
allFutures.add(f);
}
final Status st = cliService.rangeSplit(regionId, newRegionId, groupId, conf);
if (!st.isOk()) {
System.err.println("Status:" + st);
throw new RuntimeException(st.toString());
}
// wait for all writes finished
for (final Future<?> f : allFutures) {
f.get(30, TimeUnit.SECONDS);
}
break;
} catch (final Exception e) {
System.err.println("Fail to put data, try again...");
e.printStackTrace();
for (final Future<?> f : allFutures) {
f.cancel(true);
}
if (cluster != null) {
cluster.stopAll();
}
cluster = null;
} finally {
ExecutorServiceHelper.shutdownAndAwaitTermination(executor);
}
}
if (cluster == null) {
throw new RuntimeException("fail to put data, can not check data");
}
try {
chaosSplittingCheckData(cluster);
} finally {
cluster.stopAll();
}
}
use of com.alipay.sofa.jraft.rhea.client.RheaKVCliService in project sofa-jraft by sofastack.
the class AbstractRheaKVStoreTest method rangeSplitTest.
@Test
public void rangeSplitTest() {
final RheaKVStore store = getRandomLeaderStore();
final long regionId = 1;
for (int i = 0; i < 20; i++) {
store.bPut("a" + i, BytesUtil.writeUtf8("split"));
}
final CliOptions opts = new CliOptions();
opts.setTimeoutMs(30000);
final RheaKVCliService cliService = RheaKVServiceFactory.createAndInitRheaKVCliService(opts);
final long newRegionId = 101;
final String groupId = JRaftHelper.getJRaftGroupId("rhea_test", regionId);
final Configuration conf = JRaftUtils.getConfiguration("127.0.0.1:18181,127.0.0.1:18182,127.0.0.1:18183");
final Status st = cliService.rangeSplit(regionId, newRegionId, groupId, conf);
System.err.println("Status:" + st);
assertTrue(st.isOk());
final RheaKVStore newStore = getLeaderStore(101);
newStore.bPut("f_first_key", BytesUtil.writeUtf8("split_ok"));
assertArrayEquals(BytesUtil.writeUtf8("split_ok"), newStore.bGet("f_first_key"));
}
Aggregations