tillrohrmann commented on a change in pull request #10754: 
[FLINK-14091][coordination] Allow updates to connection state when 
ZKCheckpointIDCounter reconnects to ZK
URL: https://github.com/apache/flink/pull/10754#discussion_r366360933
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/checkpoint/ZKCheckpointIDCounterMultiServersTest.java
 ##########
 @@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.checkpoint;
+
+import org.apache.flink.runtime.zookeeper.ZooKeeperTestEnvironment;
+import org.apache.flink.util.TestLogger;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.state.ConnectionState;
+import org.apache.curator.test.TestingCluster;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link ZooKeeperCheckpointIDCounter} in a ZooKeeper ensemble.
+ */
+public final class ZKCheckpointIDCounterMultiServersTest extends TestLogger {
+
+       private static final ZooKeeperTestEnvironment ZOOKEEPER = new 
ZooKeeperTestEnvironment(3);
+
+       @AfterClass
+       public static void tearDown() throws Exception {
+               ZOOKEEPER.shutdown();
+       }
+
+       @Before
+       public void cleanUp() throws Exception {
+               ZOOKEEPER.deleteAll();
+       }
+
+       /**
+        * Tests that {@link ZooKeeperCheckpointIDCounter} can be recovered 
after a
+        * connection loss exception from ZooKeeper ensemble.
+        *
+        * See also FLINK-14091.
+        */
+       @Test
+       public void testRecoveredAfterConnectionLoss() throws Exception {
+               CuratorFramework client = ZOOKEEPER.getClient();
+
+               ZooKeeperCheckpointIDCounter idCounter = new 
ZooKeeperCheckpointIDCounter(client, "/checkpoint-id-counter");
+               idCounter.start();
+
+               AtomicLong localCounter = new AtomicLong(1L);
+
+               assertThat(
+                       "ZooKeeperCheckpointIDCounter doesn't properly work.",
+                       idCounter.getAndIncrement(),
+                       is(localCounter.getAndIncrement()));
+
+               TestingCluster cluster = ZOOKEEPER.getZooKeeperCluster();
+               assertThat(cluster, is(notNullValue()));
+
+               // close the server this client connected to, which triggers a 
connection loss exception
+               
cluster.restartServer(cluster.findConnectionInstance(client.getZookeeperClient().getZooKeeper()));
+
+               // encountered connected loss, this prevents us from getting 
false positive
+               while (true) {
+                       try {
+                               idCounter.get();
+                       } catch (IllegalStateException ignore) {
+                               log.debug("Encountered connection loss.");
+                               break;
+                       }
+               }
 
 Review comment:
   Are you sure that this always happens? This looks quite brittle to me. What 
if the restart is so fast that the client does not lose its connection?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to