Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
package org.apache.flink.connector.jdbc;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.ValidationException;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand All @@ -32,7 +30,9 @@
import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.fail;
import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/** Tests for all DataTypes and Dialects of JDBC connector. */
@RunWith(Parameterized.class)
Expand Down Expand Up @@ -170,7 +170,7 @@ public static List<TestItem> testData() {
}

private static TestItem createTestItem(Object... args) {
assert args.length >= 2;
assertThat(args).hasSizeGreaterThanOrEqualTo(2);
TestItem item = TestItem.fromDialectAndType((String) args[0], (String) args[1]);
if (args.length == 3) {
item.withExpectError((String) args[2]);
Expand All @@ -190,16 +190,8 @@ public void testDataTypeValidate() {
tEnv.executeSql(sqlDDL);

if (testItem.expectError != null) {
try {
tEnv.sqlQuery("SELECT * FROM T");
fail();
} catch (ValidationException ex) {
Assert.assertEquals(testItem.expectError, ex.getCause().getMessage());
} catch (UnsupportedOperationException ex) {
Assert.assertEquals(testItem.expectError, ex.getMessage());
} catch (Exception e) {
fail(e);
}
assertThatThrownBy(() -> tEnv.sqlQuery("SELECT * FROM T"))
.satisfies(anyCauseMatches(testItem.expectError));
} else {
tEnv.sqlQuery("SELECT * FROM T");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import static org.apache.flink.connector.jdbc.JdbcTestFixture.TEST_DATA;
import static org.apache.flink.connector.jdbc.JdbcTestFixture.TestEntry;
import static org.apache.flink.util.Preconditions.checkNotNull;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

/** Smoke tests for the {@link JdbcSink} and the underlying classes. */
public class JdbcITCase extends JdbcTestBase {
Expand Down Expand Up @@ -78,7 +78,7 @@ public void testInsert() throws Exception {
.build()));
env.execute();

assertEquals(Arrays.asList(TEST_DATA), selectBooks());
assertThat(selectBooks()).isEqualTo(Arrays.asList(TEST_DATA));
}

@Test
Expand Down Expand Up @@ -112,7 +112,7 @@ public void testObjectReuse() throws Exception {
.build()));
env.execute();

assertEquals(Arrays.asList(words), selectWords());
assertThat(selectWords()).isEqualTo(Arrays.asList(words));
}

private List<String> selectWords() throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.flink.types.Row;

import org.junit.After;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -44,6 +43,7 @@
import static org.apache.flink.connector.jdbc.JdbcTestFixture.SELECT_EMPTY;
import static org.apache.flink.connector.jdbc.JdbcTestFixture.TEST_DATA;
import static org.apache.flink.connector.jdbc.JdbcTestFixture.TestEntry;
import static org.assertj.core.api.Assertions.assertThat;

/** Tests for the {@link JdbcInputFormat}. */
public class JdbcInputFormatTest extends JdbcDataTestBase {
Expand Down Expand Up @@ -176,7 +176,7 @@ public void testDefaultFetchSizeIsUsedIfNotConfiguredOtherwise()
.createStatement()
.getFetchSize();

Assert.assertEquals(defaultFetchSize, jdbcInputFormat.getStatement().getFetchSize());
assertThat(jdbcInputFormat.getStatement().getFetchSize()).isEqualTo(defaultFetchSize);
}

@Test
Expand All @@ -191,7 +191,7 @@ public void testFetchSizeCanBeConfigured() throws SQLException {
.setFetchSize(desiredFetchSize)
.finish();
jdbcInputFormat.openInputFormat();
Assert.assertEquals(desiredFetchSize, jdbcInputFormat.getStatement().getFetchSize());
assertThat(jdbcInputFormat.getStatement().getFetchSize()).isEqualTo(desiredFetchSize);
}

@Test
Expand All @@ -211,7 +211,7 @@ public void testDefaultAutoCommitIsUsedIfNotConfiguredOtherwise()
final boolean defaultAutoCommit =
DriverManager.getConnection(DERBY_EBOOKSHOP_DB.getUrl()).getAutoCommit();

Assert.assertEquals(defaultAutoCommit, jdbcInputFormat.getDbConn().getAutoCommit());
assertThat(jdbcInputFormat.getDbConn().getAutoCommit()).isEqualTo(defaultAutoCommit);
}

@Test
Expand All @@ -228,7 +228,7 @@ public void testAutoCommitCanBeConfigured() throws SQLException {
.finish();

jdbcInputFormat.openInputFormat();
Assert.assertEquals(desiredAutoCommit, jdbcInputFormat.getDbConn().getAutoCommit());
assertThat(jdbcInputFormat.getDbConn().getAutoCommit()).isEqualTo(desiredAutoCommit);
}

@Test
Expand All @@ -242,7 +242,7 @@ public void testJdbcInputFormatWithoutParallelism() throws IOException {
.setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)
.finish();
// this query does not exploit parallelism
Assert.assertEquals(1, jdbcInputFormat.createInputSplits(1).length);
assertThat(jdbcInputFormat.createInputSplits(1)).hasSize(1);
jdbcInputFormat.openInputFormat();
jdbcInputFormat.open(null);
Row row = new Row(5);
Expand All @@ -256,7 +256,7 @@ public void testJdbcInputFormatWithoutParallelism() throws IOException {
}
jdbcInputFormat.close();
jdbcInputFormat.closeInputFormat();
Assert.assertEquals(TEST_DATA.length, recordCount);
assertThat(recordCount).isEqualTo(TEST_DATA.length);
}

@Test
Expand All @@ -279,7 +279,7 @@ public void testJdbcInputFormatWithParallelismAndNumericColumnSplitting() throws
jdbcInputFormat.openInputFormat();
InputSplit[] splits = jdbcInputFormat.createInputSplits(1);
// this query exploit parallelism (1 split for every id)
Assert.assertEquals(TEST_DATA.length, splits.length);
assertThat(splits).hasSameSizeAs(TEST_DATA);
int recordCount = 0;
Row row = new Row(5);
for (InputSplit split : splits) {
Expand All @@ -294,7 +294,7 @@ public void testJdbcInputFormatWithParallelismAndNumericColumnSplitting() throws
jdbcInputFormat.close();
}
jdbcInputFormat.closeInputFormat();
Assert.assertEquals(TEST_DATA.length, recordCount);
assertThat(recordCount).isEqualTo(TEST_DATA.length);
}

@Test
Expand All @@ -318,7 +318,7 @@ public void testJdbcInputFormatWithoutParallelismAndNumericColumnSplitting()
jdbcInputFormat.openInputFormat();
InputSplit[] splits = jdbcInputFormat.createInputSplits(1);
// assert that a single split was generated
Assert.assertEquals(1, splits.length);
assertThat(splits).hasSize(1);
int recordCount = 0;
Row row = new Row(5);
for (InputSplit split : splits) {
Expand All @@ -333,7 +333,7 @@ public void testJdbcInputFormatWithoutParallelismAndNumericColumnSplitting()
jdbcInputFormat.close();
}
jdbcInputFormat.closeInputFormat();
Assert.assertEquals(TEST_DATA.length, recordCount);
assertThat(recordCount).isEqualTo(TEST_DATA.length);
}

@Test
Expand All @@ -356,7 +356,7 @@ public void testJdbcInputFormatWithParallelismAndGenericSplitting() throws IOExc
jdbcInputFormat.openInputFormat();
InputSplit[] splits = jdbcInputFormat.createInputSplits(1);
// this query exploit parallelism (1 split for every queryParameters row)
Assert.assertEquals(queryParameters.length, splits.length);
assertThat(splits).hasSameSizeAs(queryParameters);

verifySplit(splits[0], TEST_DATA[3].id);
verifySplit(splits[1], TEST_DATA[0].id + TEST_DATA[1].id);
Expand All @@ -379,7 +379,7 @@ private void verifySplit(InputSplit split, int expectedIDSum) throws IOException
sum += id;
}

Assert.assertEquals(expectedIDSum, sum);
assertThat(sum).isEqualTo(expectedIDSum);
}

@Test
Expand All @@ -395,18 +395,18 @@ public void testEmptyResults() throws IOException {
try {
jdbcInputFormat.openInputFormat();
jdbcInputFormat.open(null);
Assert.assertTrue(jdbcInputFormat.reachedEnd());
assertThat(jdbcInputFormat.reachedEnd()).isTrue();
} finally {
jdbcInputFormat.close();
jdbcInputFormat.closeInputFormat();
}
}

private static void assertEquals(TestEntry expected, Row actual) {
Assert.assertEquals(expected.id, actual.getField(0));
Assert.assertEquals(expected.title, actual.getField(1));
Assert.assertEquals(expected.author, actual.getField(2));
Assert.assertEquals(expected.price, actual.getField(3));
Assert.assertEquals(expected.qty, actual.getField(4));
assertThat(actual.getField(0)).isEqualTo(expected.id);
assertThat(actual.getField(1)).isEqualTo(expected.title);
assertThat(actual.getField(2)).isEqualTo(expected.author);
assertThat(actual.getField(3)).isEqualTo(expected.price);
assertThat(actual.getField(4)).isEqualTo(expected.qty);
}
}
Loading