Skip to content

Commit

Permalink
feat: add remaining tcc and spring-saga e2e case (#699)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjlgod authored Oct 29, 2024
1 parent af6124e commit 7eaf5c7
Show file tree
Hide file tree
Showing 41 changed files with 1,589 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ private void printPassedCases(List<String> passedProjects) {
private static int runTest(File file) {
try {
ProcessBuilder builder = new ProcessBuilder();
// builder.inheritIO();
builder.directory(file);
// builder.inheritIO();
// builder.command("docker-compose", "up", "--timeout", "120");
builder.command("e2e", "run");
Process process = builder.start();
Expand Down
1 change: 1 addition & 0 deletions saga-sample/spring-seata-saga/e2e-files/commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"res": "commit"}
1 change: 1 addition & 0 deletions saga-sample/spring-seata-saga/e2e-files/rollback.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"res": "rollback"}
126 changes: 126 additions & 0 deletions saga-sample/spring-seata-saga/e2e-replace/file.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#
# 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.
#

transport {
# tcp, unix-domain-socket
type = "TCP"
#NIO, NATIVE
server = "NIO"
#enable heartbeat
heartbeat = true
# the tm client batch send request enable
enableTmClientBatchSendRequest = false
# the rm client batch send request enable
enableRmClientBatchSendRequest = true
# the rm client rpc request timeout
rpcRmRequestTimeout = 2000
# the tm client rpc request timeout
rpcTmRequestTimeout = 30000
# the rm client rpc request timeout
rpcRmRequestTimeout = 15000
#thread factory for netty
threadFactory {
bossThreadPrefix = "NettyBoss"
workerThreadPrefix = "NettyServerNIOWorker"
serverExecutorThread-prefix = "NettyServerBizHandler"
shareBossWorker = false
clientSelectorThreadPrefix = "NettyClientSelector"
clientSelectorThreadSize = 1
clientWorkerThreadPrefix = "NettyClientWorkerThread"
# netty boss thread size
bossThreadSize = 1
#auto default pin or 8
workerThreadSize = "default"
}
shutdown {
# when destroy server, wait seconds
wait = 3
}
serialization = "seata"
compressor = "none"
}
service {
#transaction service group mapping
vgroupMapping.my_test_tx_group = "default"
#only support when registry.type=file, please don't set multiple addresses
default.grouplist = "seata:8091"
#degrade, current not support
enableDegrade = false
#disable seata
disableGlobalTransaction = false
}

client {
rm {
asyncCommitBufferLimit = 10000
lock {
retryInterval = 10
retryTimes = 30
retryPolicyBranchRollbackOnConflict = true
}
reportRetryCount = 5
tableMetaCheckEnable = false
tableMetaCheckerInterval = 60000
reportSuccessEnable = false
sagaBranchRegisterEnable = false
sagaJsonParser = "fastjson"
sagaRetryPersistModeUpdate = false
sagaCompensatePersistModeUpdate = false
tccActionInterceptorOrder = -2147482648 #Ordered.HIGHEST_PRECEDENCE + 1000
sqlParserType = "druid"
branchExecutionTimeoutXA = 60000
connectionTwoPhaseHoldTimeoutXA = 10000
}
tm {
commitRetryCount = 5
rollbackRetryCount = 5
defaultGlobalTransactionTimeout = 60000
degradeCheck = false
degradeCheckPeriod = 2000
degradeCheckAllowTimes = 10
interceptorOrder = -2147482648 #Ordered.HIGHEST_PRECEDENCE + 1000
}
undo {
dataValidation = true
onlyCareUpdateColumns = true
logSerialization = "jackson"
logTable = "undo_log"
compress {
enable = true
# allow zip, gzip, deflater, lz4, bzip2, zstd default is zip
type = zip
# if rollback info size > threshold, then will be compress
# allow k m g t
threshold = 64k
}
}
loadBalance {
type = "XID"
virtualNodes = 10
}
}
log {
exceptionRate = 100
}
tcc {
fence {
# tcc fence log table name
logTableName = tcc_fence_log
# tcc fence log clean period
cleanPeriod = 1h
}
}
32 changes: 32 additions & 0 deletions saga-sample/spring-seata-saga/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,36 @@
<version>2.2.220</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.apache.seata.SagaTransactionStarter</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
43 changes: 43 additions & 0 deletions saga-sample/spring-seata-saga/seata-e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
e2e:
scene_name: saga-spring-seata-saga
# retry config
retry:
max: 5
interval: 10s
total_timeout: 10m
# services in docker-compose
modules:
# consumer service
consumers:
- name: spring-seata-saga
docker_service:
hostname: spring-seata-saga
restart: on-failure
container_name: test
depends_on:
seata-server:
condition: service_started
environment:
E2E_ENV: open
seata.address: seata
# infrastructure services
infrastructures:
- name: seata-server
docker_service:
hostname: seata
image: apache/seata-server:2.1.0
environment:
SEATA_PORT: 8091
STORE_MODE: file
replace:
- source: e2e-replace/file.conf
dest: src/main/resources/file.conf

# cases to verify
cases:
- name: normal test rollback
invoke: 'docker exec test cat rollback.yaml'
verify: './e2e-files/rollback.yaml'
- name: normal test commit
invoke: 'docker exec test cat commit.yaml'
verify: './e2e-files/commit.yaml'
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@
import java.util.HashMap;
import java.util.Map;

import static org.apache.seata.e2e.E2EUtil.isInE2ETest;
import static org.apache.seata.e2e.E2EUtil.writeE2EResFile;

public class SagaTransactionStarter {

private static final Logger LOGGER = LoggerFactory.getLogger(SagaTransactionStarter.class);

public static void main(String[] args) {
public static void main(String[] args) throws Exception {
if (isInE2ETest()) {
// wait seata-server
Thread.sleep(5000);
}
AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[]{"spring/seata-saga.xml"});
applicationContext.start();

Expand Down Expand Up @@ -76,6 +83,11 @@ private static void transactionCommittedDemo(StateMachineEngine stateMachineEngi

Assert.isTrue(ExecutionStatus.SU.equals(inst.getStatus()),
"saga transaction execute failed. XID: " + inst.getId());

if (isInE2ETest()) {
String res = "{\"res\": \"commit\"}";
writeE2EResFile(res, "commit.yaml");
}
LOGGER.info("saga transaction commit succeed. XID: " + inst.getId());
}

Expand All @@ -96,6 +108,10 @@ private static void transactionCompensatedDemo(StateMachineEngine stateMachineEn

Assert.isTrue(ExecutionStatus.SU.equals(inst.getCompensationStatus()),
"saga transaction compensate failed. XID: " + inst.getId());
if (isInE2ETest()) {
String res = "{\"res\": \"rollback\"}";
writeE2EResFile(res, "rollback.yaml");
}
LOGGER.info("saga transaction compensate succeed. XID: " + inst.getId());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.apache.seata.e2e;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map;

public class E2EUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(E2EUtil.class);
private E2EUtil() {
}
public static void writeE2EResFile(String outPutRes, String name) {
try {
Files.write(Paths.get(name), outPutRes.getBytes());
} catch (IOException e) {
LOGGER.error("write E2EResFile error", e);
}
}

public static boolean isInE2ETest() {
Map<String, String> envs = System.getenv();
String env = envs.getOrDefault("E2E_ENV", "");
return "open".equals(env);
}
}
1 change: 1 addition & 0 deletions tcc-sample/spring-dubbo-seata-tcc/e2e-files/commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"res": "commit"}
1 change: 1 addition & 0 deletions tcc-sample/spring-dubbo-seata-tcc/e2e-files/rollback.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"res": "rollback"}
Loading

0 comments on commit 7eaf5c7

Please sign in to comment.