You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by zh...@apache.org on 2021/09/04 15:57:52 UTC
[dubbo-go-samples] 10/18: Feature/1.5 seata test (#166)
This is an automated email from the ASF dual-hosted git repository.
zhaoyunxing pushed a commit to branch 1.5
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
commit bb2883ce524043729ebcc2286d3c9f8833fd14db
Author: phil <ph...@foxmail.com>
AuthorDate: Tue Jul 13 13:20:19 2021 +0800
Feature/1.5 seata test (#166)
* update: test pass by tesing
* update: mysql init sql auto
Co-authored-by: yuefengbo <yu...@meituan.com>
---
.run/seata/seata_client_app.run.xml | 2 +-
.run/seata/seata_order-svc_app.run.xml | 2 +-
.run/seata/seata_product-svc_app.run.xml | 2 +-
seata/client/app/client.go | 17 +++---
seata/client/app/svc/svc.go | 1 +
seata/docker/docker-compose.yml | 34 ++++++++++++
seata/docker/mysql/script/seata.sql | 62 ++++++++++++++++++++++
.../mysql/script}/seata_order.sql | 0
.../mysql/script}/seata_product.sql | 0
seata/order-svc/app/dao/dao.go | 5 +-
seata/order-svc/app/order_svc.go | 1 +
seata/order-svc/app/server.go | 19 ++++---
seata/product-svc/app/dao/dao.go | 1 +
seata/product-svc/app/product_svc.go | 1 +
seata/product-svc/app/server.go | 19 ++++---
15 files changed, 131 insertions(+), 35 deletions(-)
diff --git a/.run/seata/seata_client_app.run.xml b/.run/seata/seata_client_app.run.xml
index c34da8c..97941d0 100644
--- a/.run/seata/seata_client_app.run.xml
+++ b/.run/seata/seata_client_app.run.xml
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
- <configuration default="false" name="seata/client/app" type="GoApplicationRunConfiguration" factoryName="Go Application">
+ <configuration default="false" name="seata/client/app" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="seata">
<module name="dubbo-go-samples" />
<working_directory value="$PROJECT_DIR$" />
<envs>
diff --git a/.run/seata/seata_order-svc_app.run.xml b/.run/seata/seata_order-svc_app.run.xml
index def3fd7..f12d2bf 100644
--- a/.run/seata/seata_order-svc_app.run.xml
+++ b/.run/seata/seata_order-svc_app.run.xml
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
- <configuration default="false" name="seata/order-svc/app" type="GoApplicationRunConfiguration" factoryName="Go Application">
+ <configuration default="false" name="seata/order-svc/app" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="seata">
<module name="dubbo-go-samples" />
<working_directory value="$PROJECT_DIR$" />
<envs>
diff --git a/.run/seata/seata_product-svc_app.run.xml b/.run/seata/seata_product-svc_app.run.xml
index 7fcfc16..264f05f 100644
--- a/.run/seata/seata_product-svc_app.run.xml
+++ b/.run/seata/seata_product-svc_app.run.xml
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
- <configuration default="false" name="seata/product-svc/app" type="GoApplicationRunConfiguration" factoryName="Go Application">
+ <configuration default="false" name="seata/product-svc/app" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="seata">
<module name="dubbo-go-samples" />
<working_directory value="$PROJECT_DIR$" />
<envs>
diff --git a/seata/client/app/client.go b/seata/client/app/client.go
index 451fdbf..2a7809e 100644
--- a/seata/client/app/client.go
+++ b/seata/client/app/client.go
@@ -27,24 +27,23 @@ import (
)
import (
- "github.com/apache/dubbo-go-samples/seata/client/app/svc"
-)
-
-import (
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
"github.com/apache/dubbo-go/common/logger"
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
_ "github.com/apache/dubbo-go/protocol/dubbo"
_ "github.com/apache/dubbo-go/registry/protocol"
+ _ "github.com/apache/dubbo-go/registry/zookeeper"
+
"github.com/transaction-wg/seata-golang/pkg/client"
config2 "github.com/transaction-wg/seata-golang/pkg/client/config"
"github.com/transaction-wg/seata-golang/pkg/client/tm"
+)
- _ "github.com/apache/dubbo-go/filter/filter_impl"
-
- _ "github.com/apache/dubbo-go/cluster/cluster_impl"
- _ "github.com/apache/dubbo-go/cluster/loadbalance"
- _ "github.com/apache/dubbo-go/registry/zookeeper"
+import (
+ "github.com/apache/dubbo-go-samples/seata/client/app/svc"
)
const (
diff --git a/seata/client/app/svc/svc.go b/seata/client/app/svc/svc.go
index 5a53342..8d219d1 100644
--- a/seata/client/app/svc/svc.go
+++ b/seata/client/app/svc/svc.go
@@ -25,6 +25,7 @@ import (
import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/config"
+
context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
"github.com/transaction-wg/seata-golang/pkg/client/tm"
)
diff --git a/seata/docker/docker-compose.yml b/seata/docker/docker-compose.yml
new file mode 100644
index 0000000..d5dca01
--- /dev/null
+++ b/seata/docker/docker-compose.yml
@@ -0,0 +1,34 @@
+version: '3.1'
+services:
+ # mysql
+ mysql:
+ image: mysql:5.7
+ container_name: mysqlt
+ privileged: true # 授权
+ command: --default-authentication-plugin=mysql_native_password --default-time-zone='+08:00' # 指定使用插件
+ volumes:
+ - ./mysql/script:/docker-entrypoint-initdb.d
+ ports:
+ - 3306:3306
+ environment:
+ MYSQL_ROOT_PASSWORD: '123456' # root用户密码
+ # seata
+ seata:
+ image: seataio/seata-server:latest
+ container_name: seatat
+ hostname: seata-server
+ ports:
+ - 8091:8091
+ environment:
+ - SEATA_PORT=8091
+ expose:
+ - 8091
+ # nacos
+ nacos:
+ image: nacos/nacos-server:2.0.0
+ container_name: nacost
+# network_mode: host
+ ports:
+ - 8848:8848
+ environment:
+ - MODE=standalone #启动模式是独立模式
\ No newline at end of file
diff --git a/seata/docker/mysql/script/seata.sql b/seata/docker/mysql/script/seata.sql
new file mode 100644
index 0000000..cfbe50e
--- /dev/null
+++ b/seata/docker/mysql/script/seata.sql
@@ -0,0 +1,62 @@
+-- -------------------------------- The script used when storeMode is 'db' --------------------------------
+
+CREATE database if NOT EXISTS `seata` default character set utf8mb4 collate utf8mb4_unicode_ci;
+USE `seata`;
+
+SET NAMES utf8mb4;
+SET FOREIGN_KEY_CHECKS = 0;
+-- the table to store GlobalSession data
+CREATE TABLE IF NOT EXISTS `global_table`
+(
+ `xid` VARCHAR(128) NOT NULL,
+ `transaction_id` BIGINT,
+ `status` TINYINT NOT NULL,
+ `application_id` VARCHAR(32),
+ `transaction_service_group` VARCHAR(32),
+ `transaction_name` VARCHAR(128),
+ `timeout` INT,
+ `begin_time` BIGINT,
+ `application_data` VARCHAR(2000),
+ `gmt_create` DATETIME,
+ `gmt_modified` DATETIME,
+ PRIMARY KEY (`xid`),
+ KEY `idx_gmt_modified_status` (`gmt_modified`, `status`),
+ KEY `idx_transaction_id` (`transaction_id`)
+) ENGINE = InnoDB
+ DEFAULT CHARSET = utf8;
+
+-- the table to store BranchSession data
+CREATE TABLE IF NOT EXISTS `branch_table`
+(
+ `branch_id` BIGINT NOT NULL,
+ `xid` VARCHAR(128) NOT NULL,
+ `transaction_id` BIGINT,
+ `resource_group_id` VARCHAR(32),
+ `resource_id` VARCHAR(256),
+ `branch_type` VARCHAR(8),
+ `status` TINYINT,
+ `client_id` VARCHAR(64),
+ `application_data` VARCHAR(2000),
+ `gmt_create` DATETIME(6),
+ `gmt_modified` DATETIME(6),
+ PRIMARY KEY (`branch_id`),
+ KEY `idx_xid` (`xid`)
+) ENGINE = InnoDB
+ DEFAULT CHARSET = utf8;
+
+-- the table to store lock data
+CREATE TABLE IF NOT EXISTS `lock_table`
+(
+ `row_key` VARCHAR(128) NOT NULL,
+ `xid` VARCHAR(96),
+ `transaction_id` BIGINT,
+ `branch_id` BIGINT NOT NULL,
+ `resource_id` VARCHAR(256),
+ `table_name` VARCHAR(32),
+ `pk` VARCHAR(36),
+ `gmt_create` DATETIME,
+ `gmt_modified` DATETIME,
+ PRIMARY KEY (`row_key`),
+ KEY `idx_branch_id` (`branch_id`)
+) ENGINE = InnoDB
+ DEFAULT CHARSET = utf8;
diff --git a/seata/scripts/seata_order.sql b/seata/docker/mysql/script/seata_order.sql
similarity index 100%
rename from seata/scripts/seata_order.sql
rename to seata/docker/mysql/script/seata_order.sql
diff --git a/seata/scripts/seata_product.sql b/seata/docker/mysql/script/seata_product.sql
similarity index 100%
rename from seata/scripts/seata_product.sql
rename to seata/docker/mysql/script/seata_product.sql
diff --git a/seata/order-svc/app/dao/dao.go b/seata/order-svc/app/dao/dao.go
index a216fae..ece4584 100644
--- a/seata/order-svc/app/dao/dao.go
+++ b/seata/order-svc/app/dao/dao.go
@@ -18,15 +18,14 @@
package dao
import (
- hessian "github.com/apache/dubbo-go-hessian2"
"time"
)
import (
+ hessian "github.com/apache/dubbo-go-hessian2"
+
"github.com/bwmarrin/snowflake"
-)
-import (
"github.com/transaction-wg/seata-golang/pkg/client/at/exec"
"github.com/transaction-wg/seata-golang/pkg/client/context"
)
diff --git a/seata/order-svc/app/order_svc.go b/seata/order-svc/app/order_svc.go
index 1cbc4bc..100136d 100644
--- a/seata/order-svc/app/order_svc.go
+++ b/seata/order-svc/app/order_svc.go
@@ -23,6 +23,7 @@ import (
import (
"github.com/apache/dubbo-go/common/constant"
+
context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
)
diff --git a/seata/order-svc/app/server.go b/seata/order-svc/app/server.go
index c45c1a1..95b71b0 100644
--- a/seata/order-svc/app/server.go
+++ b/seata/order-svc/app/server.go
@@ -27,24 +27,23 @@ import (
)
import (
- dao2 "github.com/apache/dubbo-go-samples/seata/order-svc/app/dao"
-)
-
-import (
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
"github.com/apache/dubbo-go/common/logger"
+ _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
_ "github.com/apache/dubbo-go/protocol/dubbo"
_ "github.com/apache/dubbo-go/registry/protocol"
+ _ "github.com/apache/dubbo-go/registry/zookeeper"
+
"github.com/transaction-wg/seata-golang/pkg/client"
"github.com/transaction-wg/seata-golang/pkg/client/at/exec"
config2 "github.com/transaction-wg/seata-golang/pkg/client/config"
+)
- _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
- _ "github.com/apache/dubbo-go/filter/filter_impl"
-
- _ "github.com/apache/dubbo-go/cluster/cluster_impl"
- _ "github.com/apache/dubbo-go/cluster/loadbalance"
- _ "github.com/apache/dubbo-go/registry/zookeeper"
+import (
+ dao2 "github.com/apache/dubbo-go-samples/seata/order-svc/app/dao"
)
const (
diff --git a/seata/product-svc/app/dao/dao.go b/seata/product-svc/app/dao/dao.go
index 5e5fe4f..a9f5e89 100644
--- a/seata/product-svc/app/dao/dao.go
+++ b/seata/product-svc/app/dao/dao.go
@@ -19,6 +19,7 @@ package dao
import (
hessian "github.com/apache/dubbo-go-hessian2"
+
"github.com/transaction-wg/seata-golang/pkg/client/at/exec"
"github.com/transaction-wg/seata-golang/pkg/client/context"
)
diff --git a/seata/product-svc/app/product_svc.go b/seata/product-svc/app/product_svc.go
index 9d97211..d32c518 100644
--- a/seata/product-svc/app/product_svc.go
+++ b/seata/product-svc/app/product_svc.go
@@ -23,6 +23,7 @@ import (
import (
"github.com/apache/dubbo-go/common/constant"
+
context2 "github.com/transaction-wg/seata-golang/pkg/client/context"
)
diff --git a/seata/product-svc/app/server.go b/seata/product-svc/app/server.go
index f39b1ac..68db9be 100644
--- a/seata/product-svc/app/server.go
+++ b/seata/product-svc/app/server.go
@@ -27,24 +27,23 @@ import (
)
import (
- dao2 "github.com/apache/dubbo-go-samples/seata/product-svc/app/dao"
-)
-
-import (
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
"github.com/apache/dubbo-go/common/logger"
+ _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config"
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
_ "github.com/apache/dubbo-go/protocol/dubbo"
_ "github.com/apache/dubbo-go/registry/protocol"
+ _ "github.com/apache/dubbo-go/registry/zookeeper"
+
"github.com/transaction-wg/seata-golang/pkg/client"
"github.com/transaction-wg/seata-golang/pkg/client/at/exec"
config2 "github.com/transaction-wg/seata-golang/pkg/client/config"
+)
- _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
- _ "github.com/apache/dubbo-go/filter/filter_impl"
-
- _ "github.com/apache/dubbo-go/cluster/cluster_impl"
- _ "github.com/apache/dubbo-go/cluster/loadbalance"
- _ "github.com/apache/dubbo-go/registry/zookeeper"
+import (
+ dao2 "github.com/apache/dubbo-go-samples/seata/product-svc/app/dao"
)
const (