You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by az...@apache.org on 2024/01/12 06:07:24 UTC
(shardingsphere) branch master updated: add tests for CDCResponseUtils (#29620)
This is an automated email from the ASF dual-hosted git repository.
azexin 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 75a551970ef add tests for CDCResponseUtils (#29620)
75a551970ef is described below
commit 75a551970efd4ec765d35d86b68759323da5cf2f
Author: K <45...@users.noreply.github.com>
AuthorDate: Fri Jan 12 07:07:18 2024 +0100
add tests for CDCResponseUtils (#29620)
* add tests for CDCResponseUtils
* fix checkStyle issue
---
.../cdc/generator/CDCResponseUtilsTest.java | 76 ++++++++++++++++++++++
1 file changed, 76 insertions(+)
diff --git a/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/generator/CDCResponseUtilsTest.java b/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/generator/CDCResponseUtilsTest.java
new file mode 100644
index 00000000000..e4c921862f7
--- /dev/null
+++ b/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/generator/CDCResponseUtilsTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.cdc.generator;
+
+import com.google.protobuf.Message;
+import org.apache.shardingsphere.data.pipeline.cdc.protocol.response.CDCResponse;
+import org.apache.shardingsphere.data.pipeline.cdc.protocol.response.DataRecordResult;
+import org.apache.shardingsphere.data.pipeline.cdc.protocol.response.ServerGreetingResult;
+import org.apache.shardingsphere.data.pipeline.cdc.protocol.response.StreamDataResult;
+import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+class CDCResponseUtilsTest {
+
+ @Test
+ public void assertSucceedWhenResponseNotSet() {
+ CDCResponse actualResponse = CDCResponseUtils.succeed("request_id_1");
+ assertThat(actualResponse.getStatus(), is(CDCResponse.Status.SUCCEED));
+ assertThat(actualResponse.getRequestId(), is("request_id_1"));
+ }
+
+ @Test
+ public void assertSucceedWhenResponseCaseServerGreetingResult() {
+ Message msg = ServerGreetingResult.newBuilder().build();
+ CDCResponse actualResponse = CDCResponseUtils.succeed("request_id_1", CDCResponse.ResponseCase.SERVER_GREETING_RESULT, msg);
+ assertThat(actualResponse.getStatus(), is(CDCResponse.Status.SUCCEED));
+ assertThat(actualResponse.getRequestId(), is("request_id_1"));
+ assertNotNull(actualResponse.getServerGreetingResult());
+ }
+
+ @Test
+ public void assertSucceedWhenResponseCaseDataRecordResult() {
+ Message msg = DataRecordResult.newBuilder().build();
+ CDCResponse actualResponse = CDCResponseUtils.succeed("request_id_1", CDCResponse.ResponseCase.DATA_RECORD_RESULT, msg);
+ assertThat(actualResponse.getStatus(), is(CDCResponse.Status.SUCCEED));
+ assertThat(actualResponse.getRequestId(), is("request_id_1"));
+ assertNotNull(actualResponse.getDataRecordResult());
+ }
+
+ @Test
+ public void assertSucceedWhenResponseCaseStreamDataResult() {
+ Message msg = StreamDataResult.newBuilder().build();
+ CDCResponse actualResponse = CDCResponseUtils.succeed("request_id_1", CDCResponse.ResponseCase.STREAM_DATA_RESULT, msg);
+ assertThat(actualResponse.getStatus(), is(CDCResponse.Status.SUCCEED));
+ assertThat(actualResponse.getRequestId(), is("request_id_1"));
+ assertNotNull(actualResponse.getStreamDataResult());
+ }
+
+ @Test
+ public void assertFailed() {
+ CDCResponse actualResponse = CDCResponseUtils.failed("request_id_1", XOpenSQLState.GENERAL_ERROR.getValue(), "Error");
+ assertThat(actualResponse.getStatus(), is(CDCResponse.Status.FAILED));
+ assertThat(actualResponse.getRequestId(), is("request_id_1"));
+ assertThat(actualResponse.getErrorCode(), is(XOpenSQLState.GENERAL_ERROR.getValue()));
+ assertThat(actualResponse.getErrorMessage(), is("Error"));
+ }
+}