use of org.apache.twill.zookeeper.ZKClientService in project cdap by caskdata.
the class ZKExtOperationsTest method testSetOrCreate.
@Test
public void testSetOrCreate() throws Exception {
String path = "/parent/testSetOrCreate";
ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
zkClient.startAndWait();
// Create with "1"
Assert.assertEquals(1, ZKExtOperations.setOrCreate(zkClient, path, Suppliers.ofInstance(1), INT_CODEC, 0).get().intValue());
// Should get "1" back
Assert.assertEquals(1, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue());
// Set with "2"
Assert.assertEquals(2, ZKExtOperations.setOrCreate(zkClient, path, Suppliers.ofInstance(2), INT_CODEC, 0).get().intValue());
// Should get "2" back
Assert.assertEquals(2, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue());
zkClient.stopAndWait();
}
use of org.apache.twill.zookeeper.ZKClientService in project phoenix by apache.
the class TephraTransactionContext method setTransactionClient.
@Override
public ZKClientService setTransactionClient(Configuration config, ReadOnlyProps props, ConnectionInfo connectionInfo) {
String zkQuorumServersString = props.get(TxConstants.Service.CFG_DATA_TX_ZOOKEEPER_QUORUM);
if (zkQuorumServersString == null) {
zkQuorumServersString = connectionInfo.getZookeeperQuorum() + ":" + connectionInfo.getPort();
}
int timeOut = props.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT);
// Create instance of the tephra zookeeper client
ZKClientService txZKClientService = ZKClientServices.delegate(ZKClients.reWatchOnExpire(ZKClients.retryOnFailure(new TephraZKClientService(zkQuorumServersString, timeOut, null, ArrayListMultimap.<String, byte[]>create()), RetryStrategies.exponentialDelay(500, 2000, TimeUnit.MILLISECONDS))));
txZKClientService.startAndWait();
ZKDiscoveryService zkDiscoveryService = new ZKDiscoveryService(txZKClientService);
PooledClientProvider pooledClientProvider = new PooledClientProvider(config, zkDiscoveryService);
txClient = this.txServiceClient = new TransactionServiceClient(config, pooledClientProvider);
return txZKClientService;
}
Aggregations