You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2024/10/19 13:00:45 UTC

(shardingsphere) branch master updated: Add test cases on ImporterConfiguration (#33321)

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

duanzhengqiang 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 70037984764 Add test cases on ImporterConfiguration (#33321)
70037984764 is described below

commit 70037984764ae4c2affe26f15dac7454ae4929f8
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Oct 19 21:00:39 2024 +0800

    Add test cases on ImporterConfiguration (#33321)
---
 .../core/importer/ImporterConfigurationTest.java   | 64 ++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/importer/ImporterConfigurationTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/importer/ImporterConfigurationTest.java
new file mode 100644
index 00000000000..e7725dcd564
--- /dev/null
+++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/importer/ImporterConfigurationTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.importer;
+
+import org.apache.shardingsphere.data.pipeline.api.PipelineDataSourceConfiguration;
+import org.apache.shardingsphere.data.pipeline.core.ingest.dumper.mapper.TableAndSchemaNameMapper;
+import org.apache.shardingsphere.data.pipeline.core.ratelimit.JobRateLimitAlgorithm;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.metadata.caseinsensitive.CaseInsensitiveIdentifier;
+import org.apache.shardingsphere.infra.metadata.caseinsensitive.CaseInsensitiveQualifiedTable;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class ImporterConfigurationTest {
+    
+    @Test
+    void assertGetShardingColumns() {
+        ImporterConfiguration importerConfig = new ImporterConfiguration(
+                mock(PipelineDataSourceConfiguration.class), Collections.singletonMap(new CaseInsensitiveIdentifier("foo_tbl"), Collections.singleton("foo_col")),
+                mock(TableAndSchemaNameMapper.class), 1, mock(JobRateLimitAlgorithm.class), 1, 1);
+        assertThat(importerConfig.getShardingColumns("foo_tbl"), is(Collections.singleton("foo_col")));
+    }
+    
+    @Test
+    void assertFindSchemaName() {
+        PipelineDataSourceConfiguration dataSourceConfig = mock(PipelineDataSourceConfiguration.class);
+        when(dataSourceConfig.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
+        ImporterConfiguration importerConfig = new ImporterConfiguration(dataSourceConfig, Collections.emptyMap(), mock(TableAndSchemaNameMapper.class), 1, mock(JobRateLimitAlgorithm.class), 1, 1);
+        assertFalse(importerConfig.findSchemaName("foo_schema").isPresent());
+    }
+    
+    @Test
+    void assertGetQualifiedTables() {
+        TableAndSchemaNameMapper tableAndSchemaNameMapper = mock(TableAndSchemaNameMapper.class);
+        when(tableAndSchemaNameMapper.getSchemaName("foo_tbl")).thenReturn("foo_schema");
+        ImporterConfiguration importerConfig = new ImporterConfiguration(
+                mock(PipelineDataSourceConfiguration.class), Collections.singletonMap(new CaseInsensitiveIdentifier("foo_tbl"), Collections.singleton("foo_col")),
+                tableAndSchemaNameMapper, 1, mock(JobRateLimitAlgorithm.class), 1, 1);
+        assertThat(importerConfig.getQualifiedTables(), is(Collections.singletonList(new CaseInsensitiveQualifiedTable("foo_schema", "foo_tbl"))));
+    }
+}