pvary commented on code in PR #11010:
URL: https://github.com/apache/iceberg/pull/11010#discussion_r1732394823

##########
flink/v1.20/flink/src/test/java/org/apache/iceberg/flink/maintenance/operator/TestLockRemover.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * 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.iceberg.flink.maintenance.operator;
+
+import static 
org.apache.iceberg.flink.maintenance.operator.ConstantsForTests.DUMMY_NAME;
+import static 
org.apache.iceberg.flink.maintenance.operator.TableMaintenanceMetrics.FAILED_STREAM_COUNTER;
+import static 
org.apache.iceberg.flink.maintenance.operator.TableMaintenanceMetrics.SUCCESSFUL_STREAM_COUNTER;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.util.concurrent.TimeoutException;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.core.execution.JobClient;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class TestLockRemover extends OperatorTestBase {
+  private static final String TASK_0 = "task0";
+  private static final String TASK_1 = "task1";
+  private static final TriggerLockFactory.Lock LOCK = new TestingLock();
+  private static final TriggerLockFactory.Lock RECOVERY_LOCK = new 
TestingLock();
+
+  @BeforeEach
+  void before() {
+    MetricsReporterFactoryForTests.reset();
+  }
+
+  @Test
+  void testProcess() throws Exception {
+    StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
+    ManualSource<TaskResult> source = new ManualSource<>(env, 
TypeInformation.of(TaskResult.class));
+    CollectingSink<MaintenanceResult> result = new CollectingSink<>();
+    source
+        .dataStream()
+        .transform(
+            DUMMY_NAME,
+            TypeInformation.of(MaintenanceResult.class),
+            new LockRemover(new TestingLockFactory(), 
Lists.newArrayList(TASK_0, TASK_1)))
+        .setParallelism(1)
+        .sinkTo(result);
+
+    JobClient jobClient = null;

Review Comment:
   Done



##########
flink/v1.20/flink/src/test/java/org/apache/iceberg/flink/maintenance/operator/TestLockRemover.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * 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.iceberg.flink.maintenance.operator;
+
+import static 
org.apache.iceberg.flink.maintenance.operator.ConstantsForTests.DUMMY_NAME;
+import static 
org.apache.iceberg.flink.maintenance.operator.TableMaintenanceMetrics.FAILED_STREAM_COUNTER;
+import static 
org.apache.iceberg.flink.maintenance.operator.TableMaintenanceMetrics.SUCCESSFUL_STREAM_COUNTER;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.util.concurrent.TimeoutException;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.core.execution.JobClient;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class TestLockRemover extends OperatorTestBase {
+  private static final String TASK_0 = "task0";
+  private static final String TASK_1 = "task1";
+  private static final TriggerLockFactory.Lock LOCK = new TestingLock();
+  private static final TriggerLockFactory.Lock RECOVERY_LOCK = new 
TestingLock();
+
+  @BeforeEach
+  void before() {
+    MetricsReporterFactoryForTests.reset();
+  }
+
+  @Test
+  void testProcess() throws Exception {
+    StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
+    ManualSource<TaskResult> source = new ManualSource<>(env, 
TypeInformation.of(TaskResult.class));
+    CollectingSink<MaintenanceResult> result = new CollectingSink<>();
+    source
+        .dataStream()
+        .transform(
+            DUMMY_NAME,
+            TypeInformation.of(MaintenanceResult.class),
+            new LockRemover(new TestingLockFactory(), 
Lists.newArrayList(TASK_0, TASK_1)))
+        .setParallelism(1)
+        .sinkTo(result);
+
+    JobClient jobClient = null;
+    try {
+      jobClient = env.executeAsync();
+
+      LOCK.tryLock();
+      assertThat(LOCK.isHeld()).isTrue();
+
+      // Start a successful trigger for task1 and assert the return value is 
correct
+      processAndCheck(source, result, new TaskResult(0, 0L, true, 
Lists.newArrayList()));
+
+      // Assert that the lock is removed
+      assertThat(LOCK.isHeld()).isFalse();
+    } finally {
+      closeJobClient(jobClient);
+    }
+  }
+
+  @Test
+  void testMetrics() throws Exception {
+    StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
+    ManualSource<TaskResult> source = new ManualSource<>(env, 
TypeInformation.of(TaskResult.class));
+    CollectingSink<MaintenanceResult> result = new CollectingSink<>();
+    source
+        .dataStream()
+        .transform(
+            DUMMY_NAME,
+            TypeInformation.of(MaintenanceResult.class),
+            new LockRemover(new TestingLockFactory(), 
Lists.newArrayList(TASK_0, TASK_1)))
+        .setParallelism(1)
+        .sinkTo(result);
+
+    JobClient jobClient = null;
+    try {
+      jobClient = env.executeAsync();
+
+      // Start the 2 successful and one failed result trigger for task1, and 3 
successful for task2
+      processAndCheck(source, result, new TaskResult(0, 0L, true, 
Lists.newArrayList()));
+      processAndCheck(source, result, new TaskResult(1, 1L, true, 
Lists.newArrayList()));
+      processAndCheck(source, result, new TaskResult(1, 2L, true, 
Lists.newArrayList()));
+      processAndCheck(source, result, new TaskResult(0, 3L, false, 
Lists.newArrayList()));
+      processAndCheck(source, result, new TaskResult(0, 4L, true, 
Lists.newArrayList()));
+      processAndCheck(source, result, new TaskResult(1, 5L, true, 
Lists.newArrayList()));
+
+      Awaitility.await()
+          .until(
+              () ->
+                  MetricsReporterFactoryForTests.counter(
+                          DUMMY_NAME + "." + TASK_1 + "." + 
SUCCESSFUL_STREAM_COUNTER)
+                      .equals(3L));
+
+      // Final check all the counters
+      MetricsReporterFactoryForTests.assertCounters(
+          new ImmutableMap.Builder<String, Long>()
+              .put(DUMMY_NAME + "." + TASK_0 + "." + 
SUCCESSFUL_STREAM_COUNTER, 2L)
+              .put(DUMMY_NAME + "." + TASK_0 + "." + FAILED_STREAM_COUNTER, 1L)
+              .put(DUMMY_NAME + "." + TASK_1 + "." + 
SUCCESSFUL_STREAM_COUNTER, 3L)
+              .put(DUMMY_NAME + "." + TASK_1 + "." + FAILED_STREAM_COUNTER, 0L)
+              .build());
+    } finally {
+      closeJobClient(jobClient);
+    }
+  }
+
+  /**
+   * The test checks if the recovery watermark is only removed if the 
watermark has arrived from
+   * both downstream sources.

Review Comment:
   Done



-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to