SERIALIZER_MAP = new HashMap<>();
diff --git a/core/src/main/java/org/apache/seata/core/serializer/SerializerType.java b/core/src/main/java/org/apache/seata/core/serializer/SerializerType.java
index 56fd8136d17..7112f8a32a8 100644
--- a/core/src/main/java/org/apache/seata/core/serializer/SerializerType.java
+++ b/core/src/main/java/org/apache/seata/core/serializer/SerializerType.java
@@ -70,6 +70,21 @@ public enum SerializerType {
* Math.pow(2, 6)
*/
FASTJSON2((byte)0x64),
+
+
+ /**
+ * The grpc
+ *
+ * Math.pow(2, 7)
+ */
+ GRPC((byte) 0x128),
+
+ /**
+ * The fury.
+ *
+ * Math.pow(2, 8)
+ */
+ FURY((byte) 0x256)
;
private final byte code;
diff --git a/core/src/main/java/org/apache/seata/core/store/db/AbstractDataSourceProvider.java b/core/src/main/java/org/apache/seata/core/store/db/AbstractDataSourceProvider.java
index c11a55f0979..bb8306b2b22 100644
--- a/core/src/main/java/org/apache/seata/core/store/db/AbstractDataSourceProvider.java
+++ b/core/src/main/java/org/apache/seata/core/store/db/AbstractDataSourceProvider.java
@@ -16,6 +16,15 @@
*/
package org.apache.seata.core.store.db;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Stream;
+
import javax.sql.DataSource;
import org.apache.seata.common.exception.StoreException;
@@ -47,8 +56,20 @@ public abstract class AbstractDataSourceProvider implements DataSourceProvider,
*/
protected static final Configuration CONFIG = ConfigurationFactory.getInstance();
+ private final static String MYSQL_DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver";
+
+ private final static String MYSQL8_DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver";
+
+ private final static String MYSQL_DRIVER_FILE_PREFIX = "mysql-connector-java-";
+
+ private final static Map MYSQL_DRIVER_LOADERS;
+
private static final long DEFAULT_DB_MAX_WAIT = 5000;
+ static {
+ MYSQL_DRIVER_LOADERS = createMysqlDriverClassLoaders();
+ }
+
@Override
public void init() {
this.dataSource = generate();
@@ -67,7 +88,7 @@ public DataSource generate() {
public void validate() {
//valid driver class name
String driverClassName = getDriverClassName();
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ ClassLoader loader = getDriverClassLoader();
if (null == loader) {
throw new StoreException("class loader set error, you should not use the Bootstrap classloader");
}
@@ -124,7 +145,50 @@ protected Long getMaxWait() {
}
protected ClassLoader getDriverClassLoader() {
- return ClassLoader.getSystemClassLoader();
+ return MYSQL_DRIVER_LOADERS.getOrDefault(getDriverClassName(), ClassLoader.getSystemClassLoader());
+ }
+
+ private static Map createMysqlDriverClassLoaders() {
+ Map loaders = new HashMap<>();
+ String cp = System.getProperty("java.class.path");
+ if (cp == null || cp.isEmpty()) {
+ return loaders;
+ }
+ Stream.of(cp.split(File.pathSeparator))
+ .map(File::new)
+ .filter(File::exists)
+ .map(file -> file.isFile() ? file.getParentFile() : file)
+ .filter(Objects::nonNull)
+ .filter(File::isDirectory)
+ .map(file -> new File(file, "jdbc"))
+ .filter(File::exists)
+ .filter(File::isDirectory)
+ .distinct()
+ .flatMap(file -> {
+ File[] files = file.listFiles((f, name) -> name.startsWith(MYSQL_DRIVER_FILE_PREFIX));
+ if (files != null) {
+ return Stream.of(files);
+ } else {
+ return Stream.of();
+ }
+ })
+ .forEach(file -> {
+ if (loaders.containsKey(MYSQL8_DRIVER_CLASS_NAME) && loaders.containsKey(MYSQL_DRIVER_CLASS_NAME)) {
+ return;
+ }
+ try {
+ URL url = file.toURI().toURL();
+ ClassLoader loader = new URLClassLoader(new URL[]{url}, ClassLoader.getSystemClassLoader());
+ try {
+ loader.loadClass(MYSQL8_DRIVER_CLASS_NAME);
+ loaders.putIfAbsent(MYSQL8_DRIVER_CLASS_NAME, loader);
+ } catch (ClassNotFoundException e) {
+ loaders.putIfAbsent(MYSQL_DRIVER_CLASS_NAME, loader);
+ }
+ } catch (MalformedURLException ignore) {
+ }
+ });
+ return loaders;
}
/**
diff --git a/core/src/test/java/org/apache/seata/core/compressor/CompressorFactoryTest.java b/core/src/test/java/org/apache/seata/core/compressor/CompressorFactoryTest.java
new file mode 100644
index 00000000000..b32cae92776
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/compressor/CompressorFactoryTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.seata.core.compressor;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class CompressorFactoryTest {
+
+ @Test
+ void testGetCompressorNone() {
+ Compressor compressor = CompressorFactory.getCompressor(CompressorType.NONE.getCode());
+ assertNotNull(compressor);
+ assertTrue(compressor instanceof CompressorFactory.NoneCompressor);
+ }
+
+ @Test
+ void testNoneCompressor() {
+ CompressorFactory.NoneCompressor noneCompressor = new CompressorFactory.NoneCompressor();
+ byte[] testData = "Test data".getBytes();
+
+ byte[] compressed = noneCompressor.compress(testData);
+ assertArrayEquals(testData, compressed);
+
+ byte[] decompressed = noneCompressor.decompress(compressed);
+ assertArrayEquals(testData, decompressed);
+ }
+
+ @Test
+ void testCompressorCaching() {
+ Compressor compressor1 = CompressorFactory.getCompressor(CompressorType.NONE.getCode());
+ Compressor compressor2 = CompressorFactory.getCompressor(CompressorType.NONE.getCode());
+ assertSame(compressor1, compressor2);
+ }
+
+ @Test
+ void testInvalidCompressorCode() {
+ assertThrows(IllegalArgumentException.class, () -> CompressorFactory.getCompressor((byte) -1));
+ }
+
+ @Test
+ void testCompressorMapInitialization() {
+ assertTrue(CompressorFactory.COMPRESSOR_MAP.containsKey(CompressorType.NONE));
+ assertTrue(CompressorFactory.COMPRESSOR_MAP.get(CompressorType.NONE) instanceof CompressorFactory.NoneCompressor);
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/exception/BranchTransactionExceptionTest.java b/core/src/test/java/org/apache/seata/core/exception/BranchTransactionExceptionTest.java
new file mode 100644
index 00000000000..73a29cde7c9
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/exception/BranchTransactionExceptionTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.seata.core.exception;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class BranchTransactionExceptionTest {
+
+ @Test
+ public void testConstructorWithCode() {
+ BranchTransactionException exception = new BranchTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable);
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndCause() {
+ Throwable cause = new RuntimeException("test");
+ BranchTransactionException exception = new BranchTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable, cause);
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessage() {
+ BranchTransactionException exception = new BranchTransactionException("test message");
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndMessage() {
+ BranchTransactionException exception = new BranchTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable, "test message");
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCause() {
+ Throwable cause = new RuntimeException("test");
+ BranchTransactionException exception = new BranchTransactionException(cause);
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ BranchTransactionException exception = new BranchTransactionException("test message", cause);
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithCodeMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ BranchTransactionException exception = new BranchTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable, "test message", cause);
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/exception/DecodeExceptionTest.java b/core/src/test/java/org/apache/seata/core/exception/DecodeExceptionTest.java
new file mode 100644
index 00000000000..3981c54b156
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/exception/DecodeExceptionTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.seata.core.exception;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class DecodeExceptionTest {
+
+ @Test
+ public void testConstructorWithCause() {
+ Throwable cause = new RuntimeException("test");
+ DecodeException exception = new DecodeException(cause);
+ assertEquals(cause, exception.getCause());
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/exception/GlobalTransactionExceptionTest.java b/core/src/test/java/org/apache/seata/core/exception/GlobalTransactionExceptionTest.java
new file mode 100644
index 00000000000..093e853b7b0
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/exception/GlobalTransactionExceptionTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.seata.core.exception;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class GlobalTransactionExceptionTest {
+
+ @Test
+ public void testConstructorWithCode() {
+ GlobalTransactionException exception = new GlobalTransactionException(TransactionExceptionCode.GlobalTransactionNotExist);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndCause() {
+ Throwable cause = new RuntimeException("test");
+ GlobalTransactionException exception = new GlobalTransactionException(TransactionExceptionCode.GlobalTransactionNotExist, cause);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessage() {
+ GlobalTransactionException exception = new GlobalTransactionException("test message");
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndMessage() {
+ GlobalTransactionException exception = new GlobalTransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "test message");
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCause() {
+ Throwable cause = new RuntimeException("test");
+ GlobalTransactionException exception = new GlobalTransactionException(cause);
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ GlobalTransactionException exception = new GlobalTransactionException("test message", cause);
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithCodeMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ GlobalTransactionException exception = new GlobalTransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "test message", cause);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/exception/RmTransactionExceptionTest.java b/core/src/test/java/org/apache/seata/core/exception/RmTransactionExceptionTest.java
new file mode 100644
index 00000000000..a8b89386517
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/exception/RmTransactionExceptionTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.seata.core.exception;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class RmTransactionExceptionTest {
+
+ @Test
+ public void testConstructorWithCode() {
+ RmTransactionException exception = new RmTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable);
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndCause() {
+ Throwable cause = new RuntimeException("test");
+ RmTransactionException exception = new RmTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable, cause);
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessage() {
+ RmTransactionException exception = new RmTransactionException("test message");
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndMessage() {
+ RmTransactionException exception = new RmTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable, "test message");
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCause() {
+ Throwable cause = new RuntimeException("test");
+ RmTransactionException exception = new RmTransactionException(cause);
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ RmTransactionException exception = new RmTransactionException("test message", cause);
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithCodeMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ RmTransactionException exception = new RmTransactionException(TransactionExceptionCode.BranchRollbackFailed_Retriable, "test message", cause);
+ assertEquals(TransactionExceptionCode.BranchRollbackFailed_Retriable, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/exception/TmTransactionExceptionTest.java b/core/src/test/java/org/apache/seata/core/exception/TmTransactionExceptionTest.java
new file mode 100644
index 00000000000..a1b64e5bb95
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/exception/TmTransactionExceptionTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.seata.core.exception;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class TmTransactionExceptionTest {
+
+ @Test
+ public void testConstructorWithCode() {
+ TmTransactionException exception = new TmTransactionException(TransactionExceptionCode.GlobalTransactionNotExist);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndCause() {
+ Throwable cause = new RuntimeException("test");
+ TmTransactionException exception = new TmTransactionException(TransactionExceptionCode.GlobalTransactionNotExist, cause);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessage() {
+ TmTransactionException exception = new TmTransactionException("test message");
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndMessage() {
+ TmTransactionException exception = new TmTransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "test message");
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCause() {
+ Throwable cause = new RuntimeException("test");
+ TmTransactionException exception = new TmTransactionException(cause);
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ TmTransactionException exception = new TmTransactionException("test message", cause);
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithCodeMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ TmTransactionException exception = new TmTransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "test message", cause);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/exception/TransactionExceptionTest.java b/core/src/test/java/org/apache/seata/core/exception/TransactionExceptionTest.java
new file mode 100644
index 00000000000..1b19a33480f
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/exception/TransactionExceptionTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.seata.core.exception;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class TransactionExceptionTest {
+
+ @Test
+ public void testConstructorWithCode() {
+ TransactionException exception = new TransactionException(TransactionExceptionCode.GlobalTransactionNotExist);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndCause() {
+ Throwable cause = new RuntimeException("test");
+ TransactionException exception = new TransactionException(TransactionExceptionCode.GlobalTransactionNotExist, cause);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessage() {
+ TransactionException exception = new TransactionException("test message");
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCodeAndMessage() {
+ TransactionException exception = new TransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "test message");
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithCause() {
+ Throwable cause = new RuntimeException("test");
+ TransactionException exception = new TransactionException(cause);
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ TransactionException exception = new TransactionException("test message", cause);
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+
+ @Test
+ public void testConstructorWithCodeMessageAndCause() {
+ Throwable cause = new RuntimeException("test");
+ TransactionException exception = new TransactionException(TransactionExceptionCode.GlobalTransactionNotExist, "test message", cause);
+ assertEquals(TransactionExceptionCode.GlobalTransactionNotExist, exception.getCode());
+ assertEquals("test message", exception.getMessage());
+ assertEquals(cause, exception.getCause());
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/rpc/netty/RmNettyClientTest.java b/core/src/test/java/org/apache/seata/core/rpc/netty/RmNettyClientTest.java
index 1709246e884..08151d58219 100644
--- a/core/src/test/java/org/apache/seata/core/rpc/netty/RmNettyClientTest.java
+++ b/core/src/test/java/org/apache/seata/core/rpc/netty/RmNettyClientTest.java
@@ -26,6 +26,7 @@
import org.apache.seata.config.ConfigurationCache;
import org.apache.seata.core.model.Resource;
import org.apache.seata.core.model.ResourceManager;
+import org.apache.seata.core.protocol.HeartbeatMessage;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
@@ -37,6 +38,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Rm RPC client test.
@@ -96,4 +98,13 @@ private AtomicBoolean getInitializeStatus(final RmNettyRemotingClient rmNettyRem
throw new RuntimeException(ex.getMessage());
}
}
+
+ @Test
+ public void testSendAsyncRequestWithNullChannelLogsWarning() {
+ RmNettyRemotingClient remotingClient = RmNettyRemotingClient.getInstance();
+ Object message = HeartbeatMessage.PING;
+ assertThrows(FrameworkException.class, () -> {
+ remotingClient.sendAsyncRequest(null, message);
+ });
+ }
}
diff --git a/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/BaseDistributedLockSqlServerTest.java b/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/BaseDistributedLockSqlServerTest.java
new file mode 100644
index 00000000000..4a51509c9e0
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/BaseDistributedLockSqlServerTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.seata.core.store.db.sql.distributed.lock;
+
+import org.apache.seata.core.constants.ServerTableColumnsName;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+class BaseDistributedLockSqlServerTest {
+
+ private BaseDistributedLockSqlServer baseDistributedLockSqlServer;
+ private final String testTable = "test_lock_table";
+
+ @BeforeEach
+ void setUp() {
+ baseDistributedLockSqlServer = new BaseDistributedLockSqlServer();
+ }
+
+ @Test
+ void testGetSelectDistributeForUpdateSql() {
+ String expected = "SELECT " + ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + "," +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_VALUE + "," + ServerTableColumnsName.DISTRIBUTED_LOCK_EXPIRE +
+ " FROM " + testTable + " WITH (ROWLOCK, UPDLOCK, HOLDLOCK) WHERE " + ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + " = ?";
+ String actual = baseDistributedLockSqlServer.getSelectDistributeForUpdateSql(testTable);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ void testGetInsertSql() {
+ String expected = "INSERT INTO " + testTable + "(" +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + "," +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_VALUE + "," + ServerTableColumnsName.DISTRIBUTED_LOCK_EXPIRE +
+ ") VALUES (?, ?, ?)";
+ String actual = baseDistributedLockSqlServer.getInsertSql(testTable);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ void testGetUpdateSql() {
+ String expected = "UPDATE " + testTable + " SET " +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_VALUE + "=?, " + ServerTableColumnsName.DISTRIBUTED_LOCK_EXPIRE + "=?" +
+ " WHERE " + ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + "=?";
+ String actual = baseDistributedLockSqlServer.getUpdateSql(testTable);
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/BaseDistributedLockSqlTest.java b/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/BaseDistributedLockSqlTest.java
new file mode 100644
index 00000000000..2b98cb1f78b
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/BaseDistributedLockSqlTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.seata.core.store.db.sql.distributed.lock;
+
+import org.apache.seata.core.constants.ServerTableColumnsName;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+class BaseDistributedLockSqlTest {
+
+ private BaseDistributedLockSql baseDistributedLockSql;
+ private final String testTable = "test_lock_table";
+
+ @BeforeEach
+ void setUp() {
+ baseDistributedLockSql = new BaseDistributedLockSql();
+ }
+
+ @Test
+ void testGetSelectDistributeForUpdateSql() {
+ String expected = "SELECT " + ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + "," +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_VALUE + "," + ServerTableColumnsName.DISTRIBUTED_LOCK_EXPIRE +
+ " FROM " + testTable + " WHERE " + ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + " = ? FOR UPDATE";
+ String actual = baseDistributedLockSql.getSelectDistributeForUpdateSql(testTable);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ void testGetInsertSql() {
+ String expected = "INSERT INTO " + testTable + "(" +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + "," +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_VALUE + "," + ServerTableColumnsName.DISTRIBUTED_LOCK_EXPIRE +
+ ") VALUES (?, ?, ?)";
+ String actual = baseDistributedLockSql.getInsertSql(testTable);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ void testGetUpdateSql() {
+ String expected = "UPDATE " + testTable + " SET " +
+ ServerTableColumnsName.DISTRIBUTED_LOCK_VALUE + "=?, " + ServerTableColumnsName.DISTRIBUTED_LOCK_EXPIRE + "=?" +
+ " WHERE " + ServerTableColumnsName.DISTRIBUTED_LOCK_KEY + "=?";
+ String actual = baseDistributedLockSql.getUpdateSql(testTable);
+ assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/DistributedLockSqlFactoryTest.java b/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/DistributedLockSqlFactoryTest.java
new file mode 100644
index 00000000000..9d1c892b2e6
--- /dev/null
+++ b/core/src/test/java/org/apache/seata/core/store/db/sql/distributed/lock/DistributedLockSqlFactoryTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.seata.core.store.db.sql.distributed.lock;
+
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+class DistributedLockSqlFactoryTest {
+
+ @Test
+ void testGetDistributedLogStoreSqlForMysql() {
+ DistributedLockSql sql = DistributedLockSqlFactory.getDistributedLogStoreSql("mysql");
+ assertNotNull(sql);
+ assertTrue(sql instanceof BaseDistributedLockSql);
+ }
+
+ @Test
+ void testGetDistributedLogStoreSqlForSqlServer() {
+ DistributedLockSql sql = DistributedLockSqlFactory.getDistributedLogStoreSql("sqlserver");
+ assertNotNull(sql);
+ assertTrue(sql instanceof BaseDistributedLockSqlServer);
+ }
+
+ @Test
+ void testGetDistributedLogStoreSqlForUnsupportedDb() {
+ DistributedLockSql sql = DistributedLockSqlFactory.getDistributedLogStoreSql("unsupported");
+ assertNotNull(sql);
+ assertTrue(sql instanceof BaseDistributedLockSql);
+ }
+
+ @Test
+ void testCacheImplementation() {
+ DistributedLockSql sql1 = DistributedLockSqlFactory.getDistributedLogStoreSql("mysql");
+ DistributedLockSql sql2 = DistributedLockSqlFactory.getDistributedLogStoreSql("mysql");
+ assertSame(sql1, sql2);
+ }
+}
\ No newline at end of file
diff --git a/dependencies/pom.xml b/dependencies/pom.xml
index 6b93148e613..2b567d6927f 100644
--- a/dependencies/pom.xml
+++ b/dependencies/pom.xml
@@ -77,7 +77,7 @@
4.0.3
1.6.7
3.25.4
- 1.66.0
+ 1.55.1
5.4.0
0.45
4.0.63
@@ -127,7 +127,6 @@
1.7.3
- 5.3.26
9.0.90
@@ -137,6 +136,9 @@
3.1.10
4.12.0
2.4.0
+
+
+ 0.8.0
@@ -529,6 +531,10 @@
com.google.guava
guava
+
+ io.grpc
+ grpc-core
+