use of io.pravega.controller.store.host.ZKHostStore in project pravega by pravega.
the class SegmentContainerMonitorTest method testMonitorWithZKStore.
@Test(timeout = 30000)
public void testMonitorWithZKStore() throws Exception {
HostMonitorConfig config = HostMonitorConfigImpl.builder().hostMonitorEnabled(true).containerCount(Config.HOST_STORE_CONTAINER_COUNT).hostMonitorMinRebalanceInterval(Config.CLUSTER_MIN_REBALANCE_INTERVAL).build();
HostControllerStore hostStore = HostStoreFactory.createStore(config, StoreClientFactory.createZKStoreClient(PRAVEGA_ZK_CURATOR_RESOURCE.client));
// 6 latches to match 6 operations of register/deregiter done in the test
List<CompletableFuture<Void>> latches = Arrays.asList(new CompletableFuture<>(), new CompletableFuture<>(), new CompletableFuture<>(), new CompletableFuture<>(), new CompletableFuture<>(), new CompletableFuture<>());
AtomicInteger next = new AtomicInteger(0);
((ZKHostStore) hostStore).addListener(() -> {
latches.get(next.getAndIncrement()).complete(null);
});
testMonitor(hostStore, latches);
}
use of io.pravega.controller.store.host.ZKHostStore in project pravega by pravega.
the class HostStoreTest method zkHostStoreTests.
@Test(timeout = 10000L)
public void zkHostStoreTests() throws Exception {
@Cleanup TestingServer zkTestServer = new TestingServerStarter().start();
ZKClientConfig zkClientConfig = ZKClientConfigImpl.builder().connectionString(zkTestServer.getConnectString()).initialSleepInterval(2000).maxRetries(1).sessionTimeoutMs(10 * 1000).namespace("hostStoreTest/" + UUID.randomUUID()).build();
StoreClientConfig storeClientConfig = StoreClientConfigImpl.withZKClient(zkClientConfig);
@Cleanup StoreClient storeClient = StoreClientFactory.createStoreClient(storeClientConfig);
HostMonitorConfig hostMonitorConfig = HostMonitorConfigImpl.builder().hostMonitorEnabled(true).hostMonitorMinRebalanceInterval(10).containerCount(containerCount).build();
// Update host store map.
Map<Host, Set<Integer>> hostContainerMap = HostMonitorConfigImpl.getHostContainerMap(host, controllerPort, containerCount);
// Create ZK based host store.
HostControllerStore hostStore = HostStoreFactory.createStore(hostMonitorConfig, storeClient);
CompletableFuture<Void> latch1 = new CompletableFuture<>();
CompletableFuture<Void> latch2 = new CompletableFuture<>();
((ZKHostStore) hostStore).addListener(() -> {
// wait for the second operation to complete (related to updateHostContainersMap()).
if (latch1.isDone()) {
latch2.complete(null);
}
latch1.complete(null);
});
hostStore.updateHostContainersMap(hostContainerMap);
latch1.join();
latch2.join();
validateStore(hostStore);
// verify that a new hostStore is initialized with map set by previous host store.
HostControllerStore hostStore2 = HostStoreFactory.createStore(hostMonitorConfig, storeClient);
Map<Host, Set<Integer>> map = hostStore2.getHostContainersMap();
assertEquals(hostContainerMap, map);
}
use of io.pravega.controller.store.host.ZKHostStore in project pravega by pravega.
the class TestUtils method createDummyHostContainerAssignment.
/**
* This method creates a dummy Host-Container mapping, given that it is not created in Pravega standalone.
*
* @param zkConnectString Connection endpoint for Zookeeper.
* @param hostIp Name of the host to connect to.
* @param hostPort Port of the host to connect to.
*/
public static void createDummyHostContainerAssignment(String zkConnectString, String hostIp, int hostPort) {
@Cleanup CuratorFramework curatorFramework = CuratorFrameworkFactory.builder().namespace("pravega/pravega-cluster").connectString(zkConnectString).retryPolicy(new RetryOneTime(5000)).build();
curatorFramework.start();
ZKHostStore zkHostStore = new ZKHostStore(curatorFramework, 4);
Map<Host, Set<Integer>> dummyHostContainerAssignment = new HashMap<>();
dummyHostContainerAssignment.put(new Host(hostIp, hostPort, ""), new HashSet<>(Arrays.asList(0, 1, 2, 3)));
zkHostStore.updateHostContainersMap(dummyHostContainerAssignment);
}
Aggregations