You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2023/04/27 15:44:32 UTC

[shardingsphere] branch master updated: Add test cases of execute process swapper (#25378)

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

sunnianjun 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 8134eceba65 Add test cases of execute process swapper (#25378)
8134eceba65 is described below

commit 8134eceba658801003651a5a2153bf7a3942b588
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Apr 27 23:44:23 2023 +0800

    Add test cases of execute process swapper (#25378)
---
 .../YamlExecuteProcessContextSwapperTest.java      | 60 ++++++++++++++++++++++
 .../swapper/YamlExecuteProcessUnitSwapperTest.java | 48 +++++++++++++++++
 2 files changed, 108 insertions(+)

diff --git a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/model/yaml/swapper/YamlExecuteProcessContextSwapperTest.java b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/model/yaml/swapper/YamlExecuteProcessContextSwapperTest.java
new file mode 100644
index 00000000000..172a9c24a18
--- /dev/null
+++ b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/model/yaml/swapper/YamlExecuteProcessContextSwapperTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.infra.executor.sql.process.model.yaml.swapper;
+
+import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
+import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupReportContext;
+import org.apache.shardingsphere.infra.executor.sql.execute.engine.SQLExecutionUnit;
+import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcessContext;
+import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcessStatusEnum;
+import org.apache.shardingsphere.infra.executor.sql.process.model.yaml.YamlExecuteProcessContext;
+import org.apache.shardingsphere.infra.metadata.user.Grantee;
+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.hamcrest.Matchers.lessThanOrEqualTo;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class YamlExecuteProcessContextSwapperTest {
+    
+    @Test
+    void assertSwapToYamlConfiguration() {
+        ExecutionGroupReportContext reportContext = new ExecutionGroupReportContext("foo_db", new Grantee("root", "localhost"));
+        ExecutionGroupContext<? extends SQLExecutionUnit> executionGroupContext = new ExecutionGroupContext<>(Collections.emptyList(), reportContext);
+        ExecuteProcessContext executeProcessContext = new ExecuteProcessContext("SELECT 1", executionGroupContext, ExecuteProcessStatusEnum.START, true);
+        YamlExecuteProcessContext actual = new YamlExecuteProcessContextSwapper().swapToYamlConfiguration(executeProcessContext);
+        assertNotNull(actual.getExecutionID());
+        assertThat(actual.getDatabaseName(), is("foo_db"));
+        assertThat(actual.getUsername(), is("root"));
+        assertThat(actual.getHostname(), is("localhost"));
+        assertThat(actual.getSql(), is("SELECT 1"));
+        assertTrue(actual.getUnitStatuses().isEmpty());
+        assertThat(actual.getStartTimeMillis(), lessThanOrEqualTo(System.currentTimeMillis()));
+        assertThat(actual.getProcessStatus(), is(ExecuteProcessStatusEnum.START));
+    }
+    
+    @Test
+    void assertSwapToObject() {
+        assertThrows(UnsupportedOperationException.class, () -> new YamlExecuteProcessContextSwapper().swapToObject(new YamlExecuteProcessContext()));
+    }
+}
diff --git a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/model/yaml/swapper/YamlExecuteProcessUnitSwapperTest.java b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/model/yaml/swapper/YamlExecuteProcessUnitSwapperTest.java
new file mode 100644
index 00000000000..95aed85801f
--- /dev/null
+++ b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/model/yaml/swapper/YamlExecuteProcessUnitSwapperTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.infra.executor.sql.process.model.yaml.swapper;
+
+import org.apache.shardingsphere.infra.executor.sql.context.ExecutionUnit;
+import org.apache.shardingsphere.infra.executor.sql.context.SQLUnit;
+import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcessStatusEnum;
+import org.apache.shardingsphere.infra.executor.sql.process.model.ExecuteProcessUnit;
+import org.apache.shardingsphere.infra.executor.sql.process.model.yaml.YamlExecuteProcessUnit;
+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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class YamlExecuteProcessUnitSwapperTest {
+    
+    @Test
+    void assertSwapToYamlConfiguration() {
+        ExecuteProcessUnit executeProcessUnit = new ExecuteProcessUnit(new ExecutionUnit("foo_ds", new SQLUnit("SELECT 1", Collections.emptyList())), ExecuteProcessStatusEnum.START);
+        YamlExecuteProcessUnit actual = new YamlExecuteProcessUnitSwapper().swapToYamlConfiguration(executeProcessUnit);
+        assertNotNull(actual.getUnitID());
+        assertThat(actual.getProcessStatus(), is(ExecuteProcessStatusEnum.START));
+    }
+    
+    @Test
+    void assertSwapToObject() {
+        assertThrows(UnsupportedOperationException.class, () -> new YamlExecuteProcessUnitSwapper().swapToObject(new YamlExecuteProcessUnit()));
+    }
+}