|
|
@ -17,59 +17,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.apache.flink.cdc.common.utils;
|
|
|
|
package org.apache.flink.cdc.common.utils;
|
|
|
|
|
|
|
|
|
|
|
|
import org.assertj.core.api.Assertions;
|
|
|
|
import org.apache.flink.cdc.common.event.SchemaChangeEventType;
|
|
|
|
|
|
|
|
import org.apache.flink.cdc.common.event.SchemaChangeEventTypeFamily;
|
|
|
|
|
|
|
|
|
|
|
|
import org.assertj.core.util.Sets;
|
|
|
|
import org.assertj.core.util.Sets;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.apache.flink.cdc.common.event.SchemaChangeEventType.ADD_COLUMN;
|
|
|
|
import static org.apache.flink.cdc.common.event.SchemaChangeEventType.ADD_COLUMN;
|
|
|
|
import static org.apache.flink.cdc.common.event.SchemaChangeEventType.ALTER_COLUMN_TYPE;
|
|
|
|
import static org.apache.flink.cdc.common.event.SchemaChangeEventType.ALTER_COLUMN_TYPE;
|
|
|
|
import static org.apache.flink.cdc.common.event.SchemaChangeEventType.CREATE_TABLE;
|
|
|
|
import static org.apache.flink.cdc.common.event.SchemaChangeEventType.CREATE_TABLE;
|
|
|
|
import static org.apache.flink.cdc.common.event.SchemaChangeEventType.DROP_COLUMN;
|
|
|
|
import static org.apache.flink.cdc.common.event.SchemaChangeEventType.DROP_COLUMN;
|
|
|
|
import static org.apache.flink.cdc.common.event.SchemaChangeEventType.RENAME_COLUMN;
|
|
|
|
import static org.apache.flink.cdc.common.event.SchemaChangeEventType.RENAME_COLUMN;
|
|
|
|
|
|
|
|
import static org.apache.flink.cdc.common.testutils.assertions.EventAssertions.assertThat;
|
|
|
|
|
|
|
|
|
|
|
|
/** A test for the {@link org.apache.flink.cdc.common.utils.ChangeEventUtils}. */
|
|
|
|
/** A test for the {@link org.apache.flink.cdc.common.utils.ChangeEventUtils}. */
|
|
|
|
public class ChangeEventUtilsTest {
|
|
|
|
public class ChangeEventUtilsTest {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testResolveSchemaEvolutionOptions() {
|
|
|
|
public void testResolveSchemaEvolutionOptions() {
|
|
|
|
Assertions.assertThat(
|
|
|
|
|
|
|
|
ChangeEventUtils.resolveSchemaEvolutionOptions(
|
|
|
|
List<String> allTags =
|
|
|
|
Collections.emptyList(), Collections.emptyList()))
|
|
|
|
Arrays.stream(SchemaChangeEventTypeFamily.ALL)
|
|
|
|
|
|
|
|
.map(SchemaChangeEventType::getTag)
|
|
|
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionOptions(allTags, Collections.emptyList()))
|
|
|
|
.isEqualTo(
|
|
|
|
.isEqualTo(
|
|
|
|
Sets.set(
|
|
|
|
Sets.set(
|
|
|
|
|
|
|
|
RENAME_COLUMN,
|
|
|
|
CREATE_TABLE,
|
|
|
|
CREATE_TABLE,
|
|
|
|
ADD_COLUMN,
|
|
|
|
|
|
|
|
ALTER_COLUMN_TYPE,
|
|
|
|
ALTER_COLUMN_TYPE,
|
|
|
|
DROP_COLUMN,
|
|
|
|
ADD_COLUMN,
|
|
|
|
RENAME_COLUMN));
|
|
|
|
DROP_COLUMN));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(
|
|
|
|
assertThat(
|
|
|
|
ChangeEventUtils.resolveSchemaEvolutionOptions(
|
|
|
|
ChangeEventUtils.resolveSchemaEvolutionOptions(
|
|
|
|
Collections.emptyList(), Collections.singletonList("drop")))
|
|
|
|
allTags, Collections.singletonList("drop")))
|
|
|
|
.isEqualTo(Sets.set(CREATE_TABLE, ADD_COLUMN, ALTER_COLUMN_TYPE, RENAME_COLUMN));
|
|
|
|
.isEqualTo(Sets.set(ADD_COLUMN, ALTER_COLUMN_TYPE, RENAME_COLUMN, CREATE_TABLE));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(
|
|
|
|
assertThat(
|
|
|
|
ChangeEventUtils.resolveSchemaEvolutionOptions(
|
|
|
|
ChangeEventUtils.resolveSchemaEvolutionOptions(
|
|
|
|
Arrays.asList("create", "add"), Collections.emptyList()))
|
|
|
|
Arrays.asList("create", "add"), Collections.emptyList()))
|
|
|
|
.isEqualTo(Sets.set(CREATE_TABLE, ADD_COLUMN));
|
|
|
|
.isEqualTo(Sets.set(ADD_COLUMN, CREATE_TABLE));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(
|
|
|
|
assertThat(
|
|
|
|
ChangeEventUtils.resolveSchemaEvolutionOptions(
|
|
|
|
ChangeEventUtils.resolveSchemaEvolutionOptions(
|
|
|
|
Collections.singletonList("column"),
|
|
|
|
Collections.singletonList("column"),
|
|
|
|
Collections.singletonList("drop.column")))
|
|
|
|
Collections.singletonList("drop.column")))
|
|
|
|
.isEqualTo(Sets.set(ADD_COLUMN, ALTER_COLUMN_TYPE, RENAME_COLUMN));
|
|
|
|
.isEqualTo(Sets.set(ADD_COLUMN, ALTER_COLUMN_TYPE, RENAME_COLUMN));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(
|
|
|
|
assertThat(
|
|
|
|
ChangeEventUtils.resolveSchemaEvolutionOptions(
|
|
|
|
ChangeEventUtils.resolveSchemaEvolutionOptions(
|
|
|
|
Collections.emptyList(), Collections.singletonList("drop.column")))
|
|
|
|
allTags, Collections.singletonList("drop.column")))
|
|
|
|
.isEqualTo(Sets.set(CREATE_TABLE, ADD_COLUMN, ALTER_COLUMN_TYPE, RENAME_COLUMN));
|
|
|
|
.isEqualTo(Sets.set(ADD_COLUMN, RENAME_COLUMN, ALTER_COLUMN_TYPE, CREATE_TABLE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testResolveSchemaEvolutionTag() {
|
|
|
|
public void testResolveSchemaEvolutionTag() {
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("all"))
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("all"))
|
|
|
|
.isEqualTo(
|
|
|
|
.isEqualTo(
|
|
|
|
Arrays.asList(
|
|
|
|
Arrays.asList(
|
|
|
|
ADD_COLUMN,
|
|
|
|
ADD_COLUMN,
|
|
|
@ -78,41 +86,38 @@ public class ChangeEventUtilsTest {
|
|
|
|
DROP_COLUMN,
|
|
|
|
DROP_COLUMN,
|
|
|
|
RENAME_COLUMN));
|
|
|
|
RENAME_COLUMN));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("column"))
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("column"))
|
|
|
|
.isEqualTo(
|
|
|
|
.isEqualTo(
|
|
|
|
Arrays.asList(ADD_COLUMN, ALTER_COLUMN_TYPE, DROP_COLUMN, RENAME_COLUMN));
|
|
|
|
Arrays.asList(ADD_COLUMN, ALTER_COLUMN_TYPE, DROP_COLUMN, RENAME_COLUMN));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("table"))
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("table"))
|
|
|
|
.isEqualTo(Collections.singletonList(CREATE_TABLE));
|
|
|
|
.isEqualTo(Collections.singletonList(CREATE_TABLE));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("rename"))
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("rename.column"))
|
|
|
|
.isEqualTo(Collections.singletonList(RENAME_COLUMN));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("rename.column"))
|
|
|
|
|
|
|
|
.isEqualTo(Collections.singletonList(RENAME_COLUMN));
|
|
|
|
.isEqualTo(Collections.singletonList(RENAME_COLUMN));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("drop"))
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("drop"))
|
|
|
|
.isEqualTo(Collections.singletonList(DROP_COLUMN));
|
|
|
|
.isEqualTo(Collections.singletonList(DROP_COLUMN));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("drop.column"))
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("drop.column"))
|
|
|
|
.isEqualTo(Collections.singletonList(DROP_COLUMN));
|
|
|
|
.isEqualTo(Collections.singletonList(DROP_COLUMN));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("create"))
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("create"))
|
|
|
|
.isEqualTo(Collections.singletonList(CREATE_TABLE));
|
|
|
|
.isEqualTo(Collections.singletonList(CREATE_TABLE));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("create.table"))
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("create.table"))
|
|
|
|
.isEqualTo(Collections.singletonList(CREATE_TABLE));
|
|
|
|
.isEqualTo(Collections.singletonList(CREATE_TABLE));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("alter"))
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("alter"))
|
|
|
|
.isEqualTo(Collections.singletonList(ALTER_COLUMN_TYPE));
|
|
|
|
.isEqualTo(Collections.singletonList(ALTER_COLUMN_TYPE));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("alter.column.type"))
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("alter.column.type"))
|
|
|
|
.isEqualTo(Collections.singletonList(ALTER_COLUMN_TYPE));
|
|
|
|
.isEqualTo(Collections.singletonList(ALTER_COLUMN_TYPE));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("add"))
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("add"))
|
|
|
|
.isEqualTo(Collections.singletonList(ADD_COLUMN));
|
|
|
|
.isEqualTo(Collections.singletonList(ADD_COLUMN));
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("add.column"))
|
|
|
|
assertThat(ChangeEventUtils.resolveSchemaEvolutionTag("add.column"))
|
|
|
|
.isEqualTo(Collections.singletonList(ADD_COLUMN));
|
|
|
|
.isEqualTo(Collections.singletonList(ADD_COLUMN));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|