yuanoOo commented on code in PR #3360: URL: https://github.com/apache/flink-cdc/pull/3360#discussion_r1849992101
########## flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-oceanbase/src/test/java/org/apache/flink/cdc/connectors/oceanbase/sink/OceanBaseMetadataApplierTest.java: ########## @@ -0,0 +1,256 @@ +/* + * 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.connectors.oceanbase.sink; + +import org.apache.flink.cdc.common.event.AlterColumnTypeEvent; +import org.apache.flink.cdc.common.event.CreateTableEvent; +import org.apache.flink.cdc.common.event.DropColumnEvent; +import org.apache.flink.cdc.common.event.DropTableEvent; +import org.apache.flink.cdc.common.event.TableId; +import org.apache.flink.cdc.common.event.TruncateTableEvent; +import org.apache.flink.cdc.common.schema.Schema; +import org.apache.flink.cdc.common.types.BooleanType; +import org.apache.flink.cdc.common.types.DataType; +import org.apache.flink.cdc.common.types.IntType; +import org.apache.flink.cdc.common.types.LocalZonedTimestampType; +import org.apache.flink.cdc.connectors.oceanbase.OceanBaseTestUtils; +import org.apache.flink.cdc.connectors.oceanbase.catalog.OceanBaseColumn; +import org.apache.flink.cdc.connectors.oceanbase.catalog.OceanBaseTable; +import org.apache.flink.cdc.connectors.oceanbase.testutils.OceanBaseContainer; +import org.apache.flink.cdc.connectors.oceanbase.utils.OceanBaseTestMySQLCatalog; + +import org.apache.flink.shaded.guava31.com.google.common.collect.ImmutableMap; +import org.apache.flink.shaded.guava31.com.google.common.collect.Lists; + +import com.oceanbase.connector.flink.OceanBaseConnectorOptions; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.containers.output.Slf4jLogConsumer; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import static org.apache.flink.cdc.connectors.oceanbase.table.OceanBaseMySQLModeITCase.NETWORK; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** Tests for {@link OceanBaseMetadataApplier}. */ +public class OceanBaseMetadataApplierTest { + private static final Logger LOG = LoggerFactory.getLogger(OceanBaseMetadataApplierTest.class); + + private OceanBaseMetadataApplier metadataApplier; + private OceanBaseTestMySQLCatalog catalog; + + @ClassRule + public static final OceanBaseContainer OB_SERVER = + OceanBaseTestUtils.createOceanBaseContainerForJdbc() + .withNetwork(NETWORK) + .withNetworkAliases("oceanbase") + .withLogConsumer(new Slf4jLogConsumer(LOG)); + + @Before + public void setup() throws Exception { + final ImmutableMap<String, String> configMap = + ImmutableMap.<String, String>builder() + .put("url", OB_SERVER.getJdbcUrl()) + .put("username", OB_SERVER.getUsername()) + .put("password", OB_SERVER.getPassword()) + .build(); + OceanBaseConnectorOptions connectorOptions = new OceanBaseConnectorOptions(configMap); + metadataApplier = new OceanBaseMetadataApplier(connectorOptions); + catalog = new OceanBaseTestMySQLCatalog(connectorOptions); + catalog.open(); + } + + @AfterClass + public static void close() { + OB_SERVER.close(); + } + + @Test + public void testCreateTable() { + TableId tableId = TableId.parse("test.tbl1"); + Schema schema = + Schema.newBuilder() + .physicalColumn("col1", new IntType(false)) + .physicalColumn("col2", new BooleanType()) + .physicalColumn("col3", new LocalZonedTimestampType()) + .primaryKey("col1") + .build(); + CreateTableEvent createTableEvent = new CreateTableEvent(tableId, schema); + metadataApplier.applySchemaChange(createTableEvent); + + OceanBaseTable actualTable = + catalog.getTable(tableId.getSchemaName(), tableId.getTableName()).orElse(null); + assertNotNull(actualTable); + + List<OceanBaseColumn> columns = new ArrayList<>(); + columns.add( + new OceanBaseColumn.Builder() + .setColumnName("col1") + .setOrdinalPosition(0) + .setDataType("int") + .setNumericScale(0) + .setNullable(false) + .build()); + columns.add( + new OceanBaseColumn.Builder() + .setColumnName("col2") + .setOrdinalPosition(1) + .setDataType("tinyint") + .setNumericScale(0) + .setNullable(true) + .build()); + columns.add( + new OceanBaseColumn.Builder() + .setColumnName("col3") + .setOrdinalPosition(2) + .setDataType("datetime") + .setNullable(true) + .build()); + OceanBaseTable expectTable = + new OceanBaseTable.Builder() + .setDatabaseName(tableId.getSchemaName()) + .setTableName(tableId.getTableName()) + .setTableType(OceanBaseTable.TableType.PRIMARY_KEY) + .setColumns(columns) + .setTableKeys(schema.primaryKeys()) + .build(); + + System.out.println(expectTable); + System.out.println(actualTable); Review Comment: Removed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
