use of org.apache.helix.zookeeper.impl.client.ZkClient in project helix by apache.
the class ZkRoutingDataReader method getRawRoutingData.
/**
* Returns a map form of metadata store routing data.
* The map fields stand for metadata store realm address (key), and a corresponding list of ZK
* path sharding keys (key).
* @param endpoint
* @return
*/
@Override
public Map<String, List<String>> getRawRoutingData(String endpoint) {
ZkClient zkClient = new ZkClient.Builder().setZkServer(endpoint).setZkSerializer(new ZNRecordSerializer()).build();
Map<String, List<String>> routingData = new HashMap<>();
List<String> allRealmAddresses;
try {
allRealmAddresses = zkClient.getChildren(MetadataStoreRoutingConstants.ROUTING_DATA_PATH);
} catch (ZkNoNodeException e) {
throw new MultiZkException("Routing data directory ZNode " + MetadataStoreRoutingConstants.ROUTING_DATA_PATH + " does not exist. Routing ZooKeeper address: " + endpoint);
}
if (allRealmAddresses != null) {
for (String realmAddress : allRealmAddresses) {
ZNRecord record = zkClient.readData(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/" + realmAddress, true);
if (record != null) {
List<String> shardingKeys = record.getListField(MetadataStoreRoutingConstants.ZNRECORD_LIST_FIELD_KEY);
routingData.put(realmAddress, shardingKeys != null ? shardingKeys : Collections.emptyList());
}
}
}
zkClient.close();
return routingData;
}
use of org.apache.helix.zookeeper.impl.client.ZkClient in project helix by apache.
the class ZkTestBase method simulateSessionExpiry.
protected void simulateSessionExpiry(HelixZkClient client) throws IOException, InterruptedException, IOException {
ZkClient zkClient = (ZkClient) client;
IZkStateListener listener = new IZkStateListener() {
@Override
public void handleStateChanged(Watcher.Event.KeeperState state) throws Exception {
LOG.info("In Old connection, state changed:" + state);
}
@Override
public void handleNewSession(final String sessionId) throws Exception {
LOG.info("In Old connection, new session: {}.", sessionId);
}
@Override
public void handleSessionEstablishmentError(Throwable var1) throws Exception {
}
};
zkClient.subscribeStateChanges(listener);
ZkConnection connection = ((ZkConnection) zkClient.getConnection());
ZooKeeper oldZookeeper = connection.getZookeeper();
LOG.info("Old sessionId = " + oldZookeeper.getSessionId());
Watcher watcher = new Watcher() {
@Override
public void process(WatchedEvent event) {
LOG.info("In New connection, process event:" + event);
}
};
ZooKeeper newZookeeper = new ZooKeeper(connection.getServers(), oldZookeeper.getSessionTimeout(), watcher, oldZookeeper.getSessionId(), oldZookeeper.getSessionPasswd());
LOG.info("New sessionId = " + newZookeeper.getSessionId());
// Thread.sleep(3000);
newZookeeper.close();
Thread.sleep(10000);
connection = (ZkConnection) zkClient.getConnection();
oldZookeeper = connection.getZookeeper();
LOG.info("After session expiry sessionId = " + oldZookeeper.getSessionId());
}
use of org.apache.helix.zookeeper.impl.client.ZkClient in project helix by apache.
the class TestZkBasis method testCloseZkClient.
@Test
public void testCloseZkClient() {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
ZkClient client = new ZkClient(ZK_ADDR, HelixZkClient.DEFAULT_SESSION_TIMEOUT, HelixZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
String path = String.format("/%s", clusterName);
client.createEphemeral(path);
client.close();
Assert.assertFalse(_gZkClient.exists(path), "Ephemeral node: " + path + " should be removed after ZkClient#close()");
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.zookeeper.impl.client.ZkClient in project helix by apache.
the class TestZkBasis method testZkSessionExpiry.
@Test
public void testZkSessionExpiry() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
ZkClient client = new ZkClient(ZK_ADDR, HelixZkClient.DEFAULT_SESSION_TIMEOUT, HelixZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
String path = String.format("/%s", clusterName);
client.createEphemeral(path);
String oldSessionId = ZkTestHelper.getSessionId(client);
ZkTestHelper.expireSession(client);
String newSessionId = ZkTestHelper.getSessionId(client);
Assert.assertNotSame(newSessionId, oldSessionId);
Assert.assertFalse(client.exists(path), "Ephemeral znode should be gone after session expiry");
client.close();
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.zookeeper.impl.client.ZkClient in project helix by apache.
the class TestPrefetchChangedData method testPrefetchChangedDataDisabled.
@Test
public void testPrefetchChangedDataDisabled() throws InterruptedException {
String path = "/" + TestHelper.getTestMethodName();
ZkClient zkClient = new ZkClient(ZkTestBase.ZK_ADDR);
try {
zkClient.createPersistent(path, "v1");
CountDownLatch countDownLatch = new CountDownLatch(1);
PreFetchZkDataListener dataListener = new PreFetchDisabledZkDataListener(countDownLatch);
zkClient.subscribeDataChanges(path, dataListener);
zkClient.writeData(path, "v2");
Assert.assertTrue(countDownLatch.await(3L, TimeUnit.SECONDS));
Assert.assertFalse(dataListener.isDataPreFetched());
} finally {
zkClient.unsubscribeAll();
zkClient.delete(path);
zkClient.close();
}
}
Aggregations