This is an automated email from the ASF dual-hosted git repository.
totalo 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 3ed2420 Added unit tests for RecordUtil (#15980)
3ed2420 is described below
commit 3ed2420b6097178fe55dfd1f058db36a21d112c3
Author: BashCache <[email protected]>
AuthorDate: Sun Mar 13 11:30:41 2022 +0530
Added unit tests for RecordUtil (#15980)
---
.../data/pipeline/core/record/RecordUtilTest.java | 69 ++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git
a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/record/RecordUtilTest.java
b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/record/RecordUtilTest.java
new file mode 100644
index 0000000..25378c3
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/record/RecordUtilTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.record;
+
+import
org.apache.shardingsphere.data.pipeline.api.ingest.position.PlaceholderPosition;
+import org.apache.shardingsphere.data.pipeline.api.ingest.record.Column;
+import org.apache.shardingsphere.data.pipeline.api.ingest.record.DataRecord;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.junit.Assert.assertThat;
+
+public final class RecordUtilTest {
+
+ @Test
+ public void assertExtractPrimaryColumns() {
+ DataRecord dataRecord = mockDataRecord("t2");
+ Collection<Column> actual =
RecordUtil.extractPrimaryColumns(dataRecord);
+ assertThat(actual.size(), is(2));
+ assertThat(Arrays.asList("sc", "id"),
hasItems(actual.iterator().next().getName()));
+ }
+
+ @Test
+ public void assertExtractConditionalColumns() {
+ DataRecord dataRecord = mockDataRecord("t2");
+ Collection<Column> actual =
RecordUtil.extractConditionColumns(dataRecord, Collections.singleton("c1"));
+ assertThat(actual.size(), is(3));
+ assertThat(Arrays.asList("sc", "id", "c1"),
hasItems(actual.iterator().next().getName()));
+ }
+
+ @Test
+ public void assertExtractUpdatedColumns() {
+ DataRecord dataRecord = mockDataRecord("t2");
+ Collection<Column> actual =
RecordUtil.extractUpdatedColumns(dataRecord);
+ assertThat(actual.size(), is(3));
+ assertThat(Arrays.asList("c2", "c3", "c1"),
hasItems(actual.iterator().next().getName()));
+ }
+
+ private DataRecord mockDataRecord(final String tableName) {
+ DataRecord result = new DataRecord(new PlaceholderPosition(), 4);
+ result.setTableName(tableName);
+ result.addColumn(new Column("id", "", false, true));
+ result.addColumn(new Column("sc", "", false, true));
+ result.addColumn(new Column("c1", "", true, false));
+ result.addColumn(new Column("c2", "", true, false));
+ result.addColumn(new Column("c3", "", true, false));
+ return result;
+ }
+}