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


##########
flink/v1.20/flink/src/test/java/org/apache/iceberg/flink/maintenance/stream/TestExpireSnapshots.java:
##########
@@ -0,0 +1,248 @@
+/*
+ * 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.stream;
+
+import static org.apache.iceberg.flink.SimpleDataUtil.createRecord;
+import static 
org.apache.iceberg.flink.maintenance.operator.TableMaintenanceMetrics.DELETE_FILE_FAILED_COUNTER;
+import static 
org.apache.iceberg.flink.maintenance.operator.TableMaintenanceMetrics.DELETE_FILE_SUCCEEDED_COUNTER;
+import static 
org.apache.iceberg.flink.maintenance.stream.ExpireSnapshots.DELETE_FILES_TASK_NAME;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.Duration;
+import java.util.Set;
+import org.apache.flink.core.execution.JobClient;
+import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
+import org.apache.iceberg.SerializableTable;
+import org.apache.iceberg.Snapshot;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.flink.SimpleDataUtil;
+import org.apache.iceberg.flink.TableLoader;
+import 
org.apache.iceberg.flink.maintenance.operator.MetricsReporterFactoryForTests;
+import org.apache.iceberg.flink.maintenance.operator.Trigger;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class TestExpireSnapshots extends ScheduledBuilderTestBase {
+  @BeforeEach
+  void before() {
+    MetricsReporterFactoryForTests.reset();
+  }
+
+  @Test
+  void testExpireSnapshots() throws Exception {
+    sql.exec("CREATE TABLE %s (id int, data varchar)", TABLE_NAME);
+    sql.exec("INSERT INTO %s VALUES (1, 'a')", TABLE_NAME);
+    sql.exec("INSERT INTO %s VALUES (2, 'b')", TABLE_NAME);
+    sql.exec("INSERT INTO %s VALUES (3, 'c')", TABLE_NAME);
+    sql.exec("INSERT INTO %s VALUES (4, 'd')", TABLE_NAME);
+
+    TableLoader tableLoader = sql.tableLoader(TABLE_NAME);
+    Table table = tableLoader.loadTable();
+    Set<Snapshot> snapshots = Sets.newHashSet(table.snapshots());
+    assertThat(snapshots).hasSize(4);
+
+    ExpireSnapshots.builder()
+        .parallelism(1)
+        .planningWorkerPoolSize(2)
+        .deleteAttemptNum(2)
+        .deleteWorkerPoolSize(5)
+        .maxSnapshotAge(Duration.ZERO)
+        .retainLast(1)
+        .uidSuffix(UID_SUFFIX)
+        .append(
+            infra.triggerStream(),
+            0,
+            DUMMY_NAME,
+            tableLoader,
+            "OTHER",
+            StreamGraphGenerator.DEFAULT_SLOT_SHARING_GROUP,
+            1)
+        .sinkTo(infra.sink());
+
+    runAndWaitForSuccess(
+        infra.env(), infra.source(), infra.sink(), () -> 
checkDeleteFinished(3L), table);
+
+    // Check that the table data not changed
+    table.refresh();
+    assertThat(Sets.newHashSet(table.snapshots())).hasSize(1);
+    SimpleDataUtil.assertTableRecords(
+        table,
+        ImmutableList.of(
+            createRecord(1, "a"),
+            createRecord(2, "b"),
+            createRecord(3, "c"),
+            createRecord(4, "d")));
+  }
+
+  @Test
+  void testFailure() throws Exception {
+    sql.exec("CREATE TABLE %s (id int, data varchar)", TABLE_NAME);
+    sql.exec("INSERT INTO %s VALUES (1, 'a')", TABLE_NAME);
+    sql.exec("INSERT INTO %s VALUES (2, 'b')", TABLE_NAME);
+
+    TableLoader tableLoader = sql.tableLoader(TABLE_NAME);
+    Table table = tableLoader.loadTable();
+    SerializableTable serializableTable = (SerializableTable) 
SerializableTable.copyOf(table);
+
+    ExpireSnapshots.builder()
+        .append(
+            infra.triggerStream(),
+            0,
+            DUMMY_NAME,
+            tableLoader,
+            UID_SUFFIX,
+            StreamGraphGenerator.DEFAULT_SLOT_SHARING_GROUP,
+            1)
+        .sinkTo(infra.sink());
+
+    JobClient jobClient = null;
+    try {
+      jobClient = infra.env().executeAsync();
+
+      // Do a single task run
+      long time = System.currentTimeMillis();
+      infra
+          .source()
+          .sendRecord(Trigger.create(time, serializableTable, 1), 
System.currentTimeMillis());
+
+      // First successful run (ensure that the operators are loaded/opened 
etc.)
+      assertThat(infra.sink().poll(Duration.ofSeconds(5)).success()).isTrue();
+
+      // Drop the table, so it will cause an exception
+      sql.catalogLoader().loadCatalog().dropTable(TableIdentifier.of(DB_NAME, 
TABLE_NAME));
+
+      // Failed run
+      infra.source().sendRecord(Trigger.create(time + 1, serializableTable, 
1), time + 1);
+
+      assertThat(infra.sink().poll(Duration.ofSeconds(5)).success()).isFalse();
+    } finally {
+      closeJobClient(jobClient);
+    }
+
+    // Check the metrics
+    MetricsReporterFactoryForTests.assertCounters(

Review Comment:
   The failure happened before the delete file operation. The counters are not 
affected. The failure counter will increased by `LockManager` down the pipeline



##########
flink/v1.20/flink/src/test/java/org/apache/iceberg/flink/maintenance/operator/OperatorTestBase.java:
##########
@@ -126,12 +119,45 @@ public static Configuration closeJobClient(JobClient 
jobClient, File savepointDi
    *
    * @param jobClient the job to close
    */
-  public static void closeJobClient(JobClient jobClient) {
+  protected static void closeJobClient(JobClient jobClient) {
     closeJobClient(jobClient, null);
   }
 
+  protected static void checkUidsAreSet(StreamExecutionEnvironment env, String 
uidPrefix) {

Review Comment:
   Renamed



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