use of mousio.etcd4j.EtcdClient in project camel by apache.
the class EtcdRoutePolicy method doStart.
@Override
protected void doStart() throws Exception {
ObjectHelper.notNull(camelContext, "camelContext");
ObjectHelper.notNull(clientUris, "clientUris");
if (client == null) {
client = new EtcdClient(EtcdHelper.resolveURIs(camelContext, clientUris));
managedClient = true;
}
setLeader(tryTakeLeadership());
watch();
super.doStart();
}
use of mousio.etcd4j.EtcdClient in project camel by apache.
the class EtcdKeysTest method testKeys.
@Test(expected = EtcdException.class)
public void testKeys() throws Exception {
final String path = "/camel/" + UUID.randomUUID().toString();
final String value = UUID.randomUUID().toString();
final EtcdClient client = getClient();
final Map<String, Object> headers = new HashMap<>();
// *******************************************
// SET
// *******************************************
headers.clear();
headers.put(EtcdConstants.ETCD_ACTION, EtcdConstants.ETCD_KEYS_ACTION_SET);
headers.put(EtcdConstants.ETCD_PATH, path);
sendBody("direct:keys-set", value, headers);
MockEndpoint mockSet = getMockEndpoint("mock:result-set");
mockSet.expectedMinimumMessageCount(1);
mockSet.expectedHeaderReceived(EtcdConstants.ETCD_NAMESPACE, EtcdNamespace.keys.name());
mockSet.expectedHeaderReceived(EtcdConstants.ETCD_PATH, path);
mockSet.assertIsSatisfied();
// *******************************************
// GET
// *******************************************
headers.clear();
headers.put(EtcdConstants.ETCD_ACTION, EtcdConstants.ETCD_KEYS_ACTION_GET);
headers.put(EtcdConstants.ETCD_PATH, path);
sendBody("direct:keys-get", value, headers);
MockEndpoint mockGet = getMockEndpoint("mock:result-get");
mockGet.expectedMinimumMessageCount(1);
mockSet.expectedHeaderReceived(EtcdConstants.ETCD_NAMESPACE, EtcdNamespace.keys.name());
mockGet.expectedHeaderReceived(EtcdConstants.ETCD_PATH, path);
mockGet.expectedMessagesMatches(new Predicate() {
@Override
public boolean matches(Exchange exchange) {
EtcdKeysResponse keysResponse = exchange.getIn().getBody(EtcdKeysResponse.class);
assertNotNull(keysResponse);
assertNotNull(keysResponse.node);
assertNotNull(keysResponse.node.value);
return keysResponse.node.value.equals(value);
}
});
mockGet.assertIsSatisfied();
// *******************************************
// DELETE
// *******************************************
headers.clear();
headers.put(EtcdConstants.ETCD_ACTION, EtcdConstants.ETCD_KEYS_ACTION_DELETE);
headers.put(EtcdConstants.ETCD_PATH, path);
sendBody("direct:keys-del", "value", headers);
MockEndpoint mockDel = getMockEndpoint("mock:result-del");
mockDel.expectedMinimumMessageCount(1);
mockSet.expectedHeaderReceived(EtcdConstants.ETCD_NAMESPACE, EtcdNamespace.keys.name());
mockDel.expectedHeaderReceived(EtcdConstants.ETCD_PATH, path);
mockDel.assertIsSatisfied();
// *******************************************
// VALIDATION
// *******************************************
client.get(path).send().get();
fail("EtcdException should have been thrown");
}
use of mousio.etcd4j.EtcdClient in project camel by apache.
the class EtcdWatchTest method testWatch.
private void testWatch(String mockEndpoint, final String key, int updates) throws Exception {
final String[] values = new String[updates];
for (int i = 0; i < updates; i++) {
values[i] = key + "=myValue-" + i;
}
MockEndpoint mock = getMockEndpoint(mockEndpoint);
mock.expectedMessageCount(2);
mock.expectedHeaderReceived(EtcdConstants.ETCD_NAMESPACE, EtcdNamespace.watch.name());
mock.expectedHeaderReceived(EtcdConstants.ETCD_PATH, key);
mock.expectedBodiesReceived(values);
final EtcdClient client = getClient();
for (int i = 0; i < updates; i++) {
client.put(key, "myValue-" + i).send().get();
}
mock.assertIsSatisfied();
}
use of mousio.etcd4j.EtcdClient in project camel by apache.
the class EtcdWatchTest method testWatchRecovery.
@Test
public void testWatchRecovery() throws Exception {
final String key = "/myKeyRecovery";
final EtcdClient client = getClient();
try {
// Delete the key if present
client.delete(key).send().get();
} catch (EtcdException e) {
if (!e.isErrorCode(EtcdErrorCode.KeyNotFound)) {
throw e;
}
}
// Fill the vent backlog ( > 1000)
for (int i = 0; i < 2000; i++) {
client.put(key, "v" + i).send().get();
}
context().startRoute("watchRecovery");
testWatch("mock:watch-recovery", key, 10);
}
Aggregations