chore(project): 添加项目配置文件和忽略规则

- 添加 Babel 配置文件支持 ES6+ 语法转换
- 添加 ESLint 忽略规则和配置文件
- 添加 Git 忽略规则文件
- 添加 Travis CI 配置文件
- 添加 1.4.2 版本变更日志文件
- 添加 Helm 图表辅助模板文件
- 添加 Helm 忽略规则文件
This commit is contained in:
2026-03-27 17:36:48 +08:00
commit c2453d6434
1703 changed files with 277582 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.seata</groupId>
<artifactId>seata-serializer</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>seata-serializer-seata</artifactId>
<packaging>jar</packaging>
<name>seata-serializer-seata ${project.version}</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>seata-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,346 @@
/*
* 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.seata;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import io.seata.serializer.seata.protocol.MergeResultMessageCodec;
import io.seata.serializer.seata.protocol.MergedWarpMessageCodec;
import io.seata.serializer.seata.protocol.RegisterRMRequestCodec;
import io.seata.serializer.seata.protocol.RegisterRMResponseCodec;
import io.seata.serializer.seata.protocol.RegisterTMRequestCodec;
import io.seata.serializer.seata.protocol.RegisterTMResponseCodec;
import io.seata.serializer.seata.protocol.transaction.BranchCommitRequestCodec;
import io.seata.serializer.seata.protocol.transaction.BranchCommitResponseCodec;
import io.seata.serializer.seata.protocol.transaction.BranchRegisterRequestCodec;
import io.seata.serializer.seata.protocol.transaction.BranchRegisterResponseCodec;
import io.seata.serializer.seata.protocol.transaction.BranchReportRequestCodec;
import io.seata.serializer.seata.protocol.transaction.BranchReportResponseCodec;
import io.seata.serializer.seata.protocol.transaction.BranchRollbackRequestCodec;
import io.seata.serializer.seata.protocol.transaction.BranchRollbackResponseCodec;
import io.seata.serializer.seata.protocol.transaction.GlobalBeginRequestCodec;
import io.seata.serializer.seata.protocol.transaction.GlobalBeginResponseCodec;
import io.seata.serializer.seata.protocol.transaction.GlobalCommitRequestCodec;
import io.seata.serializer.seata.protocol.transaction.GlobalCommitResponseCodec;
import io.seata.serializer.seata.protocol.transaction.GlobalLockQueryRequestCodec;
import io.seata.serializer.seata.protocol.transaction.GlobalLockQueryResponseCodec;
import io.seata.serializer.seata.protocol.transaction.GlobalReportRequestCodec;
import io.seata.serializer.seata.protocol.transaction.GlobalReportResponseCodec;
import io.seata.serializer.seata.protocol.transaction.GlobalRollbackRequestCodec;
import io.seata.serializer.seata.protocol.transaction.GlobalRollbackResponseCodec;
import io.seata.serializer.seata.protocol.transaction.GlobalStatusRequestCodec;
import io.seata.serializer.seata.protocol.transaction.GlobalStatusResponseCodec;
import io.seata.serializer.seata.protocol.transaction.UndoLogDeleteRequestCodec;
import io.seata.core.protocol.AbstractMessage;
import io.seata.core.protocol.MergeResultMessage;
import io.seata.core.protocol.MergedWarpMessage;
import io.seata.core.protocol.MessageType;
import io.seata.core.protocol.RegisterRMRequest;
import io.seata.core.protocol.RegisterRMResponse;
import io.seata.core.protocol.RegisterTMRequest;
import io.seata.core.protocol.RegisterTMResponse;
import io.seata.core.protocol.transaction.BranchCommitRequest;
import io.seata.core.protocol.transaction.BranchCommitResponse;
import io.seata.core.protocol.transaction.BranchRegisterRequest;
import io.seata.core.protocol.transaction.BranchRegisterResponse;
import io.seata.core.protocol.transaction.BranchReportRequest;
import io.seata.core.protocol.transaction.BranchReportResponse;
import io.seata.core.protocol.transaction.BranchRollbackRequest;
import io.seata.core.protocol.transaction.BranchRollbackResponse;
import io.seata.core.protocol.transaction.GlobalBeginRequest;
import io.seata.core.protocol.transaction.GlobalBeginResponse;
import io.seata.core.protocol.transaction.GlobalCommitRequest;
import io.seata.core.protocol.transaction.GlobalCommitResponse;
import io.seata.core.protocol.transaction.GlobalLockQueryRequest;
import io.seata.core.protocol.transaction.GlobalLockQueryResponse;
import io.seata.core.protocol.transaction.GlobalReportRequest;
import io.seata.core.protocol.transaction.GlobalReportResponse;
import io.seata.core.protocol.transaction.GlobalRollbackRequest;
import io.seata.core.protocol.transaction.GlobalRollbackResponse;
import io.seata.core.protocol.transaction.GlobalStatusRequest;
import io.seata.core.protocol.transaction.GlobalStatusResponse;
import io.seata.core.protocol.transaction.UndoLogDeleteRequest;
/**
* The type Message codec factory.
*
* @author zhangsen
*/
public class MessageCodecFactory {
/**
* The constant UTF8.
*/
protected static final Charset UTF8 = StandardCharsets.UTF_8;
/**
* Get message codec message codec.
*
* @param abstractMessage the abstract message
* @return the message codec
*/
public static MessageSeataCodec getMessageCodec(AbstractMessage abstractMessage) {
return getMessageCodec(abstractMessage.getTypeCode());
}
/**
* Gets msg instance by code.
*
* @param typeCode the type code
* @return the msg instance by code
*/
public static MessageSeataCodec getMessageCodec(short typeCode) {
MessageSeataCodec msgCodec = null;
switch (typeCode) {
case MessageType.TYPE_SEATA_MERGE:
msgCodec = new MergedWarpMessageCodec();
break;
case MessageType.TYPE_SEATA_MERGE_RESULT:
msgCodec = new MergeResultMessageCodec();
break;
case MessageType.TYPE_REG_CLT:
msgCodec = new RegisterTMRequestCodec();
break;
case MessageType.TYPE_REG_CLT_RESULT:
msgCodec = new RegisterTMResponseCodec();
break;
case MessageType.TYPE_REG_RM:
msgCodec = new RegisterRMRequestCodec();
break;
case MessageType.TYPE_REG_RM_RESULT:
msgCodec = new RegisterRMResponseCodec();
break;
case MessageType.TYPE_BRANCH_COMMIT:
msgCodec = new BranchCommitRequestCodec();
break;
case MessageType.TYPE_BRANCH_ROLLBACK:
msgCodec = new BranchRollbackRequestCodec();
break;
case MessageType.TYPE_GLOBAL_REPORT:
msgCodec = new GlobalReportRequestCodec();
break;
default:
break;
}
if (msgCodec != null) {
return msgCodec;
}
try {
msgCodec = getMergeRequestMessageSeataCodec(typeCode);
} catch (Exception exx) {
}
if (msgCodec != null) {
return msgCodec;
}
msgCodec = getMergeResponseMessageSeataCodec(typeCode);
return msgCodec;
}
/**
* Gets merge request instance by code.
*
* @param typeCode the type code
* @return the merge request instance by code
*/
protected static MessageSeataCodec getMergeRequestMessageSeataCodec(int typeCode) {
switch (typeCode) {
case MessageType.TYPE_GLOBAL_BEGIN:
return new GlobalBeginRequestCodec();
case MessageType.TYPE_GLOBAL_COMMIT:
return new GlobalCommitRequestCodec();
case MessageType.TYPE_GLOBAL_ROLLBACK:
return new GlobalRollbackRequestCodec();
case MessageType.TYPE_GLOBAL_STATUS:
return new GlobalStatusRequestCodec();
case MessageType.TYPE_GLOBAL_LOCK_QUERY:
return new GlobalLockQueryRequestCodec();
case MessageType.TYPE_BRANCH_REGISTER:
return new BranchRegisterRequestCodec();
case MessageType.TYPE_BRANCH_STATUS_REPORT:
return new BranchReportRequestCodec();
case MessageType.TYPE_GLOBAL_REPORT:
return new GlobalReportRequestCodec();
default:
throw new IllegalArgumentException("not support typeCode," + typeCode);
}
}
/**
* Gets merge response instance by code.
*
* @param typeCode the type code
* @return the merge response instance by code
*/
protected static MessageSeataCodec getMergeResponseMessageSeataCodec(int typeCode) {
switch (typeCode) {
case MessageType.TYPE_GLOBAL_BEGIN_RESULT:
return new GlobalBeginResponseCodec();
case MessageType.TYPE_GLOBAL_COMMIT_RESULT:
return new GlobalCommitResponseCodec();
case MessageType.TYPE_GLOBAL_ROLLBACK_RESULT:
return new GlobalRollbackResponseCodec();
case MessageType.TYPE_GLOBAL_STATUS_RESULT:
return new GlobalStatusResponseCodec();
case MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT:
return new GlobalLockQueryResponseCodec();
case MessageType.TYPE_BRANCH_REGISTER_RESULT:
return new BranchRegisterResponseCodec();
case MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT:
return new BranchReportResponseCodec();
case MessageType.TYPE_BRANCH_COMMIT_RESULT:
return new BranchCommitResponseCodec();
case MessageType.TYPE_BRANCH_ROLLBACK_RESULT:
return new BranchRollbackResponseCodec();
case MessageType.TYPE_RM_DELETE_UNDOLOG:
return new UndoLogDeleteRequestCodec();
case MessageType.TYPE_GLOBAL_REPORT_RESULT:
return new GlobalReportResponseCodec();
default:
throw new IllegalArgumentException("not support typeCode," + typeCode);
}
}
/**
* Gets message.
*
* @param typeCode the type code
* @return the message
*/
public static AbstractMessage getMessage(short typeCode) {
AbstractMessage abstractMessage = null;
switch (typeCode) {
case MessageType.TYPE_SEATA_MERGE:
abstractMessage = new MergedWarpMessage();
break;
case MessageType.TYPE_SEATA_MERGE_RESULT:
abstractMessage = new MergeResultMessage();
break;
case MessageType.TYPE_REG_CLT:
abstractMessage = new RegisterTMRequest();
break;
case MessageType.TYPE_REG_CLT_RESULT:
abstractMessage = new RegisterTMResponse();
break;
case MessageType.TYPE_REG_RM:
abstractMessage = new RegisterRMRequest();
break;
case MessageType.TYPE_REG_RM_RESULT:
abstractMessage = new RegisterRMResponse();
break;
case MessageType.TYPE_BRANCH_COMMIT:
abstractMessage = new BranchCommitRequest();
break;
case MessageType.TYPE_BRANCH_ROLLBACK:
abstractMessage = new BranchRollbackRequest();
break;
case MessageType.TYPE_RM_DELETE_UNDOLOG:
abstractMessage = new UndoLogDeleteRequest();
break;
case MessageType.TYPE_GLOBAL_REPORT:
abstractMessage = new GlobalReportRequest();
break;
case MessageType.TYPE_GLOBAL_REPORT_RESULT:
abstractMessage = new GlobalReportResponse();
break;
default:
break;
}
if (abstractMessage != null) {
return abstractMessage;
}
try {
abstractMessage = getMergeRequestInstanceByCode(typeCode);
} catch (Exception exx) {
}
if (abstractMessage != null) {
return abstractMessage;
}
return getMergeResponseInstanceByCode(typeCode);
}
/**
* Gets merge request instance by code.
*
* @param typeCode the type code
* @return the merge request instance by code
*/
protected static AbstractMessage getMergeRequestInstanceByCode(int typeCode) {
switch (typeCode) {
case MessageType.TYPE_GLOBAL_BEGIN:
return new GlobalBeginRequest();
case MessageType.TYPE_GLOBAL_COMMIT:
return new GlobalCommitRequest();
case MessageType.TYPE_GLOBAL_ROLLBACK:
return new GlobalRollbackRequest();
case MessageType.TYPE_GLOBAL_STATUS:
return new GlobalStatusRequest();
case MessageType.TYPE_GLOBAL_LOCK_QUERY:
return new GlobalLockQueryRequest();
case MessageType.TYPE_BRANCH_REGISTER:
return new BranchRegisterRequest();
case MessageType.TYPE_BRANCH_STATUS_REPORT:
return new BranchReportRequest();
case MessageType.TYPE_GLOBAL_REPORT:
return new GlobalReportRequest();
default:
throw new IllegalArgumentException("not support typeCode," + typeCode);
}
}
/**
* Gets merge response instance by code.
*
* @param typeCode the type code
* @return the merge response instance by code
*/
protected static AbstractMessage getMergeResponseInstanceByCode(int typeCode) {
switch (typeCode) {
case MessageType.TYPE_GLOBAL_BEGIN_RESULT:
return new GlobalBeginResponse();
case MessageType.TYPE_GLOBAL_COMMIT_RESULT:
return new GlobalCommitResponse();
case MessageType.TYPE_GLOBAL_ROLLBACK_RESULT:
return new GlobalRollbackResponse();
case MessageType.TYPE_GLOBAL_STATUS_RESULT:
return new GlobalStatusResponse();
case MessageType.TYPE_GLOBAL_LOCK_QUERY_RESULT:
return new GlobalLockQueryResponse();
case MessageType.TYPE_BRANCH_REGISTER_RESULT:
return new BranchRegisterResponse();
case MessageType.TYPE_BRANCH_STATUS_REPORT_RESULT:
return new BranchReportResponse();
case MessageType.TYPE_BRANCH_COMMIT_RESULT:
return new BranchCommitResponse();
case MessageType.TYPE_BRANCH_ROLLBACK_RESULT:
return new BranchRollbackResponse();
case MessageType.TYPE_GLOBAL_REPORT_RESULT:
return new GlobalReportResponse();
default:
throw new IllegalArgumentException("not support typeCode," + typeCode);
}
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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.seata;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
/**
* The interface Message seata codec.
*/
public interface MessageSeataCodec {
/**
* Gets message class type.
*
* @return the message class type
*/
Class<?> getMessageClassType();
/**
* Encode.
*
* @param <T> the type parameter
* @param t the t
* @param out the out
*/
<T> void encode(T t, ByteBuf out);
/**
* Decode.
*
* @param <T> the type parameter
* @param t the t
* @param in the in
*/
<T> void decode(T t, ByteBuffer in);
}

View File

@@ -0,0 +1,86 @@
/*
* 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.seata;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.seata.common.loader.LoadLevel;
import io.seata.core.protocol.AbstractMessage;
import io.seata.core.serializer.Serializer;
import java.nio.ByteBuffer;
/**
* The Seata codec.
*
* @author zhangsen
*/
@LoadLevel(name = "SEATA")
public class SeataSerializer implements Serializer {
@Override
public <T> byte[] serialize(T t) {
if (t == null || !(t instanceof AbstractMessage)) {
throw new IllegalArgumentException("AbstractMessage isn't available.");
}
AbstractMessage abstractMessage = (AbstractMessage)t;
//typecode
short typecode = abstractMessage.getTypeCode();
//msg codec
MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typecode);
//get empty ByteBuffer
ByteBuf out = Unpooled.buffer(1024);
//msg encode
messageCodec.encode(t, out);
byte[] body = new byte[out.readableBytes()];
out.readBytes(body);
//typecode + body
ByteBuffer byteBuffer = ByteBuffer.allocate(2 + body.length);
byteBuffer.putShort(typecode);
byteBuffer.put(body);
byteBuffer.flip();
byte[] content = new byte[byteBuffer.limit()];
byteBuffer.get(content);
return content;
}
@Override
public <T> T deserialize(byte[] bytes) {
if (bytes == null || bytes.length == 0) {
throw new IllegalArgumentException("Nothing to decode.");
}
if (bytes.length < 2) {
throw new IllegalArgumentException("The byte[] isn't available for decode.");
}
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
//typecode
short typecode = byteBuffer.getShort();
//msg body
byte[] body = new byte[byteBuffer.remaining()];
byteBuffer.get(body);
ByteBuffer in = ByteBuffer.wrap(body);
//new Messgae
AbstractMessage abstractMessage = MessageCodecFactory.getMessage(typecode);
//get messageCodec
MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typecode);
//decode
messageCodec.decode(abstractMessage, in);
return (T)abstractMessage;
}
}

View File

@@ -0,0 +1,154 @@
/*
* 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.seata.protocol;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.protocol.AbstractIdentifyRequest;
/**
* The type Abstract identify request codec.
*/
public abstract class AbstractIdentifyRequestCodec extends AbstractMessageCodec {
@Override
public Class<?> getMessageClassType() {
return AbstractIdentifyRequest.class;
}
/**
* Do encode.
*
* @param <T> the type parameter
* @param t the t
* @param out the out
*/
protected <T> void doEncode(T t, ByteBuf out) {
AbstractIdentifyRequest abstractIdentifyRequest = (AbstractIdentifyRequest)t;
String version = abstractIdentifyRequest.getVersion();
String applicationId = abstractIdentifyRequest.getApplicationId();
String transactionServiceGroup = abstractIdentifyRequest.getTransactionServiceGroup();
String extraData = abstractIdentifyRequest.getExtraData();
if (version != null) {
byte[] bs = version.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
if (applicationId != null) {
byte[] bs = applicationId.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
if (transactionServiceGroup != null) {
byte[] bs = transactionServiceGroup.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
if (extraData != null) {
byte[] bs = extraData.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
}
@Override
public <T> void encode(T t, ByteBuf out) {
doEncode(t, out);
}
@Override
public <T> void decode(T t, ByteBuffer in) {
AbstractIdentifyRequest abstractIdentifyRequest = (AbstractIdentifyRequest)t;
//version len
short len = 0;
if (in.remaining() < 2) {
return;
}
len = in.getShort();
//version
if (in.remaining() < len) {
return;
}
byte[] bs = new byte[len];
in.get(bs);
abstractIdentifyRequest.setVersion(new String(bs, UTF8));
//applicationId len
if (in.remaining() < 2) {
return;
}
len = in.getShort();
//applicationId
if (in.remaining() < len) {
return;
}
bs = new byte[len];
in.get(bs);
abstractIdentifyRequest.setApplicationId(new String(bs, UTF8));
//transactionServiceGroup len
if (in.remaining() < 2) {
return;
}
len = in.getShort();
//transactionServiceGroup
if (in.remaining() < len) {
return;
}
bs = new byte[len];
in.get(bs);
abstractIdentifyRequest.setTransactionServiceGroup(new String(bs, UTF8));
//ExtraData len
if (in.remaining() < 2) {
return;
}
len = in.getShort();
if (in.remaining() >= len) {
bs = new byte[len];
in.get(bs);
abstractIdentifyRequest.setExtraData(new String(bs, UTF8));
} else {
//maybe null
}
}
}

View File

@@ -0,0 +1,70 @@
/*
* 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.seata.protocol;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.protocol.AbstractIdentifyResponse;
/**
* The type Abstract identify response.
*
* @author sharajava
*/
public abstract class AbstractIdentifyResponseCodec extends AbstractResultMessageCodec {
@Override
public Class<?> getMessageClassType() {
return AbstractIdentifyResponse.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
AbstractIdentifyResponse abstractIdentifyResponse = (AbstractIdentifyResponse)t;
boolean identified = abstractIdentifyResponse.isIdentified();
String version = abstractIdentifyResponse.getVersion();
out.writeByte(identified ? (byte)1 : (byte)0);
if (version != null) {
byte[] bs = version.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
}
@Override
public <T> void decode(T t, ByteBuffer in) {
AbstractIdentifyResponse abstractIdentifyResponse = (AbstractIdentifyResponse)t;
abstractIdentifyResponse.setIdentified(in.get() == 1);
short len = in.getShort();
if (len <= 0) {
return;
}
if (in.remaining() < len) {
return;
}
byte[] bs = new byte[len];
in.get(bs);
abstractIdentifyResponse.setVersion(new String(bs, UTF8));
}
}

View File

@@ -0,0 +1,72 @@
/*
* 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.seata.protocol;
import io.seata.serializer.seata.MessageSeataCodec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
/**
* The type Abstract message codec.
*
* @author zhangsen
*/
public abstract class AbstractMessageCodec implements MessageSeataCodec {
/**
* The constant LOGGER.
*/
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractMessageCodec.class);
/**
* The constant UTF8.
*/
protected static final Charset UTF8 = StandardCharsets.UTF_8;
/**
* Bytes to int int.
*
* @param bytes the bytes
* @param offset the offset
* @return the int
*/
public static int bytesToInt(byte[] bytes, int offset) {
int ret = 0;
for (int i = 0; i < 4 && i + offset < bytes.length; i++) {
ret <<= 8;
ret |= (int)bytes[i + offset] & 0xFF;
}
return ret;
}
/**
* Int to bytes.
*
* @param i the
* @param bytes the bytes
* @param offset the offset
*/
public static void intToBytes(int i, byte[] bytes, int offset) {
bytes[offset] = (byte)((i >> 24) & 0xFF);
bytes[offset + 1] = (byte)((i >> 16) & 0xFF);
bytes[offset + 2] = (byte)((i >> 8) & 0xFF);
bytes[offset + 3] = (byte)(i & 0xFF);
}
}

View File

@@ -0,0 +1,77 @@
/*
* 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.seata.protocol;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.common.util.StringUtils;
import io.seata.core.protocol.AbstractResultMessage;
import io.seata.core.protocol.ResultCode;
/**
* The type Abstract result message codec.
*
* @author zhangsen
*/
public abstract class AbstractResultMessageCodec extends AbstractMessageCodec {
@Override
public Class<?> getMessageClassType() {
return AbstractResultMessage.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
AbstractResultMessage abstractResultMessage = (AbstractResultMessage)t;
ResultCode resultCode = abstractResultMessage.getResultCode();
String resultMsg = abstractResultMessage.getMsg();
out.writeByte(resultCode.ordinal());
if (resultCode == ResultCode.Failed) {
if (StringUtils.isNotEmpty(resultMsg)) {
String msg;
if (resultMsg.length() > Short.MAX_VALUE) {
msg = resultMsg.substring(0, Short.MAX_VALUE);
} else {
msg = resultMsg;
}
byte[] bs = msg.getBytes(UTF8);
out.writeShort((short)bs.length);
out.writeBytes(bs);
} else {
out.writeShort((short)0);
}
}
}
@Override
public <T> void decode(T t, ByteBuffer in) {
AbstractResultMessage abstractResultMessage = (AbstractResultMessage)t;
ResultCode resultCode = ResultCode.get(in.get());
abstractResultMessage.setResultCode(resultCode);
if (resultCode == ResultCode.Failed) {
short len = in.getShort();
if (len > 0) {
byte[] msg = new byte[len];
in.get(msg);
abstractResultMessage.setMsg(new String(msg, UTF8));
}
}
}
}

View File

@@ -0,0 +1,101 @@
/*
* 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.seata.protocol;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.serializer.seata.MessageCodecFactory;
import io.seata.serializer.seata.MessageSeataCodec;
import io.seata.core.protocol.AbstractMessage;
import io.seata.core.protocol.AbstractResultMessage;
import io.seata.core.protocol.MergeResultMessage;
/**
* The type Merge result message codec.
*
* @author zhangsen
*/
public class MergeResultMessageCodec extends AbstractMessageCodec {
@Override
public Class<?> getMessageClassType() {
return MergeResultMessage.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
MergeResultMessage mergeResultMessage = (MergeResultMessage)t;
AbstractResultMessage[] msgs = mergeResultMessage.getMsgs();
int writeIndex = out.writerIndex();
out.writeInt(0);
out.writeShort((short)msgs.length);
for (AbstractMessage msg : msgs) {
//get messageCodec
short typeCode = msg.getTypeCode();
//put typeCode
out.writeShort(typeCode);
MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode);
messageCodec.encode(msg, out);
}
int length = out.readableBytes() - 4;
out.setInt(writeIndex,length);
if (msgs.length > 20) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("msg in one services merge packet:" + msgs.length + ",buffer size:" + length);
}
}
}
@Override
public <T> void decode(T t, ByteBuffer in) {
MergeResultMessage mergeResultMessage = (MergeResultMessage)t;
if (in.remaining() < 4) {
return;
}
int length = in.getInt();
if (in.remaining() < length) {
return;
}
byte[] buffer = new byte[length];
in.get(buffer);
ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
decode(mergeResultMessage, byteBuffer);
}
/**
* Decode.
*
* @param mergeResultMessage the merge result message
* @param byteBuffer the byte buffer
*/
protected void decode(MergeResultMessage mergeResultMessage, ByteBuffer byteBuffer) {
//msgs size
short msgNum = byteBuffer.getShort();
AbstractResultMessage[] msgs = new AbstractResultMessage[msgNum];
for (int idx = 0; idx < msgNum; idx++) {
short typeCode = byteBuffer.getShort();
AbstractMessage abstractResultMessage = MessageCodecFactory.getMessage(typeCode);
MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode);
messageCodec.decode(abstractResultMessage, byteBuffer);
msgs[idx] = (AbstractResultMessage)abstractResultMessage;
}
mergeResultMessage.setMsgs(msgs);
}
}

View File

@@ -0,0 +1,102 @@
/*
* 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.seata.protocol;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.seata.serializer.seata.MessageCodecFactory;
import io.seata.serializer.seata.MessageSeataCodec;
import io.seata.core.protocol.AbstractMessage;
import io.seata.core.protocol.MergedWarpMessage;
/**
* The type Merged warp message codec.
*
* @author zhangsen
*/
public class MergedWarpMessageCodec extends AbstractMessageCodec {
@Override
public Class<?> getMessageClassType() {
return MergedWarpMessage.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
MergedWarpMessage mergedWarpMessage = (MergedWarpMessage)t;
List<AbstractMessage> msgs = mergedWarpMessage.msgs;
final ByteBuf buffer = Unpooled.buffer(1024);
buffer.writeInt(0); // write placeholder for content length
buffer.writeShort((short)msgs.size());
for (final AbstractMessage msg : msgs) {
final ByteBuf subBuffer = Unpooled.buffer(1024);
short typeCode = msg.getTypeCode();
MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode);
messageCodec.encode(msg, subBuffer);
buffer.writeShort(msg.getTypeCode());
buffer.writeBytes(subBuffer);
}
final int length = buffer.readableBytes();
final byte[] content = new byte[length];
buffer.setInt(0, length - 4); // minus the placeholder length itself
buffer.readBytes(content);
if (msgs.size() > 20) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("msg in one packet:" + msgs.size() + ",buffer size:" + content.length);
}
}
out.writeBytes(content);
}
@Override
public <T> void decode(T t, ByteBuffer in) {
MergedWarpMessage mergedWarpMessage = (MergedWarpMessage)t;
if (in.remaining() < 4) {
return;
}
int length = in.getInt();
if (in.remaining() < length) {
return;
}
byte[] buffer = new byte[length];
in.get(buffer);
ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
doDecode(mergedWarpMessage, byteBuffer);
}
private void doDecode(MergedWarpMessage mergedWarpMessage, ByteBuffer byteBuffer) {
short msgNum = byteBuffer.getShort();
List<AbstractMessage> msgs = new ArrayList<AbstractMessage>();
for (int idx = 0; idx < msgNum; idx++) {
short typeCode = byteBuffer.getShort();
AbstractMessage abstractMessage = MessageCodecFactory.getMessage(typeCode);
MessageSeataCodec messageCodec = MessageCodecFactory.getMessageCodec(typeCode);
messageCodec.decode(abstractMessage, byteBuffer);
msgs.add(abstractMessage);
}
mergedWarpMessage.msgs = msgs;
}
}

View File

@@ -0,0 +1,127 @@
/*
* 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.seata.protocol;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.protocol.RegisterRMRequest;
/**
* The type Register rm request codec.
*
* @author zhangsen
*/
public class RegisterRMRequestCodec extends AbstractIdentifyRequestCodec {
@Override
public Class<?> getMessageClassType() {
return RegisterRMRequest.class;
}
@Override
protected <T> void doEncode(T t, ByteBuf out) {
super.doEncode(t, out);
RegisterRMRequest registerRMRequest = (RegisterRMRequest)t;
String resourceIds = registerRMRequest.getResourceIds();
if (resourceIds != null) {
byte[] bs = resourceIds.getBytes(UTF8);
out.writeInt(bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeInt(0);
}
}
@Override
public <T> void decode(T t, ByteBuffer in) {
RegisterRMRequest registerRMRequest = (RegisterRMRequest)t;
if (in.remaining() < 2) {
return;
}
short len = in.getShort();
if (len > 0) {
if (in.remaining() < len) {
return;
}
byte[] bs = new byte[len];
in.get(bs);
registerRMRequest.setVersion(new String(bs, UTF8));
} else {
return;
}
if (in.remaining() < 2) {
return;
}
len = in.getShort();
if (len > 0) {
if (in.remaining() < len) {
return;
}
byte[] bs = new byte[len];
in.get(bs);
registerRMRequest.setApplicationId(new String(bs, UTF8));
}
if (in.remaining() < 2) {
return;
}
len = in.getShort();
if (in.remaining() < len) {
return;
}
byte[] bs = new byte[len];
in.get(bs);
registerRMRequest.setTransactionServiceGroup(new String(bs, UTF8));
if (in.remaining() < 2) {
return;
}
len = in.getShort();
if (len > 0) {
if (in.remaining() < len) {
return;
}
bs = new byte[len];
in.get(bs);
registerRMRequest.setExtraData(new String(bs, UTF8));
}
int iLen;
if (in.remaining() < 4) {
return;
}
iLen = in.getInt();
if (iLen > 0) {
if (in.remaining() < iLen) {
return;
}
bs = new byte[iLen];
in.get(bs);
registerRMRequest.setResourceIds(new String(bs, UTF8));
}
}
}

View File

@@ -0,0 +1,31 @@
/*
* 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.seata.protocol;
import io.seata.core.protocol.RegisterRMResponse;
/**
* The type Register rm response codec.
*
* @author zhangsen
*/
public class RegisterRMResponseCodec extends AbstractIdentifyResponseCodec {
@Override
public Class<?> getMessageClassType() {
return RegisterRMResponse.class;
}
}

View File

@@ -0,0 +1,33 @@
/*
* 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.seata.protocol;
import io.seata.core.protocol.RegisterTMRequest;
/**
* The type Register tm request codec.
*
* @author zhangsen
*/
public class RegisterTMRequestCodec extends AbstractIdentifyRequestCodec {
@Override
public Class<?> getMessageClassType() {
return RegisterTMRequest.class;
}
}

View File

@@ -0,0 +1,33 @@
/*
* 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.seata.protocol;
import io.seata.core.protocol.RegisterTMResponse;
/**
* The type Register tm response codec.
*
* @author zhangsen
*/
public class RegisterTMResponseCodec extends AbstractIdentifyResponseCodec {
@Override
public Class<?> getMessageClassType() {
return RegisterTMResponse.class;
}
}

View File

@@ -0,0 +1,143 @@
/*
* 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.seata.protocol.transaction;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.model.BranchType;
import io.seata.core.protocol.transaction.AbstractBranchEndRequest;
/**
* The type Abstract branch end request codec.
*
* @author zhangsen
*/
public abstract class AbstractBranchEndRequestCodec extends AbstractTransactionRequestToRMCodec {
@Override
public Class<?> getMessageClassType() {
return AbstractBranchEndRequest.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
AbstractBranchEndRequest abstractBranchEndRequest = (AbstractBranchEndRequest)t;
String xid = abstractBranchEndRequest.getXid();
long branchId = abstractBranchEndRequest.getBranchId();
BranchType branchType = abstractBranchEndRequest.getBranchType();
String resourceId = abstractBranchEndRequest.getResourceId();
String applicationData = abstractBranchEndRequest.getApplicationData();
// 1. xid
if (xid != null) {
byte[] bs = xid.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
// 2. Branch Id
out.writeLong(branchId);
// 3. Branch Type
out.writeByte(branchType.ordinal());
// 4. Resource Id
if (resourceId != null) {
byte[] bs = resourceId.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
// 5. Application Data
byte[] applicationDataBytes = null;
if (applicationData != null) {
applicationDataBytes = applicationData.getBytes(UTF8);
out.writeInt(applicationDataBytes.length);
if (applicationDataBytes.length > 0) {
out.writeBytes(applicationDataBytes);
}
} else {
out.writeInt(0);
}
}
@Override
public <T> void decode(T t, ByteBuffer in) {
AbstractBranchEndRequest abstractBranchEndRequest = (AbstractBranchEndRequest)t;
int xidLen = 0;
if (in.remaining() >= 2) {
xidLen = in.getShort();
}
if (xidLen <= 0) {
return;
}
if (in.remaining() < xidLen) {
return;
}
byte[] bs = new byte[xidLen];
in.get(bs);
abstractBranchEndRequest.setXid(new String(bs, UTF8));
if (in.remaining() < 8) {
return;
}
abstractBranchEndRequest.setBranchId(in.getLong());
if (in.remaining() < 1) {
return;
}
abstractBranchEndRequest.setBranchType(BranchType.get(in.get()));
int resourceIdLen = 0;
if (in.remaining() < 2) {
return;
}
resourceIdLen = in.getShort();
if (resourceIdLen <= 0) {
return;
}
if (in.remaining() < resourceIdLen) {
return;
}
bs = new byte[resourceIdLen];
in.get(bs);
abstractBranchEndRequest.setResourceId(new String(bs, UTF8));
int applicationDataLen = 0;
if (in.remaining() < 4) {
return;
}
applicationDataLen = in.getInt();
if (applicationDataLen > 0) {
if (in.remaining() < applicationDataLen) {
return;
}
bs = new byte[applicationDataLen];
in.get(bs);
abstractBranchEndRequest.setApplicationData(new String(bs, UTF8));
}
}
}

View File

@@ -0,0 +1,73 @@
/*
* 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.seata.protocol.transaction;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.model.BranchStatus;
import io.seata.core.protocol.transaction.AbstractBranchEndResponse;
/**
* The type Abstract branch end response codec.
*
* @author zhangsen
*/
public abstract class AbstractBranchEndResponseCodec extends AbstractTransactionResponseCodec {
@Override
public Class<?> getMessageClassType() {
return AbstractBranchEndResponse.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
super.encode(t, out);
AbstractBranchEndResponse abstractBranchEndResponse = (AbstractBranchEndResponse)t;
String xid = abstractBranchEndResponse.getXid();
long branchId = abstractBranchEndResponse.getBranchId();
BranchStatus branchStatus = abstractBranchEndResponse.getBranchStatus();
if (xid != null) {
byte[] bs = xid.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
out.writeLong(branchId);
out.writeByte(branchStatus.getCode());
}
@Override
public <T> void decode(T t, ByteBuffer in) {
super.decode(t, in);
AbstractBranchEndResponse abstractBranchEndResponse = (AbstractBranchEndResponse)t;
short xidLen = in.getShort();
if (xidLen > 0) {
byte[] bs = new byte[xidLen];
in.get(bs);
abstractBranchEndResponse.setXid(new String(bs, UTF8));
}
abstractBranchEndResponse.setBranchId(in.getLong());
abstractBranchEndResponse.setBranchStatus(BranchStatus.get(in.get()));
}
}

View File

@@ -0,0 +1,80 @@
/*
* 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.seata.protocol.transaction;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.protocol.transaction.AbstractGlobalEndRequest;
/**
* The type Abstract global end request codec.
*
* @author zhangsen
*/
public abstract class AbstractGlobalEndRequestCodec extends AbstractTransactionRequestToTCCodec {
@Override
public Class<?> getMessageClassType() {
return AbstractGlobalEndRequest.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
AbstractGlobalEndRequest abstractGlobalEndRequest = (AbstractGlobalEndRequest)t;
String xid = abstractGlobalEndRequest.getXid();
String extraData = abstractGlobalEndRequest.getExtraData();
// 1. xid
if (xid != null) {
byte[] bs = xid.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
if (extraData != null) {
byte[] bs = extraData.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
}
@Override
public <T> void decode(T t, ByteBuffer in) {
AbstractGlobalEndRequest abstractGlobalEndRequest = (AbstractGlobalEndRequest)t;
short xidLen = in.getShort();
if (xidLen > 0) {
byte[] bs = new byte[xidLen];
in.get(bs);
abstractGlobalEndRequest.setXid(new String(bs, UTF8));
}
short len = in.getShort();
if (len > 0) {
byte[] bs = new byte[len];
in.get(bs);
abstractGlobalEndRequest.setExtraData(new String(bs, UTF8));
}
}
}

View File

@@ -0,0 +1,54 @@
/*
* 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.seata.protocol.transaction;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.model.GlobalStatus;
import io.seata.core.protocol.transaction.AbstractGlobalEndResponse;
/**
* The type Abstract global end response codec.
*
* @author zhangsen
*/
public abstract class AbstractGlobalEndResponseCodec extends AbstractTransactionResponseCodec {
@Override
public Class<?> getMessageClassType() {
return AbstractGlobalEndResponse.class;
}
@Override
public <T> void encode(T t, ByteBuf in) {
super.encode(t, in);
AbstractGlobalEndResponse abstractGlobalEndResponse = (AbstractGlobalEndResponse)t;
GlobalStatus globalStatus = abstractGlobalEndResponse.getGlobalStatus();
in.writeByte(globalStatus.getCode());
}
@Override
public <T> void decode(T t, ByteBuffer in) {
super.decode(t, in);
AbstractGlobalEndResponse abstractGlobalEndResponse = (AbstractGlobalEndResponse)t;
abstractGlobalEndResponse.setGlobalStatus(GlobalStatus.get(in.get()));
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.protocol.AbstractMessageCodec;
import io.seata.core.protocol.transaction.AbstractTransactionRequest;
/**
* The type Abstract transaction request codec.
*
* @author zhangsen
*/
public abstract class AbstractTransactionRequestCodec extends AbstractMessageCodec {
@Override
public Class<?> getMessageClassType() {
return AbstractTransactionRequest.class;
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.AbstractTransactionRequestToRM;
/**
* The type Abstract transaction request to rm codec.
*
* @author zhangsen
*/
public abstract class AbstractTransactionRequestToRMCodec extends AbstractTransactionRequestCodec {
@Override
public Class<?> getMessageClassType() {
return AbstractTransactionRequestToRM.class;
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.AbstractTransactionRequestToTC;
/**
* The type Abstract transaction request to tc codec.
*
* @author zhangsen
*/
public abstract class AbstractTransactionRequestToTCCodec extends AbstractTransactionRequestCodec {
@Override
public Class<?> getMessageClassType() {
return AbstractTransactionRequestToTC.class;
}
}

View File

@@ -0,0 +1,54 @@
/*
* 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.seata.protocol.transaction;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.serializer.seata.protocol.AbstractResultMessageCodec;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.protocol.transaction.AbstractTransactionResponse;
/**
* The type Abstract transaction response codec.
*
* @author zhangsen
*/
public abstract class AbstractTransactionResponseCodec extends AbstractResultMessageCodec {
@Override
public Class<?> getMessageClassType() {
return AbstractTransactionResponse.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
super.encode(t, out);
AbstractTransactionResponse abstractTransactionResponse = (AbstractTransactionResponse)t;
TransactionExceptionCode transactionExceptionCode = abstractTransactionResponse.getTransactionExceptionCode();
out.writeByte(transactionExceptionCode.ordinal());
}
@Override
public <T> void decode(T t, ByteBuffer out) {
super.decode(t, out);
AbstractTransactionResponse abstractTransactionResponse = (AbstractTransactionResponse)t;
abstractTransactionResponse.setTransactionExceptionCode(TransactionExceptionCode.get(out.get()));
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.BranchCommitRequest;
/**
* The type Branch commit request codec.
*
* @author zhangsen
*/
public class BranchCommitRequestCodec extends AbstractBranchEndRequestCodec {
@Override
public Class<?> getMessageClassType() {
return BranchCommitRequest.class;
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.BranchCommitResponse;
/**
* The type Branch commit response codec.
*
* @author zhangsen
*/
public class BranchCommitResponseCodec extends AbstractBranchEndResponseCodec {
@Override
public Class<?> getMessageClassType() {
return BranchCommitResponse.class;
}
}

View File

@@ -0,0 +1,133 @@
/*
* 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.seata.protocol.transaction;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.model.BranchType;
import io.seata.core.protocol.transaction.BranchRegisterRequest;
/**
* The type Branch register request codec.
*
* @author zhangsen
*/
public class BranchRegisterRequestCodec extends AbstractTransactionRequestToTCCodec {
@Override
public Class<?> getMessageClassType() {
return BranchRegisterRequest.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
BranchRegisterRequest branchRegisterRequest = (BranchRegisterRequest)t;
String xid = branchRegisterRequest.getXid();
BranchType branchType = branchRegisterRequest.getBranchType();
String resourceId = branchRegisterRequest.getResourceId();
String lockKey = branchRegisterRequest.getLockKey();
String applicationData = branchRegisterRequest.getApplicationData();
byte[] lockKeyBytes = null;
if (lockKey != null) {
lockKeyBytes = lockKey.getBytes(UTF8);
}
byte[] applicationDataBytes = null;
if (applicationData != null) {
applicationDataBytes = applicationData.getBytes(UTF8);
}
// 1. xid
if (xid != null) {
byte[] bs = xid.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
// 2. Branch Type
out.writeByte(branchType.ordinal());
// 3. Resource Id
if (resourceId != null) {
byte[] bs = resourceId.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
// 4. Lock Key
if (lockKey != null) {
out.writeInt(lockKeyBytes.length);
if (lockKeyBytes.length > 0) {
out.writeBytes(lockKeyBytes);
}
} else {
out.writeInt(0);
}
//5. applicationData
if (applicationData != null) {
out.writeInt(applicationDataBytes.length);
if (applicationDataBytes.length > 0) {
out.writeBytes(applicationDataBytes);
}
} else {
out.writeInt(0);
}
}
@Override
public <T> void decode(T t, ByteBuffer in) {
BranchRegisterRequest branchRegisterRequest = (BranchRegisterRequest)t;
short xidLen = in.getShort();
if (xidLen > 0) {
byte[] bs = new byte[xidLen];
in.get(bs);
branchRegisterRequest.setXid(new String(bs, UTF8));
}
branchRegisterRequest.setBranchType(BranchType.get(in.get()));
short len = in.getShort();
if (len > 0) {
byte[] bs = new byte[len];
in.get(bs);
branchRegisterRequest.setResourceId(new String(bs, UTF8));
}
int iLen = in.getInt();
if (iLen > 0) {
byte[] bs = new byte[iLen];
in.get(bs);
branchRegisterRequest.setLockKey(new String(bs, UTF8));
}
int applicationDataLen = in.getInt();
if (applicationDataLen > 0) {
byte[] bs = new byte[applicationDataLen];
in.get(bs);
branchRegisterRequest.setApplicationData(new String(bs, UTF8));
}
}
}

View File

@@ -0,0 +1,53 @@
/*
* 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.seata.protocol.transaction;
import java.io.Serializable;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.protocol.transaction.BranchRegisterResponse;
/**
* The type Branch register response codec.
*
* @author zhangsen
*/
public class BranchRegisterResponseCodec extends AbstractTransactionResponseCodec implements Serializable {
@Override
public Class<?> getMessageClassType() {
return BranchRegisterResponse.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
super.encode(t, out);
BranchRegisterResponse branchRegisterResponse = (BranchRegisterResponse)t;
long branchId = branchRegisterResponse.getBranchId();
out.writeLong(branchId);
}
@Override
public <T> void decode(T t, ByteBuffer in) {
super.decode(t, in);
BranchRegisterResponse branchRegisterResponse = (BranchRegisterResponse)t;
branchRegisterResponse.setBranchId(in.getLong());
}
}

View File

@@ -0,0 +1,118 @@
/*
* 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.seata.protocol.transaction;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.model.BranchStatus;
import io.seata.core.model.BranchType;
import io.seata.core.protocol.transaction.BranchReportRequest;
/**
* The type Branch report request codec.
*
* @author zhangsen
*/
public class BranchReportRequestCodec extends AbstractTransactionRequestToTCCodec {
@Override
public Class<?> getMessageClassType() {
return BranchReportRequest.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
BranchReportRequest branchReportRequest = (BranchReportRequest)t;
String xid = branchReportRequest.getXid();
long branchId = branchReportRequest.getBranchId();
BranchStatus status = branchReportRequest.getStatus();
String resourceId = branchReportRequest.getResourceId();
String applicationData = branchReportRequest.getApplicationData();
BranchType branchType = branchReportRequest.getBranchType();
byte[] applicationDataBytes = null;
if (applicationData != null) {
applicationDataBytes = applicationData.getBytes(UTF8);
}
// 1. xid
if (xid != null) {
byte[] bs = xid.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
// 2. Branch Id
out.writeLong(branchId);
// 3. Branch Status
out.writeByte(status.getCode());
// 4. Resource Id
if (resourceId != null) {
byte[] bs = resourceId.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
// 5. Application Data
if (applicationData != null) {
out.writeInt(applicationDataBytes.length);
if (applicationDataBytes.length > 0) {
out.writeBytes(applicationDataBytes);
}
} else {
out.writeInt(0);
}
//6. branchType
out.writeByte(branchType.ordinal());
}
@Override
public <T> void decode(T t, ByteBuffer in) {
BranchReportRequest branchReportRequest = (BranchReportRequest)t;
short xidLen = in.getShort();
if (xidLen > 0) {
byte[] bs = new byte[xidLen];
in.get(bs);
branchReportRequest.setXid(new String(bs, UTF8));
}
branchReportRequest.setBranchId(in.getLong());
branchReportRequest.setStatus(BranchStatus.get(in.get()));
short len = in.getShort();
if (len > 0) {
byte[] bs = new byte[len];
in.get(bs);
branchReportRequest.setResourceId(new String(bs, UTF8));
}
int iLen = in.getInt();
if (iLen > 0) {
byte[] bs = new byte[iLen];
in.get(bs);
branchReportRequest.setApplicationData(new String(bs, UTF8));
}
branchReportRequest.setBranchType(BranchType.get(in.get()));
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.BranchReportResponse;
/**
* The type Branch report response codec.
*
* @author zhangsen
*/
public class BranchReportResponseCodec extends AbstractTransactionResponseCodec {
@Override
public Class<?> getMessageClassType() {
return BranchReportResponse.class;
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.BranchRollbackRequest;
/**
* The type Branch rollback request codec.
*
* @author zhangsen
*/
public class BranchRollbackRequestCodec extends AbstractBranchEndRequestCodec {
@Override
public Class<?> getMessageClassType() {
return BranchRollbackRequest.class;
}
}

View File

@@ -0,0 +1,33 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.BranchRollbackResponse;
/**
* The type Branch rollback response codec.
*
* @author zhangsen
*/
public class BranchRollbackResponseCodec extends AbstractBranchEndResponseCodec {
@Override
public Class<?> getMessageClassType() {
return BranchRollbackResponse.class;
}
}

View File

@@ -0,0 +1,66 @@
/*
* 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.seata.protocol.transaction;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.protocol.transaction.GlobalBeginRequest;
/**
* The type Global begin request codec.
*
* @author zhangsen
*/
public class GlobalBeginRequestCodec extends AbstractTransactionRequestToTCCodec {
@Override
public Class<?> getMessageClassType() {
return GlobalBeginRequest.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
GlobalBeginRequest globalBeginRequest = (GlobalBeginRequest)t;
int timeout = globalBeginRequest.getTimeout();
String transactionName = globalBeginRequest.getTransactionName();
out.writeInt(timeout);
if (transactionName != null) {
byte[] bs = transactionName.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
}
@Override
public <T> void decode(T t, ByteBuffer in) {
GlobalBeginRequest globalBeginRequest = (GlobalBeginRequest)t;
globalBeginRequest.setTimeout(in.getInt());
short len = in.getShort();
if (len > 0) {
byte[] bs = new byte[len];
in.get(bs);
globalBeginRequest.setTransactionName(new String(bs, UTF8));
}
}
}

View File

@@ -0,0 +1,84 @@
/*
* 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.seata.protocol.transaction;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.protocol.transaction.GlobalBeginResponse;
/**
* The type Global begin response codec.
*
* @author zhangsen
*/
public class GlobalBeginResponseCodec extends AbstractTransactionResponseCodec {
@Override
public Class<?> getMessageClassType() {
return GlobalBeginResponse.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
super.encode(t, out);
GlobalBeginResponse globalBeginResponse = (GlobalBeginResponse)t;
String xid = globalBeginResponse.getXid();
String extraData = globalBeginResponse.getExtraData();
if (xid != null) {
byte[] bs = xid.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
if (extraData != null) {
byte[] bs = extraData.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
}
@Override
public <T> void decode(T t, ByteBuffer in) {
super.decode(t, in);
GlobalBeginResponse globalBeginResponse = (GlobalBeginResponse)t;
short len = in.getShort();
if (len > 0) {
byte[] bs = new byte[len];
in.get(bs);
globalBeginResponse.setXid(new String(bs, UTF8));
}
len = in.getShort();
if (len > 0) {
byte[] bs = new byte[len];
in.get(bs);
globalBeginResponse.setExtraData(new String(bs, UTF8));
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.GlobalCommitRequest;
/**
* The type Global commit request codec.
*
* @author zhangsen
*/
public class GlobalCommitRequestCodec extends AbstractGlobalEndRequestCodec {
@Override
public Class<?> getMessageClassType() {
return GlobalCommitRequest.class;
}
}

View File

@@ -0,0 +1,31 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.GlobalCommitResponse;
/**
* The type Global commit response codec.
*
* @author zhangsen
*/
public class GlobalCommitResponseCodec extends AbstractGlobalEndResponseCodec {
@Override
public Class<?> getMessageClassType() {
return GlobalCommitResponse.class;
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.GlobalLockQueryRequest;
/**
* The type Global lock query request codec.
*
* @author zhangsen
*/
public class GlobalLockQueryRequestCodec extends BranchRegisterRequestCodec {
@Override
public Class<?> getMessageClassType() {
return GlobalLockQueryRequest.class;
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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.seata.protocol.transaction;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.protocol.transaction.GlobalLockQueryResponse;
/**
* The type Global lock query response codec.
*
* @author zhangsen
*/
public class GlobalLockQueryResponseCodec extends AbstractTransactionResponseCodec {
@Override
public Class<?> getMessageClassType() {
return GlobalLockQueryResponse.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
super.encode(t, out);
GlobalLockQueryResponse globalLockQueryResponse = (GlobalLockQueryResponse)t;
boolean lockable = globalLockQueryResponse.isLockable();
out.writeShort((short)(lockable ? 1 : 0));
}
@Override
public <T> void decode(T t, ByteBuffer in) {
super.decode(t, in);
GlobalLockQueryResponse globalLockQueryResponse = (GlobalLockQueryResponse)t;
globalLockQueryResponse.setLockable(in.getShort() == 1);
}
}

View File

@@ -0,0 +1,59 @@
/*
* 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.seata.protocol.transaction;
import io.netty.buffer.ByteBuf;
import io.seata.core.model.GlobalStatus;
import io.seata.core.protocol.transaction.GlobalReportRequest;
import java.nio.ByteBuffer;
/**
* The type Global status report codec.
*
* @author lorne.cl
*/
public class GlobalReportRequestCodec extends AbstractGlobalEndRequestCodec {
@Override
public Class<?> getMessageClassType() {
return GlobalReportRequest.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
super.encode(t, out);
GlobalReportRequest reportRequest = (GlobalReportRequest)t;
GlobalStatus globalStatus = reportRequest.getGlobalStatus();
if (globalStatus != null) {
out.writeByte((byte)globalStatus.getCode());
} else {
out.writeByte((byte)-1);
}
}
@Override
public <T> void decode(T t, ByteBuffer in) {
super.decode(t, in);
GlobalReportRequest reportRequest = (GlobalReportRequest)t;
byte b = in.get();
if (b > -1) {
reportRequest.setGlobalStatus(GlobalStatus.get(b));
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.GlobalReportResponse;
/**
* The type Global report response codec.
*
* @author lorne.cl
*/
public class GlobalReportResponseCodec extends AbstractGlobalEndResponseCodec {
@Override
public Class<?> getMessageClassType() {
return GlobalReportResponse.class;
}
}

View File

@@ -0,0 +1,31 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.GlobalRollbackRequest;
/**
* The type Global rollback request codec.
*
* @author zhangsen
*/
public class GlobalRollbackRequestCodec extends AbstractGlobalEndRequestCodec {
@Override
public Class<?> getMessageClassType() {
return GlobalRollbackRequest.class;
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.GlobalRollbackResponse;
/**
* The type Global rollback response codec.
*
* @author zhangsen
*/
public class GlobalRollbackResponseCodec extends AbstractGlobalEndResponseCodec {
@Override
public Class<?> getMessageClassType() {
return GlobalRollbackResponse.class;
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.GlobalStatusRequest;
/**
* The type Global status request codec.
*
* @author zhangsen
*/
public class GlobalStatusRequestCodec extends AbstractGlobalEndRequestCodec {
@Override
public Class<?> getMessageClassType() {
return GlobalStatusRequest.class;
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.seata.protocol.transaction;
import io.seata.core.protocol.transaction.GlobalStatusResponse;
/**
* The type Global status response codec.
*
* @author zhangsen
*/
public class GlobalStatusResponseCodec extends AbstractGlobalEndResponseCodec {
@Override
public Class<?> getMessageClassType() {
return GlobalStatusResponse.class;
}
}

View File

@@ -0,0 +1,87 @@
/*
* 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.seata.protocol.transaction;
import java.nio.ByteBuffer;
import io.netty.buffer.ByteBuf;
import io.seata.core.model.BranchType;
import io.seata.core.protocol.transaction.UndoLogDeleteRequest;
/**
* The type UndoLog Delete end request codec.
*
* @author yuanguoyao
*/
public class UndoLogDeleteRequestCodec extends AbstractTransactionRequestToRMCodec {
@Override
public Class<?> getMessageClassType() {
return UndoLogDeleteRequest.class;
}
@Override
public <T> void encode(T t, ByteBuf out) {
UndoLogDeleteRequest undoLogDeleteRequest = (UndoLogDeleteRequest)t;
short saveDays = undoLogDeleteRequest.getSaveDays();
BranchType branchType = undoLogDeleteRequest.getBranchType();
String resourceId = undoLogDeleteRequest.getResourceId();
// 1. Branch Type
out.writeByte((byte)branchType.ordinal());
// 2. Resource Id
if (resourceId != null) {
byte[] bs = resourceId.getBytes(UTF8);
out.writeShort((short)bs.length);
if (bs.length > 0) {
out.writeBytes(bs);
}
} else {
out.writeShort((short)0);
}
//3.save days
out.writeShort(saveDays);
}
@Override
public <T> void decode(T t, ByteBuffer in) {
UndoLogDeleteRequest undoLogDeleteRequest = (UndoLogDeleteRequest)t;
if (in.remaining() < 1) {
return;
}
undoLogDeleteRequest.setBranchType(BranchType.get(in.get()));
if (in.remaining() < 2) {
return;
}
int resourceIdLen = in.getShort();
if (resourceIdLen <= 0 || in.remaining() < resourceIdLen) {
return;
}
byte[] bs = new byte[resourceIdLen];
in.get(bs);
undoLogDeleteRequest.setResourceId(new String(bs, UTF8));
if (in.remaining() < 2) {
return;
}
undoLogDeleteRequest.setSaveDays(in.getShort());
}
}

View File

@@ -0,0 +1 @@
io.seata.serializer.seata.SeataSerializer

View File

@@ -0,0 +1,84 @@
/*
* 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.seata.protocol;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.protocol.AbstractResultMessage;
import io.seata.core.protocol.MergeResultMessage;
import io.seata.core.protocol.ResultCode;
import io.seata.core.protocol.transaction.GlobalBeginResponse;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Merge result message codec test.
*
* @author zhangsen
*/
public class MergeResultMessageSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
MergeResultMessage mergeResultMessage = new MergeResultMessage();
final AbstractResultMessage[] msgs = new AbstractResultMessage[2];
final GlobalBeginResponse globalBeginResponse1 = buildGlobalBeginResponse("a1");
final GlobalBeginResponse globalBeginResponse2 = buildGlobalBeginResponse("a2");
msgs[0] = globalBeginResponse1;
msgs[1] = globalBeginResponse2;
mergeResultMessage.setMsgs(msgs);
byte[] body = seataSerializer.serialize(mergeResultMessage);
MergeResultMessage mergeResultMessage2 = seataSerializer.deserialize(body);
assertThat(mergeResultMessage2.msgs.length).isEqualTo(mergeResultMessage.msgs.length);
GlobalBeginResponse globalBeginResponse21 = (GlobalBeginResponse) mergeResultMessage2.msgs[0];
assertThat(globalBeginResponse21.getXid()).isEqualTo(globalBeginResponse1.getXid());
assertThat(globalBeginResponse21.getExtraData()).isEqualTo(globalBeginResponse1.getExtraData());
assertThat(globalBeginResponse21.getMsg()).isEqualTo(globalBeginResponse1.getMsg());
assertThat(globalBeginResponse21.getResultCode()).isEqualTo(globalBeginResponse1.getResultCode());
assertThat(globalBeginResponse21.getTransactionExceptionCode()).isEqualTo(globalBeginResponse1.getTransactionExceptionCode());
GlobalBeginResponse globalBeginResponse22 = (GlobalBeginResponse) mergeResultMessage2.msgs[1];
assertThat(globalBeginResponse22.getXid()).isEqualTo(globalBeginResponse2.getXid());
assertThat(globalBeginResponse22.getExtraData()).isEqualTo(globalBeginResponse2.getExtraData());
assertThat(globalBeginResponse22.getMsg()).isEqualTo(globalBeginResponse2.getMsg());
assertThat(globalBeginResponse22.getResultCode()).isEqualTo(globalBeginResponse2.getResultCode());
assertThat(globalBeginResponse22.getTransactionExceptionCode()).isEqualTo(globalBeginResponse2.getTransactionExceptionCode());
}
private GlobalBeginResponse buildGlobalBeginResponse(String xid) {
final GlobalBeginResponse globalBeginResponse = new GlobalBeginResponse();
globalBeginResponse.setXid(xid);
globalBeginResponse.setExtraData("data");
globalBeginResponse.setMsg("success");
globalBeginResponse.setResultCode(ResultCode.Failed);
globalBeginResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
return globalBeginResponse;
}
}

View File

@@ -0,0 +1,76 @@
/*
* 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.seata.protocol;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.protocol.AbstractMessage;
import io.seata.core.protocol.MergedWarpMessage;
import io.seata.core.protocol.transaction.GlobalBeginRequest;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
/**
* The type Merged warp message codec test.
*
* @author zhangsen
*/
public class MergedWarpMessageSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
MergedWarpMessage mergedWarpMessage = new MergedWarpMessage();
final ArrayList<AbstractMessage> msgs = new ArrayList<>();
final GlobalBeginRequest globalBeginRequest1 = buildGlobalBeginRequest("x1");
final GlobalBeginRequest globalBeginRequest2 = buildGlobalBeginRequest("x2");
msgs.add(globalBeginRequest1);
msgs.add(globalBeginRequest2);
mergedWarpMessage.msgs = msgs;
byte[] body = seataSerializer.serialize(mergedWarpMessage);
MergedWarpMessage mergedWarpMessage2 = seataSerializer.deserialize(body);
assertThat(mergedWarpMessage2.msgs.size()).isEqualTo(mergedWarpMessage.msgs.size());
GlobalBeginRequest globalBeginRequest21 = (GlobalBeginRequest) mergedWarpMessage2.msgs.get(0);
assertThat(globalBeginRequest21.getTimeout()).isEqualTo(globalBeginRequest1.getTimeout());
assertThat(globalBeginRequest21.getTransactionName()).isEqualTo(globalBeginRequest1.getTransactionName());
GlobalBeginRequest globalBeginRequest22 = (GlobalBeginRequest) mergedWarpMessage2.msgs.get(1);
assertThat(globalBeginRequest22.getTimeout()).isEqualTo(globalBeginRequest2.getTimeout());
assertThat(globalBeginRequest22.getTransactionName()).isEqualTo(globalBeginRequest2.getTransactionName());
}
private GlobalBeginRequest buildGlobalBeginRequest(String name) {
final GlobalBeginRequest globalBeginRequest = new GlobalBeginRequest();
globalBeginRequest.setTransactionName(name);
globalBeginRequest.setTimeout(3000);
return globalBeginRequest;
}
}

View File

@@ -0,0 +1,59 @@
/*
* 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.seata.protocol;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.protocol.RegisterRMRequest;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Register rm request codec test.
*
* @author zhangsen
*/
public class RegisterRMRequestSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec() {
RegisterRMRequest registerRMRequest = new RegisterRMRequest();
registerRMRequest.setResourceIds("a1,a2");
registerRMRequest.setApplicationId("abc");
registerRMRequest.setExtraData("abc124");
registerRMRequest.setTransactionServiceGroup("def");
registerRMRequest.setVersion("1");
byte[] body = seataSerializer.serialize(registerRMRequest);
RegisterRMRequest registerRMRequest2 = seataSerializer.deserialize(body);
assertThat(registerRMRequest2.getResourceIds()).isEqualTo(registerRMRequest.getResourceIds());
assertThat(registerRMRequest2.getExtraData()).isEqualTo(registerRMRequest.getExtraData());
assertThat(registerRMRequest2.getApplicationId()).isEqualTo(registerRMRequest.getApplicationId());
assertThat(registerRMRequest2.getVersion()).isEqualTo(registerRMRequest.getVersion());
assertThat(registerRMRequest2.getTransactionServiceGroup()).isEqualTo(registerRMRequest.getTransactionServiceGroup());
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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.seata.protocol;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.protocol.RegisterRMResponse;
import io.seata.core.protocol.ResultCode;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Register rm response codec test.
*
* @author zhangsen
*/
public class RegisterRMResponseSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
RegisterRMResponse registerRMResponse = new RegisterRMResponse();
registerRMResponse.setExtraData("abc123");
registerRMResponse.setIdentified(true);
registerRMResponse.setMsg("123456");
registerRMResponse.setVersion("12");
registerRMResponse.setResultCode(ResultCode.Failed);
byte[] body = seataSerializer.serialize(registerRMResponse);
RegisterRMResponse registerRMRespons2 = seataSerializer.deserialize(body);
assertThat(registerRMRespons2.isIdentified()).isEqualTo(registerRMResponse.isIdentified());
assertThat(registerRMRespons2.getVersion()).isEqualTo(registerRMResponse.getVersion());
// Assert.assertEquals(registerRMRespons2.getExtraData(), registerRMResponse.getExtraData());
// Assert.assertEquals(registerRMRespons2.getMsg(), registerRMResponse.getMsg());
// Assert.assertEquals(registerRMRespons2.getByCode(), registerRMResponse.getByCode());
}
}

View File

@@ -0,0 +1,249 @@
/*
* 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.seata.protocol;
import io.netty.buffer.ByteBuf;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.protocol.AbstractIdentifyRequest;
import io.seata.core.protocol.RegisterTMRequest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static io.netty.buffer.Unpooled.buffer;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Register tm request codec test.
*
* @author zhangsen
*/
public class RegisterTMRequestSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
private static RegisterTMRequest registerTMRequest;
private static AbstractIdentifyRequest air;
private static final String APP_ID = "applicationId";
private static final String TSG = "transactionServiceGroup";
private static final String ED = "extraData";
private static final short TYPE_CODE = 101;
private static final ByteBuf BB = buffer(128);
/**
* Test codec.
*/
@Test
public void test_codec() {
RegisterTMRequest registerTMRequest = new RegisterTMRequest();
registerTMRequest.setApplicationId("abc");
registerTMRequest.setExtraData("abc123");
registerTMRequest.setTransactionServiceGroup("def");
registerTMRequest.setVersion("1");
byte[] body = seataSerializer.serialize(registerTMRequest);
RegisterTMRequest registerTMRequest2 = seataSerializer.deserialize(body);
assertThat(registerTMRequest2.getApplicationId()).isEqualTo(registerTMRequest.getApplicationId());
assertThat(registerTMRequest2.getExtraData()).isEqualTo(registerTMRequest.getExtraData());
assertThat(registerTMRequest2.getTransactionServiceGroup()).isEqualTo(registerTMRequest.getTransactionServiceGroup());
assertThat(registerTMRequest2.getVersion()).isEqualTo(registerTMRequest.getVersion());
}
/**
* Constructor without arguments
**/
@BeforeAll
public static void setupNull() {
registerTMRequest = new RegisterTMRequest();
air = Mockito.mock(
AbstractIdentifyRequest.class,
Mockito.CALLS_REAL_METHODS);
}
/**
* Constructor with arguments
**/
@BeforeAll
public static void setupWithValues() {
registerTMRequest = new RegisterTMRequest(APP_ID, TSG, ED);
air = Mockito.mock(
AbstractIdentifyRequest.class,
Mockito.CALLS_REAL_METHODS);
}
/**
* Test get type code
**/
@Test
public void testGetTypeCode() {
Assertions.assertEquals(TYPE_CODE, registerTMRequest.getTypeCode());
}
/**
* Test toString having all the parameters initialized to null
*/
@Test
public void testToStringNullValues() {
Assertions.assertEquals("RegisterTMRequest{" + "applicationId='" + null + '\'' + ", transactionServiceGroup='"
+ null + '\'' + '}', registerTMRequest.toString());
}
/**
* Test decode method with empty parameter
*/
@Test
public void testDecodeEmpty() {
BB.clear();
try {
seataSerializer.deserialize(BB.array());
Assertions.fail();
} catch (Exception e) {
Assertions.assertTrue(e.getMessage().contains("not support "), "error data");
}
}
/**
* Test decode method with initialized parameter
*/
@Test
public void testDecodeLessThanTwo() {
BB.clear();
for (int i = 0; i < 2; i++) {
BB.writeShort(i);
}
try {
seataSerializer.deserialize(BB.array());
Assertions.fail();
} catch (Exception e) {
Assertions.assertTrue(e.getMessage().contains("not support "), "error data");
}
}
/**
* Test decode method with initialized parameter
*/
@Test
public void testDecodeMoreThanThree() {
BB.clear();
for (int i = 0; i < 3; i++) {
BB.writeShort(i);
}
try {
seataSerializer.deserialize(BB.array());
Assertions.fail();
} catch (Exception e) {
Assertions.assertTrue(e.getMessage().contains("not support "), "error data");
}
}
/**
* Test decode method with initialized parameter
*/
@Test
public void testDecodeLessThanFour() {
BB.clear();
for (int i = 0; i < 4; i++) {
BB.writeShort(i);
}
try {
seataSerializer.deserialize(BB.array());
Assertions.fail();
} catch (Exception e) {
Assertions.assertTrue(e.getMessage().contains("not support "), "error data");
}
}
/**
* Test decode method with initialized parameter
*/
@Test
public void testDecodeMoreLessThanOne() {
BB.clear();
for (int i = 0; i < 1; i++) {
BB.writeShort(i);
}
try {
seataSerializer.deserialize(BB.array());
Assertions.fail();
} catch (Exception e) {
Assertions.assertTrue(e.getMessage().contains("not support "), "error data");
}
}
/**
* Test decode method with initialized parameter
*/
@Test
public void testDecodeMoreLessThanFourWithZero() {
BB.clear();
for (int i = 0; i < 4; i++) {
BB.writeZero(i);
}
try {
seataSerializer.deserialize(BB.array());
Assertions.fail();
} catch (Exception e) {
Assertions.assertTrue(e.getMessage().contains("not support "), "error data");
}
}
/**
* Test decode method with initialized parameter
*/
@Test
public void testDecodeTrueLessThanFive() {
BB.clear();
for (int i = 0; i < 4; i++) {
BB.writeZero(i);
}
for (int i = 4; i < 5; i++) {
BB.writeShort(i);
}
try {
seataSerializer.deserialize(BB.array());
Assertions.fail();
} catch (Exception e) {
Assertions.assertTrue(e.getMessage().contains("not support "), "error data");
}
}
/**
* Test decode method with initialized parameter
*/
@Test
public void testDecodeTrueLessThanSixteen() {
BB.clear();
for (int i = 0; i < 15; i++) {
BB.writeZero(i);
}
for (int i = 15; i < 16; i++) {
BB.writeShort(i);
}
try {
seataSerializer.deserialize(BB.array());
Assertions.fail();
} catch (Exception e) {
Assertions.assertTrue(e.getMessage().contains("not support "), "error data");
}
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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.seata.protocol;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.protocol.RegisterTMResponse;
import io.seata.core.protocol.ResultCode;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Register tm response codec test.
*
* @author zhangsen
*/
public class RegisterTMResponseSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
RegisterTMResponse registerTMResponse = new RegisterTMResponse();
registerTMResponse.setVersion("abc");
registerTMResponse.setExtraData("abc123");
registerTMResponse.setIdentified(true);
registerTMResponse.setMsg("123456");
registerTMResponse.setResultCode(ResultCode.Failed);
byte[] bytes = seataSerializer.serialize(registerTMResponse);
RegisterTMResponse registerTMResponse2 = seataSerializer.deserialize(bytes);
assertThat(registerTMResponse2.isIdentified()).isEqualTo(registerTMResponse.isIdentified());
assertThat(registerTMResponse2.getVersion()).isEqualTo(registerTMResponse.getVersion());
// Assert.assertEquals(registerTMResponse2.getExtraData(), registerTMResponse.getExtraData());
// Assert.assertEquals(registerTMResponse2.getMsg(), registerTMResponse.getMsg());
// Assert.assertEquals(registerTMResponse2.getByCode(), registerTMResponse.getByCode());
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.model.BranchType;
import io.seata.core.protocol.transaction.BranchCommitRequest;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Branch commit request codec test.
*
* @author zhangsen
*/
public class BranchCommitRequestSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
BranchCommitRequest branchCommitRequest = new BranchCommitRequest();
branchCommitRequest.setApplicationData("abc");
branchCommitRequest.setBranchId(123);
branchCommitRequest.setBranchType(BranchType.AT);
branchCommitRequest.setResourceId("t");
branchCommitRequest.setXid("a3");
byte[] bytes = seataSerializer.serialize(branchCommitRequest);
BranchCommitRequest branchCommitReques2 = seataSerializer.deserialize(bytes);
assertThat(branchCommitReques2.getApplicationData()).isEqualTo(branchCommitRequest.getApplicationData());
assertThat(branchCommitReques2.getBranchType()).isEqualTo(branchCommitRequest.getBranchType());
assertThat(branchCommitReques2.getBranchId()).isEqualTo(branchCommitRequest.getBranchId());
assertThat(branchCommitReques2.getResourceId()).isEqualTo(branchCommitRequest.getResourceId());
assertThat(branchCommitReques2.getXid()).isEqualTo(branchCommitRequest.getXid());
}
}

View File

@@ -0,0 +1,63 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.model.BranchStatus;
import io.seata.core.protocol.ResultCode;
import io.seata.core.protocol.transaction.BranchCommitResponse;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Branch commit response codec test.
*
* @author zhangsen
*/
public class BranchCommitResponseSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
BranchCommitResponse branchCommitResponse = new BranchCommitResponse();
branchCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
branchCommitResponse.setBranchId(123);
branchCommitResponse.setBranchStatus(BranchStatus.PhaseOne_Done);
branchCommitResponse.setMsg("abc");
branchCommitResponse.setXid("a3");
branchCommitResponse.setResultCode(ResultCode.Failed);
byte[] bytes = seataSerializer.serialize(branchCommitResponse);
BranchCommitResponse branchCommitResponse2 = seataSerializer.deserialize(bytes);
assertThat(branchCommitResponse2.getBranchStatus()).isEqualTo(branchCommitResponse.getBranchStatus());
assertThat(branchCommitResponse2.getBranchId()).isEqualTo(branchCommitResponse.getBranchId());
assertThat(branchCommitResponse2.getMsg()).isEqualTo(branchCommitResponse.getMsg());
assertThat(branchCommitResponse2.getXid()).isEqualTo(branchCommitResponse.getXid());
assertThat(branchCommitResponse2.getResultCode()).isEqualTo(branchCommitResponse.getResultCode());
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.model.BranchType;
import io.seata.core.protocol.transaction.BranchRegisterRequest;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Branch register request codec test.
*
* @author zhangsen
*/
public class BranchRegisterRequestSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
BranchRegisterRequest branchRegisterRequest = new BranchRegisterRequest();
branchRegisterRequest.setBranchType(BranchType.AT);
branchRegisterRequest.setApplicationData("abc");
branchRegisterRequest.setLockKey("a:1,b:2");
branchRegisterRequest.setResourceId("124");
branchRegisterRequest.setXid("abc134");
byte[] bytes = seataSerializer.serialize(branchRegisterRequest);
BranchRegisterRequest branchRegisterRequest2 = seataSerializer.deserialize(bytes);
assertThat(branchRegisterRequest2.getBranchType()).isEqualTo(branchRegisterRequest.getBranchType());
assertThat(branchRegisterRequest2.getApplicationData()).isEqualTo(branchRegisterRequest.getApplicationData());
assertThat(branchRegisterRequest2.getLockKey()).isEqualTo(branchRegisterRequest.getLockKey());
assertThat(branchRegisterRequest2.getResourceId()).isEqualTo(branchRegisterRequest.getResourceId());
assertThat(branchRegisterRequest2.getXid()).isEqualTo(branchRegisterRequest.getXid());
}
}

View File

@@ -0,0 +1,59 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.protocol.ResultCode;
import io.seata.core.protocol.transaction.BranchRegisterResponse;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Branch register response codec test.
*
* @author zhangsen
*/
public class BranchRegisterResponseSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
BranchRegisterResponse branchRegisterResponse = new BranchRegisterResponse();
branchRegisterResponse.setBranchId(1346);
branchRegisterResponse.setMsg("addd");
branchRegisterResponse.setResultCode(ResultCode.Failed);
branchRegisterResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
byte[] bytes = seataSerializer.serialize(branchRegisterResponse);
BranchRegisterResponse branchRegisterResponse2 = seataSerializer.deserialize(bytes);
assertThat(branchRegisterResponse2.getBranchId()).isEqualTo(branchRegisterResponse.getBranchId());
assertThat(branchRegisterResponse2.getMsg()).isEqualTo(branchRegisterResponse.getMsg());
assertThat(branchRegisterResponse2.getResultCode()).isEqualTo(branchRegisterResponse.getResultCode());
assertThat(branchRegisterResponse2.getTransactionExceptionCode()).isEqualTo(branchRegisterResponse.getTransactionExceptionCode());
}
}

View File

@@ -0,0 +1,62 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.model.BranchStatus;
import io.seata.core.model.BranchType;
import io.seata.core.protocol.transaction.BranchReportRequest;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Branch report request codec test.
*
* @author zhangsen
*/
public class BranchReportRequestSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
BranchReportRequest branchReportRequest = new BranchReportRequest();
branchReportRequest.setBranchId(1346);
branchReportRequest.setBranchType(BranchType.TCC);
branchReportRequest.setApplicationData("acds");
branchReportRequest.setResourceId("aaa");
branchReportRequest.setStatus(BranchStatus.PhaseOne_Done);
branchReportRequest.setXid("abc123");
byte[] bytes = seataSerializer.serialize(branchReportRequest);
BranchReportRequest branchReportRequest2 = seataSerializer.deserialize(bytes);
assertThat(branchReportRequest2.getBranchId()).isEqualTo(branchReportRequest.getBranchId());
assertThat(branchReportRequest2.getBranchType()).isEqualTo(branchReportRequest.getBranchType());
assertThat(branchReportRequest2.getApplicationData()).isEqualTo(branchReportRequest.getApplicationData());
assertThat(branchReportRequest2.getResourceId()).isEqualTo(branchReportRequest.getResourceId());
assertThat(branchReportRequest2.getStatus()).isEqualTo(branchReportRequest.getStatus());
assertThat(branchReportRequest2.getXid()).isEqualTo(branchReportRequest.getXid());
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.protocol.ResultCode;
import io.seata.core.protocol.transaction.BranchReportResponse;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Branch report response codec test.
*
* @author zhangsen
*/
public class BranchReportResponseSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
BranchReportResponse branchReportResponse = new BranchReportResponse();
branchReportResponse.setMsg("abac");
branchReportResponse.setResultCode(ResultCode.Failed);
branchReportResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
byte[] bytes = seataSerializer.serialize(branchReportResponse);
BranchReportResponse branchReportResponse2 = seataSerializer.deserialize(bytes);
assertThat(branchReportResponse2.getMsg()).isEqualTo(branchReportResponse.getMsg());
assertThat(branchReportResponse2.getResultCode()).isEqualTo(branchReportResponse.getResultCode());
assertThat(branchReportResponse2.getTransactionExceptionCode()).isEqualTo(branchReportResponse.getTransactionExceptionCode());
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.model.BranchType;
import io.seata.core.protocol.transaction.BranchRollbackRequest;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Branch rollback request codec test.
*
* @author zhangsen
*/
public class BranchRollbackRequestSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
BranchRollbackRequest branchRollbackRequest = new BranchRollbackRequest();
branchRollbackRequest.setApplicationData("abcd");
branchRollbackRequest.setBranchId(112232);
branchRollbackRequest.setBranchType(BranchType.TCC);
branchRollbackRequest.setResourceId("343");
branchRollbackRequest.setXid("123");
byte[] bytes = seataSerializer.serialize(branchRollbackRequest);
BranchRollbackRequest branchRollbackRequest2 = seataSerializer.deserialize(bytes);
assertThat(branchRollbackRequest2.getApplicationData()).isEqualTo(branchRollbackRequest.getApplicationData());
assertThat(branchRollbackRequest2.getBranchId()).isEqualTo(branchRollbackRequest.getBranchId());
assertThat(branchRollbackRequest2.getBranchType()).isEqualTo(branchRollbackRequest.getBranchType());
assertThat(branchRollbackRequest2.getResourceId()).isEqualTo(branchRollbackRequest.getResourceId());
assertThat(branchRollbackRequest2.getXid()).isEqualTo(branchRollbackRequest.getXid());
}
}

View File

@@ -0,0 +1,64 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.model.BranchStatus;
import io.seata.core.protocol.ResultCode;
import io.seata.core.protocol.transaction.BranchRollbackResponse;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Branch rollback response codec test.
*
* @author zhangsen
*/
public class BranchRollbackResponseSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
BranchRollbackResponse branchRollbackResponse = new BranchRollbackResponse();
branchRollbackResponse.setBranchId(112232);
branchRollbackResponse.setXid("123");
branchRollbackResponse.setBranchStatus(BranchStatus.PhaseOne_Done);
branchRollbackResponse.setResultCode(ResultCode.Success);
branchRollbackResponse.setMsg("abc");
branchRollbackResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
byte[] bytes = seataSerializer.serialize(branchRollbackResponse);
BranchRollbackResponse branchRollbackResponse2 = seataSerializer.deserialize(bytes);
assertThat(branchRollbackResponse2.getBranchId()).isEqualTo(branchRollbackResponse.getBranchId());
assertThat(branchRollbackResponse2.getBranchStatus()).isEqualTo(branchRollbackResponse.getBranchStatus());
assertThat(branchRollbackResponse2.getResultCode()).isEqualTo(branchRollbackResponse.getResultCode());
assertThat(branchRollbackResponse2.getXid()).isEqualTo(branchRollbackResponse.getXid());
assertThat(branchRollbackResponse2.getBranchStatus()).isEqualTo(branchRollbackResponse.getBranchStatus());
assertThat(branchRollbackResponse2.getTransactionExceptionCode()).isEqualTo(branchRollbackResponse.getTransactionExceptionCode());
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.protocol.transaction.GlobalBeginRequest;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Global begin request codec test.
*
* @author zhangsen
*/
public class GlobalBeginRequestSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
GlobalBeginRequest globalBeginRequest = new GlobalBeginRequest();
globalBeginRequest.setTimeout(10);
globalBeginRequest.setTransactionName("a24");
byte[] bytes = seataSerializer.serialize(globalBeginRequest);
GlobalBeginRequest globalBeginRequest2 = seataSerializer.deserialize(bytes);
assertThat(globalBeginRequest2.getTransactionName()).isEqualTo(globalBeginRequest.getTransactionName());
assertThat(globalBeginRequest2.getTimeout()).isEqualTo(globalBeginRequest.getTimeout());
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.protocol.ResultCode;
import io.seata.core.protocol.transaction.GlobalBeginResponse;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Global begin response codec test.
*
* @author zhangsen
*/
public class GlobalBeginResponseSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
GlobalBeginResponse globalBeginResponse = new GlobalBeginResponse();
globalBeginResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionNotActive);
globalBeginResponse.setExtraData("absd");
globalBeginResponse.setXid("2454");
globalBeginResponse.setResultCode(ResultCode.Failed);
globalBeginResponse.setMsg("abcs");
byte[] bytes = seataSerializer.serialize(globalBeginResponse);
GlobalBeginResponse globalBeginResponse2 = seataSerializer.deserialize(bytes);
assertThat(globalBeginResponse2.getTransactionExceptionCode()).isEqualTo(globalBeginResponse.getTransactionExceptionCode());
assertThat(globalBeginResponse2.getResultCode()).isEqualTo(globalBeginResponse.getResultCode());
assertThat(globalBeginResponse2.getXid()).isEqualTo(globalBeginResponse.getXid());
assertThat(globalBeginResponse2.getExtraData()).isEqualTo(globalBeginResponse.getExtraData());
assertThat(globalBeginResponse2.getMsg()).isEqualTo(globalBeginResponse.getMsg());
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.protocol.transaction.GlobalCommitRequest;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Global commit request codec test.
*
* @author zhangsen
*/
public class GlobalCommitRequestCodecTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
GlobalCommitRequest globalCommitRequest = new GlobalCommitRequest();
globalCommitRequest.setExtraData("aaaa");
globalCommitRequest.setXid("adf");
byte[] bytes = seataSerializer.serialize(globalCommitRequest);
GlobalCommitRequest globalCommitRequest2 = seataSerializer.deserialize(bytes);
assertThat(globalCommitRequest2.getExtraData()).isEqualTo(globalCommitRequest.getExtraData());
assertThat(globalCommitRequest2.getXid()).isEqualTo(globalCommitRequest.getXid());
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.model.GlobalStatus;
import io.seata.core.protocol.ResultCode;
import io.seata.core.protocol.transaction.GlobalCommitResponse;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Global commit response codec test.
*
* @author zhangsen
*/
public class GlobalCommitResponseSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
GlobalCommitResponse globalCommitResponse = new GlobalCommitResponse();
globalCommitResponse.setGlobalStatus(GlobalStatus.AsyncCommitting);
globalCommitResponse.setMsg("aaa");
globalCommitResponse.setResultCode(ResultCode.Failed);
globalCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionStatusInvalid);
byte[] bytes = seataSerializer.serialize(globalCommitResponse);
GlobalCommitResponse globalCommitResponse2 = seataSerializer.deserialize(bytes);
assertThat(globalCommitResponse2.getGlobalStatus()).isEqualTo(globalCommitResponse.getGlobalStatus());
assertThat(globalCommitResponse2.getMsg()).isEqualTo(globalCommitResponse.getMsg());
assertThat(globalCommitResponse2.getResultCode()).isEqualTo(globalCommitResponse.getResultCode());
assertThat(globalCommitResponse2.getTransactionExceptionCode()).isEqualTo(globalCommitResponse.getTransactionExceptionCode());
}
}

View File

@@ -0,0 +1,59 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.model.BranchType;
import io.seata.core.protocol.transaction.GlobalLockQueryRequest;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Global lock query request codec test.
*
* @author zhangsen
*/
public class GlobalLockQueryRequestSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
GlobalLockQueryRequest globalLockQueryRequest = new GlobalLockQueryRequest();
globalLockQueryRequest.setApplicationData("aaaa");
globalLockQueryRequest.setBranchType(BranchType.TCC);
globalLockQueryRequest.setLockKey("a:1,b,2");
globalLockQueryRequest.setXid("aaa");
globalLockQueryRequest.setResourceId("1s");
byte[] bytes = seataSerializer.serialize(globalLockQueryRequest);
GlobalLockQueryRequest globalLockQueryRequest2 = seataSerializer.deserialize(bytes);
assertThat(globalLockQueryRequest2.getApplicationData()).isEqualTo(globalLockQueryRequest.getApplicationData());
assertThat(globalLockQueryRequest2.getBranchType()).isEqualTo(globalLockQueryRequest.getBranchType());
assertThat(globalLockQueryRequest2.getLockKey()).isEqualTo(globalLockQueryRequest.getLockKey());
assertThat(globalLockQueryRequest2.getResourceId()).isEqualTo(globalLockQueryRequest.getResourceId());
assertThat(globalLockQueryRequest2.getXid()).isEqualTo(globalLockQueryRequest.getXid());
}
}

View File

@@ -0,0 +1,59 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.protocol.ResultCode;
import io.seata.core.protocol.transaction.GlobalLockQueryResponse;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Global lock query response codec test.
*
* @author zhangsen
*/
public class GlobalLockQueryResponseSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
GlobalLockQueryResponse globalLockQueryResponse = new GlobalLockQueryResponse();
globalLockQueryResponse.setLockable(true);
globalLockQueryResponse.setMsg("aa");
globalLockQueryResponse.setResultCode(ResultCode.Failed);
globalLockQueryResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionStatusInvalid);
byte[] bytes = seataSerializer.serialize(globalLockQueryResponse);
GlobalLockQueryResponse globalLockQueryResponse2 = seataSerializer.deserialize(bytes);
assertThat(globalLockQueryResponse2.isLockable()).isEqualTo(globalLockQueryResponse.isLockable());
assertThat(globalLockQueryResponse2.getResultCode()).isEqualTo(globalLockQueryResponse.getResultCode());
assertThat(globalLockQueryResponse2.getTransactionExceptionCode()).isEqualTo(globalLockQueryResponse.getTransactionExceptionCode());
assertThat(globalLockQueryResponse2.getMsg()).isEqualTo(globalLockQueryResponse.getMsg());
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.protocol.transaction.GlobalRollbackRequest;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Global rollback request codec test.
*
* @author zhangsen
*/
public class GlobalRollbackRequestCodecTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
GlobalRollbackRequest globalRollbackRequest = new GlobalRollbackRequest();
globalRollbackRequest.setExtraData("aaaa");
globalRollbackRequest.setXid("aaaa");
byte[] bytes = seataSerializer.serialize(globalRollbackRequest);
GlobalRollbackRequest globalRollbackRequest2 = seataSerializer.deserialize(bytes);
assertThat(globalRollbackRequest2.getXid()).isEqualTo(globalRollbackRequest.getXid());
assertThat(globalRollbackRequest2.getExtraData()).isEqualTo(globalRollbackRequest.getExtraData());
}
}

View File

@@ -0,0 +1,59 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.model.GlobalStatus;
import io.seata.core.protocol.ResultCode;
import io.seata.core.protocol.transaction.GlobalRollbackResponse;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Global rollback response codec test.
*
* @author zhangsen
*/
public class GlobalRollbackResponseSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
GlobalRollbackResponse globalRollbackResponse = new GlobalRollbackResponse();
globalRollbackResponse.setGlobalStatus(GlobalStatus.AsyncCommitting);
globalRollbackResponse.setMsg("aaa");
globalRollbackResponse.setResultCode(ResultCode.Failed);
globalRollbackResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionNotExist);
byte[] bytes = seataSerializer.serialize(globalRollbackResponse);
GlobalRollbackResponse globalRollbackResponse2 = seataSerializer.deserialize(bytes);
assertThat(globalRollbackResponse2.getGlobalStatus()).isEqualTo(globalRollbackResponse.getGlobalStatus());
assertThat(globalRollbackResponse2.getMsg()).isEqualTo(globalRollbackResponse.getMsg());
assertThat(globalRollbackResponse2.getResultCode()).isEqualTo(globalRollbackResponse.getResultCode());
assertThat(globalRollbackResponse2.getTransactionExceptionCode()).isEqualTo(globalRollbackResponse.getTransactionExceptionCode());
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.protocol.transaction.GlobalStatusRequest;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Global status request codec test.
*
* @author zhangsen
*/
public class GlobalStatusRequestCodecTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
GlobalStatusRequest globalStatusRequest = new GlobalStatusRequest();
globalStatusRequest.setExtraData("aaaa");
globalStatusRequest.setXid("aaa123");
byte[] bytes = seataSerializer.serialize(globalStatusRequest);
GlobalStatusRequest globalStatusRequest2 = seataSerializer.deserialize(bytes);
assertThat(globalStatusRequest2.getExtraData()).isEqualTo(globalStatusRequest.getExtraData());
assertThat(globalStatusRequest2.getXid()).isEqualTo(globalStatusRequest.getXid());
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.exception.TransactionExceptionCode;
import io.seata.core.model.GlobalStatus;
import io.seata.core.protocol.ResultCode;
import io.seata.core.protocol.transaction.GlobalStatusResponse;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Global status response codec test.
*
* @author zhangsen
*/
public class GlobalStatusResponseSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
GlobalStatusResponse globalStatusResponse = new GlobalStatusResponse();
globalStatusResponse.setGlobalStatus(GlobalStatus.CommitRetrying);
globalStatusResponse.setMsg("aaaa");
globalStatusResponse.setResultCode(ResultCode.Failed);
globalStatusResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionNotExist);
byte[] bytes = seataSerializer.serialize(globalStatusResponse);
GlobalStatusResponse globalStatusResponse2 = seataSerializer.deserialize(bytes);
assertThat(globalStatusResponse2.getGlobalStatus()).isEqualTo(globalStatusResponse.getGlobalStatus());
assertThat(globalStatusResponse2.getMsg()).isEqualTo(globalStatusResponse.getMsg());
assertThat(globalStatusResponse2.getTransactionExceptionCode()).isEqualTo(globalStatusResponse.getTransactionExceptionCode());
assertThat(globalStatusResponse2.getResultCode()).isEqualTo(globalStatusResponse.getResultCode());
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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.seata.protocol.transaction;
import io.seata.serializer.seata.SeataSerializer;
import io.seata.core.model.BranchType;
import io.seata.core.protocol.transaction.UndoLogDeleteRequest;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The type Undo Log Delete request codec test.
*
* @author guoyao
*/
public class UndoLogDeleteRequestSerializerTest {
/**
* The Seata codec.
*/
SeataSerializer seataSerializer = new SeataSerializer();
/**
* Test codec.
*/
@Test
public void test_codec(){
UndoLogDeleteRequest logDeleteRequest1 = new UndoLogDeleteRequest();
logDeleteRequest1.setBranchType(BranchType.AT);
logDeleteRequest1.setResourceId("t");
logDeleteRequest1.setSaveDays((short)7);
byte[] bytes = seataSerializer.serialize(logDeleteRequest1);
UndoLogDeleteRequest logDeleteRequest2 = seataSerializer.deserialize(bytes);
assertThat(logDeleteRequest2.getBranchType()).isEqualTo(logDeleteRequest1.getBranchType());
assertThat(logDeleteRequest2.getResourceId()).isEqualTo(logDeleteRequest1.getResourceId());
assertThat(logDeleteRequest2.getSaveDays()).isEqualTo(logDeleteRequest1.getSaveDays());
}
}

View File

@@ -0,0 +1,8 @@
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 = "127.0.0.1:8091"
#disable seata
disableGlobalTransaction = false
}

View File

@@ -0,0 +1,67 @@
registry {
# file 、nacos 、eureka、redis、zk、consul、etcd3、sofa
type = "file"
nacos {
serverAddr = "localhost"
namespace = ""
cluster = "default"
}
eureka {
serviceUrl = "http://localhost:8761/eureka"
application = "default"
weight = "1"
}
redis {
serverAddr = "localhost:6379"
db = "0"
}
zk {
cluster = "default"
serverAddr = "127.0.0.1:2181"
sessionTimeout = 6000
connectTimeout = 2000
}
consul {
cluster = "default"
serverAddr = "127.0.0.1:8500"
}
etcd3 {
cluster = "default"
serverAddr = "http://localhost:2379"
}
sofa {
serverAddr = "127.0.0.1:9603"
application = "default"
region = "DEFAULT_ZONE"
datacenter = "DefaultDataCenter"
cluster = "default"
group = "SEATA_GROUP"
addressWaitTime = "3000"
}
file {
name = "file.conf"
}
}
config {
# file、nacos 、apollo、zk
type = "file"
nacos {
serverAddr = "localhost"
namespace = ""
}
apollo {
appId = "seata-server"
apolloMeta = "http://192.168.1.204:8801"
}
zk {
serverAddr = "127.0.0.1:2181"
sessionTimeout = 6000
connectTimeout = 2000
}
file {
name = "file.conf"
}
}