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

jianbin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-seata-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new dc5a3b0b feature: add at-dubbo-samples-seata sample (#689)
dc5a3b0b is described below

commit dc5a3b0be2c62f6a7a802298e98224add0cf19a5
Author: A Cabbage <[email protected]>
AuthorDate: Sun Sep 29 09:38:17 2024 +0800

    feature: add at-dubbo-samples-seata sample (#689)
---
 .../src/main/resources/application.yml             |   2 +-
 .../seata/business/controller/TestController.java  |  20 +++-
 .../src/main/resources/application.yml             |   2 +-
 .../src/main/resources/application.yml             |   2 +-
 .../dubbo-samples-seata/e2e-files/commit.yaml      |   1 +
 .../dubbo-samples-seata/e2e-files/rollback.yaml    |   1 +
 .../dubbo-samples-seata/e2e-files/sqlsh/all.sql    |  64 +++++++++++++
 at-sample/dubbo-samples-seata/seata-e2e.yaml       | 105 +++++++++++++++++++++
 .../org/apache/seata/builder/ImageBuilder.java     |   5 +-
 .../main/java/org/apache/seata/util/LogUtils.java  |  11 +--
 .../seata/controller/SkyWalkingController.java     |   3 +-
 11 files changed, 195 insertions(+), 21 deletions(-)

diff --git 
a/at-sample/dubbo-samples-seata/dubbo-samples-seata-account/src/main/resources/application.yml
 
b/at-sample/dubbo-samples-seata/dubbo-samples-seata-account/src/main/resources/application.yml
index a3410ac9..f4ccbaa4 100644
--- 
a/at-sample/dubbo-samples-seata/dubbo-samples-seata-account/src/main/resources/application.yml
+++ 
b/at-sample/dubbo-samples-seata/dubbo-samples-seata-account/src/main/resources/application.yml
@@ -19,7 +19,7 @@ spring:
     datasource:
         driver-class-name: com.mysql.cj.jdbc.Driver
         url: 
jdbc:mysql://${mysql.address:127.0.0.1}:${mysql.port:3306}/seata?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true
-        username: root
+        username: ${mysql.user:root}
         password: 123456
         hikari:
             connection-timeout: 30000
diff --git 
a/at-sample/dubbo-samples-seata/dubbo-samples-seata-business/src/main/java/org/apache/dubbo/samples/seata/business/controller/TestController.java
 
b/at-sample/dubbo-samples-seata/dubbo-samples-seata-business/src/main/java/org/apache/dubbo/samples/seata/business/controller/TestController.java
index 62f66a82..a14b1c18 100644
--- 
a/at-sample/dubbo-samples-seata/dubbo-samples-seata-business/src/main/java/org/apache/dubbo/samples/seata/business/controller/TestController.java
+++ 
b/at-sample/dubbo-samples-seata/dubbo-samples-seata-business/src/main/java/org/apache/dubbo/samples/seata/business/controller/TestController.java
@@ -17,6 +17,7 @@
 
 package org.apache.dubbo.samples.seata.business.controller;
 
+import com.alibaba.fastjson2.JSONObject;
 import org.apache.dubbo.samples.seata.api.BusinessService;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -33,18 +34,27 @@ public class TestController {
     }
 
     @GetMapping("/commit")
-    public String commit(@RequestParam String userId,@RequestParam String 
commodityCode,@RequestParam int orderCount){
+    public Object commit(@RequestParam(required = false, defaultValue = 
"ACC_001") String userId,
+                         @RequestParam(required = false, defaultValue = 
"STOCK_001") String commodityCode,
+                         @RequestParam(required = false, defaultValue = "1") 
int orderCount) {
+        JSONObject jsonObject = new JSONObject();
         this.businessService.purchaseCommit(userId,commodityCode,orderCount);
-        return "commit";
+        jsonObject.put("res", "commit");
+        return jsonObject;
     }
 
     @GetMapping("/rollback")
-    public String rollback(@RequestParam String userId,@RequestParam String 
commodityCode,@RequestParam int orderCount){
+    public Object rollback(@RequestParam(required = false, defaultValue = 
"ACC_001") String userId,
+                           @RequestParam(required = false, defaultValue = 
"STOCK_001") String commodityCode,
+                           @RequestParam(required = false, defaultValue = "1") 
int orderCount) {
+        JSONObject jsonObject = new JSONObject();
         try {
             
this.businessService.purchaseRollback(userId,commodityCode,orderCount);
-            return "commit";
+            jsonObject.put("res", "rollback");
+            return jsonObject;
         }catch (Exception e){
-            return "rollback";
+            jsonObject.put("res", "rollback");
+            return jsonObject;
         }
     }
 }
diff --git 
a/at-sample/dubbo-samples-seata/dubbo-samples-seata-order/src/main/resources/application.yml
 
b/at-sample/dubbo-samples-seata/dubbo-samples-seata-order/src/main/resources/application.yml
index 0b138914..b42af745 100644
--- 
a/at-sample/dubbo-samples-seata/dubbo-samples-seata-order/src/main/resources/application.yml
+++ 
b/at-sample/dubbo-samples-seata/dubbo-samples-seata-order/src/main/resources/application.yml
@@ -19,7 +19,7 @@ spring:
     datasource:
         driver-class-name: com.mysql.cj.jdbc.Driver
         url: 
jdbc:mysql://${mysql.address:127.0.0.1}:${mysql.port:3306}/seata?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true
-        username: root
+        username: ${mysql.user:root}
         password: 123456
         hikari:
             connection-timeout: 30000
diff --git 
a/at-sample/dubbo-samples-seata/dubbo-samples-seata-stock/src/main/resources/application.yml
 
b/at-sample/dubbo-samples-seata/dubbo-samples-seata-stock/src/main/resources/application.yml
index 3a2b6bb1..8f012e99 100644
--- 
a/at-sample/dubbo-samples-seata/dubbo-samples-seata-stock/src/main/resources/application.yml
+++ 
b/at-sample/dubbo-samples-seata/dubbo-samples-seata-stock/src/main/resources/application.yml
@@ -19,7 +19,7 @@ spring:
     datasource:
         driver-class-name: com.mysql.cj.jdbc.Driver
         url: 
jdbc:mysql://${mysql.address:127.0.0.1}:${mysql.port:3306}/seata?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useOldAliasMetadataBehavior=true
-        username: root
+        username: ${mysql.user:root}
         password: 123456
         hikari:
             connection-timeout: 30000
diff --git a/at-sample/dubbo-samples-seata/e2e-files/commit.yaml 
b/at-sample/dubbo-samples-seata/e2e-files/commit.yaml
new file mode 100644
index 00000000..5aed33a4
--- /dev/null
+++ b/at-sample/dubbo-samples-seata/e2e-files/commit.yaml
@@ -0,0 +1 @@
+{"res": "commit"}
\ No newline at end of file
diff --git a/at-sample/dubbo-samples-seata/e2e-files/rollback.yaml 
b/at-sample/dubbo-samples-seata/e2e-files/rollback.yaml
new file mode 100644
index 00000000..635f7b83
--- /dev/null
+++ b/at-sample/dubbo-samples-seata/e2e-files/rollback.yaml
@@ -0,0 +1 @@
+{"res": "rollback"}
\ No newline at end of file
diff --git a/at-sample/dubbo-samples-seata/e2e-files/sqlsh/all.sql 
b/at-sample/dubbo-samples-seata/e2e-files/sqlsh/all.sql
new file mode 100644
index 00000000..e62a6e39
--- /dev/null
+++ b/at-sample/dubbo-samples-seata/e2e-files/sqlsh/all.sql
@@ -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.
+--
+
+DROP TABLE IF EXISTS `stock_tbl`;
+CREATE TABLE `stock_tbl`
+(
+    `id`             int(11) NOT NULL AUTO_INCREMENT,
+    `commodity_code` varchar(255) DEFAULT NULL,
+    `count`          int(11) DEFAULT 0,
+    PRIMARY KEY (`id`),
+    UNIQUE KEY (`commodity_code`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+
+DROP TABLE IF EXISTS `order_tbl`;
+CREATE TABLE `order_tbl`
+(
+    `id`             int(11) NOT NULL AUTO_INCREMENT,
+    `user_id`        varchar(255) DEFAULT NULL,
+    `commodity_code` varchar(255) DEFAULT NULL,
+    `count`          int(11) DEFAULT 0,
+    `money`          int(11) DEFAULT 0,
+    PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+
+DROP TABLE IF EXISTS `account_tbl`;
+CREATE TABLE `account_tbl`
+(
+    `id`      int(11) NOT NULL AUTO_INCREMENT,
+    `user_id` varchar(255) DEFAULT NULL,
+    `money`   int(11) DEFAULT 0,
+    PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+INSERT INTO account_tbl(`user_id`,`money`) VALUES('ACC_001','1000');
+INSERT INTO stock_tbl(`commodity_code`,`count`) VALUES('STOCK_001','100');
+
+CREATE TABLE IF NOT EXISTS `undo_log`
+(
+    `branch_id`     BIGINT       NOT NULL COMMENT 'branch transaction id',
+    `xid`           VARCHAR(128) NOT NULL COMMENT 'global transaction id',
+    `context`       VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as 
serialization',
+    `rollback_info` LONGBLOB     NOT NULL COMMENT 'rollback info',
+    `log_status`    INT(11)      NOT NULL COMMENT '0:normal status,1:defense 
status',
+    `log_created`   DATETIME(6)  NOT NULL COMMENT 'create datetime',
+    `log_modified`  DATETIME(6)  NOT NULL COMMENT 'modify datetime',
+    UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
+) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8mb4 COMMENT ='AT 
transaction mode undo table';
+ALTER TABLE `undo_log` ADD INDEX `ix_log_created` (`log_created`);
\ No newline at end of file
diff --git a/at-sample/dubbo-samples-seata/seata-e2e.yaml 
b/at-sample/dubbo-samples-seata/seata-e2e.yaml
new file mode 100644
index 00000000..8b129877
--- /dev/null
+++ b/at-sample/dubbo-samples-seata/seata-e2e.yaml
@@ -0,0 +1,105 @@
+e2e:
+  scene_name: at-dubbo-samples-seata
+  # retry config
+  retry:
+    max: 5
+    interval: 10s
+    total_timeout: 20m
+  # services in docker-compose
+  modules:
+    # consume services
+    consumers:
+      # docker service name
+      - name: dubbo-samples-seata-business # this name should be the same as 
module name, it is indicated to be builded as an image
+        # service params in a service of docker-compose service
+        docker_service:
+          hostname: dubbo-samples-seata-business
+          restart: on-failure
+          container_name: test
+          depends_on:
+            dubbo-samples-seata-account:
+              condition: service_started
+            dubbo-samples-seata-stock:
+              condition: service_started
+            dubbo-samples-seata-order:
+              condition: service_started
+          environment:
+            seata.address: seata
+    # provider service
+    providers:
+      - name: dubbo-samples-seata-account
+        docker_service:
+          hostname: dubbo-samples-seata-account
+          restart: on-failure
+          depends_on:
+            mysql:
+              condition: service_healthy
+          environment:
+            mysql.address: mysqlAddress
+            mysql.user: user
+            seata.address: seata
+      - name: dubbo-samples-seata-order
+        docker_service:
+          hostname: dubbo-samples-seata-order
+          restart: on-failure
+          depends_on:
+            mysql:
+              condition: service_healthy
+          environment:
+            mysql.address: mysqlAddress
+            mysql.user: user
+            seata.address: seata
+      - name: dubbo-samples-seata-stock
+        docker_service:
+          hostname: dubbo-samples-seata-order
+          restart: on-failure
+          depends_on:
+            mysql:
+              condition: service_healthy
+          environment:
+            mysql.address: mysqlAddress
+            mysql.user: user
+            seata.address: seata
+    # infrastructure services
+    infrastructures:
+      - name: mysql
+        docker_service:
+          hostname: mysqlAddress
+          image: mysql:5.7
+#          ports:
+#            - "3307:3306"
+          volumes:
+            - ./e2e-files/sqlsh:/docker-entrypoint-initdb.d
+          restart: always
+          environment:
+            MYSQL_ROOT_PASSWORD: 123456
+            MYSQL_DATABASE: seata
+            MYSQL_USER: user
+            MYSQL_PASSWORD: 123456
+          healthcheck:
+            test: '[ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]'
+            interval: 5s
+            timeout: 10s
+            retries: 10
+      - name: seata-server
+        docker_service:
+          hostname: seata
+          image: apache/seata-server:2.1.0
+#          ports:
+#            - "7091:7091"
+#            - "8091:8091"
+          environment:
+            SEATA_PORT: 8091
+            STORE_MODE: file
+
+  # cases to verify
+  cases:
+    - name: rollback test
+      # how to invoke the case
+      invoke: 'docker exec test curl http://127.0.0.1:9999/test/rollback'
+      # the result of the case to expect be
+      verify: './e2e-files/rollback.yaml'
+
+    - name: commit test
+      invoke: 'docker exec test curl http://127.0.0.1:9999/test/commit'
+      verify: './e2e-files/commit.yaml'
\ No newline at end of file
diff --git 
a/e2e-test/e2e-test-builder/src/main/java/org/apache/seata/builder/ImageBuilder.java
 
b/e2e-test/e2e-test-builder/src/main/java/org/apache/seata/builder/ImageBuilder.java
index c5b02531..53629593 100644
--- 
a/e2e-test/e2e-test-builder/src/main/java/org/apache/seata/builder/ImageBuilder.java
+++ 
b/e2e-test/e2e-test-builder/src/main/java/org/apache/seata/builder/ImageBuilder.java
@@ -21,7 +21,6 @@ import org.apache.seata.generator.DockerFileForJarGenerator;
 import org.apache.seata.model.E2EConfig;
 import org.apache.seata.model.Module;
 import org.apache.seata.model.Replace;
-import org.apache.seata.util.LogUtils;
 import org.apache.seata.util.MavenUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -93,6 +92,7 @@ public class ImageBuilder {
     private int packageMavenParentModule(File moduleDir) throws IOException, 
InterruptedException {
         LOGGER.info("Packaging Maven module: " + moduleDir.getPath());
         ProcessBuilder builder = new ProcessBuilder();
+        builder.inheritIO();
         builder.directory(moduleDir);
 //        builder.command("mvn.cmd", "clean", "package");
         if (System.getProperty("os.name").contains("Windows")) {
@@ -101,7 +101,6 @@ public class ImageBuilder {
             builder.command("mvn", "clean", "package");
         }
         Process process = builder.start();
-        LogUtils.printProcessLog(LOGGER, process);
         int exitCode = process.waitFor();
         LOGGER.info(String.format("Maven module %s packaging finished with 
exit code %d", moduleDir, exitCode));
         return exitCode;
@@ -147,10 +146,10 @@ public class ImageBuilder {
             String moduleComposeDir = new File(composeDir, 
e2EConfig.getScene_name() + "-"
                     + module.getName()).getAbsolutePath();
             ProcessBuilder builder = new ProcessBuilder();
+            builder.inheritIO();
             builder.directory(new File(moduleComposeDir));
             builder.command("docker", "build", "-t", String.format("%s:%s", 
module.getName(), "0.0.1"), ".");
             Process process = builder.start();
-            LogUtils.printProcessLog(LOGGER, process);
             int exitCode = process.waitFor();
             if (exitCode != 0) {
                 LOGGER.warn(String.format("Docker image for module %s build 
failed with exit code %d", module.getName(), exitCode));
diff --git 
a/e2e-test/e2e-test-builder/src/main/java/org/apache/seata/util/LogUtils.java 
b/e2e-test/e2e-test-builder/src/main/java/org/apache/seata/util/LogUtils.java
index e7f2ba06..856a6294 100644
--- 
a/e2e-test/e2e-test-builder/src/main/java/org/apache/seata/util/LogUtils.java
+++ 
b/e2e-test/e2e-test-builder/src/main/java/org/apache/seata/util/LogUtils.java
@@ -30,18 +30,13 @@ import java.util.concurrent.Executors;
 public class LogUtils {
     public static void printProcessLog(Logger LOGGER, Process process) {
         ExecutorService executor = Executors.newFixedThreadPool(2);
-        executor.submit(() -> printStream(LOGGER, process.getInputStream(), 
false));
-        executor.submit(() -> printStream(LOGGER, process.getErrorStream(), 
true));
+        executor.submit(() -> printStream(LOGGER, process.getInputStream()));
         executor.shutdown();
     }
 
-    private static void printStream(Logger LOGGER, InputStream inputStream, 
boolean isError) {
+    private static void printStream(Logger LOGGER, InputStream inputStream) {
         new BufferedReader(new 
InputStreamReader(inputStream)).lines().forEach(line -> {
-            if (isError) {
-                LOGGER.warn(line);
-            } else {
-                LOGGER.info(line);
-            }
+            LOGGER.info(line);
         });
     }
 }
diff --git 
a/e2e-test/e2e-test-runner/src/main/java/org/apache/seata/controller/SkyWalkingController.java
 
b/e2e-test/e2e-test-runner/src/main/java/org/apache/seata/controller/SkyWalkingController.java
index 05314346..bf6f929d 100644
--- 
a/e2e-test/e2e-test-runner/src/main/java/org/apache/seata/controller/SkyWalkingController.java
+++ 
b/e2e-test/e2e-test-runner/src/main/java/org/apache/seata/controller/SkyWalkingController.java
@@ -16,7 +16,6 @@
  */
 package org.apache.seata.controller;
 
-import org.apache.seata.util.LogUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -44,10 +43,10 @@ public class SkyWalkingController {
                 LOGGER.info("Running Seate e2e test by SkyWalking-E2E: " + 
file.getName());
                 try {
                     ProcessBuilder builder = new ProcessBuilder();
+                    builder.inheritIO();
                     builder.directory(file);
                     builder.command("e2e", "run");
                     Process process = builder.start();
-                    LogUtils.printProcessLog(LOGGER, process);
                     int exitCode = process.waitFor();
                     if (exitCode != 0) {
                         LOGGER.warn(String.format(" Seate e2e test %s by 
SkyWalking-E2E fail with exit code %d",


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to