forked from apache/flink-cdc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[minor][test] Add Flink CDC 3.1.1 version to migration test version list
This closes apache#3426.
- Loading branch information
1 parent
cbf2b19
commit 020a0ad
Showing
8 changed files
with
369 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-cdc-migration-tests</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>flink-cdc-release-3.1.1</artifactId> | ||
<name>flink-cdc-release-3.1.1</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-cdc-base</artifactId> | ||
<version>3.1.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-cdc-common</artifactId> | ||
<version>3.1.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-cdc-runtime</artifactId> | ||
<version>3.1.1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.4</version> | ||
<executions> | ||
<execution> | ||
<id>shade-flink-cdc</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
<relocations> | ||
<relocation> | ||
<pattern>org.apache.flink.cdc</pattern> | ||
<shadedPattern>org.apache.flink.cdc.v3_1_1</shadedPattern> | ||
<excludes>META-INF/*.SF,META-INF/*.DSA,META-INF/*.RSA</excludes> | ||
</relocation> | ||
</relocations> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
27 changes: 27 additions & 0 deletions
27
...c-release-3.1.1/src/main/java/org/apache/flink/cdc/migration/tests/MigrationMockBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.cdc.migration.tests; | ||
|
||
/** Base classes for migration test cases. */ | ||
public interface MigrationMockBase { | ||
int getSerializerVersion(); | ||
|
||
byte[] serializeObject() throws Exception; | ||
|
||
boolean deserializeAndCheckObject(int v, byte[] b) throws Exception; | ||
} |
68 changes: 68 additions & 0 deletions
68
...-3.1.1/src/main/java/org/apache/flink/cdc/migration/tests/SchemaManagerMigrationMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.cdc.migration.tests; | ||
|
||
import org.apache.flink.cdc.common.event.TableId; | ||
import org.apache.flink.cdc.common.schema.Schema; | ||
import org.apache.flink.cdc.common.types.DataTypes; | ||
import org.apache.flink.cdc.runtime.operators.schema.coordinator.SchemaManager; | ||
|
||
import java.util.Collections; | ||
import java.util.SortedMap; | ||
import java.util.TreeMap; | ||
|
||
/** Dummy classes for migration test. Called via reflection. */ | ||
public class SchemaManagerMigrationMock implements MigrationMockBase { | ||
private static final TableId DUMMY_TABLE_ID = | ||
TableId.tableId("dummyNamespace", "dummySchema", "dummyTable"); | ||
private static final Schema DUMMY_SCHEMA = | ||
Schema.newBuilder() | ||
.physicalColumn("id", DataTypes.INT()) | ||
.physicalColumn("name", DataTypes.STRING()) | ||
.physicalColumn("age", DataTypes.DOUBLE()) | ||
.primaryKey("id", "name") | ||
.build(); | ||
|
||
private static final String SCHEMA_MANAGER = | ||
"runtime.operators.schema.coordinator.SchemaManager"; | ||
|
||
public SchemaManager generateDummyObject() { | ||
SortedMap<Integer, Schema> schemaVersions = new TreeMap<>(); | ||
schemaVersions.put(1, DUMMY_SCHEMA); | ||
schemaVersions.put(2, DUMMY_SCHEMA); | ||
schemaVersions.put(3, DUMMY_SCHEMA); | ||
return new SchemaManager(Collections.singletonMap(DUMMY_TABLE_ID, schemaVersions)); | ||
} | ||
|
||
@Override | ||
public int getSerializerVersion() { | ||
return SchemaManager.SERIALIZER.getVersion(); | ||
} | ||
|
||
@Override | ||
public byte[] serializeObject() throws Exception { | ||
return SchemaManager.SERIALIZER.serialize(generateDummyObject()); | ||
} | ||
|
||
@Override | ||
public boolean deserializeAndCheckObject(int version, byte[] serialized) throws Exception { | ||
Object expected = generateDummyObject(); | ||
Object actual = SchemaManager.SERIALIZER.deserialize(version, serialized); | ||
return expected.equals(actual); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
...3.1.1/src/main/java/org/apache/flink/cdc/migration/tests/SchemaRegistryMigrationMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.cdc.migration.tests; | ||
|
||
import org.apache.flink.api.java.tuple.Tuple2; | ||
import org.apache.flink.cdc.common.event.TableId; | ||
import org.apache.flink.cdc.common.schema.Schema; | ||
import org.apache.flink.cdc.common.schema.Selectors; | ||
import org.apache.flink.cdc.common.types.DataTypes; | ||
import org.apache.flink.cdc.runtime.operators.schema.coordinator.SchemaDerivation; | ||
import org.apache.flink.cdc.runtime.operators.schema.coordinator.SchemaManager; | ||
import org.apache.flink.cdc.runtime.operators.schema.coordinator.SchemaRegistry; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.SortedMap; | ||
import java.util.TreeMap; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** Dummy classes for migration test. Called via reflection. */ | ||
public class SchemaRegistryMigrationMock implements MigrationMockBase { | ||
private static final TableId DUMMY_TABLE_ID = | ||
TableId.tableId("dummyNamespace", "dummySchema", "dummyTable"); | ||
private static final Schema DUMMY_SCHEMA = | ||
Schema.newBuilder() | ||
.physicalColumn("id", DataTypes.INT()) | ||
.physicalColumn("name", DataTypes.STRING()) | ||
.physicalColumn("age", DataTypes.DOUBLE()) | ||
.primaryKey("id", "name") | ||
.build(); | ||
|
||
public SchemaManager generateDummySchemaManager() { | ||
SortedMap<Integer, Schema> schemaVersions = new TreeMap<>(); | ||
schemaVersions.put(1, DUMMY_SCHEMA); | ||
schemaVersions.put(2, DUMMY_SCHEMA); | ||
schemaVersions.put(3, DUMMY_SCHEMA); | ||
return new SchemaManager(Collections.singletonMap(DUMMY_TABLE_ID, schemaVersions)); | ||
} | ||
|
||
public SchemaRegistry generateSchemaRegistry() { | ||
return new SchemaRegistry("Dummy Name", null, e -> {}, new ArrayList<>()); | ||
} | ||
|
||
private SchemaManager getSchemaManager(SchemaRegistry schemaRegistry) throws Exception { | ||
Field field = SchemaRegistry.class.getDeclaredField("schemaManager"); | ||
field.setAccessible(true); | ||
return (SchemaManager) field.get(schemaRegistry); | ||
} | ||
|
||
private void setSchemaManager(SchemaRegistry schemaRegistry, SchemaManager schemaManager) | ||
throws Exception { | ||
Field field = SchemaRegistry.class.getDeclaredField("schemaManager"); | ||
field.setAccessible(true); | ||
field.set(schemaRegistry, schemaManager); | ||
} | ||
|
||
private SchemaDerivation getSchemaDerivation(SchemaRegistry schemaRegistry) throws Exception { | ||
Field field = SchemaRegistry.class.getDeclaredField("schemaDerivation"); | ||
field.setAccessible(true); | ||
return (SchemaDerivation) field.get(schemaRegistry); | ||
} | ||
|
||
private List<Tuple2<Selectors, TableId>> getSchemaRoutes(SchemaRegistry schemaRegistry) | ||
throws Exception { | ||
SchemaDerivation schemaDerivation = getSchemaDerivation(schemaRegistry); | ||
Field field = SchemaDerivation.class.getDeclaredField("routes"); | ||
field.setAccessible(true); | ||
return (List<Tuple2<Selectors, TableId>>) field.get(schemaDerivation); | ||
} | ||
|
||
@Override | ||
public int getSerializerVersion() { | ||
return -1; | ||
} | ||
|
||
@Override | ||
public byte[] serializeObject() throws Exception { | ||
CompletableFuture<byte[]> future = new CompletableFuture<>(); | ||
SchemaRegistry registry = generateSchemaRegistry(); | ||
setSchemaManager(registry, generateDummySchemaManager()); | ||
|
||
registry.checkpointCoordinator(0, future); | ||
|
||
while (!future.isDone()) { | ||
Thread.sleep(1000); | ||
} | ||
return future.get(); | ||
} | ||
|
||
@Override | ||
public boolean deserializeAndCheckObject(int v, byte[] b) throws Exception { | ||
SchemaRegistry expected = generateSchemaRegistry(); | ||
setSchemaManager(expected, generateDummySchemaManager()); | ||
SchemaRegistry actual = generateSchemaRegistry(); | ||
actual.resetToCheckpoint(0, b); | ||
return getSchemaManager(expected).equals(getSchemaManager(actual)) | ||
&& getSchemaRoutes(expected).equals(getSchemaRoutes(actual)); | ||
} | ||
} |
Oops, something went wrong.