Search in sources :

Example 1 with Watch

use of org.apache.flink.kubernetes.kubeclient.KubernetesSharedWatcher.Watch in project flink by apache.

the class KubernetesSharedInformerITCase method testWatchWithBlockHandler.

@Test
public void testWatchWithBlockHandler() throws Exception {
    try (KubernetesConfigMapSharedWatcher watcher = client.createConfigMapSharedWatcher(labels)) {
        final String configMapName = getConfigMapName(System.currentTimeMillis());
        final long block = 500;
        final long maxUpdateVal = 30;
        final TestingBlockCallbackHandler handler = new TestingBlockCallbackHandler(block, maxUpdateVal);
        final Watch watch = watcher.watch(configMapName, handler, watchCallbackExecutorService);
        createConfigMap(configMapName);
        for (int i = 1; i <= maxUpdateVal; i++) {
            updateConfigMap(configMapName, ImmutableMap.of("val", String.valueOf(i)));
        }
        try {
            handler.expectedFuture.get(120, TimeUnit.SECONDS);
        } catch (TimeoutException e) {
            fail("expected value: " + maxUpdateVal + ", actual: " + handler.val);
        }
        try {
            handler.assertFuture.get(2 * block, TimeUnit.MILLISECONDS);
        } catch (TimeoutException e) {
        // expected
        }
        watch.close();
    }
}
Also used : KubernetesConfigMapSharedWatcher(org.apache.flink.kubernetes.kubeclient.KubernetesConfigMapSharedWatcher) Watch(org.apache.flink.kubernetes.kubeclient.KubernetesSharedWatcher.Watch) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 2 with Watch

use of org.apache.flink.kubernetes.kubeclient.KubernetesSharedWatcher.Watch in project flink by apache.

the class KubernetesSharedInformerITCase method watchInRange.

private void watchInRange(KubernetesConfigMapSharedWatcher watcher, List<TestingCallbackHandler> callbackHandlers, List<Watch> watchers, int start, int end) {
    for (int i = start; i < end; i++) {
        final String name = getConfigMapName(i % 10);
        final TestingCallbackHandler handler = new TestingCallbackHandler(name);
        callbackHandlers.add(handler);
        final Watch watch = watcher.watch(name, handler, watchCallbackExecutorService);
        watchers.add(watch);
    }
}
Also used : Watch(org.apache.flink.kubernetes.kubeclient.KubernetesSharedWatcher.Watch)

Example 3 with Watch

use of org.apache.flink.kubernetes.kubeclient.KubernetesSharedWatcher.Watch in project flink by apache.

the class KubernetesSharedInformerITCase method testWatch.

@Test(timeout = 120000)
public void testWatch() throws Exception {
    try (KubernetesConfigMapSharedWatcher watcher = client.createConfigMapSharedWatcher(labels)) {
        for (int i = 0; i < 10; i++) {
            List<TestingCallbackHandler> callbackHandlers = new ArrayList<>();
            List<Watch> watchers = new ArrayList<>();
            watchInRange(watcher, callbackHandlers, watchers, 0, 20);
            createConfigMapsInRange(0, 5);
            watchInRange(watcher, callbackHandlers, watchers, 20, 40);
            createConfigMapsInRange(5, 10);
            updateConfigMapInRange(0, 10, ImmutableMap.of("foo", "bar"));
            for (TestingCallbackHandler handler : callbackHandlers) {
                handler.addFuture.get();
                handler.addOrUpdateFuture.get();
                assertFalse(handler.assertFuture.isCompletedExceptionally());
            }
            watchers.forEach(Watch::close);
            callbackHandlers.clear();
            watchers.clear();
            watchInRange(watcher, callbackHandlers, watchers, 40, 60);
            for (TestingCallbackHandler handler : callbackHandlers) {
                handler.addFuture.get();
                handler.addOrUpdateFuture.get();
            }
            client.deleteConfigMapsByLabels(labels).get();
            for (TestingCallbackHandler handler : callbackHandlers) {
                handler.deleteFuture.get();
                if (handler.assertFuture.isCompletedExceptionally()) {
                    handler.assertFuture.get();
                }
            }
            watchers.forEach(Watch::close);
        }
    }
}
Also used : KubernetesConfigMapSharedWatcher(org.apache.flink.kubernetes.kubeclient.KubernetesConfigMapSharedWatcher) ArrayList(java.util.ArrayList) Watch(org.apache.flink.kubernetes.kubeclient.KubernetesSharedWatcher.Watch) Test(org.junit.Test)

Aggregations

Watch (org.apache.flink.kubernetes.kubeclient.KubernetesSharedWatcher.Watch)3 KubernetesConfigMapSharedWatcher (org.apache.flink.kubernetes.kubeclient.KubernetesConfigMapSharedWatcher)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 TimeoutException (java.util.concurrent.TimeoutException)1