This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new c3c9c483dab Add test cases on PipelineJobDataSourcePreparer (#33410)
c3c9c483dab is described below

commit c3c9c483dabb2f8b51cc8652763466f78a02fefd
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Oct 26 15:09:58 2024 +0800

    Add test cases on PipelineJobDataSourcePreparer (#33410)
    
    * Add test cases on PipelineJobDataSourcePreparer
    
    * Add test cases on PipelineJobDataSourcePreparer
    
    * Add test cases on PipelineJobDataSourcePreparer
---
 .../datasource/PipelineJobDataSourcePreparer.java  | 20 ++++----
 .../PipelineJobDataSourcePreparerTest.java         | 54 ++++++++++++++++++++++
 2 files changed, 64 insertions(+), 10 deletions(-)

diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PipelineJobDataSourcePreparer.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PipelineJobDataSourcePreparer.java
index 6b657fb3540..335c6ed8a42 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PipelineJobDataSourcePreparer.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PipelineJobDataSourcePreparer.java
@@ -120,6 +120,16 @@ public final class PipelineJobDataSourcePreparer {
         log.info("prepareTargetTables cost {} ms", System.currentTimeMillis() 
- startTimeMillis);
     }
     
+    private List<String> getCreateTargetTableSQL(final 
CreateTableConfiguration createTableConfig,
+                                                 final 
PipelineDataSourceManager dataSourceManager, final SQLParserEngine 
sqlParserEngine) throws SQLException {
+        DatabaseType databaseType = 
createTableConfig.getSourceDataSourceConfig().getDatabaseType();
+        DataSource sourceDataSource = 
dataSourceManager.getDataSource(createTableConfig.getSourceDataSourceConfig());
+        String schemaName = 
createTableConfig.getSourceName().getSchemaName().toString();
+        String sourceTableName = 
createTableConfig.getSourceName().getTableName().toString();
+        String targetTableName = 
createTableConfig.getTargetName().getTableName().toString();
+        return new PipelineDDLGenerator().generateLogicDDL(databaseType, 
sourceDataSource, schemaName, sourceTableName, targetTableName, 
sqlParserEngine);
+    }
+    
     private void executeTargetTableSQL(final Connection targetConnection, 
final String sql) throws SQLException {
         log.info("Execute target table SQL: {}", sql);
         try (Statement statement = targetConnection.createStatement()) {
@@ -138,14 +148,4 @@ public final class PipelineJobDataSourcePreparer {
     private String addIfNotExistsForCreateTableSQL(final String 
createTableSQL) {
         return 
PATTERN_CREATE_TABLE_IF_NOT_EXISTS.matcher(createTableSQL).find() ? 
createTableSQL : 
PATTERN_CREATE_TABLE.matcher(createTableSQL).replaceFirst("CREATE TABLE IF NOT 
EXISTS ");
     }
-    
-    private List<String> getCreateTargetTableSQL(final 
CreateTableConfiguration createTableConfig,
-                                                 final 
PipelineDataSourceManager dataSourceManager, final SQLParserEngine 
sqlParserEngine) throws SQLException {
-        DatabaseType databaseType = 
createTableConfig.getSourceDataSourceConfig().getDatabaseType();
-        DataSource sourceDataSource = 
dataSourceManager.getDataSource(createTableConfig.getSourceDataSourceConfig());
-        String schemaName = 
createTableConfig.getSourceName().getSchemaName().toString();
-        String sourceTableName = 
createTableConfig.getSourceName().getTableName().toString();
-        String targetTableName = 
createTableConfig.getTargetName().getTableName().toString();
-        return new PipelineDDLGenerator().generateLogicDDL(databaseType, 
sourceDataSource, schemaName, sourceTableName, targetTableName, 
sqlParserEngine);
-    }
 }
diff --git 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PipelineJobDataSourcePreparerTest.java
 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PipelineJobDataSourcePreparerTest.java
new file mode 100644
index 00000000000..7661cff53cd
--- /dev/null
+++ 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/PipelineJobDataSourcePreparerTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.shardingsphere.data.pipeline.core.preparer.datasource;
+
+import 
org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourceManager;
+import 
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.CreateTableConfiguration;
+import 
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetSchemasParameter;
+import 
org.apache.shardingsphere.data.pipeline.core.preparer.datasource.param.PrepareTargetTablesParameter;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.parser.SQLParserEngine;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class PipelineJobDataSourcePreparerTest {
+    
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+    
+    @Test
+    void assertPrepareTargetSchemasWithSchemaNotAvailable() {
+        PrepareTargetSchemasParameter parameter = new 
PrepareTargetSchemasParameter(databaseType, null, null);
+        assertDoesNotThrow(() -> new 
PipelineJobDataSourcePreparer(databaseType).prepareTargetSchemas(parameter));
+    }
+    
+    @Test
+    void assertPrepareTargetTables() {
+        CreateTableConfiguration createTableConfig = 
mock(CreateTableConfiguration.class, RETURNS_DEEP_STUBS);
+        
when(createTableConfig.getSourceDataSourceConfig().getDatabaseType()).thenReturn(databaseType);
+        PrepareTargetTablesParameter parameter = new 
PrepareTargetTablesParameter(
+                Collections.singleton(createTableConfig), 
mock(PipelineDataSourceManager.class, RETURNS_DEEP_STUBS), 
mock(SQLParserEngine.class));
+        assertDoesNotThrow(() -> new 
PipelineJobDataSourcePreparer(databaseType).prepareTargetTables(parameter));
+    }
+}

Reply via email to