use of org.apache.curator.test.TestingCluster in project curator by apache.
the class TestReconfiguration method testAddWithoutEnsembleTracker.
@Test
public void testAddWithoutEnsembleTracker() throws Exception {
final String initialClusterCS = cluster.getConnectString();
try (CuratorFramework client = newClient(cluster.getConnectString(), false)) {
assertEquals(((CuratorFrameworkImpl) client).getEnsembleTracker(), null);
client.start();
QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble());
assertConfig(oldConfig, cluster.getInstances());
CountDownLatch latch = setChangeWaiter(client);
try (TestingCluster newCluster = new TestingCluster(TestingCluster.makeSpecs(1, false))) {
newCluster.start();
client.reconfig().joining(toReconfigSpec(newCluster.getInstances())).fromConfig(oldConfig.getVersion()).forEnsemble();
assertTrue(timing.awaitLatch(latch));
byte[] newConfigData = client.getConfig().forEnsemble();
QuorumVerifier newConfig = toQuorumVerifier(newConfigData);
List<InstanceSpec> newInstances = Lists.newArrayList(cluster.getInstances());
newInstances.addAll(newCluster.getInstances());
assertConfig(newConfig, newInstances);
assertEquals(ensembleProvider.getConnectionString(), initialClusterCS);
assertNotEquals(EnsembleTracker.configToConnectionString(newConfig), ensembleProvider.getConnectionString());
assertEquals(client.getZookeeperClient().getCurrentConnectionString(), initialClusterCS);
final CountDownLatch reconnectLatch = new CountDownLatch(1);
client.getConnectionStateListenable().addListener((cfClient, newState) -> {
if (newState == ConnectionState.RECONNECTED)
reconnectLatch.countDown();
});
client.getZookeeperClient().getZooKeeper().getTestable().injectSessionExpiration();
assertTrue(reconnectLatch.await(2, TimeUnit.SECONDS));
assertEquals(client.getZookeeperClient().getCurrentConnectionString(), initialClusterCS);
assertEquals(ensembleProvider.getConnectionString(), initialClusterCS);
newConfigData = client.getConfig().forEnsemble();
assertNotEquals(EnsembleTracker.configToConnectionString(newConfig), ensembleProvider.getConnectionString());
}
}
}
use of org.apache.curator.test.TestingCluster in project curator by apache.
the class TestReconfiguration method testAddAndRemove.
@Test
public void testAddAndRemove() throws Exception {
try (CuratorFramework client = newClient()) {
client.start();
QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble());
assertConfig(oldConfig, cluster.getInstances());
CountDownLatch latch = setChangeWaiter(client);
try (TestingCluster newCluster = new TestingCluster(TestingCluster.makeSpecs(1, false))) {
newCluster.start();
Collection<InstanceSpec> oldInstances = cluster.getInstances();
InstanceSpec us = cluster.findConnectionInstance(client.getZookeeperClient().getZooKeeper());
InstanceSpec removeSpec = oldInstances.iterator().next();
if (us.equals(removeSpec)) {
Iterator<InstanceSpec> iterator = oldInstances.iterator();
iterator.next();
removeSpec = iterator.next();
}
Collection<InstanceSpec> instances = newCluster.getInstances();
client.reconfig().leaving(Integer.toString(removeSpec.getServerId())).joining(toReconfigSpec(instances)).fromConfig(oldConfig.getVersion()).forEnsemble();
assertTrue(timing.awaitLatch(latch));
byte[] newConfigData = client.getConfig().forEnsemble();
QuorumVerifier newConfig = toQuorumVerifier(newConfigData);
ArrayList<InstanceSpec> newInstances = Lists.newArrayList(oldInstances);
newInstances.addAll(instances);
newInstances.remove(removeSpec);
assertConfig(newConfig, newInstances);
assertEquals(EnsembleTracker.configToConnectionString(newConfig), ensembleProvider.getConnectionString());
}
}
}
use of org.apache.curator.test.TestingCluster in project exhibitor by soabase.
the class TestZookeeperConfigProvider method setup.
@BeforeMethod
public void setup() throws Exception {
timing = new Timing();
cluster = new TestingCluster(3);
cluster.start();
client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
client.start();
}
use of org.apache.curator.test.TestingCluster in project druid by druid-io.
the class RemoteTaskRunnerTestUtils method setUp.
void setUp() throws Exception {
testingCluster = new TestingCluster(1);
testingCluster.start();
cf = CuratorFrameworkFactory.builder().connectString(testingCluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1, 10)).compressionProvider(new PotentiallyGzippedCompressionProvider(false)).build();
cf.start();
cf.blockUntilConnected();
cf.create().creatingParentsIfNeeded().forPath(basePath);
cf.create().creatingParentsIfNeeded().forPath(tasksPath);
}
use of org.apache.curator.test.TestingCluster in project druid by druid-io.
the class BatchDataSegmentAnnouncerTest method setUp.
@Before
public void setUp() throws Exception {
testingCluster = new TestingCluster(1);
testingCluster.start();
cf = CuratorFrameworkFactory.builder().connectString(testingCluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1, 10)).compressionProvider(new PotentiallyGzippedCompressionProvider(false)).build();
cf.start();
cf.blockUntilConnected();
cf.create().creatingParentsIfNeeded().forPath(testBasePath);
jsonMapper = new DefaultObjectMapper();
announcer = new Announcer(cf, MoreExecutors.sameThreadExecutor());
announcer.start();
segmentReader = new SegmentReader(cf, jsonMapper);
skipDimensionsAndMetrics = false;
skipLoadSpec = false;
segmentAnnouncer = new BatchDataSegmentAnnouncer(new DruidServerMetadata("id", "host", Long.MAX_VALUE, "type", "tier", 0), new BatchDataSegmentAnnouncerConfig() {
@Override
public int getSegmentsPerNode() {
return 50;
}
@Override
public long getMaxBytesPerNode() {
return maxBytesPerNode.get();
}
@Override
public boolean isSkipDimensionsAndMetrics() {
return skipDimensionsAndMetrics;
}
@Override
public boolean isSkipLoadSpec() {
return skipLoadSpec;
}
}, new ZkPathsConfig() {
@Override
public String getBase() {
return testBasePath;
}
}, announcer, jsonMapper);
segmentAnnouncer.start();
testSegments = Sets.newHashSet();
for (int i = 0; i < 100; i++) {
testSegments.add(makeSegment(i));
}
}
Aggregations