You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ma...@apache.org on 2022/05/18 14:23:35 UTC
[flink] branch master updated: [FLINK-27185][connector] Convert connector-hive module to assertj
This is an automated email from the ASF dual-hosted git repository.
martijnvisser pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push:
new 5b8dc104f76 [FLINK-27185][connector] Convert connector-hive module to assertj
5b8dc104f76 is described below
commit 5b8dc104f76f89e1774e0446788cb29ba7788d79
Author: Alexander Preuß <11...@users.noreply.github.com>
AuthorDate: Fri May 6 11:09:59 2022 +0200
[FLINK-27185][connector] Convert connector-hive module to assertj
Co-authored-by: slinkydeveloper <fr...@gmail.com>
---
.../hive/HiveDeserializeExceptionTest.java | 10 +-
.../flink/connectors/hive/HiveDialectITCase.java | 464 ++++++++++-----------
.../connectors/hive/HiveDialectQueryITCase.java | 160 +++----
.../hive/HiveDynamicTableFactoryTest.java | 96 ++---
.../connectors/hive/HiveLookupJoinITCase.java | 40 +-
.../hive/HiveOutputFormatFactoryTest.java | 6 +-
.../flink/connectors/hive/HiveRunnerITCase.java | 127 +++---
.../flink/connectors/hive/HiveSourceITCase.java | 20 +-
.../connectors/hive/HiveTableFactoryTest.java | 12 +-
.../flink/connectors/hive/HiveTableSinkITCase.java | 85 ++--
.../connectors/hive/HiveTableSourceITCase.java | 250 ++++++-----
.../connectors/hive/PartitionMonitorTest.java | 10 +-
.../hive/TableEnvHiveConnectorITCase.java | 129 +++---
.../read/HiveInputFormatPartitionReaderITCase.java | 12 +-
.../hive/read/HivePartitionFetcherTest.java | 8 +-
.../hive/read/HiveTableFileInputFormatTest.java | 5 +-
.../connectors/hive/util/HiveConfUtilsTest.java | 19 +-
.../catalog/hive/HiveCatalogDataTypeTest.java | 4 +-
.../catalog/hive/HiveCatalogHiveMetadataTest.java | 3 +-
.../table/catalog/hive/HiveCatalogUdfITCase.java | 12 +-
.../hive/factories/HiveCatalogFactoryTest.java | 64 ++-
.../table/catalog/hive/util/HiveTableUtilTest.java | 8 +-
.../table/functions/hive/HiveGenericUDAFTest.java | 10 +-
.../table/functions/hive/HiveGenericUDFTest.java | 67 ++-
.../table/functions/hive/HiveGenericUDTFTest.java | 18 +-
.../table/functions/hive/HiveSimpleUDFTest.java | 51 ++-
.../table/module/hive/HiveModuleFactoryTest.java | 4 +-
.../flink/table/module/hive/HiveModuleTest.java | 48 +--
.../planner/delegation/hive/HiveASTParserTest.java | 4 +-
29 files changed, 846 insertions(+), 900 deletions(-)
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDeserializeExceptionTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDeserializeExceptionTest.java
index 1f81c7ec917..12560e80ede 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDeserializeExceptionTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDeserializeExceptionTest.java
@@ -41,7 +41,7 @@ import org.junit.runners.Parameterized;
import java.util.Collections;
import java.util.Properties;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assume.assumeTrue;
/**
@@ -108,11 +108,7 @@ public class HiveDeserializeExceptionTest {
ClassLoader parentLoader = object.getClass().getClassLoader().getParent();
assumeTrue(parentLoader != null);
byte[] bytes = InstantiationUtil.serializeObject(object);
- try {
- InstantiationUtil.deserializeObject(bytes, parentLoader);
- fail("Exception not thrown");
- } catch (ClassNotFoundException e) {
- // expected
- }
+ assertThatThrownBy(() -> InstantiationUtil.deserializeObject(bytes, parentLoader))
+ .isInstanceOf(ClassNotFoundException.class);
}
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectITCase.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectITCase.java
index 1aa6f506963..9ca1dcc9eb8 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectITCase.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectITCase.java
@@ -76,15 +76,8 @@ import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** Test Hive syntax when Hive dialect is used. */
public class HiveDialectITCase {
@@ -123,14 +116,14 @@ public class HiveDialectITCase {
TableEnvironmentInternal tableEnvInternal = (TableEnvironmentInternal) tableEnv;
Parser parser = tableEnvInternal.getParser();
// hive dialect should use HiveParser
- assertTrue(parser instanceof HiveParser);
+ assertThat(parser).isInstanceOf(HiveParser.class);
// execute some sql and verify the parser instance is reused
tableEnvInternal.executeSql("show databases");
- assertSame(parser, tableEnvInternal.getParser());
+ assertThat(tableEnvInternal.getParser()).isSameAs(parser);
// switching dialect will result in a new parser
tableEnvInternal.getConfig().setSqlDialect(SqlDialect.DEFAULT);
- assertNotEquals(
- parser.getClass().getName(), tableEnvInternal.getParser().getClass().getName());
+ assertThat(tableEnvInternal.getParser().getClass().getName())
+ .isNotEqualTo(parser.getClass().getName());
}
@Test
@@ -139,19 +132,19 @@ public class HiveDialectITCase {
Parser parser = tableEnvInternal.getParser();
// hive dialect should use HiveParser
- assertTrue(parser instanceof HiveParser);
- assertThat(parser.parse("HELP").get(0), instanceOf(HelpOperation.class));
- assertThat(parser.parse("clear").get(0), instanceOf(ClearOperation.class));
- assertThat(parser.parse("SET").get(0), instanceOf(SetOperation.class));
- assertThat(parser.parse("ResET").get(0), instanceOf(ResetOperation.class));
- assertThat(parser.parse("Exit").get(0), instanceOf(QuitOperation.class));
+ assertThat(parser).isInstanceOf(HiveParser.class);
+ assertThat(parser.parse("HELP").get(0)).isInstanceOf(HelpOperation.class);
+ assertThat(parser.parse("clear").get(0)).isInstanceOf(ClearOperation.class);
+ assertThat(parser.parse("SET").get(0)).isInstanceOf(SetOperation.class);
+ assertThat(parser.parse("ResET").get(0)).isInstanceOf(ResetOperation.class);
+ assertThat(parser.parse("Exit").get(0)).isInstanceOf(QuitOperation.class);
}
@Test
public void testCreateDatabase() throws Exception {
tableEnv.executeSql("create database db1 comment 'db1 comment'");
Database db = hiveCatalog.getHiveDatabase("db1");
- assertEquals("db1 comment", db.getDescription());
+ assertThat(db.getDescription()).isEqualTo("db1 comment");
String db2Location = warehouse + "/db2_location";
tableEnv.executeSql(
@@ -159,8 +152,8 @@ public class HiveDialectITCase {
"create database db2 location '%s' with dbproperties('k1'='v1')",
db2Location));
db = hiveCatalog.getHiveDatabase("db2");
- assertEquals(db2Location, locationPath(db.getLocationUri()));
- assertEquals("v1", db.getParameters().get("k1"));
+ assertThat(locationPath(db.getLocationUri())).isEqualTo(db2Location);
+ assertThat(db.getParameters().get("k1")).isEqualTo("v1");
}
@Test
@@ -169,26 +162,26 @@ public class HiveDialectITCase {
tableEnv.executeSql("create database db1 with dbproperties('k1'='v1')");
tableEnv.executeSql("alter database db1 set dbproperties ('k1'='v11','k2'='v2')");
Database db = hiveCatalog.getHiveDatabase("db1");
- assertEquals("v11", db.getParameters().get("k1"));
- assertEquals("v2", db.getParameters().get("k2"));
+ assertThat(db.getParameters().get("k1")).isEqualTo("v11");
+ assertThat(db.getParameters().get("k2")).isEqualTo("v2");
// alter owner
tableEnv.executeSql("alter database db1 set owner user user1");
db = hiveCatalog.getHiveDatabase("db1");
- assertEquals("user1", db.getOwnerName());
- assertEquals(PrincipalType.USER, db.getOwnerType());
+ assertThat(db.getOwnerName()).isEqualTo("user1");
+ assertThat(db.getOwnerType()).isEqualTo(PrincipalType.USER);
tableEnv.executeSql("alter database db1 set owner role role1");
db = hiveCatalog.getHiveDatabase("db1");
- assertEquals("role1", db.getOwnerName());
- assertEquals(PrincipalType.ROLE, db.getOwnerType());
+ assertThat(db.getOwnerName()).isEqualTo("role1");
+ assertThat(db.getOwnerType()).isEqualTo(PrincipalType.ROLE);
// alter location
if (hiveCatalog.getHiveVersion().compareTo("2.4.0") >= 0) {
String newLocation = warehouse + "/db1_new_location";
tableEnv.executeSql(String.format("alter database db1 set location '%s'", newLocation));
db = hiveCatalog.getHiveDatabase("db1");
- assertEquals(newLocation, locationPath(db.getLocationUri()));
+ assertThat(locationPath(db.getLocationUri())).isEqualTo(newLocation);
}
}
@@ -200,86 +193,85 @@ public class HiveDialectITCase {
"create external table tbl1 (d decimal(10,0),ts timestamp) partitioned by (p string) location '%s' tblproperties('k1'='v1')",
location));
Table hiveTable = hiveCatalog.getHiveTable(new ObjectPath("default", "tbl1"));
- assertEquals(TableType.EXTERNAL_TABLE.toString(), hiveTable.getTableType());
- assertEquals(1, hiveTable.getPartitionKeysSize());
- assertEquals(location, locationPath(hiveTable.getSd().getLocation()));
- assertEquals("v1", hiveTable.getParameters().get("k1"));
- assertFalse(hiveTable.getParameters().containsKey(SqlCreateHiveTable.TABLE_LOCATION_URI));
+ assertThat(hiveTable.getTableType()).isEqualTo(TableType.EXTERNAL_TABLE.toString());
+ assertThat(hiveTable.getPartitionKeysSize()).isEqualTo(1);
+ assertThat(locationPath(hiveTable.getSd().getLocation())).isEqualTo(location);
+ assertThat(hiveTable.getParameters().get("k1")).isEqualTo("v1");
+ assertThat(hiveTable.getParameters())
+ .doesNotContainKey(SqlCreateHiveTable.TABLE_LOCATION_URI);
tableEnv.executeSql("create table tbl2 (s struct<ts:timestamp,bin:binary>) stored as orc");
hiveTable = hiveCatalog.getHiveTable(new ObjectPath("default", "tbl2"));
- assertEquals(TableType.MANAGED_TABLE.toString(), hiveTable.getTableType());
- assertEquals(
- OrcSerde.class.getName(), hiveTable.getSd().getSerdeInfo().getSerializationLib());
- assertEquals(OrcInputFormat.class.getName(), hiveTable.getSd().getInputFormat());
- assertEquals(OrcOutputFormat.class.getName(), hiveTable.getSd().getOutputFormat());
+ assertThat(hiveTable.getTableType()).isEqualTo(TableType.MANAGED_TABLE.toString());
+ assertThat(hiveTable.getSd().getSerdeInfo().getSerializationLib())
+ .isEqualTo(OrcSerde.class.getName());
+ assertThat(hiveTable.getSd().getInputFormat()).isEqualTo(OrcInputFormat.class.getName());
+ assertThat(hiveTable.getSd().getOutputFormat()).isEqualTo(OrcOutputFormat.class.getName());
tableEnv.executeSql(
"create table tbl3 (m map<timestamp,binary>) partitioned by (p1 bigint,p2 tinyint) "
+ "row format serde 'org.apache.hadoop.hive.serde2.lazybinary.LazyBinarySerDe'");
hiveTable = hiveCatalog.getHiveTable(new ObjectPath("default", "tbl3"));
- assertEquals(2, hiveTable.getPartitionKeysSize());
- assertEquals(
- LazyBinarySerDe.class.getName(),
- hiveTable.getSd().getSerdeInfo().getSerializationLib());
+ assertThat(hiveTable.getPartitionKeysSize()).isEqualTo(2);
+ assertThat(hiveTable.getSd().getSerdeInfo().getSerializationLib())
+ .isEqualTo(LazyBinarySerDe.class.getName());
tableEnv.executeSql(
"create table tbl4 (x int,y smallint) row format delimited fields terminated by '|' lines terminated by '\n'");
hiveTable = hiveCatalog.getHiveTable(new ObjectPath("default", "tbl4"));
- assertEquals(
- "|",
- hiveTable.getSd().getSerdeInfo().getParameters().get(serdeConstants.FIELD_DELIM));
- assertEquals(
- "|",
- hiveTable
- .getSd()
- .getSerdeInfo()
- .getParameters()
- .get(serdeConstants.SERIALIZATION_FORMAT));
- assertEquals(
- "\n",
- hiveTable.getSd().getSerdeInfo().getParameters().get(serdeConstants.LINE_DELIM));
+ assertThat(hiveTable.getSd().getSerdeInfo().getParameters().get(serdeConstants.FIELD_DELIM))
+ .isEqualTo("|");
+ assertThat(
+ hiveTable
+ .getSd()
+ .getSerdeInfo()
+ .getParameters()
+ .get(serdeConstants.SERIALIZATION_FORMAT))
+ .isEqualTo("|");
+ assertThat(hiveTable.getSd().getSerdeInfo().getParameters().get(serdeConstants.LINE_DELIM))
+ .isEqualTo("\n");
tableEnv.executeSql(
"create table tbl5 (m map<bigint,string>) row format delimited collection items terminated by ';' "
+ "map keys terminated by ':'");
hiveTable = hiveCatalog.getHiveTable(new ObjectPath("default", "tbl5"));
- assertEquals(
- ";",
- hiveTable
- .getSd()
- .getSerdeInfo()
- .getParameters()
- .get(serdeConstants.COLLECTION_DELIM));
- assertEquals(
- ":",
- hiveTable.getSd().getSerdeInfo().getParameters().get(serdeConstants.MAPKEY_DELIM));
+ assertThat(
+ hiveTable
+ .getSd()
+ .getSerdeInfo()
+ .getParameters()
+ .get(serdeConstants.COLLECTION_DELIM))
+ .isEqualTo(";");
+ assertThat(
+ hiveTable
+ .getSd()
+ .getSerdeInfo()
+ .getParameters()
+ .get(serdeConstants.MAPKEY_DELIM))
+ .isEqualTo(":");
int createdTimeForTableExists = hiveTable.getCreateTime();
tableEnv.executeSql("create table if not exists tbl5 (m map<bigint,string>)");
hiveTable = hiveCatalog.getHiveTable(new ObjectPath("default", "tbl5"));
- assertEquals(createdTimeForTableExists, hiveTable.getCreateTime());
+ assertThat(hiveTable.getCreateTime()).isEqualTo(createdTimeForTableExists);
// test describe table
Parser parser = ((TableEnvironmentInternal) tableEnv).getParser();
DescribeTableOperation operation =
(DescribeTableOperation) parser.parse("desc tbl1").get(0);
- assertFalse(operation.isExtended());
- assertEquals(
- ObjectIdentifier.of(hiveCatalog.getName(), "default", "tbl1"),
- operation.getSqlIdentifier());
+ assertThat(operation.isExtended()).isFalse();
+ assertThat(operation.getSqlIdentifier())
+ .isEqualTo(ObjectIdentifier.of(hiveCatalog.getName(), "default", "tbl1"));
operation = (DescribeTableOperation) parser.parse("describe default.tbl2").get(0);
- assertFalse(operation.isExtended());
- assertEquals(
- ObjectIdentifier.of(hiveCatalog.getName(), "default", "tbl2"),
- operation.getSqlIdentifier());
+ assertThat(operation.isExtended()).isFalse();
+ assertThat(operation.getSqlIdentifier())
+ .isEqualTo(ObjectIdentifier.of(hiveCatalog.getName(), "default", "tbl2"));
operation = (DescribeTableOperation) parser.parse("describe extended tbl3").get(0);
- assertTrue(operation.isExtended());
- assertEquals(
- ObjectIdentifier.of(hiveCatalog.getName(), "default", "tbl3"),
- operation.getSqlIdentifier());
+ assertThat(operation.isExtended()).isTrue();
+ assertThat(operation.getSqlIdentifier())
+ .isEqualTo(ObjectIdentifier.of(hiveCatalog.getName(), "default", "tbl3"));
}
@Test
@@ -291,17 +283,17 @@ public class HiveDialectITCase {
CatalogTable catalogTable =
(CatalogTable) hiveCatalog.getTable(new ObjectPath("default", "tbl"));
TableSchema tableSchema = catalogTable.getSchema();
- assertTrue("PK not present", tableSchema.getPrimaryKey().isPresent());
- assertEquals("pk_name", tableSchema.getPrimaryKey().get().getName());
- assertFalse(
- "PK cannot be null",
- tableSchema.getFieldDataTypes()[0].getLogicalType().isNullable());
- assertFalse(
- "RELY NOT NULL should be reflected in schema",
- tableSchema.getFieldDataTypes()[1].getLogicalType().isNullable());
- assertTrue(
- "NORELY NOT NULL shouldn't be reflected in schema",
- tableSchema.getFieldDataTypes()[2].getLogicalType().isNullable());
+ assertThat(tableSchema.getPrimaryKey()).as("PK not present").isPresent();
+ assertThat(tableSchema.getPrimaryKey().get().getName()).isEqualTo("pk_name");
+ assertThat(tableSchema.getFieldDataTypes()[0].getLogicalType().isNullable())
+ .as("PK cannot be null")
+ .isFalse();
+ assertThat(tableSchema.getFieldDataTypes()[1].getLogicalType().isNullable())
+ .as("RELY NOT NULL should be reflected in schema")
+ .isFalse();
+ assertThat(tableSchema.getFieldDataTypes()[2].getLogicalType().isNullable())
+ .as("NORELY NOT NULL shouldn't be reflected in schema")
+ .isTrue();
}
@Test
@@ -309,20 +301,20 @@ public class HiveDialectITCase {
tableEnv.executeSql("create table src (x int,y string)");
tableEnv.executeSql("create table tbl1 as select x from src group by x").await();
Table hiveTable = hiveCatalog.getHiveTable(new ObjectPath("default", "tbl1"));
- assertEquals(1, hiveTable.getSd().getCols().size());
- assertEquals("x", hiveTable.getSd().getCols().get(0).getName());
- assertEquals("int", hiveTable.getSd().getCols().get(0).getType());
+ assertThat(hiveTable.getSd().getCols()).hasSize(1);
+ assertThat(hiveTable.getSd().getCols().get(0).getName()).isEqualTo("x");
+ assertThat(hiveTable.getSd().getCols().get(0).getType()).isEqualTo("int");
tableEnv.executeSql(
"create table default.tbl2 stored as orc as select x,max(y) as m from src group by x order by x limit 1")
.await();
hiveTable = hiveCatalog.getHiveTable(new ObjectPath("default", "tbl2"));
- assertEquals(2, hiveTable.getSd().getCols().size());
- assertEquals("x", hiveTable.getSd().getCols().get(0).getName());
- assertEquals("m", hiveTable.getSd().getCols().get(1).getName());
- assertEquals(
- OrcSerde.class.getName(), hiveTable.getSd().getSerdeInfo().getSerializationLib());
- assertEquals(OrcInputFormat.class.getName(), hiveTable.getSd().getInputFormat());
- assertEquals(OrcOutputFormat.class.getName(), hiveTable.getSd().getOutputFormat());
+ assertThat(hiveTable.getSd().getCols()).hasSize(2);
+ assertThat(hiveTable.getSd().getCols().get(0).getName()).isEqualTo("x");
+ assertThat(hiveTable.getSd().getCols().get(1).getName()).isEqualTo("m");
+ assertThat(hiveTable.getSd().getSerdeInfo().getSerializationLib())
+ .isEqualTo(OrcSerde.class.getName());
+ assertThat(hiveTable.getSd().getInputFormat()).isEqualTo(OrcInputFormat.class.getName());
+ assertThat(hiveTable.getSd().getOutputFormat()).isEqualTo(OrcOutputFormat.class.getName());
}
@Test
@@ -335,28 +327,29 @@ public class HiveDialectITCase {
tableEnv.executeSql("create table dest (x int)");
tableEnv.executeSql("insert into dest select x from src").await();
List<Row> results = queryResult(tableEnv.sqlQuery("select * from dest"));
- assertEquals("[+I[1], +I[2], +I[3]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1], +I[2], +I[3]]");
tableEnv.executeSql("insert overwrite dest values (3),(4),(5)").await();
results = queryResult(tableEnv.sqlQuery("select * from dest"));
- assertEquals("[+I[3], +I[4], +I[5]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[3], +I[4], +I[5]]");
// partitioned dest table
tableEnv.executeSql("create table dest2 (x int) partitioned by (p1 int,p2 string)");
tableEnv.executeSql("insert into dest2 partition (p1=0,p2='static') select x from src")
.await();
results = queryResult(tableEnv.sqlQuery("select * from dest2 order by x,p1,p2"));
- assertEquals("[+I[1, 0, static], +I[2, 0, static], +I[3, 0, static]]", results.toString());
+ assertThat(results.toString())
+ .isEqualTo("[+I[1, 0, static], +I[2, 0, static], +I[3, 0, static]]");
tableEnv.executeSql("insert into dest2 partition (p1=1,p2) select x,y from src").await();
results = queryResult(tableEnv.sqlQuery("select * from dest2 order by x,p1,p2"));
- assertEquals(
- "[+I[1, 0, static], +I[1, 1, a], +I[2, 0, static], +I[2, 1, b], +I[3, 0, static], +I[3, 1, c]]",
- results.toString());
+ assertThat(results.toString())
+ .isEqualTo(
+ "[+I[1, 0, static], +I[1, 1, a], +I[2, 0, static], +I[2, 1, b], +I[3, 0, static], +I[3, 1, c]]");
tableEnv.executeSql("insert overwrite dest2 partition (p1,p2) select 1,x,y from src")
.await();
results = queryResult(tableEnv.sqlQuery("select * from dest2 order by x,p1,p2"));
- assertEquals(
- "[+I[1, 0, static], +I[1, 1, a], +I[1, 2, b], +I[1, 3, c], +I[2, 0, static], +I[2, 1, b], +I[3, 0, static], +I[3, 1, c]]",
- results.toString());
+ assertThat(results.toString())
+ .isEqualTo(
+ "[+I[1, 0, static], +I[1, 1, a], +I[1, 2, b], +I[1, 3, c], +I[2, 0, static], +I[2, 1, b], +I[3, 0, static], +I[3, 1, c]]");
}
@Test
@@ -369,23 +362,23 @@ public class HiveDialectITCase {
// change properties
tableEnv.executeSql("alter table `default`.tbl1 set tblproperties ('k2'='v2')");
Table hiveTable = hiveCatalog.getHiveTable(tablePath);
- assertEquals("v1", hiveTable.getParameters().get("k1"));
- assertEquals("v2", hiveTable.getParameters().get("k2"));
+ assertThat(hiveTable.getParameters().get("k1")).isEqualTo("v1");
+ assertThat(hiveTable.getParameters().get("k2")).isEqualTo("v2");
// change location
String newLocation = warehouse + "/tbl1_new_location";
tableEnv.executeSql(
String.format("alter table default.tbl1 set location '%s'", newLocation));
hiveTable = hiveCatalog.getHiveTable(tablePath);
- assertEquals(newLocation, locationPath(hiveTable.getSd().getLocation()));
+ assertThat(locationPath(hiveTable.getSd().getLocation())).isEqualTo(newLocation);
// change file format
tableEnv.executeSql("alter table tbl1 set fileformat orc");
hiveTable = hiveCatalog.getHiveTable(tablePath);
- assertEquals(
- OrcSerde.class.getName(), hiveTable.getSd().getSerdeInfo().getSerializationLib());
- assertEquals(OrcInputFormat.class.getName(), hiveTable.getSd().getInputFormat());
- assertEquals(OrcOutputFormat.class.getName(), hiveTable.getSd().getOutputFormat());
+ assertThat(hiveTable.getSd().getSerdeInfo().getSerializationLib())
+ .isEqualTo(OrcSerde.class.getName());
+ assertThat(hiveTable.getSd().getInputFormat()).isEqualTo(OrcInputFormat.class.getName());
+ assertThat(hiveTable.getSd().getOutputFormat()).isEqualTo(OrcOutputFormat.class.getName());
// change serde
tableEnv.executeSql(
@@ -393,58 +386,54 @@ public class HiveDialectITCase {
"alter table tbl1 set serde '%s' with serdeproperties('%s'='%s')",
LazyBinarySerDe.class.getName(), serdeConstants.FIELD_DELIM, "\u0001"));
hiveTable = hiveCatalog.getHiveTable(tablePath);
- assertEquals(
- LazyBinarySerDe.class.getName(),
- hiveTable.getSd().getSerdeInfo().getSerializationLib());
- assertEquals(
- "\u0001",
- hiveTable.getSd().getSerdeInfo().getParameters().get(serdeConstants.FIELD_DELIM));
+ assertThat(hiveTable.getSd().getSerdeInfo().getSerializationLib())
+ .isEqualTo(LazyBinarySerDe.class.getName());
+ assertThat(hiveTable.getSd().getSerdeInfo().getParameters().get(serdeConstants.FIELD_DELIM))
+ .isEqualTo("\u0001");
// replace columns
tableEnv.executeSql(
"alter table tbl1 replace columns (t tinyint,s smallint,i int,b bigint,f float,d double,num decimal,"
+ "ts timestamp,dt date,str string,var varchar(10),ch char(123),bool boolean,bin binary)");
hiveTable = hiveCatalog.getHiveTable(tablePath);
- assertEquals(14, hiveTable.getSd().getColsSize());
- assertEquals("varchar(10)", hiveTable.getSd().getCols().get(10).getType());
- assertEquals("char(123)", hiveTable.getSd().getCols().get(11).getType());
+ assertThat(hiveTable.getSd().getColsSize()).isEqualTo(14);
+ assertThat(hiveTable.getSd().getCols().get(10).getType()).isEqualTo("varchar(10)");
+ assertThat(hiveTable.getSd().getCols().get(11).getType()).isEqualTo("char(123)");
tableEnv.executeSql(
"alter table tbl1 replace columns (a array<array<int>>,s struct<f1:struct<f11:int,f12:binary>, f2:map<double,date>>,"
+ "m map<char(5),map<timestamp,decimal(20,10)>>)");
hiveTable = hiveCatalog.getHiveTable(tablePath);
- assertEquals("array<array<int>>", hiveTable.getSd().getCols().get(0).getType());
- assertEquals(
- "struct<f1:struct<f11:int,f12:binary>,f2:map<double,date>>",
- hiveTable.getSd().getCols().get(1).getType());
- assertEquals(
- "map<char(5),map<timestamp,decimal(20,10)>>",
- hiveTable.getSd().getCols().get(2).getType());
+ assertThat(hiveTable.getSd().getCols().get(0).getType()).isEqualTo("array<array<int>>");
+ assertThat(hiveTable.getSd().getCols().get(1).getType())
+ .isEqualTo("struct<f1:struct<f11:int,f12:binary>,f2:map<double,date>>");
+ assertThat(hiveTable.getSd().getCols().get(2).getType())
+ .isEqualTo("map<char(5),map<timestamp,decimal(20,10)>>");
// add columns
tableEnv.executeSql("alter table tbl1 add columns (x int,y int)");
hiveTable = hiveCatalog.getHiveTable(tablePath);
- assertEquals(5, hiveTable.getSd().getColsSize());
+ assertThat(hiveTable.getSd().getColsSize()).isEqualTo(5);
// change column
tableEnv.executeSql("alter table tbl1 change column x x1 string comment 'new x col'");
hiveTable = hiveCatalog.getHiveTable(tablePath);
- assertEquals(5, hiveTable.getSd().getColsSize());
+ assertThat(hiveTable.getSd().getColsSize()).isEqualTo(5);
FieldSchema newField = hiveTable.getSd().getCols().get(3);
- assertEquals("x1", newField.getName());
- assertEquals("string", newField.getType());
+ assertThat(newField.getName()).isEqualTo("x1");
+ assertThat(newField.getType()).isEqualTo("string");
tableEnv.executeSql("alter table tbl1 change column y y int first");
hiveTable = hiveCatalog.getHiveTable(tablePath);
newField = hiveTable.getSd().getCols().get(0);
- assertEquals("y", newField.getName());
- assertEquals("int", newField.getType());
+ assertThat(newField.getName()).isEqualTo("y");
+ assertThat(newField.getType()).isEqualTo("int");
tableEnv.executeSql("alter table tbl1 change column x1 x2 timestamp after y");
hiveTable = hiveCatalog.getHiveTable(tablePath);
newField = hiveTable.getSd().getCols().get(1);
- assertEquals("x2", newField.getName());
- assertEquals("timestamp", newField.getType());
+ assertThat(newField.getName()).isEqualTo("x2");
+ assertThat(newField.getType()).isEqualTo("timestamp");
// add/replace columns cascade
tableEnv.executeSql("create table tbl2 (x int) partitioned by (dt date,id bigint)");
@@ -470,28 +459,28 @@ public class HiveDialectITCase {
ObjectPath tablePath2 = new ObjectPath("default", "tbl2");
hiveTable = hiveCatalog.getHiveTable(tablePath2);
Partition hivePartition = hiveCatalog.getHivePartition(hiveTable, partitionSpec1);
- assertEquals(2, hivePartition.getSd().getColsSize());
+ assertThat(hivePartition.getSd().getColsSize()).isEqualTo(2);
hivePartition = hiveCatalog.getHivePartition(hiveTable, partitionSpec2);
- assertEquals(2, hivePartition.getSd().getColsSize());
+ assertThat(hivePartition.getSd().getColsSize()).isEqualTo(2);
tableEnv.executeSql("alter table tbl2 add columns (ch char(5),vch varchar(9)) cascade");
hivePartition = hiveCatalog.getHivePartition(hiveTable, partitionSpec1);
- assertEquals(4, hivePartition.getSd().getColsSize());
+ assertThat(hivePartition.getSd().getColsSize()).isEqualTo(4);
hivePartition = hiveCatalog.getHivePartition(hiveTable, partitionSpec2);
- assertEquals(4, hivePartition.getSd().getColsSize());
+ assertThat(hivePartition.getSd().getColsSize()).isEqualTo(4);
// change column cascade
tableEnv.executeSql("alter table tbl2 change column ch ch char(10) cascade");
hivePartition = hiveCatalog.getHivePartition(hiveTable, partitionSpec1);
- assertEquals("char(10)", hivePartition.getSd().getCols().get(2).getType());
+ assertThat(hivePartition.getSd().getCols().get(2).getType()).isEqualTo("char(10)");
hivePartition = hiveCatalog.getHivePartition(hiveTable, partitionSpec2);
- assertEquals("char(10)", hivePartition.getSd().getCols().get(2).getType());
+ assertThat(hivePartition.getSd().getCols().get(2).getType()).isEqualTo("char(10)");
tableEnv.executeSql("alter table tbl2 change column vch str string first cascade");
hivePartition = hiveCatalog.getHivePartition(hiveTable, partitionSpec1);
- assertEquals("str", hivePartition.getSd().getCols().get(0).getName());
+ assertThat(hivePartition.getSd().getCols().get(0).getName()).isEqualTo("str");
hivePartition = hiveCatalog.getHivePartition(hiveTable, partitionSpec2);
- assertEquals("str", hivePartition.getSd().getCols().get(0).getName());
+ assertThat(hivePartition.getSd().getCols().get(0).getName()).isEqualTo("str");
}
@Test
@@ -527,17 +516,17 @@ public class HiveDialectITCase {
"alter table tbl partition (p1=1000,p2='2020-05-01') set location '%s'",
location));
Partition partition = hiveCatalog.getHivePartition(hiveTable, spec1);
- assertEquals(location, locationPath(partition.getSd().getLocation()));
+ assertThat(locationPath(partition.getSd().getLocation())).isEqualTo(location);
// change file format
tableEnv.executeSql(
"alter table tbl partition (p1=2000,p2='2020-01-01') set fileformat rcfile");
partition = hiveCatalog.getHivePartition(hiveTable, spec2);
- assertEquals(
- LazyBinaryColumnarSerDe.class.getName(),
- partition.getSd().getSerdeInfo().getSerializationLib());
- assertEquals(RCFileInputFormat.class.getName(), partition.getSd().getInputFormat());
- assertEquals(RCFileOutputFormat.class.getName(), partition.getSd().getOutputFormat());
+ assertThat(partition.getSd().getSerdeInfo().getSerializationLib())
+ .isEqualTo(LazyBinaryColumnarSerDe.class.getName());
+ assertThat(partition.getSd().getInputFormat()).isEqualTo(RCFileInputFormat.class.getName());
+ assertThat(partition.getSd().getOutputFormat())
+ .isEqualTo(RCFileOutputFormat.class.getName());
// change serde
tableEnv.executeSql(
@@ -545,12 +534,10 @@ public class HiveDialectITCase {
"alter table tbl partition (p1=1000,p2='2020-05-01') set serde '%s' with serdeproperties('%s'='%s')",
LazyBinarySerDe.class.getName(), serdeConstants.LINE_DELIM, "\n"));
partition = hiveCatalog.getHivePartition(hiveTable, spec1);
- assertEquals(
- LazyBinarySerDe.class.getName(),
- partition.getSd().getSerdeInfo().getSerializationLib());
- assertEquals(
- "\n",
- partition.getSd().getSerdeInfo().getParameters().get(serdeConstants.LINE_DELIM));
+ assertThat(partition.getSd().getSerdeInfo().getSerializationLib())
+ .isEqualTo(LazyBinarySerDe.class.getName());
+ assertThat(partition.getSd().getSerdeInfo().getParameters().get(serdeConstants.LINE_DELIM))
+ .isEqualTo("\n");
}
@Test
@@ -562,28 +549,30 @@ public class HiveDialectITCase {
"create view v(vx) comment 'v comment' tblproperties ('k1'='v1') as select x from tbl");
ObjectPath viewPath = new ObjectPath("default", "v");
CatalogBaseTable catalogBaseTable = hiveCatalog.getTable(viewPath);
- assertTrue(catalogBaseTable instanceof CatalogView);
- assertEquals("vx", catalogBaseTable.getUnresolvedSchema().getColumns().get(0).getName());
- assertEquals("v1", catalogBaseTable.getOptions().get("k1"));
+ assertThat(catalogBaseTable).isInstanceOf(CatalogView.class);
+ assertThat(catalogBaseTable.getUnresolvedSchema().getColumns().get(0).getName())
+ .isEqualTo("vx");
+ assertThat(catalogBaseTable.getOptions().get("k1")).isEqualTo("v1");
// change properties
tableEnv.executeSql("alter view v set tblproperties ('k1'='v11')");
catalogBaseTable = hiveCatalog.getTable(viewPath);
- assertEquals("v11", catalogBaseTable.getOptions().get("k1"));
+ assertThat(catalogBaseTable.getOptions().get("k1")).isEqualTo("v11");
// change query
tableEnv.executeSql("alter view v as select y from tbl");
catalogBaseTable = hiveCatalog.getTable(viewPath);
- assertEquals("y", catalogBaseTable.getUnresolvedSchema().getColumns().get(0).getName());
+ assertThat(catalogBaseTable.getUnresolvedSchema().getColumns().get(0).getName())
+ .isEqualTo("y");
// rename
tableEnv.executeSql("alter view v rename to v1");
viewPath = new ObjectPath("default", "v1");
- assertTrue(hiveCatalog.tableExists(viewPath));
+ assertThat(hiveCatalog.tableExists(viewPath)).isTrue();
// drop
tableEnv.executeSql("drop view v1");
- assertFalse(hiveCatalog.tableExists(viewPath));
+ assertThat(hiveCatalog.tableExists(viewPath)).isFalse();
}
@Test
@@ -594,16 +583,15 @@ public class HiveDialectITCase {
"create function default.my_abs as '%s'", GenericUDFAbs.class.getName()));
List<Row> functions =
CollectionUtil.iteratorToList(tableEnv.executeSql("show functions").collect());
- assertTrue(functions.toString().contains("my_abs"));
+ assertThat(functions.toString()).contains("my_abs");
// call the function
tableEnv.executeSql("create table src(x int)");
tableEnv.executeSql("insert into src values (1),(-1)").await();
- assertEquals(
- "[+I[1], +I[1]]",
- queryResult(tableEnv.sqlQuery("select my_abs(x) from src")).toString());
+ assertThat(queryResult(tableEnv.sqlQuery("select my_abs(x) from src")).toString())
+ .isEqualTo("[+I[1], +I[1]]");
// drop the function
tableEnv.executeSql("drop function my_abs");
- assertFalse(hiveCatalog.functionExists(new ObjectPath("default", "my_abs")));
+ assertThat(hiveCatalog.functionExists(new ObjectPath("default", "my_abs"))).isFalse();
tableEnv.executeSql("drop function if exists foo");
}
@@ -615,23 +603,23 @@ public class HiveDialectITCase {
"create temporary function temp_abs as '%s'",
GenericUDFAbs.class.getName()));
String[] functions = tableEnv.listUserDefinedFunctions();
- assertArrayEquals(new String[] {"temp_abs"}, functions);
+ assertThat(functions).isEqualTo(new String[] {"temp_abs"});
// call the function
tableEnv.executeSql("create table src(x int)");
tableEnv.executeSql("insert into src values (1),(-1)").await();
- assertEquals(
- "[+I[1], +I[1]]",
- queryResult(tableEnv.sqlQuery("select temp_abs(x) from src")).toString());
+ assertThat(queryResult(tableEnv.sqlQuery("select temp_abs(x) from src")).toString())
+ .isEqualTo("[+I[1], +I[1]]");
// switch DB and the temp function can still be used
tableEnv.executeSql("create database db1");
tableEnv.useDatabase("db1");
- assertEquals(
- "[+I[1], +I[1]]",
- queryResult(tableEnv.sqlQuery("select temp_abs(x) from `default`.src")).toString());
+ assertThat(
+ queryResult(tableEnv.sqlQuery("select temp_abs(x) from `default`.src"))
+ .toString())
+ .isEqualTo("[+I[1], +I[1]]");
// drop the function
tableEnv.executeSql("drop temporary function temp_abs");
functions = tableEnv.listUserDefinedFunctions();
- assertEquals(0, functions.length);
+ assertThat(functions).isEmpty();
tableEnv.executeSql("drop temporary function if exists foo");
}
@@ -643,24 +631,23 @@ public class HiveDialectITCase {
"create temporary function temp_count as '%s'",
GenericUDAFCount.class.getName()));
String[] functions = tableEnv.listUserDefinedFunctions();
- assertArrayEquals(new String[] {"temp_count"}, functions);
+ assertThat(functions).isEqualTo(new String[] {"temp_count"});
// call the function
tableEnv.executeSql("create table src(x int)");
tableEnv.executeSql("insert into src values (1),(-1)").await();
- assertEquals(
- "[+I[2]]",
- queryResult(tableEnv.sqlQuery("select temp_count(x) from src")).toString());
+ assertThat(queryResult(tableEnv.sqlQuery("select temp_count(x) from src")).toString())
+ .isEqualTo("[+I[2]]");
// switch DB and the temp function can still be used
tableEnv.executeSql("create database db1");
tableEnv.useDatabase("db1");
- assertEquals(
- "[+I[2]]",
- queryResult(tableEnv.sqlQuery("select temp_count(x) from `default`.src"))
- .toString());
+ assertThat(
+ queryResult(tableEnv.sqlQuery("select temp_count(x) from `default`.src"))
+ .toString())
+ .isEqualTo("[+I[2]]");
// drop the function
tableEnv.executeSql("drop temporary function temp_count");
functions = tableEnv.listUserDefinedFunctions();
- assertEquals(0, functions.length);
+ assertThat(functions).isEmpty();
tableEnv.executeSql("drop temporary function if exists foo");
}
@@ -668,19 +655,19 @@ public class HiveDialectITCase {
public void testCatalog() {
List<Row> catalogs =
CollectionUtil.iteratorToList(tableEnv.executeSql("show catalogs").collect());
- assertEquals(2, catalogs.size());
+ assertThat(catalogs).hasSize(2);
tableEnv.executeSql("use catalog " + CatalogManagerMocks.DEFAULT_CATALOG);
List<Row> databases =
CollectionUtil.iteratorToList(tableEnv.executeSql("show databases").collect());
- assertEquals(1, databases.size());
- assertEquals(
- "+I[" + CatalogManagerMocks.DEFAULT_DATABASE + "]", databases.get(0).toString());
+ assertThat(databases).hasSize(1);
+ assertThat(databases.get(0).toString())
+ .isEqualTo("+I[" + CatalogManagerMocks.DEFAULT_DATABASE + "]");
String catalogName =
tableEnv.executeSql("show current catalog").collect().next().toString();
- assertEquals("+I[" + CatalogManagerMocks.DEFAULT_CATALOG + "]", catalogName);
+ assertThat(catalogName).isEqualTo("+I[" + CatalogManagerMocks.DEFAULT_CATALOG + "]");
String databaseName =
tableEnv.executeSql("show current database").collect().next().toString();
- assertEquals("+I[" + CatalogManagerMocks.DEFAULT_DATABASE + "]", databaseName);
+ assertThat(databaseName).isEqualTo("+I[" + CatalogManagerMocks.DEFAULT_DATABASE + "]");
}
@Test
@@ -691,7 +678,7 @@ public class HiveDialectITCase {
"alter table tbl add partition (dt='2020-04-30',country='china') partition (dt='2020-04-30',country='us')");
ObjectPath tablePath = new ObjectPath("default", "tbl");
- assertEquals(2, hiveCatalog.listPartitions(tablePath).size());
+ assertThat(hiveCatalog.listPartitions(tablePath)).hasSize(2);
String partLocation = warehouse + "/part3_location";
tableEnv.executeSql(
@@ -708,11 +695,11 @@ public class HiveDialectITCase {
}
});
Partition hivePartition = hiveCatalog.getHivePartition(hiveTable, spec);
- assertEquals(partLocation, locationPath(hivePartition.getSd().getLocation()));
+ assertThat(locationPath(hivePartition.getSd().getLocation())).isEqualTo(partLocation);
tableEnv.executeSql(
"alter table tbl drop partition (dt='2020-04-30',country='china'),partition (dt='2020-05-01',country='belgium')");
- assertEquals(1, hiveCatalog.listPartitions(tablePath).size());
+ assertThat(hiveCatalog.listPartitions(tablePath)).hasSize(1);
}
@Test
@@ -723,55 +710,55 @@ public class HiveDialectITCase {
"alter table tbl add partition (dt='2020-04-30',country='china') partition (dt='2020-04-30',country='us')");
ObjectPath tablePath = new ObjectPath("default", "tbl");
- assertEquals(2, hiveCatalog.listPartitions(tablePath).size());
+ assertThat(hiveCatalog.listPartitions(tablePath)).hasSize(2);
List<Row> partitions =
CollectionUtil.iteratorToList(tableEnv.executeSql("show partitions tbl").collect());
- assertEquals(2, partitions.size());
- assertTrue(partitions.toString().contains("dt=2020-04-30/country=china"));
- assertTrue(partitions.toString().contains("dt=2020-04-30/country=us"));
+ assertThat(partitions).hasSize(2);
+ assertThat(partitions.toString()).contains("dt=2020-04-30/country=china");
+ assertThat(partitions.toString()).contains("dt=2020-04-30/country=us");
partitions =
CollectionUtil.iteratorToList(
tableEnv.executeSql("show partitions tbl partition (dt='2020-04-30')")
.collect());
- assertEquals(2, partitions.size());
- assertTrue(partitions.toString().contains("dt=2020-04-30/country=china"));
- assertTrue(partitions.toString().contains("dt=2020-04-30/country=us"));
+ assertThat(partitions).hasSize(2);
+ assertThat(partitions.toString()).contains("dt=2020-04-30/country=china");
+ assertThat(partitions.toString()).contains("dt=2020-04-30/country=us");
partitions =
CollectionUtil.iteratorToList(
tableEnv.executeSql("show partitions tbl partition (country='china')")
.collect());
- assertEquals(1, partitions.size());
- assertTrue(partitions.toString().contains("dt=2020-04-30/country=china"));
+ assertThat(partitions).hasSize(1);
+ assertThat(partitions.toString()).contains("dt=2020-04-30/country=china");
partitions =
CollectionUtil.iteratorToList(
tableEnv.executeSql(
"show partitions tbl partition (dt='2020-04-30',country='china')")
.collect());
- assertEquals(1, partitions.size());
- assertTrue(partitions.toString().contains("dt=2020-04-30/country=china"));
+ assertThat(partitions).hasSize(1);
+ assertThat(partitions.toString()).contains("dt=2020-04-30/country=china");
partitions =
CollectionUtil.iteratorToList(
tableEnv.executeSql(
"show partitions tbl partition (dt='2020-05-01',country='japan')")
.collect());
- assertEquals(0, partitions.size());
- try {
- CollectionUtil.iteratorToList(
- tableEnv.executeSql(
- "show partitions tbl partition (de='2020-04-30',city='china')")
- .collect());
- } catch (TableException e) {
- assertEquals(
- String.format(
- "Could not execute SHOW PARTITIONS %s.%s PARTITION (de=2020-04-30, city=china)",
- hiveCatalog.getName(), tablePath),
- e.getMessage());
- }
+ assertThat(partitions).isEmpty();
+
+ assertThatThrownBy(
+ () ->
+ CollectionUtil.iteratorToList(
+ tableEnv.executeSql(
+ "show partitions tbl partition (de='2020-04-30',city='china')")
+ .collect()))
+ .isInstanceOf(TableException.class)
+ .hasMessage(
+ String.format(
+ "Could not execute SHOW PARTITIONS %s.%s PARTITION (de=2020-04-30, city=china)",
+ hiveCatalog.getName(), tablePath));
tableEnv.executeSql(
"alter table tbl drop partition (dt='2020-04-30',country='china'),partition (dt='2020-04-30',country='us')");
- assertEquals(0, hiveCatalog.listPartitions(tablePath).size());
+ assertThat(hiveCatalog.listPartitions(tablePath)).isEmpty();
tableEnv.executeSql("drop table tbl");
tableEnv.executeSql(
@@ -781,30 +768,30 @@ public class HiveDialectITCase {
partitions =
CollectionUtil.iteratorToList(tableEnv.executeSql("show partitions tbl").collect());
- assertEquals(2, partitions.size());
- assertTrue(partitions.toString().contains("dt=2020-04-30 01:02:03/country=china"));
- assertTrue(partitions.toString().contains("dt=2020-04-30 04:05:06/country=us"));
+ assertThat(partitions).hasSize(2);
+ assertThat(partitions.toString()).contains("dt=2020-04-30 01:02:03/country=china");
+ assertThat(partitions.toString()).contains("dt=2020-04-30 04:05:06/country=us");
partitions =
CollectionUtil.iteratorToList(
tableEnv.executeSql(
"show partitions tbl partition (dt='2020-04-30 01:02:03')")
.collect());
- assertEquals(1, partitions.size());
- assertTrue(partitions.toString().contains("dt=2020-04-30 01:02:03/country=china"));
+ assertThat(partitions).hasSize(1);
+ assertThat(partitions.toString()).contains("dt=2020-04-30 01:02:03/country=china");
partitions =
CollectionUtil.iteratorToList(
tableEnv.executeSql(
"show partitions tbl partition (dt='2020-04-30 04:05:06')")
.collect());
- assertEquals(1, partitions.size());
- assertTrue(partitions.toString().contains("dt=2020-04-30 04:05:06/country=us"));
+ assertThat(partitions).hasSize(1);
+ assertThat(partitions.toString()).contains("dt=2020-04-30 04:05:06/country=us");
partitions =
CollectionUtil.iteratorToList(
tableEnv.executeSql(
"show partitions tbl partition (dt='2020-04-30 01:02:03',country='china')")
.collect());
- assertEquals(1, partitions.size());
- assertTrue(partitions.toString().contains("dt=2020-04-30 01:02:03/country=china"));
+ assertThat(partitions).hasSize(1);
+ assertThat(partitions.toString()).contains("dt=2020-04-30 01:02:03/country=china");
}
@Test
@@ -830,15 +817,10 @@ public class HiveDialectITCase {
}
private void verifyUnsupportedOperation(String ddl) {
- try {
- tableEnv.executeSql(ddl);
- fail("We don't support " + ddl);
- } catch (ValidationException e) {
- // expected
- assertTrue(
- "Expect UnsupportedOperationException for " + ddl,
- e.getCause() instanceof UnsupportedOperationException);
- }
+ assertThatThrownBy(() -> tableEnv.executeSql(ddl))
+ .isInstanceOf(ValidationException.class)
+ .getCause()
+ .isInstanceOf(UnsupportedOperationException.class);
}
private static String locationPath(String locationURI) throws URISyntaxException {
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectQueryITCase.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectQueryITCase.java
index b815bde0763..a41686bdd47 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectQueryITCase.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectQueryITCase.java
@@ -50,7 +50,7 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test hive query compatibility. */
public class HiveDialectQueryITCase {
@@ -187,59 +187,59 @@ public class HiveDialectQueryITCase {
.sorted()
.collect(Collectors.toList());
if (HiveParserUtils.legacyGrouping(hiveCatalog.getHiveConf())) {
- assertEquals(
- "["
- + "+I[1, 1, 3, 1],"
- + " +I[1, null, 1, 1],"
- + " +I[2, 2, 3, 1],"
- + " +I[2, null, 1, 1],"
- + " +I[3, 3, 3, 1],"
- + " +I[3, null, 1, 1],"
- + " +I[4, 4, 3, 1],"
- + " +I[4, null, 1, 1],"
- + " +I[5, 5, 3, 1],"
- + " +I[5, null, 1, 1]]",
- results1.toString());
- assertEquals(
- "["
- + "+I[1, 1, 1, 1],"
- + " +I[1, null, 1, 1],"
- + " +I[2, 2, 1, 1],"
- + " +I[2, null, 1, 1],"
- + " +I[3, 3, 1, 1],"
- + " +I[3, null, 1, 1],"
- + " +I[4, 4, 1, 1],"
- + " +I[4, null, 1, 1],"
- + " +I[5, 5, 1, 1],"
- + " +I[5, null, 1, 1]]",
- results2.toString());
+ assertThat(results1.toString())
+ .isEqualTo(
+ "["
+ + "+I[1, 1, 3, 1],"
+ + " +I[1, null, 1, 1],"
+ + " +I[2, 2, 3, 1],"
+ + " +I[2, null, 1, 1],"
+ + " +I[3, 3, 3, 1],"
+ + " +I[3, null, 1, 1],"
+ + " +I[4, 4, 3, 1],"
+ + " +I[4, null, 1, 1],"
+ + " +I[5, 5, 3, 1],"
+ + " +I[5, null, 1, 1]]");
+ assertThat(results2.toString())
+ .isEqualTo(
+ "["
+ + "+I[1, 1, 1, 1],"
+ + " +I[1, null, 1, 1],"
+ + " +I[2, 2, 1, 1],"
+ + " +I[2, null, 1, 1],"
+ + " +I[3, 3, 1, 1],"
+ + " +I[3, null, 1, 1],"
+ + " +I[4, 4, 1, 1],"
+ + " +I[4, null, 1, 1],"
+ + " +I[5, 5, 1, 1],"
+ + " +I[5, null, 1, 1]]");
} else {
- assertEquals(
- "["
- + "+I[1, 1, 0, 1],"
- + " +I[1, null, 1, 1],"
- + " +I[2, 2, 0, 1],"
- + " +I[2, null, 1, 1],"
- + " +I[3, 3, 0, 1],"
- + " +I[3, null, 1, 1],"
- + " +I[4, 4, 0, 1],"
- + " +I[4, null, 1, 1],"
- + " +I[5, 5, 0, 1],"
- + " +I[5, null, 1, 1]]",
- results1.toString());
- assertEquals(
- "["
- + "+I[1, 1, 0, 1],"
- + " +I[1, null, 0, 1],"
- + " +I[2, 2, 0, 1],"
- + " +I[2, null, 0, 1],"
- + " +I[3, 3, 0, 1],"
- + " +I[3, null, 0, 1],"
- + " +I[4, 4, 0, 1],"
- + " +I[4, null, 0, 1],"
- + " +I[5, 5, 0, 1],"
- + " +I[5, null, 0, 1]]",
- results2.toString());
+ assertThat(results1.toString())
+ .isEqualTo(
+ "["
+ + "+I[1, 1, 0, 1],"
+ + " +I[1, null, 1, 1],"
+ + " +I[2, 2, 0, 1],"
+ + " +I[2, null, 1, 1],"
+ + " +I[3, 3, 0, 1],"
+ + " +I[3, null, 1, 1],"
+ + " +I[4, 4, 0, 1],"
+ + " +I[4, null, 1, 1],"
+ + " +I[5, 5, 0, 1],"
+ + " +I[5, null, 1, 1]]");
+ assertThat(results2.toString())
+ .isEqualTo(
+ "["
+ + "+I[1, 1, 0, 1],"
+ + " +I[1, null, 0, 1],"
+ + " +I[2, 2, 0, 1],"
+ + " +I[2, null, 0, 1],"
+ + " +I[3, 3, 0, 1],"
+ + " +I[3, null, 0, 1],"
+ + " +I[4, 4, 0, 1],"
+ + " +I[4, null, 0, 1],"
+ + " +I[5, 5, 0, 1],"
+ + " +I[5, null, 0, 1]]");
}
}
@@ -260,29 +260,29 @@ public class HiveDialectQueryITCase {
if (HiveParserUtils.legacyGrouping(hiveCatalog.getHiveConf())) {
// the grouping function in older version (2.2.0) hive has some serious bug and is
// barely usable, therefore we only care about the group__id here
- assertEquals(
- "["
- + "+I[1, 2, 3, 7, 1, 1],"
- + " +I[1, 2, null, 3, 1, 0],"
- + " +I[1, null, 3, 5, 1, 1],"
- + " +I[1, null, null, 1, 1, 0],"
- + " +I[null, 2, 3, 6, 0, 1],"
- + " +I[null, 2, null, 2, 0, 0],"
- + " +I[null, null, 3, 4, 0, 1],"
- + " +I[null, null, null, 0, 0, 0]]",
- results.toString());
+ assertThat(results.toString())
+ .isEqualTo(
+ "["
+ + "+I[1, 2, 3, 7, 1, 1],"
+ + " +I[1, 2, null, 3, 1, 0],"
+ + " +I[1, null, 3, 5, 1, 1],"
+ + " +I[1, null, null, 1, 1, 0],"
+ + " +I[null, 2, 3, 6, 0, 1],"
+ + " +I[null, 2, null, 2, 0, 0],"
+ + " +I[null, null, 3, 4, 0, 1],"
+ + " +I[null, null, null, 0, 0, 0]]");
} else {
- assertEquals(
- "["
- + "+I[1, 2, 3, 0, 0, 0],"
- + " +I[1, 2, null, 1, 0, 1],"
- + " +I[1, null, 3, 2, 0, 0],"
- + " +I[1, null, null, 3, 0, 1],"
- + " +I[null, 2, 3, 4, 1, 0],"
- + " +I[null, 2, null, 5, 1, 1],"
- + " +I[null, null, 3, 6, 1, 0],"
- + " +I[null, null, null, 7, 1, 1]]",
- results.toString());
+ assertThat(results.toString())
+ .isEqualTo(
+ "["
+ + "+I[1, 2, 3, 0, 0, 0],"
+ + " +I[1, 2, null, 1, 0, 1],"
+ + " +I[1, null, 3, 2, 0, 0],"
+ + " +I[1, null, null, 3, 0, 1],"
+ + " +I[null, 2, 3, 4, 1, 0],"
+ + " +I[null, 2, null, 5, 1, 1],"
+ + " +I[null, null, 3, 6, 1, 0],"
+ + " +I[null, null, null, 7, 1, 1]]");
}
} finally {
tableEnv.executeSql("drop table temp");
@@ -303,9 +303,9 @@ public class HiveDialectQueryITCase {
List<Row> result =
CollectionUtil.iteratorToList(
tableEnv.executeSql("select * from test_values").collect());
- assertEquals(
- "[+I[1, -2, 3, 4, 1.1, 1.1, 1.10000, 2021-08-04T16:26:33.400, 2021-08-04, null, 123, 56, false]]",
- result.toString());
+ assertThat(result.toString())
+ .isEqualTo(
+ "[+I[1, -2, 3, 4, 1.1, 1.1, 1.10000, 2021-08-04T16:26:33.400, 2021-08-04, null, 123, 56, false]]");
} finally {
tableEnv.executeSql("drop table test_values");
}
@@ -323,7 +323,7 @@ public class HiveDialectQueryITCase {
tableEnv.executeSql(
"select * from test2b join test2a on test2b.a = test2a.a[1]")
.collect());
- assertEquals("[+I[2, [1, 2]]]", result.toString());
+ assertThat(result.toString()).isEqualTo("[+I[2, [1, 2]]]");
} finally {
tableEnv.executeSql("drop table test2a");
tableEnv.executeSql("drop table test2b");
@@ -476,7 +476,7 @@ public class HiveDialectQueryITCase {
this.statements = statements;
this.results = results;
this.sortResults = sortResults;
- assertEquals(statements.size(), results.size());
+ assertThat(results).hasSize(statements.size());
}
}
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDynamicTableFactoryTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDynamicTableFactoryTest.java
index 90e3bc72e7c..2703044a140 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDynamicTableFactoryTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDynamicTableFactoryTest.java
@@ -33,7 +33,6 @@ import org.apache.flink.table.connector.source.DynamicTableSource;
import org.apache.flink.table.factories.DynamicTableSinkFactory;
import org.apache.flink.table.factories.DynamicTableSourceFactory;
import org.apache.flink.table.factories.FactoryUtil;
-import org.apache.flink.util.ExceptionUtils;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.security.Credentials;
@@ -52,10 +51,8 @@ import static org.apache.flink.connectors.hive.HiveOptions.STREAMING_SOURCE_ENAB
import static org.apache.flink.connectors.hive.HiveOptions.STREAMING_SOURCE_MONITOR_INTERVAL;
import static org.apache.flink.connectors.hive.HiveOptions.STREAMING_SOURCE_PARTITION_INCLUDE;
import static org.apache.flink.connectors.hive.HiveOptions.STREAMING_SOURCE_PARTITION_ORDER;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/** Unit tests for {@link HiveDynamicTableFactory}. */
public class HiveDynamicTableFactoryTest {
@@ -82,13 +79,12 @@ public class HiveDynamicTableFactoryTest {
+ " tblproperties ('%s' = 'true')",
STREAMING_SOURCE_ENABLE.key()));
DynamicTableSource tableSource1 = getTableSource("table1");
- assertFalse(tableSource1 instanceof HiveLookupTableSource);
+ assertThat(tableSource1).isNotInstanceOf(HiveLookupTableSource.class);
HiveTableSource tableSource = (HiveTableSource) tableSource1;
Configuration configuration = new Configuration();
tableSource.catalogTable.getOptions().forEach(configuration::setString);
- assertEquals(
- HiveOptions.PartitionOrder.PARTITION_NAME,
- configuration.get(STREAMING_SOURCE_PARTITION_ORDER));
+ assertThat(configuration.get(STREAMING_SOURCE_PARTITION_ORDER))
+ .isEqualTo(HiveOptions.PartitionOrder.PARTITION_NAME);
// test table can't be selected when set 'streaming-source.partition.include' to 'latest'
tableEnv.executeSql(
@@ -98,17 +94,11 @@ public class HiveDynamicTableFactoryTest {
+ " tblproperties ('%s' = 'true', '%s' = 'latest')",
STREAMING_SOURCE_ENABLE.key(), STREAMING_SOURCE_PARTITION_INCLUDE.key()));
DynamicTableSource tableSource2 = getTableSource("table2");
- assertTrue(tableSource2 instanceof HiveLookupTableSource);
- try {
- tableEnv.executeSql("select * from table2");
- } catch (Throwable t) {
- assertTrue(
- ExceptionUtils.findThrowableWithMessage(
- t,
- "The only supported 'streaming-source.partition.include' is 'all' in"
- + " hive table scan, but is 'latest'")
- .isPresent());
- }
+ assertThat(tableSource2).isInstanceOf(HiveLookupTableSource.class);
+ assertThatThrownBy(() -> tableEnv.executeSql("select * from table2"))
+ .hasMessage(
+ "The only supported 'streaming-source.partition.include' is 'all' in"
+ + " hive table scan, but is 'latest'");
// test table support 'partition-name' in option 'streaming-source.partition.order'.
tableEnv.executeSql(
@@ -118,12 +108,12 @@ public class HiveDynamicTableFactoryTest {
+ " tblproperties ('%s' = 'true', '%s' = 'partition-name')",
STREAMING_SOURCE_ENABLE.key(), STREAMING_SOURCE_PARTITION_ORDER.key()));
DynamicTableSource tableSource3 = getTableSource("table3");
- assertTrue(tableSource3 instanceof HiveTableSource);
+ assertThat(tableSource3).isInstanceOf(HiveTableSource.class);
HiveTableSource hiveTableSource3 = (HiveTableSource) tableSource3;
Configuration configuration1 = new Configuration();
hiveTableSource3.catalogTable.getOptions().forEach(configuration1::setString);
PartitionOrder partitionOrder1 = configuration1.get(STREAMING_SOURCE_PARTITION_ORDER);
- assertEquals(HiveOptions.PartitionOrder.PARTITION_NAME, partitionOrder1);
+ assertThat(partitionOrder1).isEqualTo(HiveOptions.PartitionOrder.PARTITION_NAME);
// test deprecated option key 'streaming-source.consume-order' and new key
// 'streaming-source.partition-order'
@@ -134,13 +124,13 @@ public class HiveDynamicTableFactoryTest {
+ " tblproperties ('%s' = 'true', '%s' = 'partition-time')",
STREAMING_SOURCE_ENABLE.key(), "streaming-source.consume-order"));
DynamicTableSource tableSource4 = getTableSource("table4");
- assertTrue(tableSource4 instanceof HiveTableSource);
+ assertThat(tableSource4).isInstanceOf(HiveTableSource.class);
HiveTableSource hiveTableSource = (HiveTableSource) tableSource4;
Configuration configuration2 = new Configuration();
hiveTableSource.catalogTable.getOptions().forEach(configuration2::setString);
PartitionOrder partitionOrder2 = configuration2.get(STREAMING_SOURCE_PARTITION_ORDER);
- assertEquals(HiveOptions.PartitionOrder.PARTITION_TIME, partitionOrder2);
+ assertThat(partitionOrder2).isEqualTo(HiveOptions.PartitionOrder.PARTITION_TIME);
}
@Test
@@ -151,7 +141,7 @@ public class HiveDynamicTableFactoryTest {
"create table table5 (x int, y string, z int) tblproperties ('%s'='5min')",
LOOKUP_JOIN_CACHE_TTL.key()));
DynamicTableSource tableSource1 = getTableSource("table5");
- assertTrue(tableSource1 instanceof HiveLookupTableSource);
+ assertThat(tableSource1).isInstanceOf(HiveLookupTableSource.class);
// test hive streaming source is a lookup source when 'streaming-source.partition.include' =
// 'latest'
@@ -161,18 +151,17 @@ public class HiveDynamicTableFactoryTest {
+ " tblproperties ('%s' = 'true', '%s' = 'latest')",
STREAMING_SOURCE_ENABLE.key(), STREAMING_SOURCE_PARTITION_INCLUDE.key()));
DynamicTableSource tableSource2 = getTableSource("table6");
- assertTrue(tableSource2 instanceof HiveLookupTableSource);
+ assertThat(tableSource2).isInstanceOf(HiveLookupTableSource.class);
FileSystemLookupFunction lookupFunction =
(FileSystemLookupFunction)
((HiveLookupTableSource) tableSource2).getLookupFunction(new int[][] {{0}});
// test default lookup cache ttl for streaming-source is 1 hour
- assertEquals(Duration.ofHours(1), lookupFunction.getReloadInterval());
+ assertThat(lookupFunction.getReloadInterval()).isEqualTo(Duration.ofHours(1));
HiveLookupTableSource lookupTableSource = (HiveLookupTableSource) tableSource2;
Configuration configuration = new Configuration();
lookupTableSource.catalogTable.getOptions().forEach(configuration::setString);
- assertEquals(
- configuration.get(STREAMING_SOURCE_PARTITION_ORDER),
- HiveOptions.PartitionOrder.PARTITION_NAME);
+ assertThat(HiveOptions.PartitionOrder.PARTITION_NAME)
+ .isEqualTo(configuration.get(STREAMING_SOURCE_PARTITION_ORDER));
// test lookup with partition-time extractor options
tableEnv.executeSql(
@@ -193,16 +182,16 @@ public class HiveDynamicTableFactoryTest {
PARTITION_TIME_EXTRACTOR_CLASS.key()));
DynamicTableSource tableSource3 = getTableSource("table7");
- assertTrue(tableSource3 instanceof HiveLookupTableSource);
+ assertThat(tableSource3).isInstanceOf(HiveLookupTableSource.class);
HiveLookupTableSource tableSource = (HiveLookupTableSource) tableSource3;
Configuration configuration1 = new Configuration();
tableSource.catalogTable.getOptions().forEach(configuration1::setString);
- assertEquals(
- configuration1.get(STREAMING_SOURCE_PARTITION_ORDER),
- HiveOptions.PartitionOrder.PARTITION_TIME);
- assertEquals(configuration1.get(PARTITION_TIME_EXTRACTOR_KIND), "custom");
- assertEquals(configuration1.get(PARTITION_TIME_EXTRACTOR_CLASS), "path.to..TimeExtractor");
+ assertThat(HiveOptions.PartitionOrder.PARTITION_TIME)
+ .isEqualTo(configuration1.get(STREAMING_SOURCE_PARTITION_ORDER));
+ assertThat("custom").isEqualTo(configuration1.get(PARTITION_TIME_EXTRACTOR_KIND));
+ assertThat("path.to..TimeExtractor")
+ .isEqualTo(configuration1.get(PARTITION_TIME_EXTRACTOR_CLASS));
tableEnv.executeSql(
String.format(
@@ -212,15 +201,16 @@ public class HiveDynamicTableFactoryTest {
STREAMING_SOURCE_PARTITION_INCLUDE.key(),
STREAMING_SOURCE_MONITOR_INTERVAL.key()));
DynamicTableSource tableSource4 = getTableSource("table8");
- assertTrue(tableSource4 instanceof HiveLookupTableSource);
+ assertThat(tableSource4).isInstanceOf(HiveLookupTableSource.class);
HiveLookupTableSource lookupTableSource4 = (HiveLookupTableSource) tableSource4;
Configuration configuration4 = new Configuration();
lookupTableSource4.catalogTable.getOptions().forEach(configuration4::setString);
- assertEquals(configuration4.get(STREAMING_SOURCE_MONITOR_INTERVAL), Duration.ofMinutes(5L));
+ assertThat(Duration.ofMinutes(5L))
+ .isEqualTo(configuration4.get(STREAMING_SOURCE_MONITOR_INTERVAL));
}
@Test
- public void testInvalidOptions() throws Exception {
+ public void testInvalidOptions() {
tableEnv.executeSql(
String.format(
"create table table9 (x int, y string, z int)"
@@ -229,17 +219,11 @@ public class HiveDynamicTableFactoryTest {
STREAMING_SOURCE_PARTITION_INCLUDE.key(),
STREAMING_SOURCE_MONITOR_INTERVAL.key(),
STREAMING_SOURCE_CONSUME_START_OFFSET.key()));
-
- try {
- getTableSource("table9");
- } catch (Throwable t) {
- assertTrue(
- ExceptionUtils.findThrowableWithMessage(
- t,
- "The 'streaming-source.consume-start-offset' is not supported when "
- + "set 'streaming-source.partition.include' to 'latest'")
- .isPresent());
- }
+ assertThatThrownBy(() -> getTableSource("table9"))
+ .getRootCause()
+ .hasMessage(
+ "The 'streaming-source.consume-start-offset' is not supported when "
+ + "set 'streaming-source.partition.include' to 'latest'");
}
@Test
@@ -266,17 +250,17 @@ public class HiveDynamicTableFactoryTest {
HiveTableSource tableSource = (HiveTableSource) tableSource1;
Token token =
tableSource.getJobConf().getCredentials().getToken(hdfsDelegationTokenService);
- assertNotNull(token);
- assertEquals(hdfsDelegationTokenKind, token.getKind());
- assertEquals(hdfsDelegationTokenService, token.getService());
+ assertThat(token).isNotNull();
+ assertThat(token.getKind()).isEqualTo(hdfsDelegationTokenKind);
+ assertThat(token.getService()).isEqualTo(hdfsDelegationTokenService);
// test table sink's jobConf with credentials
DynamicTableSink tableSink1 = getTableSink("table10");
HiveTableSink tableSink = (HiveTableSink) tableSink1;
token = tableSink.getJobConf().getCredentials().getToken(hdfsDelegationTokenService);
- assertNotNull(token);
- assertEquals(hdfsDelegationTokenKind, token.getKind());
- assertEquals(hdfsDelegationTokenService, token.getService());
+ assertThat(token).isNotNull();
+ assertThat(token.getKind()).isEqualTo(hdfsDelegationTokenKind);
+ assertThat(token.getService()).isEqualTo(hdfsDelegationTokenService);
}
private DynamicTableSource getTableSource(String tableName) throws Exception {
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveLookupJoinITCase.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveLookupJoinITCase.java
index 38834a123c3..5fd2a56269a 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveLookupJoinITCase.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveLookupJoinITCase.java
@@ -56,8 +56,7 @@ import static org.apache.flink.connectors.hive.HiveOptions.STREAMING_SOURCE_ENAB
import static org.apache.flink.connectors.hive.HiveOptions.STREAMING_SOURCE_MONITOR_INTERVAL;
import static org.apache.flink.connectors.hive.HiveOptions.STREAMING_SOURCE_PARTITION_INCLUDE;
import static org.apache.flink.connectors.hive.HiveOptions.STREAMING_SOURCE_PARTITION_ORDER;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test lookup join of hive tables. */
public class HiveLookupJoinITCase {
@@ -170,8 +169,8 @@ public class HiveLookupJoinITCase {
lookupFunction2.open(null);
// verify lookup cache TTL option is properly configured
- assertEquals(Duration.ofMinutes(5), lookupFunction1.getReloadInterval());
- assertEquals(Duration.ofMinutes(120), lookupFunction2.getReloadInterval());
+ assertThat(lookupFunction1.getReloadInterval()).isEqualTo(Duration.ofMinutes(5));
+ assertThat(lookupFunction2.getReloadInterval()).isEqualTo(Duration.ofMinutes(120));
}
@Test
@@ -196,7 +195,7 @@ public class HiveLookupJoinITCase {
PartitionFetcher.Context<HiveTablePartition> context = lookupFunction.getFetcherContext();
List<HiveTablePartition> partitions = fetcher.fetch(context);
// fetch latest partition by partition-name
- assertEquals(1, partitions.size());
+ assertThat(partitions).hasSize(1);
PartitionReader<HiveTablePartition, RowData> reader = lookupFunction.getPartitionReader();
reader.open(partitions);
@@ -216,7 +215,7 @@ public class HiveLookupJoinITCase {
res.add(serializer.copy(row));
}
res.sort(Comparator.comparingInt(o -> o.getInt(0)));
- assertEquals("[+I(3,c,33,2020,09,31)]", res.toString());
+ assertThat(res.toString()).isEqualTo("[+I(3,c,33,2020,09,31)]");
}
@Test
@@ -232,7 +231,7 @@ public class HiveLookupJoinITCase {
+ " default_catalog.default_database.probe as p "
+ " join bounded_table for system_time as of p.p as b on p.x=b.x and p.y=b.y");
List<Row> results = CollectionUtil.iteratorToList(flinkTable.execute().collect());
- assertEquals("[+I[1, a, 10], +I[2, b, 22], +I[3, c, 33]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1, a, 10], +I[2, b, 22], +I[3, c, 33]]");
}
@Test
@@ -256,9 +255,9 @@ public class HiveLookupJoinITCase {
+ " default_catalog.default_database.probe as p"
+ " join bounded_partition_table for system_time as of p.p as b on p.x=b.x and p.y=b.y");
List<Row> results = CollectionUtil.iteratorToList(flinkTable.execute().collect());
- assertEquals(
- "[+I[1, a, 8, 2019, 08, 01], +I[1, a, 10, 2020, 08, 31], +I[2, b, 22, 2020, 08, 31]]",
- results.toString());
+ assertThat(results.toString())
+ .isEqualTo(
+ "[+I[1, a, 8, 2019, 08, 01], +I[1, a, 10, 2020, 08, 31], +I[2, b, 22, 2020, 08, 31]]");
}
@Test
@@ -286,9 +285,9 @@ public class HiveLookupJoinITCase {
+ " default_catalog.default_database.probe as p"
+ " join partition_table_1 for system_time as of p.p as b on p.x=b.x and p.y=b.y");
List<Row> results = CollectionUtil.iteratorToList(flinkTable.execute().collect());
- assertEquals(
- "[+I[1, a, 10, 2020, 09, 31], +I[2, b, 22, 2020, 09, 31], +I[3, c, 33, 2020, 09, 31]]",
- results.toString());
+ assertThat(results.toString())
+ .isEqualTo(
+ "[+I[1, a, 10, 2020, 09, 31], +I[2, b, 22, 2020, 09, 31], +I[3, c, 33, 2020, 09, 31]]");
}
@Test
@@ -316,8 +315,8 @@ public class HiveLookupJoinITCase {
+ " default_catalog.default_database.probe as p"
+ " join partition_table_2 for system_time as of p.p as b on p.x=b.x and p.y=b.y");
List<Row> results = CollectionUtil.iteratorToList(flinkTable.execute().collect());
- assertEquals(
- "[+I[1, a, 10, 2020, 08, 31], +I[2, b, 22, 2020, 08, 31]]", results.toString());
+ assertThat(results.toString())
+ .isEqualTo("[+I[1, a, 10, 2020, 08, 31], +I[2, b, 22, 2020, 08, 31]]");
}
@Test
@@ -354,8 +353,8 @@ public class HiveLookupJoinITCase {
+ " default_catalog.default_database.probe as p"
+ " join partition_table_3 for system_time as of p.p as b on p.x=b.x and p.y=b.y");
List<Row> results = CollectionUtil.iteratorToList(flinkTable.execute().collect());
- assertEquals(
- "[+I[1, a, 101, 2020, 08, 01], +I[2, b, 122, 2020, 08, 01]]", results.toString());
+ assertThat(results.toString())
+ .isEqualTo("[+I[1, a, 101, 2020, 08, 01], +I[2, b, 122, 2020, 08, 01]]");
}
@Test
@@ -385,9 +384,10 @@ public class HiveLookupJoinITCase {
+ "left join columnar_table for system_time as of t.p c "
+ "on t.x = c.x where c.x is null");
List<Row> results = CollectionUtil.iteratorToList(flinkTable.execute().collect());
- assertTrue(
- "All records should be able to be joined, and the final results should be empty.",
- results.size() == 0);
+ assertThat(results)
+ .as(
+ "All records should be able to be joined, and the final results should be empty.")
+ .isEmpty();
}
private FileSystemLookupFunction<HiveTablePartition> getLookupFunction(String tableName)
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveOutputFormatFactoryTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveOutputFormatFactoryTest.java
index b47296fc8dc..50f18495d4a 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveOutputFormatFactoryTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveOutputFormatFactoryTest.java
@@ -40,7 +40,7 @@ import java.net.URI;
import java.util.Collections;
import java.util.Properties;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for HiveOutputFormatFactory. */
public class HiveOutputFormatFactoryTest {
@@ -82,8 +82,8 @@ public class HiveOutputFormatFactoryTest {
Progressable progress)
throws IOException {
URI uri = finalOutPath.toUri();
- assertEquals(TEST_URI_SCHEME, uri.getScheme());
- assertEquals(TEST_URI_AUTHORITY, uri.getAuthority());
+ assertThat(uri.getScheme()).isEqualTo(TEST_URI_SCHEME);
+ assertThat(uri.getAuthority()).isEqualTo(TEST_URI_AUTHORITY);
return null;
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveRunnerITCase.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveRunnerITCase.java
index 657fd82a024..03138093caf 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveRunnerITCase.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveRunnerITCase.java
@@ -63,8 +63,8 @@ import java.util.stream.IntStream;
import static org.apache.hadoop.hive.conf.HiveConf.ConfVars.HIVE_IN_TEST;
import static org.apache.hadoop.hive.conf.HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY;
import static org.apache.hadoop.hive.conf.HiveConf.ConfVars.HIVE_TXN_MANAGER;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Tests that need to run with hive runner. Since hive runner is heavy, make sure to add test cases
@@ -161,8 +161,9 @@ public class HiveRunnerITCase {
"insert into dest select * from default_catalog.default_database.complexSrc")
.await();
List<String> result = hiveShell.executeQuery("select * from dest");
- assertEquals(1, result.size());
- assertEquals("[1,2,3]\t{1:\"a\",2:\"b\"}\t{\"f1\":3,\"f2\":\"c\"}", result.get(0));
+ assertThat(result).hasSize(1);
+ assertThat(result.get(0))
+ .isEqualTo("[1,2,3]\t{1:\"a\",2:\"b\"}\t{\"f1\":3,\"f2\":\"c\"}");
} finally {
tableEnv.executeSql("drop table dest");
}
@@ -197,10 +198,10 @@ public class HiveRunnerITCase {
"insert into dest select * from default_catalog.default_database.nestedSrc")
.await();
List<String> result = hiveShell.executeQuery("select * from dest");
- assertEquals(1, result.size());
- assertEquals(
- "[{\"f1\":1,\"f2\":\"a\"},{\"f1\":2,\"f2\":\"b\"},{\"f1\":3,\"f2\":\"c\"}]",
- result.get(0));
+ assertThat(result).hasSize(1);
+ assertThat(result.get(0))
+ .isEqualTo(
+ "[{\"f1\":1,\"f2\":\"a\"},{\"f1\":2,\"f2\":\"b\"},{\"f1\":3,\"f2\":\"c\"}]");
} finally {
tableEnv.executeSql("drop table dest");
}
@@ -229,11 +230,11 @@ public class HiveRunnerITCase {
tableEnv.executeSql("insert into db1.dest select * from db1.src").await();
List<String> results = hiveShell.executeQuery("select * from db1.dest");
- assertEquals(1, results.size());
+ assertThat(results).hasSize(1);
String[] cols = results.get(0).split("\t");
- assertEquals(17, cols.length);
- assertEquals("NULL", cols[0]);
- assertEquals(1, new HashSet<>(Arrays.asList(cols)).size());
+ assertThat(cols).hasSize(17);
+ assertThat(cols[0]).isEqualTo("NULL");
+ assertThat(new HashSet<>(Arrays.asList(cols))).hasSize(1);
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -336,7 +337,7 @@ public class HiveRunnerITCase {
tableEnv.executeSql(
"insert into db1.dest partition (p1='1\\'1', p2=1.1) select x from db1.src")
.await();
- assertEquals(1, hiveCatalog.listPartitions(new ObjectPath("db1", "dest")).size());
+ assertThat(hiveCatalog.listPartitions(new ObjectPath("db1", "dest"))).hasSize(1);
verifyHiveQueryResult(
"select * from db1.dest", Arrays.asList("1\t1'1\t1.1", "2\t1'1\t1.1"));
} finally {
@@ -358,7 +359,7 @@ public class HiveRunnerITCase {
tableEnv.executeSql(
"create table db1.dest (x int) partitioned by (p1 string, p2 double)");
tableEnv.executeSql("insert into db1.dest select * from db1.src").await();
- assertEquals(3, hiveCatalog.listPartitions(new ObjectPath("db1", "dest")).size());
+ assertThat(hiveCatalog.listPartitions(new ObjectPath("db1", "dest"))).hasSize(3);
verifyHiveQueryResult(
"select * from db1.dest", Arrays.asList("1\ta\t1.1", "2\ta\t2.2", "3\tb\t3.3"));
} finally {
@@ -381,7 +382,7 @@ public class HiveRunnerITCase {
tableEnv.executeSql(
"insert into db1.dest partition (p1=1.1,p2) select x,y from db1.src")
.await();
- assertEquals(2, hiveCatalog.listPartitions(new ObjectPath("db1", "dest")).size());
+ assertThat(hiveCatalog.listPartitions(new ObjectPath("db1", "dest"))).hasSize(2);
verifyHiveQueryResult(
"select * from db1.dest", Arrays.asList("1\t1.1\ta", "2\t1.1\tb"));
} finally {
@@ -414,11 +415,10 @@ public class HiveRunnerITCase {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select * from db1.src").execute().collect());
- assertEquals(2, results.size());
- assertEquals(LocalDateTime.of(2019, 11, 11, 0, 0), results.get(0).getField(0));
- assertEquals(
- LocalDateTime.of(2019, 12, 3, 15, 43, 32, 123456789),
- results.get(1).getField(0));
+ assertThat(results).hasSize(2);
+ assertThat(results.get(0).getField(0)).isEqualTo(LocalDateTime.of(2019, 11, 11, 0, 0));
+ assertThat(results.get(1).getField(0))
+ .isEqualTo(LocalDateTime.of(2019, 12, 3, 15, 43, 32, 123456789));
// test write timestamp to hive
tableEnv.executeSql("insert into db1.dest select max(ts) from db1.src").await();
verifyHiveQueryResult(
@@ -444,9 +444,9 @@ public class HiveRunnerITCase {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select * from db1.src").execute().collect());
- assertEquals(2, results.size());
- assertEquals(LocalDate.of(2019, 12, 9), results.get(0).getField(0));
- assertEquals(LocalDate.of(2019, 12, 12), results.get(1).getField(0));
+ assertThat(results).hasSize(2);
+ assertThat(results.get(0).getField(0)).isEqualTo(LocalDate.of(2019, 12, 9));
+ assertThat(results.get(1).getField(0)).isEqualTo(LocalDate.of(2019, 12, 12));
// test write date to hive
tableEnv.executeSql("insert into db1.dest select max(dt) from db1.src").await();
verifyHiveQueryResult(
@@ -486,15 +486,16 @@ public class HiveRunnerITCase {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select count(v) from db1.v1").execute().collect());
- assertEquals("[+I[2]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[2]]");
results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select * from db1.v2").execute().collect());
- assertEquals("[+I[1, 3], +I[3, 2]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1, 3], +I[3, 2]]");
results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select * from db1.v3").execute().collect());
- assertEquals("[+I[1, key1, 3], +I[2, key2, 1], +I[3, key3, 2]]", results.toString());
+ assertThat(results.toString())
+ .isEqualTo("[+I[1, key1, 3], +I[2, key2, 1], +I[3, key3, 2]]");
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -510,9 +511,8 @@ public class HiveRunnerITCase {
stmtSet.addInsertSql("insert into db1.dest select 1,' '");
stmtSet.addInsertSql("insert into db1.dest select 2,'a \t'");
stmtSet.execute().await();
- assertEquals(
- "[p= , p=a %09]",
- hiveShell.executeQuery("show partitions db1.dest").toString());
+ assertThat(hiveShell.executeQuery("show partitions db1.dest").toString())
+ .isEqualTo("[p= , p=a %09]");
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -542,18 +542,22 @@ public class HiveRunnerITCase {
tableEnv.getConfig().set(HiveOptions.TABLE_EXEC_HIVE_FALLBACK_MAPRED_READER, true);
tableEnv.executeSql("alter table db1.src change x x int");
- assertEquals(
- "[+I[1, 100], +I[2, 200]]",
- CollectionUtil.iteratorToList(
- tableEnv.sqlQuery("select * from db1.src").execute().collect())
- .toString());
+ assertThat(
+ CollectionUtil.iteratorToList(
+ tableEnv.sqlQuery("select * from db1.src")
+ .execute()
+ .collect())
+ .toString())
+ .isEqualTo("[+I[1, 100], +I[2, 200]]");
tableEnv.executeSql("alter table db1.src change y y string");
- assertEquals(
- "[+I[1, 100], +I[2, 200]]",
- CollectionUtil.iteratorToList(
- tableEnv.sqlQuery("select * from db1.src").execute().collect())
- .toString());
+ assertThat(
+ CollectionUtil.iteratorToList(
+ tableEnv.sqlQuery("select * from db1.src")
+ .execute()
+ .collect())
+ .toString())
+ .isEqualTo("[+I[1, 100], +I[2, 200]]");
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -567,25 +571,20 @@ public class HiveRunnerITCase {
tableEnv.executeSql("create table db1.src (x string,y string)");
hiveShell.execute(
"create table db1.dest (x string,y string) clustered by (x) into 3 buckets stored as orc tblproperties ('transactional'='true')");
- List<Exception> exceptions = new ArrayList<>();
- try {
- tableEnv.executeSql("insert into db1.src select * from db1.dest").await();
- } catch (Exception e) {
- exceptions.add(e);
- }
- try {
- tableEnv.executeSql("insert into db1.dest select * from db1.src").await();
- } catch (Exception e) {
- exceptions.add(e);
- }
- assertEquals(2, exceptions.size());
- exceptions.forEach(
- e -> {
- assertTrue(e instanceof FlinkHiveException);
- assertEquals(
- "Reading or writing ACID table db1.dest is not supported.",
- e.getMessage());
- });
+ assertThatThrownBy(
+ () ->
+ tableEnv.executeSql(
+ "insert into db1.src select * from db1.dest")
+ .await())
+ .isInstanceOf(FlinkHiveException.class)
+ .hasMessage("Reading or writing ACID table db1.dest is not supported.");
+ assertThatThrownBy(
+ () ->
+ tableEnv.executeSql(
+ "insert into db1.dest select * from db1.src")
+ .await())
+ .isInstanceOf(FlinkHiveException.class)
+ .hasMessage("Reading or writing ACID table db1.dest is not supported.");
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -703,13 +702,13 @@ public class HiveRunnerITCase {
private static void verifyWrittenData(List<Row> expected, List<String> results)
throws Exception {
- assertEquals(expected.size(), results.size());
+ assertThat(results).hasSize(expected.size());
Set<String> expectedSet = new HashSet<>();
for (int i = 0; i < results.size(); i++) {
final String rowString = expected.get(i).toString();
expectedSet.add(rowString.substring(3, rowString.length() - 1).replaceAll(", ", "\t"));
}
- assertEquals(expectedSet, new HashSet<>(results));
+ assertThat(new HashSet<>(results)).isEqualTo(expectedSet);
}
private static List<Row> generateRecords(int numRecords) {
@@ -728,8 +727,8 @@ public class HiveRunnerITCase {
private static void verifyHiveQueryResult(String query, List<String> expected) {
List<String> results = hiveShell.executeQuery(query);
- assertEquals(expected.size(), results.size());
- assertEquals(new HashSet<>(expected), new HashSet<>(results));
+ assertThat(results).hasSize(expected.size());
+ assertThat(new HashSet<>(results)).isEqualTo(new HashSet<>(expected));
}
private static void verifyFlinkQueryResult(
@@ -750,8 +749,8 @@ public class HiveRunnerITCase {
.map(Object::toString)
.collect(Collectors.joining("\t")))
.collect(Collectors.toList());
- assertEquals(expected.size(), results.size());
- assertEquals(new HashSet<>(expected), new HashSet<>(results));
+ assertThat(results).hasSize(expected.size());
+ assertThat(new HashSet<>(results)).isEqualTo(new HashSet<>(expected));
}
private static String toRowValue(List<Object> row) {
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveSourceITCase.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveSourceITCase.java
index 7a7e5801719..64fd238cc30 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveSourceITCase.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveSourceITCase.java
@@ -44,7 +44,7 @@ import java.util.Map;
import static org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable.IDENTIFIER;
import static org.apache.flink.table.factories.FactoryUtil.CONNECTOR;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for {@link HiveSource}. */
public class HiveSourceITCase {
@@ -102,9 +102,9 @@ public class HiveSourceITCase {
WatermarkStrategy.noWatermarks(),
"HiveSource-tbl1")
.executeAndCollect());
- assertEquals(2, results.size());
- assertEquals(1, results.get(0).getInt(0));
- assertEquals(2, results.get(1).getInt(0));
+ assertThat(results).hasSize(2);
+ assertThat(results.get(0).getInt(0)).isEqualTo(1);
+ assertThat(results.get(1).getInt(0)).isEqualTo(2);
hiveCatalog.dropTable(tablePath, false);
// test partitioned table
@@ -143,9 +143,9 @@ public class HiveSourceITCase {
WatermarkStrategy.noWatermarks(),
"HiveSource-tbl2")
.executeAndCollect());
- assertEquals(1, results.size());
- assertEquals(1, results.get(0).getInt(0));
- assertEquals("a", results.get(0).getString(1).toString());
+ assertThat(results).hasSize(1);
+ assertThat(results.get(0).getInt(0)).isEqualTo(1);
+ assertThat(results.get(0).getString(1).toString()).isEqualTo("a");
HiveTestUtils.createTextTableInserter(
hiveCatalog, tablePath.getDatabaseName(), tablePath.getObjectName())
@@ -178,9 +178,9 @@ public class HiveSourceITCase {
WatermarkStrategy.noWatermarks(),
"HiveSource-tbl2")
.executeAndCollect());
- assertEquals(1, results.size());
- assertEquals(3, results.get(0).getInt(0));
- assertEquals("b", results.get(0).getString(1).toString());
+ assertThat(results).hasSize(1);
+ assertThat(results.get(0).getInt(0)).isEqualTo(3);
+ assertThat(results.get(0).getString(1).toString()).isEqualTo("b");
hiveCatalog.dropTable(tablePath, false);
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableFactoryTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableFactoryTest.java
index 506dafbc491..612a96fe1ee 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableFactoryTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableFactoryTest.java
@@ -54,7 +54,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for {@link HiveTableFactory}. */
public class HiveTableFactoryTest {
@@ -87,7 +87,7 @@ public class HiveTableFactoryTest {
catalog.createTable(new ObjectPath("mydb", "mytable"), table, true);
final Optional<TableFactory> tableFactoryOpt = catalog.getTableFactory();
- assertTrue(tableFactoryOpt.isPresent());
+ assertThat(tableFactoryOpt).isPresent();
final HiveTableFactory tableFactory = (HiveTableFactory) tableFactoryOpt.get();
final TableSource tableSource =
@@ -97,7 +97,7 @@ public class HiveTableFactoryTest {
table,
new Configuration(),
false));
- assertTrue(tableSource instanceof StreamTableSource);
+ assertThat(tableSource).isInstanceOf(StreamTableSource.class);
final TableSink tableSink =
tableFactory.createTableSink(
@@ -107,7 +107,7 @@ public class HiveTableFactoryTest {
new Configuration(),
true,
false));
- assertTrue(tableSink instanceof StreamTableSink);
+ assertThat(tableSink).isInstanceOf(StreamTableSink.class);
}
@Test
@@ -135,7 +135,7 @@ public class HiveTableFactoryTest {
new Configuration(),
Thread.currentThread().getContextClassLoader(),
false);
- assertTrue(tableSource instanceof HiveTableSource);
+ assertThat(tableSource).isInstanceOf(HiveTableSource.class);
final DynamicTableSink tableSink =
FactoryUtil.createDynamicTableSink(
@@ -146,6 +146,6 @@ public class HiveTableFactoryTest {
new Configuration(),
Thread.currentThread().getContextClassLoader(),
false);
- assertTrue(tableSink instanceof HiveTableSink);
+ assertThat(tableSink).isInstanceOf(HiveTableSink.class);
}
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSinkITCase.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSinkITCase.java
index 39f7950acbc..26adb22180d 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSinkITCase.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSinkITCase.java
@@ -39,12 +39,10 @@ import org.apache.flink.table.catalog.hive.HiveTestUtils;
import org.apache.flink.types.Row;
import org.apache.flink.util.CloseableIterator;
import org.apache.flink.util.CollectionUtil;
-import org.apache.flink.util.ExceptionUtils;
import org.apache.flink.shaded.guava30.com.google.common.collect.Lists;
import org.junit.AfterClass;
-import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -72,9 +70,9 @@ import static org.apache.flink.table.planner.utils.TableTestUtil.readFromResourc
import static org.apache.flink.table.planner.utils.TableTestUtil.replaceNodeIdInOperator;
import static org.apache.flink.table.planner.utils.TableTestUtil.replaceStageId;
import static org.apache.flink.table.planner.utils.TableTestUtil.replaceStreamNodeId;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.fail;
/** Tests {@link HiveTableSink}. */
public class HiveTableSinkITCase {
@@ -131,9 +129,8 @@ public class HiveTableSinkITCase {
"insert into test_table select 1, 1", ExplainDetail.JSON_EXECUTION_PLAN);
final String expected = readFromResource(expectedResourceFileName);
- assertEquals(
- replaceNodeIdInOperator(replaceStreamNodeId(replaceStageId(expected))),
- replaceNodeIdInOperator(replaceStreamNodeId(replaceStageId(actual))));
+ assertThat(replaceNodeIdInOperator(replaceStreamNodeId(replaceStageId(actual))))
+ .isEqualTo(replaceNodeIdInOperator(replaceStreamNodeId(replaceStageId(expected))));
tEnv.executeSql("drop database db1 cascade");
}
@@ -153,7 +150,7 @@ public class HiveTableSinkITCase {
CollectionUtil.iteratorToList(
tEnv.executeSql("select * from append_table").collect());
rows.sort(Comparator.comparingInt(o -> (int) o.getField(0)));
- Assert.assertEquals(Arrays.asList(Row.of(1, 1), Row.of(2, 2)), rows);
+ assertThat(rows).isEqualTo(Arrays.asList(Row.of(1, 1), Row.of(2, 2)));
} finally {
tEnv.executeSql("drop database db1 cascade");
}
@@ -213,15 +210,13 @@ public class HiveTableSinkITCase {
StreamTableEnvironment tEnv = HiveTestUtils.createTableEnvInStreamingMode(env);
tEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
tEnv.useCatalog(hiveCatalog.getName());
-
try {
tEnv.executeSql(
"insert into db1.sink_table select 6,'a','b','2020-05-03','12'")
.await();
} catch (Exception e) {
- Assert.fail("Failed to execute sql: " + e.getMessage());
+ fail("Failed to execute sql: " + e.getMessage());
}
-
assertBatch(
"db1.sink_table",
Arrays.asList(
@@ -371,11 +366,11 @@ public class HiveTableSinkITCase {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
- Assert.assertEquals(
- Arrays.asList(
- Row.of(expectedData.get(i - 1)).toString(),
- Row.of(expectedData.get(i - 1)).toString()),
- fetchRows(iter, 2));
+ assertThat(fetchRows(iter, 2))
+ .isEqualTo(
+ Arrays.asList(
+ Row.of(expectedData.get(i - 1)).toString(),
+ Row.of(expectedData.get(i - 1)).toString()));
if (i < 6) {
HiveTestUtils.createTextTableInserter(hiveCatalog, "db1", "source_table")
@@ -418,12 +413,11 @@ public class HiveTableSinkITCase {
fail("Streaming write partitioned table without commit policy should fail");
} catch (FlinkHiveException e) {
// expected
- assertTrue(
- e.getMessage()
- .contains(
- String.format(
- "Streaming write to partitioned hive table `%s`.`%s`.`%s` without providing a commit policy",
- hiveCatalog.getName(), "db1", "dest")));
+ assertThat(e.getMessage())
+ .contains(
+ String.format(
+ "Streaming write to partitioned hive table `%s`.`%s`.`%s` without providing a commit policy",
+ hiveCatalog.getName(), "db1", "dest"));
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -433,17 +427,13 @@ public class HiveTableSinkITCase {
public void testCustomPartitionCommitPolicyNotFound() {
String customCommitPolicyClassName = "NotExistPartitionCommitPolicyClass";
- try {
- testStreamingWriteWithCustomPartitionCommitPolicy(customCommitPolicyClassName);
- fail("ExecutionException expected");
- } catch (Exception e) {
- assertTrue(
- ExceptionUtils.findThrowableWithMessage(
- e,
- "Can not create new instance for custom class from "
- + customCommitPolicyClassName)
- .isPresent());
- }
+ assertThatThrownBy(
+ () ->
+ testStreamingWriteWithCustomPartitionCommitPolicy(
+ customCommitPolicyClassName))
+ .hasStackTraceContaining(
+ "Can not create new instance for custom class from "
+ + customCommitPolicyClassName);
}
@Test
@@ -454,7 +444,7 @@ public class HiveTableSinkITCase {
private static List<String> fetchRows(Iterator<Row> iter, int size) {
List<String> strings = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
- Assert.assertTrue(iter.hasNext());
+ assertThat(iter.hasNext()).isTrue();
strings.add(iter.next().toString());
}
strings.sort(String::compareTo);
@@ -463,12 +453,12 @@ public class HiveTableSinkITCase {
private void checkSuccessFiles(String path) {
File basePath = new File(path, "d=2020-05-03");
- Assert.assertEquals(5, basePath.list().length);
- Assert.assertTrue(new File(new File(basePath, "e=7"), "_MY_SUCCESS").exists());
- Assert.assertTrue(new File(new File(basePath, "e=8"), "_MY_SUCCESS").exists());
- Assert.assertTrue(new File(new File(basePath, "e=9"), "_MY_SUCCESS").exists());
- Assert.assertTrue(new File(new File(basePath, "e=10"), "_MY_SUCCESS").exists());
- Assert.assertTrue(new File(new File(basePath, "e=11"), "_MY_SUCCESS").exists());
+ assertThat(basePath.list()).hasSize(5);
+ assertThat(new File(new File(basePath, "e=7"), "_MY_SUCCESS").exists()).isTrue();
+ assertThat(new File(new File(basePath, "e=8"), "_MY_SUCCESS").exists()).isTrue();
+ assertThat(new File(new File(basePath, "e=9"), "_MY_SUCCESS").exists()).isTrue();
+ assertThat(new File(new File(basePath, "e=10"), "_MY_SUCCESS").exists()).isTrue();
+ assertThat(new File(new File(basePath, "e=11"), "_MY_SUCCESS").exists()).isTrue();
}
private void testStreamingWriteWithCustomPartitionCommitPolicy(
@@ -546,11 +536,12 @@ public class HiveTableSinkITCase {
partitionKV -> {
String partitionPath =
new Path(new Path(base, "d=2020-05-03"), partitionKV).toString();
- Assert.assertTrue(
- "Partition(d=2020-05-03, "
- + partitionKV
- + ") is not committed successfully",
- committedPaths.contains(partitionPath));
+ assertThat(committedPaths)
+ .as(
+ "Partition(d=2020-05-03, "
+ + partitionKV
+ + ") is not committed successfully")
+ .contains(partitionPath);
});
} finally {
tEnv.executeSql("drop database if exists db1 cascade");
@@ -662,6 +653,6 @@ public class HiveTableSinkITCase {
.forEachRemaining(r -> results.add(r.toString()));
results.sort(String::compareTo);
expected.sort(String::compareTo);
- Assert.assertEquals(expected, results);
+ assertThat(results).isEqualTo(expected);
}
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSourceITCase.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSourceITCase.java
index 40757540077..1b1e06834dc 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSourceITCase.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSourceITCase.java
@@ -58,7 +58,6 @@ import org.apache.calcite.rel.RelNode;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.mapred.JobConf;
import org.junit.AfterClass;
-import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -80,10 +79,7 @@ import java.util.Optional;
import static org.apache.flink.table.catalog.hive.HiveTestUtils.createTableEnvWithHiveCatalog;
import static org.apache.flink.table.planner.utils.JavaScalaConversionUtil.toScala;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
@@ -130,11 +126,11 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
Table src = batchTableEnv.sqlQuery("select * from hive.source_db.test");
List<Row> rows = CollectionUtil.iteratorToList(src.execute().collect());
- Assert.assertEquals(4, rows.size());
- Assert.assertEquals("+I[1, 1, a, 1000, 1.11]", rows.get(0).toString());
- Assert.assertEquals("+I[2, 2, b, 2000, 2.22]", rows.get(1).toString());
- Assert.assertEquals("+I[3, 3, c, 3000, 3.33]", rows.get(2).toString());
- Assert.assertEquals("+I[4, 4, d, 4000, 4.44]", rows.get(3).toString());
+ assertThat(rows).hasSize(4);
+ assertThat(rows.get(0).toString()).isEqualTo("+I[1, 1, a, 1000, 1.11]");
+ assertThat(rows.get(1).toString()).isEqualTo("+I[2, 2, b, 2000, 2.22]");
+ assertThat(rows.get(2).toString()).isEqualTo("+I[3, 3, c, 3000, 3.33]");
+ assertThat(rows.get(3).toString()).isEqualTo("+I[4, 4, d, 4000, 4.44]");
}
@Test
@@ -154,10 +150,10 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
.commit();
Table src = batchTableEnv.sqlQuery("select * from hive.source_db.complex_test");
List<Row> rows = CollectionUtil.iteratorToList(src.execute().collect());
- Assert.assertEquals(1, rows.size());
- assertArrayEquals(array, (Integer[]) rows.get(0).getField(0));
- assertEquals(map, rows.get(0).getField(1));
- assertEquals(Row.of(struct[0], struct[1]), rows.get(0).getField(2));
+ assertThat(rows).hasSize(1);
+ assertThat((Integer[]) rows.get(0).getField(0)).isEqualTo(array);
+ assertThat(rows.get(0).getField(1)).isEqualTo(map);
+ assertThat(rows.get(0).getField(2)).isEqualTo(Row.of(struct[0], struct[1]));
}
/**
@@ -183,13 +179,13 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
Table src = batchTableEnv.sqlQuery("select * from hive.source_db.test_table_pt");
List<Row> rows = CollectionUtil.iteratorToList(src.execute().collect());
- assertEquals(4, rows.size());
+ assertThat(rows).hasSize(4);
Object[] rowStrings = rows.stream().map(Row::toString).sorted().toArray();
- assertArrayEquals(
- new String[] {
- "+I[2014, 3, 0]", "+I[2014, 4, 0]", "+I[2015, 2, 1]", "+I[2015, 5, 1]"
- },
- rowStrings);
+ assertThat(rowStrings)
+ .isEqualTo(
+ new String[] {
+ "+I[2014, 3, 0]", "+I[2014, 4, 0]", "+I[2015, 2, 1]", "+I[2015, 5, 1]"
+ });
}
@Test
@@ -211,17 +207,17 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
batchTableEnv.sqlQuery("select * from hive.source_db.test_table_pt_1 where pt = 0");
// first check execution plan to ensure partition prunning works
String[] explain = src.explain().split("==.*==\n");
- assertEquals(4, explain.length);
+ assertThat(explain).hasSize(4);
String optimizedLogicalPlan = explain[2];
- assertTrue(
- optimizedLogicalPlan,
- optimizedLogicalPlan.contains(
- "table=[[hive, source_db, test_table_pt_1, partitions=[{pt=0}], project=[year, value]]]"));
+ assertThat(optimizedLogicalPlan)
+ .as(optimizedLogicalPlan)
+ .contains(
+ "table=[[hive, source_db, test_table_pt_1, partitions=[{pt=0}], project=[year, value]]]");
// second check execute results
List<Row> rows = CollectionUtil.iteratorToList(src.execute().collect());
- assertEquals(2, rows.size());
+ assertThat(rows).hasSize(2);
Object[] rowStrings = rows.stream().map(Row::toString).sorted().toArray();
- assertArrayEquals(new String[] {"+I[2014, 3, 0]", "+I[2014, 4, 0]"}, rowStrings);
+ assertThat(rowStrings).isEqualTo(new String[] {"+I[2014, 3, 0]", "+I[2014, 4, 0]"});
}
@Test
@@ -254,71 +250,69 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
Table query =
tableEnv.sqlQuery("select x from db1.part where p1>1 or p2<>'a' order by x");
String[] explain = query.explain().split("==.*==\n");
- assertFalse(catalog.fallback);
+ assertThat(catalog.fallback).isFalse();
String optimizedPlan = explain[2];
- assertTrue(
- optimizedPlan,
- optimizedPlan.contains(
- "table=[[test-catalog, db1, part, partitions=[{p1=2, p2=b}, {p1=3, p2=c}, {p1=4, p2=c:2}]"));
+ assertThat(optimizedPlan)
+ .as(optimizedPlan)
+ .contains(
+ "table=[[test-catalog, db1, part, partitions=[{p1=2, p2=b}, {p1=3, p2=c}, {p1=4, p2=c:2}]");
List<Row> results = CollectionUtil.iteratorToList(query.execute().collect());
- assertEquals("[+I[2], +I[3], +I[4]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[2], +I[3], +I[4]]");
query = tableEnv.sqlQuery("select x from db1.part where p1>2 and p2<='a' order by x");
explain = query.explain().split("==.*==\n");
- assertFalse(catalog.fallback);
+ assertThat(catalog.fallback).isFalse();
optimizedPlan = explain[2];
- assertTrue(
- optimizedPlan,
- optimizedPlan.contains(
- "table=[[test-catalog, db1, part, partitions=[], project=[x]]]"));
+ assertThat(optimizedPlan)
+ .as(optimizedPlan)
+ .contains("table=[[test-catalog, db1, part, partitions=[], project=[x]]]");
results = CollectionUtil.iteratorToList(query.execute().collect());
- assertEquals("[]", results.toString());
+ assertThat(results.toString()).isEqualTo("[]");
query = tableEnv.sqlQuery("select x from db1.part where p1 in (1,3,5) order by x");
explain = query.explain().split("==.*==\n");
- assertFalse(catalog.fallback);
+ assertThat(catalog.fallback).isFalse();
optimizedPlan = explain[2];
- assertTrue(
- optimizedPlan,
- optimizedPlan.contains(
- "table=[[test-catalog, db1, part, partitions=[{p1=1, p2=a}, {p1=3, p2=c}], project=[x]]]"));
+ assertThat(optimizedPlan)
+ .as(optimizedPlan)
+ .contains(
+ "table=[[test-catalog, db1, part, partitions=[{p1=1, p2=a}, {p1=3, p2=c}], project=[x]]]");
results = CollectionUtil.iteratorToList(query.execute().collect());
- assertEquals("[+I[1], +I[3]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1], +I[3]]");
query =
tableEnv.sqlQuery(
"select x from db1.part where (p1=1 and p2='a') or ((p1=2 and p2='b') or p2='d') order by x");
explain = query.explain().split("==.*==\n");
- assertFalse(catalog.fallback);
+ assertThat(catalog.fallback).isFalse();
optimizedPlan = explain[2];
- assertTrue(
- optimizedPlan,
- optimizedPlan.contains(
- "table=[[test-catalog, db1, part, partitions=[{p1=1, p2=a}, {p1=2, p2=b}], project=[x]]]"));
+ assertThat(optimizedPlan)
+ .as(optimizedPlan)
+ .contains(
+ "table=[[test-catalog, db1, part, partitions=[{p1=1, p2=a}, {p1=2, p2=b}], project=[x]]]");
results = CollectionUtil.iteratorToList(query.execute().collect());
- assertEquals("[+I[1], +I[2]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1], +I[2]]");
query = tableEnv.sqlQuery("select x from db1.part where p2 = 'c:2' order by x");
explain = query.explain().split("==.*==\n");
- assertFalse(catalog.fallback);
+ assertThat(catalog.fallback).isFalse();
optimizedPlan = explain[2];
- assertTrue(
- optimizedPlan,
- optimizedPlan.contains(
- "table=[[test-catalog, db1, part, partitions=[{p1=4, p2=c:2}], project=[x]]]"));
+ assertThat(optimizedPlan)
+ .as(optimizedPlan)
+ .contains(
+ "table=[[test-catalog, db1, part, partitions=[{p1=4, p2=c:2}], project=[x]]]");
results = CollectionUtil.iteratorToList(query.execute().collect());
- assertEquals("[+I[4]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[4]]");
query = tableEnv.sqlQuery("select x from db1.part where '' = p2");
explain = query.explain().split("==.*==\n");
- assertFalse(catalog.fallback);
+ assertThat(catalog.fallback).isFalse();
optimizedPlan = explain[2];
- assertTrue(
- optimizedPlan,
- optimizedPlan.contains(
- "table=[[test-catalog, db1, part, partitions=[], project=[x]]]"));
+ assertThat(optimizedPlan)
+ .as(optimizedPlan)
+ .contains("table=[[test-catalog, db1, part, partitions=[], project=[x]]]");
results = CollectionUtil.iteratorToList(query.execute().collect());
- assertEquals("[]", results.toString());
+ assertThat(results.toString()).isEqualTo("[]");
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -353,21 +347,21 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
tableEnv.sqlQuery(
"select x from db1.part where p1>cast('2018-08-09' as date) and p2<>cast('2018-08-08 08:08:09.1' as timestamp)");
String[] explain = query.explain().split("==.*==\n");
- assertTrue(catalog.fallback);
+ assertThat(catalog.fallback).isTrue();
String optimizedPlan = explain[2];
- assertTrue(
- optimizedPlan,
- optimizedPlan.contains(
- "table=[[test-catalog, db1, part, partitions=[{p1=2018-08-10, p2=2018-08-08 08:08:10.1}]"));
+ assertThat(optimizedPlan)
+ .as(optimizedPlan)
+ .contains(
+ "table=[[test-catalog, db1, part, partitions=[{p1=2018-08-10, p2=2018-08-08 08:08:10.1}]");
List<Row> results = CollectionUtil.iteratorToList(query.execute().collect());
- assertEquals("[+I[3]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[3]]");
// filter by timestamp partition
query =
tableEnv.sqlQuery(
"select x from db1.part where timestamp '2018-08-08 08:08:09.1' = p2");
results = CollectionUtil.iteratorToList(query.execute().collect());
- assertEquals("[+I[2]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[2]]");
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -389,15 +383,15 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
batchTableEnv.sqlQuery(
"select p1, count(y) from hive.`default`.src group by p1");
String[] explain = table.explain().split("==.*==\n");
- assertEquals(4, explain.length);
+ assertThat(explain).hasSize(4);
String logicalPlan = explain[2];
String expectedExplain = "table=[[hive, default, src, project=[p1, y]]]";
- assertTrue(logicalPlan, logicalPlan.contains(expectedExplain));
+ assertThat(logicalPlan).as(logicalPlan).contains(expectedExplain);
List<Row> rows = CollectionUtil.iteratorToList(table.execute().collect());
- assertEquals(2, rows.size());
+ assertThat(rows).hasSize(2);
Object[] rowStrings = rows.stream().map(Row::toString).sorted().toArray();
- assertArrayEquals(new String[] {"+I[2013, 2]", "+I[2014, 1]"}, rowStrings);
+ assertThat(rowStrings).isEqualTo(new String[] {"+I[2013, 2]", "+I[2014, 1]"});
} finally {
batchTableEnv.executeSql("drop table src");
}
@@ -415,15 +409,16 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
.commit();
Table table = batchTableEnv.sqlQuery("select * from hive.`default`.src limit 1");
String[] explain = table.explain().split("==.*==\n");
- assertEquals(4, explain.length);
+ assertThat(explain).hasSize(4);
String logicalPlan = explain[2];
- assertTrue(
- logicalPlan, logicalPlan.contains("table=[[hive, default, src, limit=[1]]]"));
+ assertThat(logicalPlan)
+ .as(logicalPlan)
+ .contains("table=[[hive, default, src, limit=[1]]]");
List<Row> rows = CollectionUtil.iteratorToList(table.execute().collect());
- assertEquals(1, rows.size());
+ assertThat(rows).hasSize(1);
Object[] rowStrings = rows.stream().map(Row::toString).sorted().toArray();
- assertArrayEquals(new String[] {"+I[a]"}, rowStrings);
+ assertThat(rowStrings).isEqualTo(new String[] {"+I[a]"});
} finally {
batchTableEnv.executeSql("drop table src");
}
@@ -486,7 +481,7 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
.getRootNodes()
.get(0);
Transformation<?> transformation = execNode.translateToPlan(planner);
- Assert.assertEquals(expected, transformation.getParallelism());
+ assertThat(transformation.getParallelism()).isEqualTo(expected);
}
@Test
@@ -519,7 +514,7 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
Transformation<?> transformation =
(execNode.translateToPlan(planner).getInputs().get(0)).getInputs().get(0);
// when there's no infer, should use the default parallelism configured
- Assert.assertEquals(2, transformation.getParallelism());
+ assertThat(transformation.getParallelism()).isEqualTo(2);
}
@Test
@@ -553,11 +548,11 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
Transformation<?> transformation =
(execNode.translateToPlan(planner).getInputs().get(0)).getInputs().get(0);
// when there's no infer, should use the default parallelism
- Assert.assertEquals(
- ExecutionConfigOptions.TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM
- .defaultValue()
- .intValue(),
- transformation.getParallelism());
+ assertThat(transformation.getParallelism())
+ .isEqualTo(
+ ExecutionConfigOptions.TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM
+ .defaultValue()
+ .intValue());
}
@Test
@@ -608,8 +603,8 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
tEnv.executeSql("select * from hive.source_db.stream_partition_name_test");
CloseableIterator<Row> iter = result.collect();
- Assert.assertEquals(
- Row.of(1, "b", "12", "2020", "09", "03").toString(), fetchRows(iter, 1).get(0));
+ assertThat(fetchRows(iter, 1).get(0))
+ .isEqualTo(Row.of(1, "b", "12", "2020", "09", "03").toString());
for (int i = 2; i < 6; i++) {
try {
@@ -622,11 +617,12 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
.addRow(new Object[] {i, "new_add_1", 11 + i})
.commit("pt_year='2020',pt_mon='10',pt_day='0" + i + "'");
- Assert.assertEquals(
- Arrays.asList(
- Row.of(i, "new_add", 11 + i, "2020", "10", "0" + i).toString(),
- Row.of(i, "new_add_1", 11 + i, "2020", "10", "0" + i).toString()),
- fetchRows(iter, 2));
+ assertThat(fetchRows(iter, 2))
+ .isEqualTo(
+ Arrays.asList(
+ Row.of(i, "new_add", 11 + i, "2020", "10", "0" + i).toString(),
+ Row.of(i, "new_add_1", 11 + i, "2020", "10", "0" + i)
+ .toString()));
}
result.getJobClient().get().cancel();
@@ -664,8 +660,8 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
tEnv.executeSql("select * from hive.source_db.stream_create_time_test");
CloseableIterator<Row> iter = result.collect();
- Assert.assertEquals(
- Row.of(0, "a", "11", "A1", "B1", "C1").toString(), fetchRows(iter, 1).get(0));
+ assertThat(fetchRows(iter, 1).get(0))
+ .isEqualTo(Row.of(0, "a", "11", "A1", "B1", "C1").toString());
for (int i = 1; i < 6; i++) {
try {
@@ -678,11 +674,11 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
.addRow(new Object[] {i, "new_add_1", 11 + i})
.commit("p1='A',p2='B',p3='" + i + "'");
- Assert.assertEquals(
- Arrays.asList(
- Row.of(i, "new_add", 11 + i, "A", "B", i).toString(),
- Row.of(i, "new_add_1", 11 + i, "A", "B", i).toString()),
- fetchRows(iter, 2));
+ assertThat(fetchRows(iter, 2))
+ .isEqualTo(
+ Arrays.asList(
+ Row.of(i, "new_add", 11 + i, "A", "B", i).toString(),
+ Row.of(i, "new_add_1", 11 + i, "A", "B", i).toString()));
}
result.getJobClient().get().cancel();
}
@@ -715,8 +711,8 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
TableResult result = tEnv.executeSql("select * from hive.source_db.stream_test");
CloseableIterator<Row> iter = result.collect();
- Assert.assertEquals(
- Row.of(0, "0", "2020-05-06 00:00:00").toString(), fetchRows(iter, 1).get(0));
+ assertThat(fetchRows(iter, 1).get(0))
+ .isEqualTo(Row.of(0, "0", "2020-05-06 00:00:00").toString());
for (int i = 1; i < 6; i++) {
try {
@@ -729,11 +725,13 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
.addRow(new Object[] {i, i + "_copy"})
.commit("ts='2020-05-06 00:" + i + "0:00'");
- Assert.assertEquals(
- Arrays.asList(
- Row.of(i, String.valueOf(i), "2020-05-06 00:" + i + "0:00").toString(),
- Row.of(i, i + "_copy", "2020-05-06 00:" + i + "0:00").toString()),
- fetchRows(iter, 2));
+ assertThat(fetchRows(iter, 2))
+ .isEqualTo(
+ Arrays.asList(
+ Row.of(i, String.valueOf(i), "2020-05-06 00:" + i + "0:00")
+ .toString(),
+ Row.of(i, i + "_copy", "2020-05-06 00:" + i + "0:00")
+ .toString()));
}
result.getJobClient().get().cancel();
@@ -742,7 +740,7 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
private static List<String> fetchRows(Iterator<Row> iter, int size) {
List<String> strings = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
- Assert.assertTrue(iter.hasNext());
+ assertThat(iter.hasNext()).isTrue();
strings.add(iter.next().toString());
}
strings.sort(String::compareTo);
@@ -793,9 +791,8 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
.executeSql(
"insert into table source_db." + tblName + " values (1,'a'), (2,'b')")
.await();
- Assert.assertEquals(
- Arrays.asList(Row.of(1, "a").toString(), Row.of(2, "b").toString()),
- fetchRows(iter, 2));
+ assertThat(fetchRows(iter, 2))
+ .isEqualTo(Arrays.asList(Row.of(1, "a").toString(), Row.of(2, "b").toString()));
}
result.getJobClient().get().cancel();
@@ -808,12 +805,12 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
doAnswer(
invocation -> {
TableSourceFactory.Context context = invocation.getArgument(0);
- assertEquals(
- fallbackMR,
- context.getConfiguration()
- .get(
- HiveOptions
- .TABLE_EXEC_HIVE_FALLBACK_MAPRED_READER));
+ assertThat(
+ context.getConfiguration()
+ .get(
+ HiveOptions
+ .TABLE_EXEC_HIVE_FALLBACK_MAPRED_READER))
+ .isEqualTo(fallbackMR);
return new TestConfigSource(
new JobConf(hiveCatalog.getHiveConf()),
context.getConfiguration(),
@@ -838,7 +835,7 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select * from db1.src order by x").execute().collect());
- assertEquals("[+I[1, a], +I[2, b]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1, a], +I[2, b]]");
}
@Test
@@ -865,8 +862,8 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
String.format(
"create external table parquet_t (i int, j int) stored as %s location '%s'",
format, folderURI));
- Assert.assertEquals(
- Row.of(1, 2), tEnv.executeSql("select * from parquet_t").collect().next());
+ assertThat(tEnv.executeSql("select * from parquet_t").collect().next())
+ .isEqualTo(Row.of(1, 2));
}
@Test(timeout = 120000)
@@ -901,7 +898,7 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
"select x, y from hive.source_db.stream_project_pushdown_test where pt_year = '2020'");
CloseableIterator<Row> iter = result.collect();
- Assert.assertEquals(Row.of(1, "b").toString(), fetchRows(iter, 1).get(0));
+ assertThat(fetchRows(iter, 1).get(0)).isEqualTo(Row.of(1, "b").toString());
for (int i = 2; i < 6; i++) {
try {
@@ -914,10 +911,11 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
.addRow(new Object[] {i, "new_add_1", 11 + i})
.commit("pt_year='2020',pt_mon='10',pt_day='0" + i + "'");
- Assert.assertEquals(
- Arrays.asList(
- Row.of(i, "new_add").toString(), Row.of(i, "new_add_1").toString()),
- fetchRows(iter, 2));
+ assertThat(fetchRows(iter, 2))
+ .isEqualTo(
+ Arrays.asList(
+ Row.of(i, "new_add").toString(),
+ Row.of(i, "new_add_1").toString()));
}
result.getJobClient().get().cancel();
@@ -950,7 +948,7 @@ public class HiveTableSourceITCase extends BatchAbstractTestBase {
DataStreamSource<RowData> dataStream =
(DataStreamSource<RowData>) super.getDataStream(providerContext, execEnv);
int parallelism = dataStream.getTransformation().getParallelism();
- assertEquals(inferParallelism ? 1 : 2, parallelism);
+ assertThat(parallelism).isEqualTo(inferParallelism ? 1 : 2);
return dataStream;
}
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/PartitionMonitorTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/PartitionMonitorTest.java
index 0816092e9ae..25075d760de 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/PartitionMonitorTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/PartitionMonitorTest.java
@@ -43,8 +43,7 @@ import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for {@link ContinuousHiveSplitEnumerator.PartitionMonitor}. */
public class PartitionMonitorTest {
@@ -80,10 +79,9 @@ public class PartitionMonitorTest {
private void assertPartitionEquals(
Collection<List<String>> expected, Collection<List<String>> actual) {
- assertTrue(expected != null && actual != null && expected.size() == actual.size());
- assertArrayEquals(
- expected.stream().map(Object::toString).sorted().toArray(),
- actual.stream().map(Object::toString).sorted().toArray());
+ assertThat(expected != null && actual != null && expected.size() == actual.size()).isTrue();
+ assertThat(actual.stream().map(Object::toString).sorted().toArray())
+ .isEqualTo(expected.stream().map(Object::toString).sorted().toArray());
}
private void commitPartitionWithGivenCreateTime(
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/TableEnvHiveConnectorITCase.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/TableEnvHiveConnectorITCase.java
index 349264d071d..8ea26b0d0e9 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/TableEnvHiveConnectorITCase.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/TableEnvHiveConnectorITCase.java
@@ -52,9 +52,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test hive connector with table API. */
public class TableEnvHiveConnectorITCase {
@@ -90,7 +88,7 @@ public class TableEnvHiveConnectorITCase {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.executeSql("select * from dest").collect());
- assertEquals(0, results.size());
+ assertThat(results).isEmpty();
// dynamic partitioned table
tableEnv.executeSql("create table destp (x int) partitioned by (p int)");
HiveTestUtils.createTextTableInserter(hiveCatalog, "db1", "destp")
@@ -104,14 +102,14 @@ public class TableEnvHiveConnectorITCase {
results =
CollectionUtil.iteratorToList(
tableEnv.executeSql("select * from destp order by x").collect());
- assertEquals("[+I[1, 1], +I[2, 2]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1, 1], +I[2, 2]]");
// static partitioned table
tableEnv.executeSql("insert overwrite table destp partition(p=1) select x from src")
.await();
results =
CollectionUtil.iteratorToList(
tableEnv.executeSql("select * from destp order by x").collect());
- assertEquals("[+I[1, 1], +I[2, 2]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1, 1], +I[2, 2]]");
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -151,8 +149,8 @@ public class TableEnvHiveConnectorITCase {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.executeSql("select * from dest order by key").collect());
- assertEquals(
- "[+I[3, val3], +I[3, val3], +I[4, null], +I[4, null]]", results.toString());
+ assertThat(results.toString())
+ .isEqualTo("[+I[3, val3], +I[3, val3], +I[4, null], +I[4, null]]");
} finally {
tableEnv.useDatabase("default");
tableEnv.executeSql("drop database db1 cascade");
@@ -177,12 +175,12 @@ public class TableEnvHiveConnectorITCase {
Table hiveTable = hmsClient.getTable("db1", "part");
Path defaultPartPath = new Path(hiveTable.getSd().getLocation(), "y=" + defaultPartName);
FileSystem fs = defaultPartPath.getFileSystem(hiveConf);
- assertTrue(fs.exists(defaultPartPath));
+ assertThat(fs.exists(defaultPartPath)).isTrue();
TableImpl flinkTable =
(TableImpl) tableEnv.sqlQuery("select y, x from db1.part order by x");
List<Row> rows = CollectionUtil.iteratorToList(flinkTable.execute().collect());
- assertEquals("[+I[1, 1], +I[null, 2]]", rows.toString());
+ assertThat(rows.toString()).isEqualTo("[+I[1, 1], +I[null, 2]]");
tableEnv.executeSql("drop database db1 cascade");
}
@@ -219,9 +217,9 @@ public class TableEnvHiveConnectorITCase {
tableEnv.sqlQuery("select * from db1.part order by x")
.execute()
.collect());
- assertEquals(
- "[+I[1, 2019-12-23, 2019-12-23T00:00], +I[2, 2019-12-23, 2019-12-23T00:00], +I[3, 2019-12-25, 2019-12-25T16:23:43.012]]",
- results.toString());
+ assertThat(results.toString())
+ .isEqualTo(
+ "[+I[1, 2019-12-23, 2019-12-23T00:00], +I[2, 2019-12-23, 2019-12-23T00:00], +I[3, 2019-12-25, 2019-12-25T16:23:43.012]]");
results =
CollectionUtil.iteratorToList(
@@ -229,7 +227,7 @@ public class TableEnvHiveConnectorITCase {
"select x from db1.part where dt=cast('2019-12-25' as date)")
.execute()
.collect());
- assertEquals("[+I[3]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[3]]");
tableEnv.executeSql(
"insert into db1.part select 4,cast('2019-12-31' as date),cast('2019-12-31 12:00:00.0' as timestamp)")
@@ -237,7 +235,7 @@ public class TableEnvHiveConnectorITCase {
results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select max(dt) from db1.part").execute().collect());
- assertEquals("[+I[2019-12-31]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[2019-12-31]]");
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -281,14 +279,14 @@ public class TableEnvHiveConnectorITCase {
"select x from db1.simple, lateral table(hiveudtf(a)) as T(x)")
.execute()
.collect());
- assertEquals("[+I[1], +I[2], +I[3]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1], +I[2], +I[3]]");
results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery(
"select x from db1.nested, lateral table(hiveudtf(a)) as T(x)")
.execute()
.collect());
- assertEquals("[+I[{1=a, 2=b}], +I[{3=c}]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[{1=a, 2=b}], +I[{3=c}]]");
tableEnv.executeSql("create table db1.ts (a array<timestamp>)");
HiveTestUtils.createTextTableInserter(hiveCatalog, "db1", "ts")
@@ -306,7 +304,8 @@ public class TableEnvHiveConnectorITCase {
"select x from db1.ts, lateral table(hiveudtf(a)) as T(x)")
.execute()
.collect());
- assertEquals("[+I[2015-04-28T15:23], +I[2016-06-03T17:05:52]]", results.toString());
+ assertThat(results.toString())
+ .isEqualTo("[+I[2015-04-28T15:23], +I[2016-06-03T17:05:52]]");
} finally {
tableEnv.executeSql("drop database db1 cascade");
tableEnv.executeSql("drop function hiveudtf");
@@ -323,15 +322,15 @@ public class TableEnvHiveConnectorITCase {
"create table db1.tbl (x int,y bigint not null enable rely,z string not null enable norely)");
CatalogBaseTable catalogTable = hiveCatalog.getTable(new ObjectPath("db1", "tbl"));
TableSchema tableSchema = catalogTable.getSchema();
- assertTrue(
- "By default columns should be nullable",
- tableSchema.getFieldDataTypes()[0].getLogicalType().isNullable());
- assertFalse(
- "NOT NULL columns should be reflected in table schema",
- tableSchema.getFieldDataTypes()[1].getLogicalType().isNullable());
- assertTrue(
- "NOT NULL NORELY columns should be considered nullable",
- tableSchema.getFieldDataTypes()[2].getLogicalType().isNullable());
+ assertThat(tableSchema.getFieldDataTypes()[0].getLogicalType().isNullable())
+ .as("By default columns should be nullable")
+ .isTrue();
+ assertThat(tableSchema.getFieldDataTypes()[1].getLogicalType().isNullable())
+ .as("NOT NULL columns should be reflected in table schema")
+ .isFalse();
+ assertThat(tableSchema.getFieldDataTypes()[2].getLogicalType().isNullable())
+ .as("NOT NULL NORELY columns should be considered nullable")
+ .isTrue();
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -351,23 +350,23 @@ public class TableEnvHiveConnectorITCase {
"create table db1.tbl1 (x tinyint,y smallint,z int, primary key (x,z) disable novalidate rely)");
CatalogBaseTable catalogTable = hiveCatalog.getTable(new ObjectPath("db1", "tbl1"));
TableSchema tableSchema = catalogTable.getSchema();
- assertTrue(tableSchema.getPrimaryKey().isPresent());
+ assertThat(tableSchema.getPrimaryKey()).isPresent();
UniqueConstraint pk = tableSchema.getPrimaryKey().get();
- assertEquals(2, pk.getColumns().size());
- assertTrue(pk.getColumns().containsAll(Arrays.asList("x", "z")));
+ assertThat(pk.getColumns()).hasSize(2);
+ assertThat(pk.getColumns().containsAll(Arrays.asList("x", "z"))).isTrue();
// test norely PK constraints
tableEnv.executeSql(
"create table db1.tbl2 (x tinyint,y smallint, primary key (x) disable norely)");
catalogTable = hiveCatalog.getTable(new ObjectPath("db1", "tbl2"));
tableSchema = catalogTable.getSchema();
- assertFalse(tableSchema.getPrimaryKey().isPresent());
+ assertThat(tableSchema.getPrimaryKey()).isNotPresent();
// test table w/o PK
tableEnv.executeSql("create table db1.tbl3 (x tinyint)");
catalogTable = hiveCatalog.getTable(new ObjectPath("db1", "tbl3"));
tableSchema = catalogTable.getSchema();
- assertFalse(tableSchema.getPrimaryKey().isPresent());
+ assertThat(tableSchema.getPrimaryKey()).isNotPresent();
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -386,13 +385,13 @@ public class TableEnvHiveConnectorITCase {
.addRow(new Object[] {1, "a"})
.addRow(new Object[] {2, "ab"})
.commit();
- assertEquals(
- "[+I[1, a], +I[2, ab]]",
- CollectionUtil.iteratorToList(
- tableEnv.sqlQuery("select * from db1.src order by x")
- .execute()
- .collect())
- .toString());
+ assertThat(
+ CollectionUtil.iteratorToList(
+ tableEnv.sqlQuery("select * from db1.src order by x")
+ .execute()
+ .collect())
+ .toString())
+ .isEqualTo("[+I[1, a], +I[2, ab]]");
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -408,11 +407,13 @@ public class TableEnvHiveConnectorITCase {
tableEnv.executeSql("insert overwrite db1.dest partition (p='1') select 1").await();
tableEnv.executeSql("alter table db1.dest set fileformat sequencefile");
tableEnv.executeSql("insert overwrite db1.dest partition (p='1') select 1").await();
- assertEquals(
- "[+I[1, 1]]",
- CollectionUtil.iteratorToList(
- tableEnv.sqlQuery("select * from db1.dest").execute().collect())
- .toString());
+ assertThat(
+ CollectionUtil.iteratorToList(
+ tableEnv.sqlQuery("select * from db1.dest")
+ .execute()
+ .collect())
+ .toString())
+ .isEqualTo("[+I[1, 1]]");
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -432,16 +433,20 @@ public class TableEnvHiveConnectorITCase {
"create table db1.t2 (y int,x int) stored as parquet location '%s'",
location));
tableEnv.getConfig().set(HiveOptions.TABLE_EXEC_HIVE_FALLBACK_MAPRED_READER, true);
- assertEquals(
- "[+I[1], +I[2]]",
- CollectionUtil.iteratorToList(
- tableEnv.sqlQuery("select x from db1.t1").execute().collect())
- .toString());
- assertEquals(
- "[+I[1], +I[2]]",
- CollectionUtil.iteratorToList(
- tableEnv.sqlQuery("select x from db1.t2").execute().collect())
- .toString());
+ assertThat(
+ CollectionUtil.iteratorToList(
+ tableEnv.sqlQuery("select x from db1.t1")
+ .execute()
+ .collect())
+ .toString())
+ .isEqualTo("[+I[1], +I[2]]");
+ assertThat(
+ CollectionUtil.iteratorToList(
+ tableEnv.sqlQuery("select x from db1.t2")
+ .execute()
+ .collect())
+ .toString())
+ .isEqualTo("[+I[1], +I[2]]");
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -474,7 +479,7 @@ public class TableEnvHiveConnectorITCase {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select * from db1.part").execute().collect());
- assertEquals("[+I[1, 1]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1, 1]]");
} finally {
tableEnv.executeSql("drop database db1 cascade");
}
@@ -492,7 +497,7 @@ public class TableEnvHiveConnectorITCase {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select * from dest").execute().collect());
- assertEquals("[+I[1, 1, a]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1, 1, a]]");
tableEnv.executeSql("drop table if exists src");
tableEnv.executeSql("drop table if exists dest");
}
@@ -505,7 +510,7 @@ public class TableEnvHiveConnectorITCase {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select * from dest").execute().collect());
- assertEquals("[+I[1, 1, a]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1, 1, a]]");
tableEnv.executeSql("drop table if exists dest");
}
@@ -525,7 +530,7 @@ public class TableEnvHiveConnectorITCase {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.executeSql("select * from dest").collect());
- assertEquals("[+I[1, 0], +I[2, 0]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1, 0], +I[2, 0]]");
} finally {
tableEnv.executeSql("drop table src");
tableEnv.executeSql("drop table dest");
@@ -545,7 +550,7 @@ public class TableEnvHiveConnectorITCase {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.executeSql("select * from tbl1").collect());
- assertEquals("[+I[1], +I[2]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1], +I[2]]");
// test partition location
tableEnv.executeSql("create table tbl2 (x int) partitioned by (p string)");
location = tempFolder.newFolder(",");
@@ -557,13 +562,13 @@ public class TableEnvHiveConnectorITCase {
results =
CollectionUtil.iteratorToList(
tableEnv.executeSql("select * from tbl2").collect());
- assertEquals("[+I[1, a], +I[2, a]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[1, a], +I[2, a]]");
tableEnv.executeSql("insert into tbl2 partition (p) values (3,'b ,')").await();
results =
CollectionUtil.iteratorToList(
tableEnv.executeSql("select * from tbl2 where p='b ,'").collect());
- assertEquals("[+I[3, b ,]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[3, b ,]]");
} finally {
if (location != null) {
IOUtils.deleteFileQuietly(location.toPath());
@@ -591,7 +596,7 @@ public class TableEnvHiveConnectorITCase {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select * from src_t").execute().collect());
- assertEquals("[+I[hehuiyuan, null, null]]", results.toString());
+ assertThat(results.toString()).isEqualTo("[+I[hehuiyuan, null, null]]");
} finally {
tableEnv.executeSql("drop table if exists src_t");
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/read/HiveInputFormatPartitionReaderITCase.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/read/HiveInputFormatPartitionReaderITCase.java
index aac9007cf10..d3abde47e21 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/read/HiveInputFormatPartitionReaderITCase.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/read/HiveInputFormatPartitionReaderITCase.java
@@ -36,7 +36,7 @@ import org.junit.Test;
import java.util.Collections;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for HiveInputFormatPartitionReader. */
public class HiveInputFormatPartitionReaderITCase {
@@ -86,11 +86,11 @@ public class HiveInputFormatPartitionReaderITCase {
while (partitionReader.read(reuse) != null) {
count++;
}
- assertEquals(
- CollectionUtil.iteratorToList(
- tableEnv.executeSql("select * from " + tableName).collect())
- .size(),
- count);
+ assertThat(count)
+ .isEqualTo(
+ CollectionUtil.iteratorToList(
+ tableEnv.executeSql("select * from " + tableName).collect())
+ .size());
}
private String prepareData(TableEnvironment tableEnv, String format) throws Exception {
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/read/HivePartitionFetcherTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/read/HivePartitionFetcherTest.java
index 46c98ec39c0..ec9ddfbfdab 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/read/HivePartitionFetcherTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/read/HivePartitionFetcherTest.java
@@ -45,7 +45,7 @@ import java.util.Map;
import java.util.Optional;
import static org.apache.flink.connectors.hive.HiveOptions.STREAMING_SOURCE_PARTITION_ORDER;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for hive partition fetch implementations. */
public class HivePartitionFetcherTest {
@@ -92,7 +92,7 @@ public class HivePartitionFetcherTest {
flinkConf,
defaultPartName);
fetcherContext.open();
- assertEquals(0, fetcherContext.getComparablePartitionValueList().size());
+ assertThat(fetcherContext.getComparablePartitionValueList()).isEmpty();
// test create-time order
flinkConf.set(STREAMING_SOURCE_PARTITION_ORDER, HiveOptions.PartitionOrder.CREATE_TIME);
@@ -107,7 +107,7 @@ public class HivePartitionFetcherTest {
flinkConf,
defaultPartName);
fetcherContext.open();
- assertEquals(0, fetcherContext.getComparablePartitionValueList().size());
+ assertThat(fetcherContext.getComparablePartitionValueList()).isEmpty();
// test partition-name order
flinkConf.set(STREAMING_SOURCE_PARTITION_ORDER, HiveOptions.PartitionOrder.PARTITION_NAME);
@@ -122,7 +122,7 @@ public class HivePartitionFetcherTest {
flinkConf,
defaultPartName);
fetcherContext.open();
- assertEquals(0, fetcherContext.getComparablePartitionValueList().size());
+ assertThat(fetcherContext.getComparablePartitionValueList()).isEmpty();
}
private static class MyHivePartitionFetcherContext
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/read/HiveTableFileInputFormatTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/read/HiveTableFileInputFormatTest.java
index b2a24853558..9d71971e119 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/read/HiveTableFileInputFormatTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/read/HiveTableFileInputFormatTest.java
@@ -23,7 +23,6 @@ import org.apache.flink.core.fs.Path;
import org.apache.flink.util.FileUtils;
import org.apache.hadoop.mapred.FileSplit;
-import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -31,6 +30,8 @@ import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
+import static org.assertj.core.api.Assertions.assertThat;
+
/** Test for {@link HiveTableFileInputFormat}. */
public class HiveTableFileInputFormatTest {
@@ -42,6 +43,6 @@ public class HiveTableFileInputFormatTest {
FileUtils.writeFileUtf8(file, "hahahahahahaha");
FileInputSplit split = new FileInputSplit(0, new Path(file.getPath()), 0, -1, null);
FileSplit fileSplit = HiveTableFileInputFormat.toHadoopFileSplit(split);
- Assert.assertEquals(14, fileSplit.getLength());
+ assertThat(fileSplit.getLength()).isEqualTo(14);
}
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/util/HiveConfUtilsTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/util/HiveConfUtilsTest.java
index bc13505dcc8..73ca94e9a86 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/util/HiveConfUtilsTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/util/HiveConfUtilsTest.java
@@ -19,7 +19,6 @@
package org.apache.flink.connectors.hive.util;
import org.apache.hadoop.hive.conf.HiveConf;
-import org.junit.Assert;
import org.junit.Test;
import java.io.ByteArrayInputStream;
@@ -27,6 +26,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
+import static org.assertj.core.api.Assertions.assertThat;
+
/** Test for {@link HiveConfUtils}. */
public class HiveConfUtilsTest {
private static final String HIVE_SITE_CONTENT =
@@ -42,17 +43,19 @@ public class HiveConfUtilsTest {
@Test
public void testCreateHiveConf() {
HiveConf hiveConf = createHiveConf();
- Assert.assertTrue(hiveConf.getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL));
+ assertThat(hiveConf.getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL)).isTrue();
// will override configurations from `hiveConf` with hive default values which default value
// is null or empty string
- Assert.assertFalse(
- new HiveConf(hiveConf, HiveConf.class)
- .getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL));
+ assertThat(
+ new HiveConf(hiveConf, HiveConf.class)
+ .getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL))
+ .isFalse();
- Assert.assertTrue(
- HiveConfUtils.create(hiveConf)
- .getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL));
+ assertThat(
+ HiveConfUtils.create(hiveConf)
+ .getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL))
+ .isTrue();
}
private HiveConf createHiveConf() {
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogDataTypeTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogDataTypeTest.java
index d5ea1be94a3..99edaec7c51 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogDataTypeTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogDataTypeTest.java
@@ -42,7 +42,7 @@ import org.junit.rules.ExpectedException;
import java.util.HashMap;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for data type mappings in HiveCatalog. */
public class HiveCatalogDataTypeTest {
@@ -212,7 +212,7 @@ public class HiveCatalogDataTypeTest {
catalog.createDatabase(db1, createDb(), false);
catalog.createTable(path1, table, false);
- assertEquals(table.getSchema(), catalog.getTable(path1).getSchema());
+ assertThat(catalog.getTable(path1).getSchema()).isEqualTo(table.getSchema());
}
private static CatalogDatabase createDb() {
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogHiveMetadataTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogHiveMetadataTest.java
index 9651a4ccbb1..b8a96f0a976 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogHiveMetadataTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogHiveMetadataTest.java
@@ -61,7 +61,6 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -269,7 +268,7 @@ class HiveCatalogHiveMetadataTest extends HiveCatalogMetadataTestBase {
assertThat(catalogTable.getSchema().getPrimaryKey()).as("PK not present").isPresent();
UniqueConstraint pk = catalogTable.getSchema().getPrimaryKey().get();
assertThat(pk.getName()).isEqualTo("pk_name");
- assertThat(pk.getColumns()).isEqualTo(Collections.singletonList("x"));
+ assertThat(pk.getColumns()).containsExactly("x");
assertThat(catalogTable.getSchema().getFieldDataTypes()[0].getLogicalType().isNullable())
.isFalse();
assertThat(catalogTable.getSchema().getFieldDataTypes()[1].getLogicalType().isNullable())
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogUdfITCase.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogUdfITCase.java
index c3efe604b34..45896775962 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogUdfITCase.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/HiveCatalogUdfITCase.java
@@ -48,7 +48,6 @@ import org.apache.hadoop.hive.ql.udf.UDFMonth;
import org.apache.hadoop.hive.ql.udf.UDFYear;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFSum;
import org.junit.AfterClass;
-import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
@@ -69,6 +68,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.lang.String.format;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* IT case for HiveCatalog. TODO: move to flink-connector-hive-test end-to-end test module once it's
@@ -223,7 +223,7 @@ public class HiveCatalogUdfITCase extends AbstractTestBase {
results = new ArrayList<>(results);
results.sort(String::compareTo);
- Assert.assertEquals(Arrays.asList("1,1,2,2", "2,2,4,4", "3,3,6,6"), results);
+ assertThat(results).isEqualTo(Arrays.asList("1,1,2,2", "2,2,4,4", "3,3,6,6"));
}
@Test
@@ -246,8 +246,8 @@ public class HiveCatalogUdfITCase extends AbstractTestBase {
tableEnv.sqlQuery("select myyear(ts) as y from src")
.execute()
.collect());
- Assert.assertEquals(2, results.size());
- Assert.assertEquals("[+I[2013], +I[2019]]", results.toString());
+ assertThat(results).hasSize(2);
+ assertThat(results.toString()).isEqualTo("[+I[2013], +I[2019]]");
} finally {
tableEnv.executeSql("drop table src");
}
@@ -273,8 +273,8 @@ public class HiveCatalogUdfITCase extends AbstractTestBase {
tableEnv.sqlQuery("select mymonth(dt) as m from src order by m")
.execute()
.collect());
- Assert.assertEquals(2, results.size());
- Assert.assertEquals("[+I[1], +I[3]]", results.toString());
+ assertThat(results).hasSize(2);
+ assertThat(results.toString()).isEqualTo("[+I[1], +I[3]]");
} finally {
tableEnv.executeSql("drop table src");
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/factories/HiveCatalogFactoryTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/factories/HiveCatalogFactoryTest.java
index c0fe191b35a..b44519534e0 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/factories/HiveCatalogFactoryTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/factories/HiveCatalogFactoryTest.java
@@ -29,7 +29,6 @@ import org.apache.flink.testutils.executor.TestExecutorResource;
import org.apache.flink.util.TestLogger;
import org.apache.hadoop.hive.conf.HiveConf;
-import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -48,9 +47,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
/** Test for {@link HiveCatalog} created by {@link HiveCatalogFactory}. */
public class HiveCatalogFactoryTest extends TestLogger {
@@ -80,11 +78,11 @@ public class HiveCatalogFactoryTest extends TestLogger {
FactoryUtil.createCatalog(
catalogName, options, null, Thread.currentThread().getContextClassLoader());
- assertEquals(
- "dummy-hms",
- ((HiveCatalog) actualCatalog)
- .getHiveConf()
- .getVar(HiveConf.ConfVars.METASTOREURIS));
+ assertThat(
+ ((HiveCatalog) actualCatalog)
+ .getHiveConf()
+ .getVar(HiveConf.ConfVars.METASTOREURIS))
+ .isEqualTo("dummy-hms");
checkEquals(expectedCatalog, (HiveCatalog) actualCatalog);
}
@@ -112,7 +110,7 @@ public class HiveCatalogFactoryTest extends TestLogger {
catalogName, options, null, Thread.currentThread().getContextClassLoader());
checkEquals(expectedCatalog, (HiveCatalog) actualCatalog);
- assertEquals(mapredVal, ((HiveCatalog) actualCatalog).getHiveConf().get(mapredKey));
+ assertThat(((HiveCatalog) actualCatalog).getHiveConf().get(mapredKey)).isEqualTo(mapredVal);
}
@Test
@@ -120,23 +118,19 @@ public class HiveCatalogFactoryTest extends TestLogger {
final String catalogName = "mycatalog";
final String hadoopConfDir = tempFolder.newFolder().getAbsolutePath();
+ final Map<String, String> options = new HashMap<>();
+ options.put(CommonCatalogOptions.CATALOG_TYPE.key(), HiveCatalogFactoryOptions.IDENTIFIER);
+ options.put(HiveCatalogFactoryOptions.HIVE_CONF_DIR.key(), CONF_DIR.getPath());
+ options.put(HiveCatalogFactoryOptions.HADOOP_CONF_DIR.key(), hadoopConfDir);
- try {
- final Map<String, String> options = new HashMap<>();
- options.put(
- CommonCatalogOptions.CATALOG_TYPE.key(), HiveCatalogFactoryOptions.IDENTIFIER);
- options.put(HiveCatalogFactoryOptions.HIVE_CONF_DIR.key(), CONF_DIR.getPath());
- options.put(HiveCatalogFactoryOptions.HADOOP_CONF_DIR.key(), hadoopConfDir);
-
- final Catalog actualCatalog =
- FactoryUtil.createCatalog(
- catalogName,
- options,
- null,
- Thread.currentThread().getContextClassLoader());
- Assert.fail();
- } catch (ValidationException e) {
- }
+ assertThatThrownBy(
+ () ->
+ FactoryUtil.createCatalog(
+ catalogName,
+ options,
+ null,
+ Thread.currentThread().getContextClassLoader()))
+ .isInstanceOf(ValidationException.class);
}
@Test
@@ -188,7 +182,7 @@ public class HiveCatalogFactoryTest extends TestLogger {
}
// validate the result
for (String key : customProps.keySet()) {
- assertEquals(customProps.get(key), hiveConf.get(key, null));
+ assertThat(hiveConf.get(key, null)).isEqualTo(customProps.get(key));
}
}
@@ -247,22 +241,22 @@ public class HiveCatalogFactoryTest extends TestLogger {
HiveCatalog catalog2 = (HiveCatalog) future2.get();
// verify we read our own props
- assertEquals("val1", catalog1.getHiveConf().get("key"));
- assertNotNull(catalog1.getHiveConf().get("conf1", null));
+ assertThat(catalog1.getHiveConf().get("key")).isEqualTo("val1");
+ assertThat(catalog1.getHiveConf().get("conf1", null)).isNotNull();
// verify we don't read props from other conf
- assertNull(catalog1.getHiveConf().get("conf2", null));
+ assertThat(catalog1.getHiveConf().get("conf2", null)).isNull();
// verify we read our own props
- assertEquals("val2", catalog2.getHiveConf().get("key"));
- assertNotNull(catalog2.getHiveConf().get("conf2", null));
+ assertThat(catalog2.getHiveConf().get("key")).isEqualTo("val2");
+ assertThat(catalog2.getHiveConf().get("conf2", null)).isNotNull();
// verify we don't read props from other conf
- assertNull(catalog2.getHiveConf().get("conf1", null));
+ assertThat(catalog2.getHiveConf().get("conf1", null)).isNull();
}
private static void checkEquals(HiveCatalog c1, HiveCatalog c2) {
// Only assert a few selected properties for now
- assertEquals(c1.getName(), c2.getName());
- assertEquals(c1.getDefaultDatabase(), c2.getDefaultDatabase());
+ assertThat(c2.getName()).isEqualTo(c1.getName());
+ assertThat(c2.getDefaultDatabase()).isEqualTo(c1.getDefaultDatabase());
}
private static void writeProperty(File file, String key, String value) throws IOException {
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/util/HiveTableUtilTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/util/HiveTableUtilTest.java
index 12b793843c9..977fe3bdcc4 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/util/HiveTableUtilTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/catalog/hive/util/HiveTableUtilTest.java
@@ -33,7 +33,7 @@ import java.util.List;
import java.util.Optional;
import static org.apache.flink.table.expressions.ApiExpressionUtils.valueLiteral;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for HiveTableUtil. */
public class HiveTableUtilTest {
@@ -64,12 +64,12 @@ public class HiveTableUtilTest {
DataTypes.BOOLEAN());
Optional<String> filter =
HiveTableUtil.makePartitionFilter(2, partColNames, Arrays.asList(p1Exp), hiveShim);
- assertEquals("(p1 = 1)", filter.orElse(null));
+ assertThat(filter.orElse(null)).isEqualTo("(p1 = 1)");
filter =
HiveTableUtil.makePartitionFilter(
2, partColNames, Arrays.asList(p1Exp, p3Exp), hiveShim);
- assertEquals("(p1 = 1) and (p3 = 1.1)", filter.orElse(null));
+ assertThat(filter.orElse(null)).isEqualTo("(p1 = 1) and (p3 = 1.1)");
filter =
HiveTableUtil.makePartitionFilter(
@@ -82,6 +82,6 @@ public class HiveTableUtilTest {
Arrays.asList(p1Exp, p3Exp),
DataTypes.BOOLEAN())),
hiveShim);
- assertEquals("(p2 = 'a') and ((p1 = 1) or (p3 = 1.1))", filter.orElse(null));
+ assertThat(filter.orElse(null)).isEqualTo("(p2 = 'a') and ((p1 = 1) or (p3 = 1.1))");
}
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDAFTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDAFTest.java
index 670651962ff..d775f72e3e3 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDAFTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDAFTest.java
@@ -32,7 +32,7 @@ import org.junit.Test;
import java.math.BigDecimal;
import java.util.Arrays;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for {@link HiveGenericUDAF}. */
public class HiveGenericUDAFTest {
@@ -52,7 +52,7 @@ public class HiveGenericUDAFTest {
udf.merge(acc, Arrays.asList());
- assertEquals(1L, udf.getValue(acc));
+ assertThat(udf.getValue(acc)).isEqualTo(1L);
}
@Test
@@ -71,7 +71,7 @@ public class HiveGenericUDAFTest {
udf.merge(acc, Arrays.asList());
- assertEquals(6.1d, udf.getValue(acc));
+ assertThat(udf.getValue(acc)).isEqualTo(6.1d);
constantArgs = new Object[] {null};
@@ -87,7 +87,7 @@ public class HiveGenericUDAFTest {
udf.merge(acc, Arrays.asList());
- assertEquals(BigDecimal.valueOf(18.666), udf.getValue(acc));
+ assertThat(udf.getValue(acc)).isEqualTo(BigDecimal.valueOf(18.666));
}
@Test
@@ -106,7 +106,7 @@ public class HiveGenericUDAFTest {
udf.merge(acc, Arrays.asList());
- assertEquals(3L, udf.getValue(acc));
+ assertThat(udf.getValue(acc)).isEqualTo(3L);
}
private static HiveGenericUDAF init(
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDFTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDFTest.java
index 4f836941d86..cabc275dee5 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDFTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDFTest.java
@@ -45,14 +45,11 @@ import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Timestamp;
-import java.util.Arrays;
import java.util.HashMap;
import static org.apache.flink.table.HiveVersionTestUtil.HIVE_230_OR_LATER;
import static org.apache.flink.table.HiveVersionTestUtil.HIVE_310_OR_LATER;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for {@link HiveGenericUDF}. */
public class HiveGenericUDFTest {
@@ -63,15 +60,15 @@ public class HiveGenericUDFTest {
HiveGenericUDF udf =
init(GenericUDFAbs.class, new Object[] {null}, new DataType[] {DataTypes.DOUBLE()});
- assertEquals(10.0d, udf.eval(-10.0d));
+ assertThat(udf.eval(-10.0d)).isEqualTo(10.0d);
udf = init(GenericUDFAbs.class, new Object[] {null}, new DataType[] {DataTypes.INT()});
- assertEquals(10, udf.eval(-10));
+ assertThat(udf.eval(-10)).isEqualTo(10);
udf = init(GenericUDFAbs.class, new Object[] {null}, new DataType[] {DataTypes.STRING()});
- assertEquals(10.0, udf.eval("-10.0"));
+ assertThat(udf.eval("-10.0")).isEqualTo(10.0);
}
@Test
@@ -83,8 +80,8 @@ public class HiveGenericUDFTest {
new Object[] {null, 1},
new DataType[] {DataTypes.STRING(), DataTypes.INT()});
- assertEquals("2009-09-30", udf.eval("2009-08-31", 1));
- assertEquals("2009-09-30", udf.eval("2009-08-31 11:11:11", 1));
+ assertThat(udf.eval("2009-08-31", 1)).isEqualTo("2009-09-30");
+ assertThat(udf.eval("2009-08-31 11:11:11", 1)).isEqualTo("2009-09-30");
}
@Test
@@ -99,7 +96,7 @@ public class HiveGenericUDFTest {
new Object[] {null, constYear},
new DataType[] {DataTypes.STRING(), DataTypes.STRING()});
- assertEquals("2009", udf.eval("2009-08-31", constYear));
+ assertThat(udf.eval("2009-08-31", constYear)).isEqualTo("2009");
udf =
init(
@@ -107,7 +104,7 @@ public class HiveGenericUDFTest {
new Object[] {null, constMonth},
new DataType[] {DataTypes.DATE(), DataTypes.STRING()});
- assertEquals("8", udf.eval(Date.valueOf("2019-08-31"), constMonth));
+ assertThat(udf.eval(Date.valueOf("2019-08-31"), constMonth)).isEqualTo("8");
}
@Test
@@ -123,7 +120,7 @@ public class HiveGenericUDFTest {
HiveSimpleUDF simpleUDF =
HiveSimpleUDFTest.init(UDFUnhex.class, new DataType[] {DataTypes.STRING()});
- assertEquals("MySQL", udf.eval(simpleUDF.eval("4D7953514C"), constDecoding));
+ assertThat(udf.eval(simpleUDF.eval("4D7953514C"), constDecoding)).isEqualTo("MySQL");
}
@Test
@@ -139,8 +136,8 @@ public class HiveGenericUDFTest {
DataTypes.STRING()
});
- assertEquals("a", udf.eval("1", "1", "a", "b"));
- assertEquals("b", udf.eval("2", "1", "a", "b"));
+ assertThat(udf.eval("1", "1", "a", "b")).isEqualTo("a");
+ assertThat(udf.eval("2", "1", "a", "b")).isEqualTo("b");
}
@Test
@@ -151,7 +148,7 @@ public class HiveGenericUDFTest {
new Object[] {null},
new DataType[] {DataTypes.DOUBLE()});
- assertEquals(0L, udf.eval(-0.1d));
+ assertThat(udf.eval(-0.1d)).isEqualTo(0L);
udf =
init(
@@ -159,7 +156,7 @@ public class HiveGenericUDFTest {
new Object[] {null},
new DataType[] {DataTypes.DECIMAL(2, 1)});
- assertEquals(BigDecimal.valueOf(4), udf.eval(BigDecimal.valueOf(3.1d)));
+ assertThat(udf.eval(BigDecimal.valueOf(3.1d))).isEqualTo(BigDecimal.valueOf(4));
}
@Test
@@ -170,7 +167,7 @@ public class HiveGenericUDFTest {
new Object[] {null, 1, null},
new DataType[] {DataTypes.INT(), DataTypes.INT(), DataTypes.INT()});
- assertEquals(1, udf.eval(null, 1, null));
+ assertThat(udf.eval(null, 1, null)).isEqualTo(1);
}
@Test
@@ -189,7 +186,7 @@ public class HiveGenericUDFTest {
DataTypes.VARCHAR(20), DataTypes.CHAR(20),
});
- assertEquals(-4182, udf.eval(t1, t2));
+ assertThat(udf.eval(t1, t2)).isEqualTo(-4182);
udf =
init(
@@ -199,7 +196,7 @@ public class HiveGenericUDFTest {
DataTypes.DATE(), DataTypes.TIMESTAMP(),
});
- assertEquals(-4182, udf.eval(Date.valueOf(d), Timestamp.valueOf(t2)));
+ assertThat(udf.eval(Date.valueOf(d), Timestamp.valueOf(t2))).isEqualTo(-4182);
// Test invalid char length
udf =
@@ -210,7 +207,7 @@ public class HiveGenericUDFTest {
DataTypes.CHAR(2), DataTypes.VARCHAR(2),
});
- assertEquals(null, udf.eval(t1, t2));
+ assertThat(udf.eval(t1, t2)).isNull();
}
@Test
@@ -221,8 +218,8 @@ public class HiveGenericUDFTest {
new Object[] {null},
new DataType[] {DataTypes.ARRAY(DataTypes.INT())});
- assertEquals(6, udf.eval(1, 2, 3));
- assertEquals(6, udf.eval(new Integer[] {1, 2, 3}));
+ assertThat(udf.eval(1, 2, 3)).isEqualTo(6);
+ assertThat(udf.eval(new Integer[] {1, 2, 3})).isEqualTo(6);
}
@Test
@@ -236,15 +233,16 @@ public class HiveGenericUDFTest {
new Object[] {null},
new DataType[] {DataTypes.VARCHAR(testInput.length())});
- assertEquals(
- new HashMap<String, String>() {
- {
- put("1", "1");
- put("2", "2");
- put("3", "3");
- }
- },
- udf.eval(testInput));
+ assertThat(udf.eval(testInput))
+ .isEqualTo(
+ new HashMap<String, String>() {
+
+ {
+ put("1", "1");
+ put("2", "2");
+ put("3", "3");
+ }
+ });
// test input as map and nested functions
HiveGenericUDF udf2 =
@@ -255,8 +253,7 @@ public class HiveGenericUDFTest {
Object[] result = (Object[]) udf2.eval(udf.eval(testInput));
- assertEquals(3, result.length);
- assertThat(Arrays.asList(result), containsInAnyOrder("1", "2", "3"));
+ assertThat(result).hasSize(3).containsExactlyInAnyOrder("1", "2", "3");
}
@Test
@@ -269,7 +266,7 @@ public class HiveGenericUDFTest {
Row result = (Row) udf.eval(1, "222", "3");
- assertEquals(Row.of(1, "22", "3"), result);
+ assertThat(result).isEqualTo(Row.of(1, "22", "3"));
udf =
init(
@@ -282,7 +279,7 @@ public class HiveGenericUDFTest {
DataTypes.FIELD("3", DataTypes.VARCHAR(10)))
});
- assertEquals(3, udf.eval(result));
+ assertThat(udf.eval(result)).isEqualTo(3);
}
private static HiveGenericUDF init(
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDTFTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDTFTest.java
index bfcf7919184..2819fadff76 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDTFTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveGenericUDTFTest.java
@@ -44,7 +44,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for {@link HiveGenericUDTF}. */
public class HiveGenericUDTFTest {
@@ -62,7 +62,7 @@ public class HiveGenericUDTFTest {
udf.eval(5, 4);
- assertEquals(Arrays.asList(Row.of(9), Row.of(9)), collector.result);
+ assertThat(collector.result).isEqualTo(Arrays.asList(Row.of(9), Row.of(9)));
// Test empty input and empty output
constantArgs = new Object[] {};
@@ -73,7 +73,7 @@ public class HiveGenericUDTFTest {
udf.eval();
- assertEquals(Arrays.asList(), collector.result);
+ assertThat(collector.result).isEqualTo(Arrays.asList());
}
@Test
@@ -86,9 +86,8 @@ public class HiveGenericUDTFTest {
udf.eval("1,2,3,5");
- assertEquals(
- Arrays.asList(Row.of("1"), Row.of("2"), Row.of("3"), Row.of("5")),
- collector.result);
+ assertThat(collector.result)
+ .isEqualTo(Arrays.asList(Row.of("1"), Row.of("2"), Row.of("3"), Row.of("5")));
}
@Test
@@ -108,7 +107,7 @@ public class HiveGenericUDTFTest {
udf.eval(2, "a", "b", "c", "d");
- assertEquals(Arrays.asList(Row.of("a", "b"), Row.of("c", "d")), collector.result);
+ assertThat(collector.result).isEqualTo(Arrays.asList(Row.of("a", "b"), Row.of("c", "d")));
}
@Test
@@ -121,7 +120,8 @@ public class HiveGenericUDTFTest {
udf.eval(new Integer[] {1, 2, 3});
- assertEquals(Arrays.asList(Row.of(0, 1), Row.of(1, 2), Row.of(2, 3)), collector.result);
+ assertThat(collector.result)
+ .isEqualTo(Arrays.asList(Row.of(0, 1), Row.of(1, 2), Row.of(2, 3)));
}
@Test
@@ -140,7 +140,7 @@ public class HiveGenericUDTFTest {
udf.eval(new Row[] {Row.of(1, 2.2d), Row.of(3, 4.4d)});
- assertEquals(Arrays.asList(Row.of(1, 2.2), Row.of(3, 4.4)), collector.result);
+ assertThat(collector.result).isEqualTo(Arrays.asList(Row.of(1, 2.2), Row.of(3, 4.4)));
}
private static HiveGenericUDTF init(
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveSimpleUDFTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveSimpleUDFTest.java
index 7ab0e5ba6a1..a0d74203673 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveSimpleUDFTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/functions/hive/HiveSimpleUDFTest.java
@@ -47,8 +47,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Optional;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for {@link HiveSimpleUDF}. */
public class HiveSimpleUDFTest {
@@ -57,25 +56,25 @@ public class HiveSimpleUDFTest {
@Test
public void testBooleanUDF() {
HiveSimpleUDF udf = init(BooleanUDF.class, new DataType[] {DataTypes.INT()});
- assertTrue((boolean) udf.eval(1));
+ assertThat((boolean) udf.eval(1)).isTrue();
}
@Test
public void testFloatUDF() {
HiveSimpleUDF udf = init(FloatUDF.class, new DataType[] {DataTypes.FLOAT()});
- assertEquals(3.0f, (float) udf.eval(3.0f), 0);
+ assertThat((float) udf.eval(3.0f)).isEqualTo(3.0f);
}
@Test
public void testIntUDF() {
HiveSimpleUDF udf = init(IntUDF.class, new DataType[] {DataTypes.INT()});
- assertEquals(3, (int) udf.eval(3));
+ assertThat((int) udf.eval(3)).isEqualTo(3);
}
@Test
public void testStringUDF() {
HiveSimpleUDF udf = init(StringUDF.class, new DataType[] {DataTypes.STRING()});
- assertEquals("test", udf.eval("test"));
+ assertThat(udf.eval("test")).isEqualTo("test");
}
@Test
@@ -84,14 +83,14 @@ public class HiveSimpleUDFTest {
double result = (double) udf.eval();
- assertTrue(result >= 0 && result < 1);
+ assertThat(result >= 0 && result < 1).isTrue();
}
@Test
public void testUDFBin() {
HiveSimpleUDF udf = init(UDFBin.class, new DataType[] {DataTypes.INT()});
- assertEquals("1100", udf.eval(12));
+ assertThat(udf.eval(12)).isEqualTo("1100");
}
@Test
@@ -101,8 +100,8 @@ public class HiveSimpleUDFTest {
UDFConv.class,
new DataType[] {DataTypes.STRING(), DataTypes.INT(), DataTypes.INT()});
- assertEquals("1", udf.eval("12", 2, 10));
- assertEquals("-16", udf.eval(-10, 16, -10));
+ assertThat(udf.eval("12", 2, 10)).isEqualTo("1");
+ assertThat(udf.eval(-10, 16, -10)).isEqualTo("-16");
}
@Test
@@ -114,14 +113,14 @@ public class HiveSimpleUDFTest {
HiveSimpleUDF udf =
init(UDFJson.class, new DataType[] {DataTypes.STRING(), DataTypes.STRING()});
- assertEquals(expected, udf.eval(json, pattern));
+ assertThat(udf.eval(json, pattern)).isEqualTo(expected);
udf =
init(
UDFJson.class,
new DataType[] {DataTypes.CHAR(100), DataTypes.CHAR(pattern.length())});
- assertEquals(expected, udf.eval(json, pattern));
+ assertThat(udf.eval(json, pattern)).isEqualTo(expected);
udf =
init(
@@ -130,7 +129,7 @@ public class HiveSimpleUDFTest {
DataTypes.VARCHAR(100), DataTypes.VARCHAR(pattern.length())
});
- assertEquals(expected, udf.eval(json, pattern));
+ assertThat(udf.eval(json, pattern)).isEqualTo(expected);
// Test invalid CHAR length
udf =
@@ -143,17 +142,17 @@ public class HiveSimpleUDFTest {
});
// Cannot find path "$.owne"
- assertEquals(null, udf.eval(json, pattern));
+ assertThat(udf.eval(json, pattern)).isNull();
}
@Test
public void testUDFWeekOfYear() throws FlinkHiveUDFException {
HiveSimpleUDF udf = init(UDFWeekOfYear.class, new DataType[] {DataTypes.STRING()});
- assertEquals(29, udf.eval("1969-07-20"));
- assertEquals(29, udf.eval(Date.valueOf("1969-07-20")));
- assertEquals(29, udf.eval(Timestamp.valueOf("1969-07-20 00:00:00")));
- assertEquals(1, udf.eval("1980-12-31 12:59:59"));
+ assertThat(udf.eval("1969-07-20")).isEqualTo(29);
+ assertThat(udf.eval(Date.valueOf("1969-07-20"))).isEqualTo(29);
+ assertThat(udf.eval(Timestamp.valueOf("1969-07-20 00:00:00"))).isEqualTo(29);
+ assertThat(udf.eval("1980-12-31 12:59:59")).isEqualTo(1);
}
@Test
@@ -163,28 +162,28 @@ public class HiveSimpleUDFTest {
UDFRegExpExtract.class,
new DataType[] {DataTypes.STRING(), DataTypes.STRING(), DataTypes.INT()});
- assertEquals("100", udf.eval("100-200", "(\\d+)-(\\d+)", 1));
+ assertThat(udf.eval("100-200", "(\\d+)-(\\d+)", 1)).isEqualTo("100");
}
@Test
public void testUDFUnbase64() {
HiveSimpleUDF udf = init(UDFBase64.class, new DataType[] {DataTypes.BYTES()});
- assertEquals("Cg==", udf.eval(new byte[] {10}));
+ assertThat(udf.eval(new byte[] {10})).isEqualTo("Cg==");
}
@Test
public void testUDFUnhex() throws UnsupportedEncodingException {
HiveSimpleUDF udf = init(UDFUnhex.class, new DataType[] {DataTypes.STRING()});
- assertEquals("MySQL", new String((byte[]) udf.eval("4D7953514C"), "UTF-8"));
+ assertThat(new String((byte[]) udf.eval("4D7953514C"), "UTF-8")).isEqualTo("MySQL");
}
@Test
public void testUDFToInteger() {
HiveSimpleUDF udf = init(UDFToInteger.class, new DataType[] {DataTypes.DECIMAL(5, 3)});
- assertEquals(1, udf.eval(BigDecimal.valueOf(1.1d)));
+ assertThat(udf.eval(BigDecimal.valueOf(1.1d))).isEqualTo(1);
}
@Test
@@ -195,8 +194,8 @@ public class HiveSimpleUDFTest {
HiveSimpleUDF udf =
init(TestHiveUDFArray.class, new DataType[] {DataTypes.ARRAY(DataTypes.DOUBLE())});
- assertEquals(3, udf.eval(1.1d, 2.2d));
- assertEquals(3, udf.eval(testInputs));
+ assertThat(udf.eval(1.1d, 2.2d)).isEqualTo(3);
+ assertThat(udf.eval(testInputs)).isEqualTo(3);
// input is not a single array
udf =
@@ -204,7 +203,7 @@ public class HiveSimpleUDFTest {
TestHiveUDFArray.class,
new DataType[] {DataTypes.INT(), DataTypes.ARRAY(DataTypes.DOUBLE())});
- assertEquals(8, udf.eval(5, testInputs));
+ assertThat(udf.eval(5, testInputs)).isEqualTo(8);
udf =
init(
@@ -215,7 +214,7 @@ public class HiveSimpleUDFTest {
DataTypes.ARRAY(DataTypes.DOUBLE())
});
- assertEquals(11, udf.eval(5, testInputs, testInputs));
+ assertThat(udf.eval(5, testInputs, testInputs)).isEqualTo(11);
}
protected static HiveSimpleUDF init(Class hiveUdfClass, DataType[] argTypes) {
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleFactoryTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleFactoryTest.java
index 0c0129c62e1..f708000a365 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleFactoryTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleFactoryTest.java
@@ -25,7 +25,7 @@ import org.junit.Test;
import java.util.Collections;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Test for {@link HiveModuleFactory}. */
public class HiveModuleFactoryTest {
@@ -44,6 +44,6 @@ public class HiveModuleFactoryTest {
}
private static void checkEquals(HiveModule m1, HiveModule m2) {
- assertEquals(m1.getHiveVersion(), m2.getHiveVersion());
+ assertThat(m2.getHiveVersion()).isEqualTo(m1.getHiveVersion());
}
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleTest.java
index fe5b87d91c3..6567c22702d 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleTest.java
@@ -38,9 +38,8 @@ import java.util.List;
import static org.apache.flink.table.catalog.hive.client.HiveShimLoader.HIVE_VERSION_V2_3_9;
import static org.apache.flink.table.catalog.hive.client.HiveShimLoader.HIVE_VERSION_V3_1_1;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
/** Test for {@link HiveModule}. */
public class HiveModuleTest {
@@ -65,19 +64,19 @@ public class HiveModuleTest {
verifyNumBuiltInFunctions(hiveVersion, hiveModule);
// explicitly verify that HiveModule doesn't consider the created functions as built-in
// functions
- assertFalse(hiveModule.getFunctionDefinition("myudf").isPresent());
- assertFalse(hiveModule.getFunctionDefinition("mygenericudf").isPresent());
- assertFalse(hiveModule.getFunctionDefinition("myudaf").isPresent());
- assertFalse(hiveModule.getFunctionDefinition("myudtf").isPresent());
+ assertThat(hiveModule.getFunctionDefinition("myudf")).isNotPresent();
+ assertThat(hiveModule.getFunctionDefinition("mygenericudf")).isNotPresent();
+ assertThat(hiveModule.getFunctionDefinition("myudaf")).isNotPresent();
+ assertThat(hiveModule.getFunctionDefinition("myudtf")).isNotPresent();
}
private void verifyNumBuiltInFunctions(String hiveVersion, HiveModule hiveModule) {
switch (hiveVersion) {
case HIVE_VERSION_V2_3_9:
- assertEquals(275, hiveModule.listFunctions().size());
+ assertThat(hiveModule.listFunctions()).hasSize(275);
break;
case HIVE_VERSION_V3_1_1:
- assertEquals(294, hiveModule.listFunctions().size());
+ assertThat(hiveModule.listFunctions()).hasSize(294);
break;
default:
fail("Unknown test version " + hiveVersion);
@@ -96,12 +95,12 @@ public class HiveModuleTest {
udf.open(null);
- assertEquals("cba", udf.eval("abc"));
+ assertThat(udf.eval("abc")).isEqualTo("cba");
}
@Test
public void testNonExistFunction() {
- assertFalse(new HiveModule().getFunctionDefinition("nonexist").isPresent());
+ assertThat(new HiveModule().getFunctionDefinition("nonexist")).isNotPresent();
}
@Test
@@ -114,21 +113,21 @@ public class HiveModuleTest {
List<Row> results =
CollectionUtil.iteratorToList(
tEnv.sqlQuery("select concat('an', 'bn')").execute().collect());
- assertEquals("[anbn]", results.toString());
+ assertThat(results.toString()).isEqualTo("[anbn]");
results =
CollectionUtil.iteratorToList(
tEnv.sqlQuery("select concat('ab', cast('cdefghi' as varchar(5)))")
.execute()
.collect());
- assertEquals("[abcdefg]", results.toString());
+ assertThat(results.toString()).isEqualTo("[abcdefg]");
results =
CollectionUtil.iteratorToList(
tEnv.sqlQuery("select concat('ab',cast(12.34 as decimal(10,5)))")
.execute()
.collect());
- assertEquals("[ab12.34]", results.toString());
+ assertThat(results.toString()).isEqualTo("[ab12.34]");
results =
CollectionUtil.iteratorToList(
@@ -136,14 +135,14 @@ public class HiveModuleTest {
"select concat(cast('2018-01-19' as date),cast('2019-12-27 17:58:23.385' as timestamp))")
.execute()
.collect());
- assertEquals("[2018-01-192019-12-27 17:58:23.385]", results.toString());
+ assertThat(results.toString()).isEqualTo("[2018-01-192019-12-27 17:58:23.385]");
// TODO: null cannot be a constant argument at the moment. This test will make more sense
// when that changes.
results =
CollectionUtil.iteratorToList(
tEnv.sqlQuery("select concat('ab',cast(null as int))").execute().collect());
- assertEquals("[null]", results.toString());
+ assertThat(results.toString()).isEqualTo("[null]");
}
@Test
@@ -157,15 +156,16 @@ public class HiveModuleTest {
CollectionUtil.iteratorToList(
tEnv.sqlQuery("select negative(5.1)").execute().collect());
- assertEquals("[-5.1]", results.toString());
+ assertThat(results.toString()).isEqualTo("[-5.1]");
}
@Test
public void testBlackList() {
HiveModule hiveModule = new HiveModule();
- assertFalse(hiveModule.listFunctions().removeAll(HiveModule.BUILT_IN_FUNC_BLACKLIST));
+ assertThat(hiveModule.listFunctions().removeAll(HiveModule.BUILT_IN_FUNC_BLACKLIST))
+ .isFalse();
for (String banned : HiveModule.BUILT_IN_FUNC_BLACKLIST) {
- assertFalse(hiveModule.getFunctionDefinition(banned).isPresent());
+ assertThat(hiveModule.getFunctionDefinition(banned)).isNotPresent();
}
}
@@ -182,7 +182,7 @@ public class HiveModuleTest {
.execute()
.collect());
- assertEquals("[{a=1, b=2, c=3}]", results.toString());
+ assertThat(results.toString()).isEqualTo("[{a=1, b=2, c=3}]");
}
@Test
@@ -198,13 +198,13 @@ public class HiveModuleTest {
tableEnv.sqlQuery("select regexp_replace('foobar','oo|ar','')")
.execute()
.collect());
- assertEquals("[fb]", results.toString());
+ assertThat(results.toString()).isEqualTo("[fb]");
// GenericUDF
results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select length('')").execute().collect());
- assertEquals("[0]", results.toString());
+ assertThat(results.toString()).isEqualTo("[0]");
}
@Test
@@ -220,7 +220,7 @@ public class HiveModuleTest {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select mod(-1,2),pmod(-1,2)").execute().collect());
- assertEquals("[-1,1]", results.toString());
+ assertThat(results.toString()).isEqualTo("[-1,1]");
}
@Test
@@ -234,6 +234,6 @@ public class HiveModuleTest {
List<Row> results =
CollectionUtil.iteratorToList(
tableEnv.sqlQuery("select `array`(),`map`()").execute().collect());
- assertEquals("[[],{}]", results.toString());
+ assertThat(results.toString()).isEqualTo("[[],{}]");
}
}
diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/planner/delegation/hive/HiveASTParserTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/planner/delegation/hive/HiveASTParserTest.java
index a2be080b945..db832bf4b81 100644
--- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/planner/delegation/hive/HiveASTParserTest.java
+++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/planner/delegation/hive/HiveASTParserTest.java
@@ -26,7 +26,7 @@ import org.apache.flink.table.planner.delegation.hive.parse.HiveASTParser;
import org.apache.hadoop.hive.conf.HiveConf;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/** Tests for the AST parser. */
public class HiveASTParserTest {
@@ -151,7 +151,7 @@ public class HiveASTParserTest {
private void assertDDLType(int type, String... sqls) throws Exception {
for (String sql : sqls) {
HiveParserContext parserContext = new HiveParserContext(hiveConf);
- assertEquals(type, HiveASTParseUtils.parse(sql, parserContext).getType());
+ assertThat(HiveASTParseUtils.parse(sql, parserContext).getType()).isEqualTo(type);
}
}
}