diff --git a/all/pom.xml b/all/pom.xml index 9a00a2a30ef..597a6a20e77 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -254,11 +254,6 @@ seata-serializer-kryo ${project.version} - - io.seata - seata-serializer-fst - ${project.version} - io.seata seata-serializer-hessian @@ -586,11 +581,6 @@ kryo provided - - de.ruedigermoeller - fst - provided - com.dameng DmJdbcDriver18 diff --git a/bom/pom.xml b/bom/pom.xml index 6fd3cf91227..f60d4b034f6 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -270,11 +270,6 @@ seata-serializer-hessian ${project.version} - - io.seata - seata-serializer-fst - ${project.version} - io.seata seata-spring-boot-starter diff --git a/changes/en-us/2.0.0.md b/changes/en-us/2.0.0.md index e5004dd5dd3..fc8b106af16 100644 --- a/changes/en-us/2.0.0.md +++ b/changes/en-us/2.0.0.md @@ -149,6 +149,8 @@ The version is updated as follows: - [[#5938](https://github.com/seata/seata/pull/5938)] support jmx port in seata - [[#5951](https://github.com/seata/seata/pull/5951)] remove un support config in jdk17 - [[#5959](https://github.com/seata/seata/pull/5959)] modify code style and remove unused import +- [[#6002](https://github.com/seata/seata/pull/6002)] remove fst serialization + ### security: - [[#5642](https://github.com/seata/seata/pull/5642)] add Hessian Serializer WhiteDenyList diff --git a/changes/zh-cn/2.0.0.md b/changes/zh-cn/2.0.0.md index 7255910102f..bb9c22850e2 100644 --- a/changes/zh-cn/2.0.0.md +++ b/changes/zh-cn/2.0.0.md @@ -150,6 +150,7 @@ Seata 是一款开源的分布式事务解决方案,提供高性能和简单 - [[#5938](https://github.com/seata/seata/pull/5938)] 支持 jmx 监控配置 - [[#5951](https://github.com/seata/seata/pull/5951)] 删除在 jdk17 中不支持的配置项 - [[#5959](https://github.com/seata/seata/pull/5959)] 修正代码风格问题及去除无用的类引用 +- [[#6002](https://github.com/seata/seata/pull/6002)] 移除fst序列化模块 ### security: diff --git a/core/src/main/java/io/seata/core/serializer/SerializerType.java b/core/src/main/java/io/seata/core/serializer/SerializerType.java index b5f468f9e7f..292c0f042ac 100644 --- a/core/src/main/java/io/seata/core/serializer/SerializerType.java +++ b/core/src/main/java/io/seata/core/serializer/SerializerType.java @@ -44,7 +44,7 @@ public enum SerializerType { KRYO((byte)0x4), /** - * The fst. + * The fst but it's been removed. *

* Math.pow(2, 3) */ @@ -56,8 +56,9 @@ public enum SerializerType { * Math.pow(2, 4) */ HESSIAN((byte)0x16), + /** - * The hessian. + * The jackson. *

* Math.pow(2, 5) */ @@ -82,6 +83,10 @@ public static SerializerType getByCode(int code) { return b; } } + if (code == SerializerType.FST.getCode()) { + throw new IllegalArgumentException( + "Since fst is no longer maintained, this serialization extension has been removed from version 2.0 for security and stability reasons."); + } throw new IllegalArgumentException("unknown codec:" + code); } diff --git a/dependencies/pom.xml b/dependencies/pom.xml index 4b3378be038..8c557cc288d 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -78,7 +78,6 @@ 5.4.0 0.45 4.0.63 - 2.57 2.4.4 1.5.0-4 1.4.20 @@ -561,11 +560,6 @@ hessian ${hessian.version} - - de.ruedigermoeller - fst - ${fst.version} - org.apache.commons commons-compress diff --git a/rm-datasource/pom.xml b/rm-datasource/pom.xml index 8c4842944ca..fe1acf6c1a6 100644 --- a/rm-datasource/pom.xml +++ b/rm-datasource/pom.xml @@ -103,12 +103,6 @@ provided true - - de.ruedigermoeller - fst - provided - true - com.alibaba fastjson diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogParserFactory.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogParserFactory.java index 1dbbf6cdeb1..b70fc114040 100644 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogParserFactory.java +++ b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/UndoLogParserFactory.java @@ -17,6 +17,7 @@ import io.seata.common.loader.EnhancedServiceLoader; import io.seata.common.util.CollectionUtils; +import io.seata.common.util.StringUtils; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -58,6 +59,10 @@ public static UndoLogParser getInstance() { * @return the UndoLogParser */ public static UndoLogParser getInstance(String name) { + if (StringUtils.equalsIgnoreCase("fst", name)) { + throw new IllegalArgumentException( + "Since fst is no longer maintained, this serialization extension has been removed from version 2.0 for security and stability reasons."); + } return CollectionUtils.computeIfAbsent(INSTANCES, name, key -> EnhancedServiceLoader.load(UndoLogParser.class, name)); } diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/FstSerializerFactory.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/FstSerializerFactory.java deleted file mode 100644 index 5006ec1cca5..00000000000 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/FstSerializerFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed 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.rm.datasource.undo.parser; - -import java.sql.Timestamp; -import javax.sql.rowset.serial.SerialBlob; -import javax.sql.rowset.serial.SerialClob; -import org.nustaq.serialization.FSTConfiguration; -import org.nustaq.serialization.FSTObjectSerializer; - -/** - * @author funkye - */ -public class FstSerializerFactory { - - private static final FstSerializerFactory FACTORY = new FstSerializerFactory(); - - private final FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration(); - - public static FstSerializerFactory getDefaultFactory() { - return FACTORY; - } - - public FstSerializerFactory() { - // support clob and blob sql type - conf.registerClass(SerialBlob.class, SerialClob.class, Timestamp.class); - UndoLogSerializerClassRegistry.getRegisteredClasses().keySet().forEach(conf::registerClass); - } - - public void registerSerializer(Class type, FSTObjectSerializer ser, boolean alsoForAllSubclasses) { - conf.registerSerializer(type, ser, alsoForAllSubclasses); - } - - public byte[] serialize(T t) { - return conf.asByteArray(t); - } - - public T deserialize(byte[] bytes) { - return (T)conf.asObject(bytes); - } - -} diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/FstUndoLogParser.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/FstUndoLogParser.java deleted file mode 100644 index 0231db22100..00000000000 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/FstUndoLogParser.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed 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.rm.datasource.undo.parser; - -import io.seata.common.executor.Initialize; -import io.seata.common.loader.EnhancedServiceLoader; -import io.seata.common.loader.EnhancedServiceNotFoundException; -import io.seata.common.loader.LoadLevel; -import io.seata.common.util.CollectionUtils; -import io.seata.rm.datasource.undo.BranchUndoLog; -import io.seata.rm.datasource.undo.UndoLogParser; -import io.seata.rm.datasource.undo.parser.spi.FstSerializer; -import org.nustaq.serialization.FSTObjectSerializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -/** - * fst serializer - * @author funkye - */ -@LoadLevel(name = FstUndoLogParser.NAME) -public class FstUndoLogParser implements UndoLogParser, Initialize { - - private static final Logger LOGGER = LoggerFactory.getLogger(FstUndoLogParser.class); - - public static final String NAME = "fst"; - - private FstSerializerFactory fstFactory = FstSerializerFactory.getDefaultFactory(); - - @Override - public void init() { - try { - List serializers = EnhancedServiceLoader.loadAll(FstSerializer.class); - if (CollectionUtils.isNotEmpty(serializers)) { - for (FstSerializer serializer : serializers) { - if (serializer != null) { - Class type = serializer.type(); - FSTObjectSerializer ser = serializer.ser(); - boolean alsoForAllSubclasses = serializer.alsoForAllSubclasses(); - if (type != null && ser != null) { - fstFactory.registerSerializer(type, ser, alsoForAllSubclasses); - LOGGER.info("fst undo log parser load [{}].", serializer.getClass().getName()); - } - } - } - } - } catch (EnhancedServiceNotFoundException e) { - LOGGER.warn("FstSerializer not found children class.", e); - } - } - - @Override - public String getName() { - return NAME; - } - - @Override - public byte[] getDefaultContent() { - return fstFactory.serialize(new BranchUndoLog()); - } - - @Override - public byte[] encode(BranchUndoLog branchUndoLog) { - return fstFactory.serialize(branchUndoLog); - } - - @Override - public BranchUndoLog decode(byte[] bytes) { - return fstFactory.deserialize(bytes); - } - -} diff --git a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/spi/FstSerializer.java b/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/spi/FstSerializer.java deleted file mode 100644 index 1721c80e3f6..00000000000 --- a/rm-datasource/src/main/java/io/seata/rm/datasource/undo/parser/spi/FstSerializer.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed 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.rm.datasource.undo.parser.spi; - -import org.nustaq.serialization.FSTObjectSerializer; - -/** - * The interface Fst serializer. - * - * @author jsbxyyx - */ -public interface FstSerializer { - - /** - * fst serializer class type - * - * @return class - */ - Class type(); - - /** - * FSTObjectSerializer custom serializer - * - * @return fst object serializer - */ - FSTObjectSerializer ser(); - - /** - * for sub classes - * - * @return boolean - */ - boolean alsoForAllSubclasses(); - -} diff --git a/rm-datasource/src/main/resources/META-INF/services/io.seata.rm.datasource.undo.UndoLogParser b/rm-datasource/src/main/resources/META-INF/services/io.seata.rm.datasource.undo.UndoLogParser index f9f91908245..7b19989f63b 100644 --- a/rm-datasource/src/main/resources/META-INF/services/io.seata.rm.datasource.undo.UndoLogParser +++ b/rm-datasource/src/main/resources/META-INF/services/io.seata.rm.datasource.undo.UndoLogParser @@ -1,5 +1,4 @@ io.seata.rm.datasource.undo.parser.FastjsonUndoLogParser io.seata.rm.datasource.undo.parser.JacksonUndoLogParser io.seata.rm.datasource.undo.parser.ProtostuffUndoLogParser -io.seata.rm.datasource.undo.parser.KryoUndoLogParser -io.seata.rm.datasource.undo.parser.FstUndoLogParser \ No newline at end of file +io.seata.rm.datasource.undo.parser.KryoUndoLogParser \ No newline at end of file diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoLogParserFactoryTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoLogParserFactoryTest.java index 6a1c099957d..8ea9de9e3f2 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoLogParserFactoryTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoLogParserFactoryTest.java @@ -26,6 +26,7 @@ class UndoLogParserFactoryTest { @Test void getInstance() { + Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> UndoLogParserFactory.getInstance("fst")); Assertions.assertTrue(UndoLogParserFactory.getInstance() instanceof JacksonUndoLogParser); } } \ No newline at end of file diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoLogParserProviderTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoLogParserProviderTest.java index 29eaab7f033..d9ac97284d4 100644 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoLogParserProviderTest.java +++ b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/UndoLogParserProviderTest.java @@ -21,7 +21,6 @@ import io.seata.common.loader.EnhancedServiceLoader; import io.seata.common.loader.EnhancedServiceNotFoundException; import io.seata.rm.datasource.undo.parser.FastjsonUndoLogParser; -import io.seata.rm.datasource.undo.parser.FstUndoLogParser; import io.seata.rm.datasource.undo.parser.JacksonUndoLogParser; import io.seata.rm.datasource.undo.parser.KryoUndoLogParser; import io.seata.rm.datasource.undo.parser.ProtostuffUndoLogParser; @@ -45,10 +44,6 @@ void testLoad(){ Assertions.assertNotNull(parser); Assertions.assertTrue(parser instanceof ProtostuffUndoLogParser); - parser = EnhancedServiceLoader.load(UndoLogParser.class, "fst"); - Assertions.assertNotNull(parser); - Assertions.assertTrue(parser instanceof FstUndoLogParser); - parser = EnhancedServiceLoader.load(UndoLogParser.class, "kryo"); Assertions.assertNotNull(parser); Assertions.assertTrue(parser instanceof KryoUndoLogParser); diff --git a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/parser/FstUndoLogParserTest.java b/rm-datasource/src/test/java/io/seata/rm/datasource/undo/parser/FstUndoLogParserTest.java deleted file mode 100644 index 693c6f12581..00000000000 --- a/rm-datasource/src/test/java/io/seata/rm/datasource/undo/parser/FstUndoLogParserTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed 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.rm.datasource.undo.parser; - -import io.seata.common.loader.EnhancedServiceLoader; -import io.seata.rm.datasource.undo.BaseUndoLogParserTest; -import io.seata.rm.datasource.undo.UndoLogParser; - -/** - * @author funkye - */ -public class FstUndoLogParserTest extends BaseUndoLogParserTest { - - FstUndoLogParser parser = (FstUndoLogParser)EnhancedServiceLoader.load(UndoLogParser.class, FstUndoLogParser.NAME); - - @Override - public UndoLogParser getParser() { - return parser; - } - -} diff --git a/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 0b20cfc4f20..46a4002c531 100644 --- a/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -405,9 +405,6 @@ }, { "value": "protostuff" - }, - { - "value": "fst" } ] }, diff --git a/serializer/pom.xml b/serializer/pom.xml index efc514f5cf9..f1d0b349d64 100644 --- a/serializer/pom.xml +++ b/serializer/pom.xml @@ -34,7 +34,6 @@ seata-serializer-seata seata-serializer-kryo seata-serializer-hessian - seata-serializer-fst diff --git a/serializer/seata-serializer-all/pom.xml b/serializer/seata-serializer-all/pom.xml index 6944dce3d83..4ddc9fa33e2 100644 --- a/serializer/seata-serializer-all/pom.xml +++ b/serializer/seata-serializer-all/pom.xml @@ -47,10 +47,5 @@ seata-serializer-hessian ${project.version} - - ${project.groupId} - seata-serializer-fst - ${project.version} - diff --git a/serializer/seata-serializer-fst/pom.xml b/serializer/seata-serializer-fst/pom.xml deleted file mode 100644 index 9f694f842f6..00000000000 --- a/serializer/seata-serializer-fst/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - seata-serializer - io.seata - ${revision} - - 4.0.0 - seata-serializer-fst - jar - seata-serializer-fst ${project.version} - serializer-fst for Seata built with Maven - - - - de.ruedigermoeller - fst - - - io.seata - seata-core - ${project.version} - - - diff --git a/serializer/seata-serializer-fst/src/main/java/io/seata/serializer/fst/FstSerializer.java b/serializer/seata-serializer-fst/src/main/java/io/seata/serializer/fst/FstSerializer.java deleted file mode 100644 index acaf1a1de51..00000000000 --- a/serializer/seata-serializer-fst/src/main/java/io/seata/serializer/fst/FstSerializer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed 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.serializer.fst; - -import io.seata.common.loader.LoadLevel; -import io.seata.core.serializer.Serializer; - -/** - * @author funkye - */ -@LoadLevel(name = "FST") -public class FstSerializer implements Serializer { - - private FstSerializerFactory fstFactory = FstSerializerFactory.getDefaultFactory(); - - @Override - public byte[] serialize(T t) { - return fstFactory.serialize(t); - } - - @Override - public T deserialize(byte[] bytes) { - return (T)fstFactory.deserialize(bytes); - } - -} diff --git a/serializer/seata-serializer-fst/src/main/java/io/seata/serializer/fst/FstSerializerFactory.java b/serializer/seata-serializer-fst/src/main/java/io/seata/serializer/fst/FstSerializerFactory.java deleted file mode 100644 index 8c1739d1e57..00000000000 --- a/serializer/seata-serializer-fst/src/main/java/io/seata/serializer/fst/FstSerializerFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed 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.serializer.fst; - -import io.seata.core.serializer.SerializerSecurityRegistry; -import org.nustaq.serialization.FSTConfiguration; - -/** - * @author funkye - */ -public class FstSerializerFactory { - - private static final FstSerializerFactory FACTORY = new FstSerializerFactory(); - - private final FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration(); - - - public static FstSerializerFactory getDefaultFactory() { - return FACTORY; - } - - public FstSerializerFactory() { - SerializerSecurityRegistry.getAllowClassType().forEach(conf::registerClass); - } - - public byte[] serialize(T t) { - return conf.asByteArray(t); - } - - public T deserialize(byte[] bytes) { - return (T)conf.asObject(bytes); - } - -} diff --git a/serializer/seata-serializer-fst/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer b/serializer/seata-serializer-fst/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer deleted file mode 100644 index 4a14492e404..00000000000 --- a/serializer/seata-serializer-fst/src/main/resources/META-INF/services/io.seata.core.serializer.Serializer +++ /dev/null @@ -1 +0,0 @@ -io.seata.serializer.fst.FstSerializer \ No newline at end of file diff --git a/serializer/seata-serializer-fst/src/test/java/io/seata/serializer/fst/FstSerializerTest.java b/serializer/seata-serializer-fst/src/test/java/io/seata/serializer/fst/FstSerializerTest.java deleted file mode 100644 index 883c8769322..00000000000 --- a/serializer/seata-serializer-fst/src/test/java/io/seata/serializer/fst/FstSerializerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 1999-2019 Seata.io Group. - * - * Licensed 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.serializer.fst; - -import io.seata.core.exception.TransactionExceptionCode; -import io.seata.core.model.BranchStatus; -import io.seata.core.model.BranchType; -import io.seata.core.protocol.ResultCode; -import io.seata.core.protocol.transaction.BranchCommitRequest; -import io.seata.core.protocol.transaction.BranchCommitResponse; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author funkye - */ -public class FstSerializerTest { - - private static FstSerializer fstSerializer; - - @BeforeAll - public static void before() { - fstSerializer = new FstSerializer(); - } - - @Test - public void testBranchCommitRequest() { - - BranchCommitRequest branchCommitRequest = new BranchCommitRequest(); - branchCommitRequest.setBranchType(BranchType.AT); - branchCommitRequest.setXid("xid"); - branchCommitRequest.setResourceId("resourceId"); - branchCommitRequest.setBranchId(20190809); - branchCommitRequest.setApplicationData("app"); - - byte[] bytes = fstSerializer.serialize(branchCommitRequest); - BranchCommitRequest t = fstSerializer.deserialize(bytes); - - assertThat(t.getTypeCode()).isEqualTo(branchCommitRequest.getTypeCode()); - assertThat(t.getBranchType()).isEqualTo(branchCommitRequest.getBranchType()); - assertThat(t.getXid()).isEqualTo(branchCommitRequest.getXid()); - assertThat(t.getResourceId()).isEqualTo(branchCommitRequest.getResourceId()); - assertThat(t.getBranchId()).isEqualTo(branchCommitRequest.getBranchId()); - assertThat(t.getApplicationData()).isEqualTo(branchCommitRequest.getApplicationData()); - - } - - @Test - public void testBranchCommitResponse() { - - BranchCommitResponse branchCommitResponse = new BranchCommitResponse(); - branchCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist); - branchCommitResponse.setBranchId(20190809); - branchCommitResponse.setBranchStatus(BranchStatus.PhaseOne_Done); - branchCommitResponse.setMsg("20190809"); - branchCommitResponse.setXid("20190809"); - branchCommitResponse.setResultCode(ResultCode.Failed); - - byte[] bytes = fstSerializer.serialize(branchCommitResponse); - BranchCommitResponse t = fstSerializer.deserialize(bytes); - - assertThat(t.getTransactionExceptionCode()).isEqualTo(branchCommitResponse.getTransactionExceptionCode()); - assertThat(t.getBranchId()).isEqualTo(branchCommitResponse.getBranchId()); - assertThat(t.getBranchStatus()).isEqualTo(branchCommitResponse.getBranchStatus()); - assertThat(t.getMsg()).isEqualTo(branchCommitResponse.getMsg()); - assertThat(t.getResultCode()).isEqualTo(branchCommitResponse.getResultCode()); - - } - -}