Unverified Commit 3a15a61e authored by Licho's avatar Licho Committed by GitHub

test: add actionType and refact clinet-base and common Table class (#1588)

* test: add actionType * style: spotless Signed-off-by: 's avatarLicho <chinabhsun@gmail.com> * feat: run unit test Signed-off-by: 's avatarLicho <chinabhsun@gmail.com> * feat: github workflow remove fast profile * test: ignore class unit test * test: remove invalid test from daemon Signed-off-by: 's avatarLicho <chinabhsun@gmail.com> * refactor: Table getFlinkDDL function, and extract FlinkCDCConfig configure constant variable. * refactor: Table getFlinkDDL function, and extract FlinkCDCConfig configure constant variable. * style: spotless * style: spotless * fix: compatible for jdk8 * fix: Column need default construct * refactor: transfer log language * refactor: simply code --------- Signed-off-by: 's avatarLicho <chinabhsun@gmail.com>
parent 2405a9bc
......@@ -114,9 +114,11 @@ jobs:
- name: Build and Package
run: |
./mvnw -B clean install \
-Dmaven.test.skip=true \
-Dmaven.test.skip=false \
-Dspotless.check.skip=true \
-P prod,scala-2.12,flink-all,maven-central,fast \
-Denforcer.skip=true \
-Dmaven.javadoc.skip=true \
-P prod,scala-2.12,flink-all,maven-central \
--no-snapshot-updates
# 检查打包的大小
......
......@@ -20,6 +20,7 @@
package org.dinky.admin;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import cn.dev33.satoken.secure.SaSecureUtil;
......@@ -30,6 +31,7 @@ import cn.dev33.satoken.secure.SaSecureUtil;
* @author wenmo
* @since 2021/6/14 17:03
*/
@Ignore
public class AdminTest {
@Test
......
......@@ -20,6 +20,7 @@
package org.dinky.security;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
/**
......@@ -28,6 +29,7 @@ import org.junit.Test;
* @author wenmo
* @since 2023/1/14 15:59
*/
@Ignore
public class SecurityAspectTest {
@Test
......
......@@ -34,6 +34,7 @@ import org.junit.Test;
* @author wenmo
* @since 2022/10/14 22:00
*/
@Ignore
public class DirUtilTest {
@Ignore
......
......@@ -40,6 +40,7 @@ import org.junit.Test;
* @author wenmo
* @since 2022/2/23 20:18
*/
@Ignore
public class DingTalkTest {
private static Map<String, String> config = new HashMap<>();
......
......@@ -41,6 +41,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Ignore
public class EmailSenderTest {
private static final Logger logger = LoggerFactory.getLogger(EmailSenderTest.class);
......
......@@ -36,6 +36,7 @@ import org.junit.Test;
*
* @date: 2022/4/2 @Description: 飞书消息发送 单元测试
*/
@Ignore
public class FeiShuSenderTest {
private static Map<String, String> feiShuConfig = new HashMap<>();
......
......@@ -32,6 +32,7 @@ import org.junit.Ignore;
import org.junit.Test;
/** WeChatSenderTest */
@Ignore
public class WeChatSenderTest {
private static Map<String, String> weChatConfig = new HashMap<>();
......
......@@ -25,8 +25,10 @@ import org.apache.flink.table.api.EnvironmentSettings;
import org.apache.flink.table.api.TableEnvironment;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class DinkyMysqlCatalogTest {
protected static String url;
......
......@@ -34,8 +34,10 @@ import java.util.HashMap;
import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class DinkyMysqlCatalogFactoryTest {
protected static String url;
......
......@@ -350,8 +350,8 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
@Override
public String getSinkSchemaName(Table table) {
String schemaName = table.getSchema();
if (config.getSink().containsKey("sink.db")) {
schemaName = config.getSink().get("sink.db");
if (config.getSink().containsKey(FlinkCDCConfig.SINK_DB)) {
schemaName = config.getSink().get(FlinkCDCConfig.SINK_DB);
}
return schemaName;
}
......@@ -364,19 +364,19 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
tableName = table.getSchema() + "_" + tableName;
}
}
if (config.getSink().containsKey("table.prefix")) {
tableName = config.getSink().get("table.prefix") + tableName;
if (config.getSink().containsKey(FlinkCDCConfig.TABLE_PREFIX)) {
tableName = config.getSink().get(FlinkCDCConfig.TABLE_PREFIX) + tableName;
}
if (config.getSink().containsKey("table.suffix")) {
tableName = tableName + config.getSink().get("table.suffix");
if (config.getSink().containsKey(FlinkCDCConfig.TABLE_SUFFIX)) {
tableName = tableName + config.getSink().get(FlinkCDCConfig.TABLE_SUFFIX);
}
if (config.getSink().containsKey("table.lower")) {
if (Boolean.valueOf(config.getSink().get("table.lower"))) {
if (config.getSink().containsKey(FlinkCDCConfig.TABLE_LOWER)) {
if (Boolean.valueOf(config.getSink().get(FlinkCDCConfig.TABLE_LOWER))) {
tableName = tableName.toLowerCase();
}
}
if (config.getSink().containsKey("table.upper")) {
if (Boolean.valueOf(config.getSink().get("table.upper"))) {
if (config.getSink().containsKey(FlinkCDCConfig.TABLE_UPPER)) {
if (Boolean.valueOf(config.getSink().get(FlinkCDCConfig.TABLE_UPPER))) {
tableName = tableName.toUpperCase();
}
}
......
......@@ -36,16 +36,11 @@ import java.util.function.Supplier;
*/
public class SinkBuilderFactory {
private static final Map<String, Supplier<SinkBuilder>> SINK_BUILDER_MAP =
new HashMap<String, Supplier<SinkBuilder>>() {
{
}
};
private static final Map<String, Supplier<SinkBuilder>> SINK_BUILDER_MAP = new HashMap<>();
public static SinkBuilder buildSinkBuilder(FlinkCDCConfig config) {
if (Asserts.isNull(config) || Asserts.isNullString(config.getSink().get("connector"))) {
throw new FlinkClientException("请指定 Sink connector。");
throw new FlinkClientException("please assign Sink connector。");
}
return SINK_BUILDER_MAP
.getOrDefault(config.getSink().get("connector"), () -> new SQLSinkBuilder())
......
......@@ -237,8 +237,8 @@ public class SQLSinkBuilder extends AbstractSinkBuilder implements Serializable
StreamExecutionEnvironment env,
CustomTableEnvironment customTableEnvironment,
DataStreamSource<String> dataStreamSource) {
final String timeZone = config.getSink().get("timezone");
config.getSink().remove("timezone");
final String timeZone = config.getSink().get(FlinkCDCConfig.TIMEZONE);
config.getSink().remove(FlinkCDCConfig.TIMEZONE);
if (Asserts.isNotNullString(timeZone)) {
sinkTimeZone = ZoneId.of(timeZone);
}
......
......@@ -39,6 +39,57 @@
<groupId>org.dinky</groupId>
<artifactId>dinky-common</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<type>jar</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
......
......@@ -21,6 +21,7 @@ package org.dinky.model;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* FlinkCDCConfig
......@@ -30,6 +31,14 @@ import java.util.Map;
*/
public class FlinkCDCConfig {
public static final String SINK_DB = "sink.db";
public static final String AUTO_CREATE = "auto.create";
public static final String TABLE_PREFIX = "table.prefix";
public static final String TABLE_SUFFIX = "table.suffix";
public static final String TABLE_UPPER = "table.upper";
public static final String TABLE_LOWER = "table.lower";
public static final String COLUMN_REPLACE_LINE_BREAK = "column.replace.line-break";
public static final String TIMEZONE = "timezone";
private String type;
private String hostname;
private Integer port;
......@@ -50,8 +59,6 @@ public class FlinkCDCConfig {
private List<Schema> schemaList;
private String schemaFieldName;
public FlinkCDCConfig() {}
public FlinkCDCConfig(
String type,
String hostname,
......@@ -69,22 +76,23 @@ public class FlinkCDCConfig {
Map<String, String> source,
Map<String, String> sink,
Map<String, String> jdbc) {
this.type = type;
this.hostname = hostname;
this.port = port;
this.username = username;
this.password = password;
this.checkpoint = checkpoint;
this.parallelism = parallelism;
this.database = database;
this.schema = schema;
this.table = table;
this.startupMode = startupMode;
this.split = split;
this.debezium = debezium;
this.source = source;
this.sink = sink;
this.jdbc = jdbc;
init(
type,
hostname,
port,
username,
password,
checkpoint,
parallelism,
database,
schema,
table,
startupMode,
split,
debezium,
source,
sink,
jdbc);
}
public void init(
......@@ -122,6 +130,29 @@ public class FlinkCDCConfig {
this.jdbc = jdbc;
}
private boolean isSkip(String key) {
switch (key) {
case SINK_DB:
case AUTO_CREATE:
case TABLE_PREFIX:
case TABLE_SUFFIX:
case TABLE_UPPER:
case TABLE_LOWER:
case COLUMN_REPLACE_LINE_BREAK:
case TIMEZONE:
return true;
default:
return false;
}
}
public String getSinkConfigurationString() {
return sink.entrySet().stream()
.filter(t -> !isSkip(t.getKey()))
.map(t -> String.format("'%s' = '%s'", t.getKey(), t.getValue()))
.collect(Collectors.joining(",\n"));
}
public String getType() {
return type;
}
......@@ -222,42 +253,6 @@ public class FlinkCDCConfig {
this.schemaTableNameList = schemaTableNameList;
}
private boolean skip(String key) {
switch (key) {
case "sink.db":
case "auto.create":
case "table.prefix":
case "table.suffix":
case "table.upper":
case "table.lower":
case "column.replace.line-break":
case "timezone":
return true;
default:
return false;
}
}
public String getSinkConfigurationString() {
StringBuilder sb = new StringBuilder();
int index = 0;
for (Map.Entry<String, String> entry : sink.entrySet()) {
if (skip(entry.getKey())) {
continue;
}
if (index > 0) {
sb.append(",");
}
sb.append("'");
sb.append(entry.getKey());
sb.append("' = '");
sb.append(entry.getValue());
sb.append("'\n");
index++;
}
return sb.toString();
}
public void setSink(Map<String, String> sink) {
this.sink = sink;
}
......
......@@ -27,21 +27,21 @@ package org.dinky.model;
*/
public class LineageRel {
private String sourceCatalog;
private final String sourceCatalog;
private String sourceDatabase;
private final String sourceDatabase;
private String sourceTable;
private final String sourceTable;
private String sourceColumn;
private final String sourceColumn;
private String targetCatalog;
private final String targetCatalog;
private String targetDatabase;
private final String targetDatabase;
private String targetTable;
private final String targetTable;
private String targetColumn;
private final String targetColumn;
private static final String DELIMITER = ".";
......
......@@ -150,15 +150,12 @@ public class FlinkBaseUtil {
}
public static String getColumnProcessing(Column column, FlinkCDCConfig config) {
if ("true".equals(config.getSink().get("column.replace.line-break"))
if ("true".equals(config.getSink().get(FlinkCDCConfig.COLUMN_REPLACE_LINE_BREAK))
&& ColumnType.STRING.equals(column.getJavaType())) {
return "REGEXP_REPLACE(`"
+ column.getName()
+ "`, '\\n', '') AS `"
+ column.getName()
+ "`";
return String.format(
"REGEXP_REPLACE(`%s`, '\\n', '') AS `%s`", column.getName(), column.getName());
} else {
return "`" + column.getName() + "`";
return String.format("`%s`", column.getName());
}
}
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.model;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
/** */
class FlinkCDCConfigTest {
@Test
void getSinkConfigurationString() {
Map<String, String> sinkConfig = new HashMap<>();
sinkConfig.put(FlinkCDCConfig.SINK_DB, "sink_db");
sinkConfig.put("propertyOne", "propertyOneValue");
sinkConfig.put("propertyTwo", "propertyTwoValue");
FlinkCDCConfig flinkCDCConfig =
new FlinkCDCConfig(
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
sinkConfig,
null);
String sinkConfigureStr = flinkCDCConfig.getSinkConfigurationString();
assertThat(
sinkConfigureStr,
equalTo(
"'propertyOne' = 'propertyOneValue',\n"
+ "'propertyTwo' = 'propertyTwoValue'"));
}
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.utils;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
/** */
class FlinkBaseUtilTest {
@Test
void getParamsFromArgs() {}
@Test
void getCDCSqlInsert() {
// FlinkBaseUtil.getCDCSqlInsert("TableName", "SourceName", "")
}
@Test
void getFlinkDDL() {}
@Test
void getSinkConfigurationString() {}
@Test
void convertSinkColumnType() {}
@Test
void getColumnProcessing() {}
}
......@@ -21,7 +21,11 @@ package org.dinky.model;
import java.io.Serializable;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
......@@ -32,6 +36,9 @@ import lombok.Setter;
*/
@Setter
@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PACKAGE)
@NoArgsConstructor
public class Column implements Serializable {
private static final long serialVersionUID = 6438514547501611599L;
......@@ -58,10 +65,11 @@ public class Column implements Serializable {
return flinkType;
}
Integer defaultPrecision = precision;
if (precision == null || precision == 0) {
return String.format("%s(%d,%d)", flinkType, 38, scale);
defaultPrecision = 38;
}
return String.format("%s(%d,%d)", flinkType, precision, scale);
return String.format("%s(%d,%d)", flinkType, defaultPrecision, scale);
}
}
......@@ -24,9 +24,12 @@ import org.dinky.utils.SqlUtil;
import java.beans.Transient;
import java.io.Serializable;
import java.util.ArrayList;
import java.text.MessageFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.Getter;
import lombok.Setter;
......@@ -97,127 +100,71 @@ public class Table implements Serializable, Comparable<Table>, Cloneable {
@Transient
public String getFlinkTableWith(String flinkConfig) {
String tableWithSql = "";
if (Asserts.isNotNullString(flinkConfig)) {
tableWithSql = SqlUtil.replaceAllParam(flinkConfig, "schemaName", schema);
tableWithSql = SqlUtil.replaceAllParam(tableWithSql, "tableName", name);
Map<String, String> replacements = new HashMap<>();
replacements.put("schemaName", schema);
replacements.put("tableName", name);
return SqlUtil.replaceAllParam(flinkConfig, replacements);
}
return tableWithSql;
return "";
}
@Transient
public String getFlinkTableSql(String flinkConfig) {
return getFlinkDDL(flinkConfig, name);
public String getFlinkDDL(String flinkConfig, String tableName) {
String columnStrs =
columns.stream()
.map(
column -> {
String comment = "";
if (Asserts.isNotNullString(column.getComment())) {
comment =
String.format(
" COMMENT '%s'",
column.getComment().replaceAll("\"|'", ""));
}
return String.format(
" `%s` %s%s",
column.getName(), column.getFlinkType(), comment);
})
.collect(Collectors.joining(",\n"));
String primaryKeyStr =
columns.stream()
.filter(Column::isKeyFlag)
.map(Column::getName)
.map(t -> String.format("`%s`", t))
.collect(
Collectors.joining(
",", ",\n PRIMARY KEY ( ", " ) NOT ENFORCED\n"));
String result =
MessageFormat.format(
"CREATE TABLE IF NOT EXISTS {0} (\n{1}{2}) WITH (\n{3})\n",
tableName, columnStrs, primaryKeyStr, flinkConfig);
return result;
}
@Transient
public String getFlinkDDL(String flinkConfig, String tableName) {
StringBuilder sb = new StringBuilder();
sb.append("CREATE TABLE IF NOT EXISTS " + tableName + " (\n");
List<String> pks = new ArrayList<>();
for (int i = 0; i < columns.size(); i++) {
String type = columns.get(i).getFlinkType();
sb.append(" ");
if (i > 0) {
sb.append(",");
}
sb.append("`" + columns.get(i).getName() + "` " + type);
if (Asserts.isNotNullString(columns.get(i).getComment())) {
if (columns.get(i).getComment().contains("\'")
| columns.get(i).getComment().contains("\"")) {
sb.append(
" COMMENT '"
+ columns.get(i).getComment().replaceAll("\"|'", "")
+ "'");
} else {
sb.append(" COMMENT '" + columns.get(i).getComment() + "'");
}
}
sb.append("\n");
if (columns.get(i).isKeyFlag()) {
pks.add(columns.get(i).getName());
}
}
StringBuilder pksb = new StringBuilder("PRIMARY KEY ( ");
for (int i = 0; i < pks.size(); i++) {
if (i > 0) {
pksb.append(",");
}
pksb.append("`" + pks.get(i) + "`");
}
pksb.append(" ) NOT ENFORCED\n");
if (pks.size() > 0) {
sb.append(" ,");
sb.append(pksb);
}
sb.append(")");
if (Asserts.isNotNullString(comment)) {
if (comment.contains("\'") | comment.contains("\"")) {
sb.append(" COMMENT '" + comment.replaceAll("\"|'", "") + "'\n");
} else {
sb.append(" COMMENT '" + comment + "'\n");
}
public String getFlinkTableSql(String catalogName, String flinkConfig) {
String createSql = getFlinkDDL(getFlinkTableWith(flinkConfig), name);
return String.format("DROP TABLE IF EXISTS %s;\n%s", name, createSql);
}
@Override
public Object clone() {
Table table = null;
try {
table = (Table) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
sb.append(" WITH (\n");
sb.append(flinkConfig);
sb.append(")\n");
return sb.toString();
return table;
}
@Transient
public String getFlinkTableSql(String catalogName, String flinkConfig) {
StringBuilder sb = new StringBuilder("DROP TABLE IF EXISTS ");
String fullSchemaName = catalogName + "." + schema + "." + name;
sb.append(name + ";\n");
sb.append("CREATE TABLE IF NOT EXISTS " + name + " (\n");
List<String> pks = new ArrayList<>();
for (int i = 0; i < columns.size(); i++) {
String type = columns.get(i).getFlinkType();
sb.append(" ");
if (i > 0) {
sb.append(",");
}
sb.append("`" + columns.get(i).getName() + "` " + type);
if (Asserts.isNotNullString(columns.get(i).getComment())) {
if (columns.get(i).getComment().contains("\'")
| columns.get(i).getComment().contains("\"")) {
sb.append(
" COMMENT '"
+ columns.get(i).getComment().replaceAll("\"|'", "")
+ "'");
} else {
sb.append(" COMMENT '" + columns.get(i).getComment() + "'");
}
}
sb.append("\n");
if (columns.get(i).isKeyFlag()) {
pks.add(columns.get(i).getName());
}
}
StringBuilder pksb = new StringBuilder("PRIMARY KEY ( ");
for (int i = 0; i < pks.size(); i++) {
if (i > 0) {
pksb.append(",");
}
pksb.append("`" + pks.get(i) + "`");
}
pksb.append(" ) NOT ENFORCED\n");
if (pks.size() > 0) {
sb.append(" ,");
sb.append(pksb);
}
sb.append(")");
if (Asserts.isNotNullString(comment)) {
if (comment.contains("\'") | comment.contains("\"")) {
sb.append(" COMMENT '" + comment.replaceAll("\"|'", "") + "'\n");
} else {
sb.append(" COMMENT '" + comment + "'\n");
}
}
sb.append(" WITH (\n");
sb.append(getFlinkTableWith(flinkConfig));
sb.append("\n);\n");
return sb.toString();
public String getFlinkTableSql(String flinkConfig) {
return getFlinkDDL(flinkConfig, name);
}
@Transient
......@@ -262,15 +209,4 @@ public class Table implements Serializable, Comparable<Table>, Cloneable {
sb.append(sourceName);
return sb.toString();
}
@Override
public Object clone() {
Table table = null;
try {
table = (Table) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return table;
}
}
......@@ -22,6 +22,8 @@ package org.dinky.utils;
import org.dinky.assertion.Asserts;
import org.dinky.model.SystemConfiguration;
import java.util.Map;
/**
* SqlUtil
*
......@@ -64,4 +66,20 @@ public class SqlUtil {
public static String replaceAllParam(String sql, String name, String value) {
return sql.replaceAll("\\$\\{" + name + "\\}", value);
}
/**
* replace sql context with values params, map's key is origin variable express by `${key}`,
* value is replacement. for example, if key="name", value="replacement", and sql is "${name}",
* the result will be "replacement".
*
* @param sql sql context
* @param values replacement
* @return replace variable result
*/
public static String replaceAllParam(String sql, Map<String, String> values) {
for (Map.Entry<String, String> entry : values.entrySet()) {
sql = replaceAllParam(sql, entry.getKey(), entry.getValue());
}
return sql;
}
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.model;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** */
class TableTest {
private Table table;
private String flinkConfig;
@BeforeEach
void setUp() {
List<Column> columns =
Arrays.asList(
Column.builder()
.name("column1")
.type("int")
.javaType(ColumnType.INT)
.comment("comment abc")
.keyFlag(true)
.build(),
Column.builder()
.name("column2")
.type("varchar")
.javaType(ColumnType.STRING)
.comment("comment 'abc'")
.keyFlag(true)
.build(),
Column.builder()
.name("column3")
.type("double")
.javaType(ColumnType.DOUBLE)
.comment("comment \"abc\"")
.build());
table = new Table("TableNameOrigin", "SchemaOrigin", columns);
flinkConfig =
"${schemaName}=schemaName, ${tableName}=tableName, ${abc}=abc, ${}=null, bcd=bcd";
}
@Test
void getFlinkDDL() {
String result = table.getFlinkDDL(flinkConfig, "NewTableName");
assertThat(
result,
equalTo(
"CREATE TABLE IF NOT EXISTS NewTableName (\n"
+ " `column1` INT NOT NULL COMMENT 'comment abc',\n"
+ " `column2` STRING COMMENT 'comment abc',\n"
+ " `column3` DOUBLE NOT NULL COMMENT 'comment abc',\n"
+ " PRIMARY KEY ( `column1`,`column2` ) NOT ENFORCED\n"
+ ") WITH (\n"
+ "${schemaName}=schemaName, ${tableName}=tableName, ${abc}=abc, ${}=null, bcd=bcd)"
+ "\n"));
}
@Test
void getFlinkTableWith() {
String result = table.getFlinkTableWith(flinkConfig);
assertThat(
result,
equalTo(
"SchemaOrigin=schemaName, TableNameOrigin=tableName, ${abc}=abc, ${}=null, "
+ "bcd=bcd"));
}
@Test
void getFlinkTableSql() {
String result = table.getFlinkTableSql("CatalogName", flinkConfig);
assertThat(
result,
equalTo(
"DROP TABLE IF EXISTS TableNameOrigin;\n"
+ "CREATE TABLE IF NOT EXISTS TableNameOrigin (\n"
+ " `column1` INT NOT NULL COMMENT 'comment abc',\n"
+ " `column2` STRING COMMENT 'comment abc',\n"
+ " `column3` DOUBLE NOT NULL COMMENT 'comment abc',\n"
+ " PRIMARY KEY ( `column1`,`column2` ) NOT ENFORCED\n"
+ ") WITH (\n"
+ "SchemaOrigin=schemaName, TableNameOrigin=tableName, ${abc}=abc, ${}=null, bcd=bcd)\n"));
}
}
......@@ -32,6 +32,7 @@ import org.junit.Test;
* @author wenmo
* @since 2022/2/7 23:15
*/
@Ignore
public class BatchTest {
@Ignore
......
......@@ -32,6 +32,7 @@ import org.junit.Test;
* @author wenmo
* @since 2021/6/23 10:37
*/
@Ignore
public class FlinkSqlPlusTest {
@Ignore
......
......@@ -36,6 +36,7 @@ import org.junit.Test;
* @author wenmo
* @since 2021/6/3
*/
@Ignore
public class JobManagerTest {
@Ignore
......
......@@ -31,6 +31,7 @@ import org.junit.Test;
* @author wenmo
* @since 2022/3/15 23:08
*/
@Ignore
public class LineageTest {
@Ignore
......
......@@ -228,19 +228,20 @@ public class CreateCDCSourceOperation extends AbstractOperation implements Opera
Driver checkAndCreateSinkSchema(FlinkCDCConfig config, String schemaName) throws Exception {
Map<String, String> sink = config.getSink();
String autoCreate = sink.get("auto.create");
String autoCreate = sink.get(FlinkCDCConfig.AUTO_CREATE);
if (!Asserts.isEqualsIgnoreCase(autoCreate, "true") || Asserts.isNullString(schemaName)) {
return null;
}
String url = sink.get("url");
String schema = SqlUtil.replaceAllParam(sink.get("sink.db"), "schemaName", schemaName);
String schema =
SqlUtil.replaceAllParam(sink.get(FlinkCDCConfig.SINK_DB), "schemaName", schemaName);
Driver driver =
Driver.build(
sink.get("connector"), url, sink.get("username"), sink.get("password"));
if (null != driver && !driver.existSchema(schema)) {
driver.createSchema(schema);
}
sink.put("sink.db", schema);
sink.put(FlinkCDCConfig.SINK_DB, schema);
sink.put("url", url + "/" + schema);
return driver;
}
......
......@@ -22,6 +22,7 @@ package org.dinky.interceptor;
import org.dinky.executor.Executor;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
/**
......@@ -30,6 +31,7 @@ import org.junit.Test;
* @author wenmo
* @since 2022/4/9 17:48
*/
@Ignore
public class FlinkInterceptorTest {
@Test
......
......@@ -17,12 +17,20 @@
*
*/
package org.dinky.daemon;
package org.dinky.gateway.config;
/**
* DeamonTest
*
* @author wenmo
* @since 2022/3/2 23:31
*/
public class DaemonTest {}
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
/** */
class ActionTypeTest {
@ParameterizedTest
@CsvSource({"savepoint, SAVEPOINT", "cancel, CANCEL"})
void get(String value, ActionType actionType) {
assertThat(ActionType.get(value), equalTo(actionType));
}
}
......@@ -37,6 +37,7 @@ import org.junit.Test;
* @author heyang
* @since 2022/4/21 1:06
*/
@Ignore
public class ClickHouseTest {
private static final String IP = "127.0.0.1";
......
......@@ -35,6 +35,7 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class DorisTest {
private Driver driver;
......
......@@ -40,6 +40,7 @@ import org.junit.Test;
* @author wenmo
* @since 2021/7/20 15:32
*/
@Ignore
public class HiveTest {
private static final String IP = "cdh1";
......
......@@ -37,6 +37,7 @@ import org.junit.Test;
* @author wenmo
* @since 2021/7/20 15:32
*/
@Ignore
public class MysqlTest {
private static final String IP = "127.0.0.1";
......
......@@ -37,6 +37,7 @@ import org.junit.Test;
* @author wenmo
* @since 2021/7/21 16:14
*/
@Ignore
public class OracleTest {
private static final String IP = "127.0.0.1";
......
......@@ -33,6 +33,7 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class PhoenixTest {
private Driver driver;
......
......@@ -35,6 +35,7 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class PrestoTest {
private Driver driver;
......
......@@ -35,6 +35,7 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class SqlServerTest {
private Driver driver;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment