zhuzhurk commented on code in PR #21962:
URL: https://github.com/apache/flink/pull/21962#discussion_r1111619664


##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSpeculativeSinkITCase.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.configuration.BatchExecutionOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.SlowTaskDetectorOptions;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobgraph.JobVertex;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import 
org.apache.flink.table.api.bridge.java.internal.StreamTableEnvironmentImpl;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.CollectionUtil;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import static 
org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests {@link HiveTableSink} with {@link
+ * org.apache.flink.connector.file.table.FileSystemOutputFormat} and 
speculative scheduling enabled.
+ */
+public class HiveTableSpeculativeSinkITCase {

Review Comment:
   Flink is now migrating to JUnit5. New tests should be implemented using 
JUnit5.



##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSpeculativeSinkITCase.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.configuration.BatchExecutionOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.SlowTaskDetectorOptions;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobgraph.JobVertex;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import 
org.apache.flink.table.api.bridge.java.internal.StreamTableEnvironmentImpl;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.CollectionUtil;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import static 
org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests {@link HiveTableSink} with {@link
+ * org.apache.flink.connector.file.table.FileSystemOutputFormat} and 
speculative scheduling enabled.
+ */
+public class HiveTableSpeculativeSinkITCase {
+
+    private static HiveCatalog hiveCatalog;
+
+    @BeforeClass
+    public static void createCatalog() {
+        hiveCatalog = HiveTestUtils.createHiveCatalog();
+        hiveCatalog.open();
+    }
+
+    @AfterClass
+    public static void closeCatalog() {
+        if (hiveCatalog != null) {
+            hiveCatalog.close();
+        }
+    }
+
+    @Test
+    public void testBatchWritingWithoutCompactionWithSpeculativeSink() {
+        StreamExecutionEnvironment env =
+                
StreamExecutionEnvironment.getExecutionEnvironment(configure(new 
Configuration()));
+        StreamTableEnvironment tEnv =
+                StreamTableEnvironment.create(env, 
EnvironmentSettings.inBatchMode());
+        tEnv.getConfig().set(TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM, 1);
+
+        tEnv.getConfig().setSqlDialect(SqlDialect.HIVE);
+        tEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
+        tEnv.useCatalog(hiveCatalog.getName());
+        tEnv.executeSql("create database db1");
+        tEnv.useDatabase("db1");
+
+        try {
+            tEnv.executeSql(
+                    "create table append_table("
+                            + "i int, "
+                            + "j int) TBLPROPERTIES ("
+                            + "'sink.parallelism' ='3')"
+                            + "");
+            DataStream<Row> ds = tEnv.toChangelogStream(tEnv.sqlQuery("select 
0, 0"));
+            ds =
+                    ds.map(
+                                    new RichMapFunction<Row, Row>() {
+                                        @Override
+                                        public Row map(Row value) throws 
Exception {
+                                            if 
(getRuntimeContext().getAttemptNumber() <= 0) {
+                                                
Thread.sleep(Integer.MAX_VALUE);
+                                            }
+                                            assert 
getRuntimeContext().getAttemptNumber() > 0;
+                                            value.setField(
+                                                    1, 
getRuntimeContext().getAttemptNumber());
+                                            return value;
+                                        }
+                                    })
+                            .name("slowMap")
+                            .returns(Types.ROW_NAMED(new String[] {"i", "j"}, 
Types.INT, Types.INT))
+                            .setParallelism(3);
+
+            Table t =
+                    tEnv.fromChangelogStream(
+                            ds,
+                            Schema.newBuilder()
+                                    .column("i", DataTypes.INT())
+                                    .column("j", DataTypes.INT())
+                                    .build(),
+                            ChangelogMode.insertOnly());
+
+            tEnv.getConfig().setSqlDialect(SqlDialect.DEFAULT);
+            tEnv.createTemporaryView("mappedTable", t);
+            String insertQuery = "insert into append_table select * from 
mappedTable";
+
+            // assert that the SlowMap operator is chained with the hive table 
sink, which will lead
+            // to a slow sink as well.
+            StreamTableEnvironmentImpl tEnvImpl = (StreamTableEnvironmentImpl) 
tEnv;
+            JobGraph jobGraph =
+                    tEnvImpl.execEnv()
+                            .generateStreamGraph(
+                                    tEnvImpl.getPlanner()
+                                            .translate(
+                                                    Collections.singletonList(
+                                                            (ModifyOperation)
+                                                                    
tEnvImpl.getParser()
+                                                                            
.parse(insertQuery)
+                                                                            
.get(0))))
+                            .getJobGraph();
+
+            for (JobVertex jobVertex : jobGraph.getVertices()) {
+                if (jobVertex.getName().contains("slowMap")) {
+                    assertThat(jobVertex.getName().contains("Sink")).isTrue();
+                }
+            }
+            tEnv.executeSql(insertQuery).await();
+
+            List<Row> rows =
+                    CollectionUtil.iteratorToList(
+                            tEnv.executeSql("select * from 
append_table").collect());
+            rows.sort(Comparator.comparingInt(o -> (int) o.getField(0)));
+
+            // Finally we will get the output value with attemptNumber larger 
than 0
+            assertThat(rows).isEqualTo(Collections.singletonList(Row.of(0, 
1)));
+        } catch (Exception e) {
+            throw new RuntimeException(e);

Review Comment:
   This catch is not needed. We can just make the test `throw Exception`.



##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSpeculativeSinkITCase.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.configuration.BatchExecutionOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.SlowTaskDetectorOptions;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobgraph.JobVertex;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import 
org.apache.flink.table.api.bridge.java.internal.StreamTableEnvironmentImpl;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.CollectionUtil;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import static 
org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests {@link HiveTableSink} with {@link
+ * org.apache.flink.connector.file.table.FileSystemOutputFormat} and 
speculative scheduling enabled.
+ */
+public class HiveTableSpeculativeSinkITCase {
+
+    private static HiveCatalog hiveCatalog;
+
+    @BeforeClass
+    public static void createCatalog() {
+        hiveCatalog = HiveTestUtils.createHiveCatalog();
+        hiveCatalog.open();
+    }
+
+    @AfterClass
+    public static void closeCatalog() {
+        if (hiveCatalog != null) {
+            hiveCatalog.close();
+        }
+    }
+
+    @Test
+    public void testBatchWritingWithoutCompactionWithSpeculativeSink() {
+        StreamExecutionEnvironment env =
+                
StreamExecutionEnvironment.getExecutionEnvironment(configure(new 
Configuration()));
+        StreamTableEnvironment tEnv =
+                StreamTableEnvironment.create(env, 
EnvironmentSettings.inBatchMode());
+        tEnv.getConfig().set(TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM, 1);
+
+        tEnv.getConfig().setSqlDialect(SqlDialect.HIVE);
+        tEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
+        tEnv.useCatalog(hiveCatalog.getName());
+        tEnv.executeSql("create database db1");
+        tEnv.useDatabase("db1");
+
+        try {
+            tEnv.executeSql(
+                    "create table append_table("
+                            + "i int, "
+                            + "j int) TBLPROPERTIES ("
+                            + "'sink.parallelism' ='3')"
+                            + "");
+            DataStream<Row> ds = tEnv.toChangelogStream(tEnv.sqlQuery("select 
0, 0"));
+            ds =
+                    ds.map(
+                                    new RichMapFunction<Row, Row>() {
+                                        @Override
+                                        public Row map(Row value) throws 
Exception {
+                                            if 
(getRuntimeContext().getAttemptNumber() <= 0) {
+                                                
Thread.sleep(Integer.MAX_VALUE);
+                                            }
+                                            assert 
getRuntimeContext().getAttemptNumber() > 0;
+                                            value.setField(
+                                                    1, 
getRuntimeContext().getAttemptNumber());
+                                            return value;
+                                        }
+                                    })
+                            .name("slowMap")
+                            .returns(Types.ROW_NAMED(new String[] {"i", "j"}, 
Types.INT, Types.INT))
+                            .setParallelism(3);
+
+            Table t =
+                    tEnv.fromChangelogStream(
+                            ds,
+                            Schema.newBuilder()
+                                    .column("i", DataTypes.INT())
+                                    .column("j", DataTypes.INT())
+                                    .build(),
+                            ChangelogMode.insertOnly());
+
+            tEnv.getConfig().setSqlDialect(SqlDialect.DEFAULT);
+            tEnv.createTemporaryView("mappedTable", t);
+            String insertQuery = "insert into append_table select * from 
mappedTable";
+
+            // assert that the SlowMap operator is chained with the hive table 
sink, which will lead
+            // to a slow sink as well.
+            StreamTableEnvironmentImpl tEnvImpl = (StreamTableEnvironmentImpl) 
tEnv;
+            JobGraph jobGraph =
+                    tEnvImpl.execEnv()
+                            .generateStreamGraph(
+                                    tEnvImpl.getPlanner()
+                                            .translate(
+                                                    Collections.singletonList(
+                                                            (ModifyOperation)
+                                                                    
tEnvImpl.getParser()
+                                                                            
.parse(insertQuery)
+                                                                            
.get(0))))
+                            .getJobGraph();
+
+            for (JobVertex jobVertex : jobGraph.getVertices()) {
+                if (jobVertex.getName().contains("slowMap")) {
+                    assertThat(jobVertex.getName().contains("Sink")).isTrue();
+                }
+            }
+            tEnv.executeSql(insertQuery).await();
+
+            List<Row> rows =
+                    CollectionUtil.iteratorToList(
+                            tEnv.executeSql("select * from 
append_table").collect());
+            rows.sort(Comparator.comparingInt(o -> (int) o.getField(0)));
+
+            // Finally we will get the output value with attemptNumber larger 
than 0
+            assertThat(rows).isEqualTo(Collections.singletonList(Row.of(0, 
1)));
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            tEnv.executeSql("drop database db1 cascade");
+        }
+    }
+
+    private Configuration configure(Configuration configuration) {
+        // for speculative execution
+        configuration.set(BatchExecutionOptions.SPECULATIVE_ENABLED, true);
+        // for testing, does not block node by default
+        if 
(!configuration.contains(BatchExecutionOptions.BLOCK_SLOW_NODE_DURATION)) {

Review Comment:
   This `if` is not needed because `configure(...)` is a private method and is 
used only by this test.



##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSpeculativeSinkITCase.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.configuration.BatchExecutionOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.SlowTaskDetectorOptions;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobgraph.JobVertex;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import 
org.apache.flink.table.api.bridge.java.internal.StreamTableEnvironmentImpl;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.CollectionUtil;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import static 
org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests {@link HiveTableSink} with {@link
+ * org.apache.flink.connector.file.table.FileSystemOutputFormat} and 
speculative scheduling enabled.
+ */
+public class HiveTableSpeculativeSinkITCase {

Review Comment:
   A reference can be `HiveTableCompactSinkITCase`.



##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSpeculativeSinkITCase.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.connectors.hive;
+
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.configuration.BatchExecutionOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.SlowTaskDetectorOptions;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobgraph.JobVertex;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.SqlDialect;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import 
org.apache.flink.table.api.bridge.java.internal.StreamTableEnvironmentImpl;
+import org.apache.flink.table.catalog.hive.HiveCatalog;
+import org.apache.flink.table.catalog.hive.HiveTestUtils;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.operations.ModifyOperation;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.CollectionUtil;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import static 
org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests {@link HiveTableSink} with {@link
+ * org.apache.flink.connector.file.table.FileSystemOutputFormat} and 
speculative scheduling enabled.

Review Comment:
   scheduling -> execution.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to