You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by ji...@apache.org on 2024/02/21 02:34:39 UTC

(incubator-seata) branch 0220 updated (20514e130a -> 7624e0d334)

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

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


    from 20514e130a optimized compatibility issues
     add 6fe0df3a65 add test case
     new 7624e0d334 add test case

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 compatible/pom.xml                                 |  6 ++++
 ...emplate.java => DefaultFailureHandlerImpl.java} |  6 ++--
 .../io/seata/tm/api/DefaultGlobalTransaction.java  |  4 +++
 .../tx/api/interceptor/parser}/Business.java       |  2 +-
 .../tx/api/interceptor/parser/BusinessImpl.java    |  4 +--
 .../GlobalTransactionalInterceptorParserTest.java  | 20 +++++++++++---
 .../tm/api/DefaultFailureHandlerImplTest.java      | 32 +++++++++++-----------
 .../tm/api/transaction/MyRuntimeException.java     |  2 +-
 .../src/test/resources/file.conf                   |  0
 .../src/test/resources/registry.conf               |  0
 .../handler/AbstractProxyInvocationHandler.java    |  8 +-----
 .../GlobalTransactionalInterceptorHandler.java     |  2 --
 .../GlobalTransactionalInterceptorParserTest.java  |  2 +-
 13 files changed, 52 insertions(+), 36 deletions(-)
 copy compatible/src/main/java/io/seata/tm/api/{TransactionalTemplate.java => DefaultFailureHandlerImpl.java} (83%)
 copy {tcc/src/test/java/org/apache/seata/rm/tcc/spring => compatible/src/test/java/io/seata/integration/tx/api/interceptor/parser}/Business.java (94%)
 copy {integration-tx-api/src/test/java/org/apache => compatible/src/test/java/io}/seata/integration/tx/api/interceptor/parser/BusinessImpl.java (90%)
 copy {integration-tx-api/src/test/java/org/apache => compatible/src/test/java/io}/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java (59%)
 copy {tm/src/test/java/org/apache => compatible/src/test/java/io}/seata/tm/api/DefaultFailureHandlerImplTest.java (80%)
 copy {tm/src/test/java/org/apache => compatible/src/test/java/io}/seata/tm/api/transaction/MyRuntimeException.java (95%)
 copy {config/seata-config-core => compatible}/src/test/resources/file.conf (100%)
 copy {core => compatible}/src/test/resources/registry.conf (100%)


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


(incubator-seata) 01/01: add test case

Posted by ji...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7624e0d334fc11483e1b51c31d62fa96dcc89291
Author: jianbin <ji...@apache.org>
AuthorDate: Wed Feb 21 10:34:30 2024 +0800

    add test case
---
 .../io/seata/tm/api/DefaultFailureHandlerImpl.java |  25 ++++
 .../io/seata/tm/api/DefaultGlobalTransaction.java  |   4 +
 .../GlobalTransactionalInterceptorParserTest.java  |   9 ++
 .../tm/api/DefaultFailureHandlerImplTest.java      | 136 +++++++++++++++++++++
 .../tm/api/transaction/MyRuntimeException.java     |  25 ++++
 5 files changed, 199 insertions(+)

diff --git a/compatible/src/main/java/io/seata/tm/api/DefaultFailureHandlerImpl.java b/compatible/src/main/java/io/seata/tm/api/DefaultFailureHandlerImpl.java
new file mode 100644
index 0000000000..5a7fcf2e93
--- /dev/null
+++ b/compatible/src/main/java/io/seata/tm/api/DefaultFailureHandlerImpl.java
@@ -0,0 +1,25 @@
+/*
+ * 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 io.seata.tm.api;
+
+/**
+ * The type Default failure handler.
+ *
+ */
+public class DefaultFailureHandlerImpl extends org.apache.seata.tm.api.DefaultFailureHandlerImpl implements
+    FailureHandler {
+}
diff --git a/compatible/src/main/java/io/seata/tm/api/DefaultGlobalTransaction.java b/compatible/src/main/java/io/seata/tm/api/DefaultGlobalTransaction.java
index 31a72c91b4..1a35047ed5 100644
--- a/compatible/src/main/java/io/seata/tm/api/DefaultGlobalTransaction.java
+++ b/compatible/src/main/java/io/seata/tm/api/DefaultGlobalTransaction.java
@@ -167,4 +167,8 @@ public class DefaultGlobalTransaction implements GlobalTransaction {
     public long getCreateTime() {
         return this.instance.getCreateTime();
     }
+
+    public org.apache.seata.tm.api.DefaultGlobalTransaction getInstance() {
+        return instance;
+    }
 }
diff --git a/compatible/src/test/java/io/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java b/compatible/src/test/java/io/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java
index efda1bea91..7ea7712c74 100644
--- a/compatible/src/test/java/io/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java
+++ b/compatible/src/test/java/io/seata/integration/tx/api/interceptor/parser/GlobalTransactionalInterceptorParserTest.java
@@ -17,7 +17,11 @@
 package io.seata.integration.tx.api.interceptor.parser;
 
 import io.seata.integration.tx.api.interceptor.handler.GlobalTransactionalInterceptorHandler;
+import io.seata.tm.api.DefaultFailureHandlerImpl;
+import io.seata.tm.api.FailureHandler;
 import org.apache.seata.integration.tx.api.interceptor.handler.ProxyInvocationHandler;
+import org.apache.seata.integration.tx.api.util.ProxyUtil;
+import org.apache.seata.tm.api.FailureHandlerHolder;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
@@ -31,6 +35,9 @@ public class GlobalTransactionalInterceptorParserTest {
 
         GlobalTransactionalInterceptorParser
 	        globalTransactionalInterceptorParser = new GlobalTransactionalInterceptorParser();
+        FailureHandler failureHandler = new DefaultFailureHandlerImpl();
+
+        FailureHandlerHolder.setFailureHandler(failureHandler);
 
         //when
         ProxyInvocationHandler proxyInvocationHandler = globalTransactionalInterceptorParser.parserInterfaceToProxy(business, business.getClass().getName());
@@ -40,6 +47,8 @@ public class GlobalTransactionalInterceptorParserTest {
 
         Assertions.assertEquals(proxyInvocationHandler.getClass(), GlobalTransactionalInterceptorHandler.class);
 
+        Business  businessProxy = ProxyUtil.createProxy(business);
+        Assertions.assertNotEquals(businessProxy, business);
 
     }
 }
diff --git a/compatible/src/test/java/io/seata/tm/api/DefaultFailureHandlerImplTest.java b/compatible/src/test/java/io/seata/tm/api/DefaultFailureHandlerImplTest.java
new file mode 100644
index 0000000000..62d8b88363
--- /dev/null
+++ b/compatible/src/test/java/io/seata/tm/api/DefaultFailureHandlerImplTest.java
@@ -0,0 +1,136 @@
+/*
+ * 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 io.seata.tm.api;
+
+import java.lang.reflect.Field;
+
+import io.seata.core.context.RootContext;
+import io.seata.tm.api.transaction.MyRuntimeException;
+import org.apache.seata.core.exception.TransactionException;
+import org.apache.seata.core.model.GlobalStatus;
+import org.apache.seata.core.model.TransactionManager;
+import org.apache.seata.tm.TransactionManagerHolder;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.netty.util.HashedWheelTimer;
+
+class DefaultFailureHandlerImplTest {
+    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultFailureHandlerImplTest.class);
+
+    private static final String DEFAULT_XID = "1234567890";
+    private static GlobalStatus globalStatus = GlobalStatus.Begin;
+
+    @BeforeAll
+    public static void init() {
+
+        TransactionManagerHolder.set(new TransactionManager() {
+            @Override
+            public String begin(String applicationId, String transactionServiceGroup, String name, int timeout)
+                    throws TransactionException {
+                return DEFAULT_XID;
+            }
+
+            @Override
+            public GlobalStatus commit(String xid) throws TransactionException {
+                return GlobalStatus.Committed;
+            }
+
+            @Override
+            public GlobalStatus rollback(String xid) throws TransactionException {
+                return GlobalStatus.Rollbacked;
+            }
+
+            @Override
+            public GlobalStatus getStatus(String xid) throws TransactionException {
+                return globalStatus;
+            }
+
+            @Override
+            public GlobalStatus globalReport(String xid, GlobalStatus globalStatus) throws TransactionException {
+                return globalStatus;
+            }
+        });
+    }
+
+    @Test
+    void onBeginFailure() {
+        RootContext.bind(DEFAULT_XID);
+        DefaultGlobalTransaction tx = (DefaultGlobalTransaction)GlobalTransactionContext.getCurrentOrCreate();
+        FailureHandler failureHandler = new DefaultFailureHandlerImpl();
+        failureHandler.onBeginFailure(tx.getInstance(), new MyRuntimeException("").getCause());
+    }
+
+    @Test
+    void onCommitFailure() throws Exception{
+
+        RootContext.bind(DEFAULT_XID);
+        DefaultGlobalTransaction tx = (DefaultGlobalTransaction)GlobalTransactionContext.getCurrentOrCreate();
+        FailureHandler failureHandler = new DefaultFailureHandlerImpl();
+        failureHandler.onCommitFailure(tx.getInstance(), new MyRuntimeException("").getCause());
+
+        // get timer
+        Class<?> c = Class.forName("io.seata.tm.api.DefaultFailureHandlerImpl");
+        Field field = c.getSuperclass().getDeclaredField("TIMER");
+        field.setAccessible(true);
+        HashedWheelTimer timer = (HashedWheelTimer) field.get(failureHandler);
+        // assert timer pendingCount: first time is 1
+        Long pendingTimeout = timer.pendingTimeouts();
+        Assertions.assertEquals(pendingTimeout,1L);
+        //set globalStatus
+        globalStatus= GlobalStatus.Committed;
+        Thread.sleep(25*1000L);
+        pendingTimeout = timer.pendingTimeouts();
+        LOGGER.info("pendingTimeout {}" ,pendingTimeout);
+        //all timer is done
+        Assertions.assertEquals(pendingTimeout,0L);
+    }
+
+    @Test
+    void onRollbackFailure() throws Exception {
+
+
+        RootContext.bind(DEFAULT_XID);
+        DefaultGlobalTransaction tx = (DefaultGlobalTransaction)GlobalTransactionContext.getCurrentOrCreate();
+        FailureHandler failureHandler = new DefaultFailureHandlerImpl();
+
+        failureHandler.onRollbackFailure(tx.getInstance(), new MyRuntimeException("").getCause());
+
+        // get timer
+        Class<?> c = Class.forName("io.seata.tm.api.DefaultFailureHandlerImpl");
+        Field field = c.getSuperclass().getDeclaredField("TIMER");
+        field.setAccessible(true);
+        HashedWheelTimer timer = (HashedWheelTimer) field.get(failureHandler);
+        // assert timer pendingCount: first time is 1
+        Long pendingTimeout = timer.pendingTimeouts();
+        Assertions.assertEquals(pendingTimeout,1L);
+        //set globalStatus
+        globalStatus= GlobalStatus.Rollbacked;
+        Thread.sleep(25*1000L);
+        pendingTimeout = timer.pendingTimeouts();
+        LOGGER.info("pendingTimeout {}" ,pendingTimeout);
+        //all timer is done
+        Assertions.assertEquals(pendingTimeout,0L);
+
+
+    }
+
+
+}
diff --git a/compatible/src/test/java/io/seata/tm/api/transaction/MyRuntimeException.java b/compatible/src/test/java/io/seata/tm/api/transaction/MyRuntimeException.java
new file mode 100644
index 0000000000..51954a24b2
--- /dev/null
+++ b/compatible/src/test/java/io/seata/tm/api/transaction/MyRuntimeException.java
@@ -0,0 +1,25 @@
+/*
+ * 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 io.seata.tm.api.transaction;
+
+
+public class MyRuntimeException extends RuntimeException {
+
+    public MyRuntimeException(String msg) {
+        super(msg);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org