Repository: alibaba/fescar
Pull request #276 (2019-01-25 00:44:18)

add unit test to core module
<!-- Please make sure you have read and understood the contributing guidelines -->

### Ⅰ. Describe what this PR did
add unit test to protocol package in  core module

### Ⅱ. Does this pull request fix one issue?
<!-- If that, add "fixes #xxx" below in the next line, for example, fixes #97. -->
https://github.com/alibaba/fescar/issues/259

### Ⅲ. Why don't you add test cases (unit test/integration test)? 


### Ⅳ. Describe how to verify it


### Ⅴ. Special notes for reviews



codecov-io: # [Codecov](https://codecov.io/gh/alibaba/fescar/pull/276?src=pr&el=h1) Report
> Merging [#276](https://codecov.io/gh/alibaba/fescar/pull/276?src=pr&el=desc) into [develop](https://codecov.io/gh/alibaba/fescar/commit/ceb1fc5383df68eb4d11a1d207f54956a14df7a8?src=pr&el=desc) will **increase** coverage by `2.53%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/alibaba/fescar/pull/276/graphs/tree.svg?width=650&token=Hy9a6MCc4p&height=150&src=pr)](https://codecov.io/gh/alibaba/fescar/pull/276?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           develop     #276      +/-   ##
===========================================
+ Coverage    12.15%   14.69%   +2.53%     
===========================================
  Files          184      184              
  Lines         6834     6874      +40     
  Branches       937      937              
===========================================
+ Hits           831     1010     +179     
+ Misses        5924     5771     -153     
- Partials        79       93      +14
```


| [Impacted Files](https://codecov.io/gh/alibaba/fescar/pull/276?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [.../core/protocol/transaction/GlobalBeginRequest.java](https://codecov.io/gh/alibaba/fescar/pull/276/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL3RyYW5zYWN0aW9uL0dsb2JhbEJlZ2luUmVxdWVzdC5qYXZh) | `78.37% <100%> (+78.37%)` | :arrow_up: |
| [...rotocol/transaction/AbstractGlobalEndResponse.java](https://codecov.io/gh/alibaba/fescar/pull/276/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL3RyYW5zYWN0aW9uL0Fic3RyYWN0R2xvYmFsRW5kUmVzcG9uc2UuamF2YQ==) | `100% <100%> (+100%)` | :arrow_up: |
| [...protocol/transaction/AbstractGlobalEndRequest.java](https://codecov.io/gh/alibaba/fescar/pull/276/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL3RyYW5zYWN0aW9uL0Fic3RyYWN0R2xvYmFsRW5kUmVxdWVzdC5qYXZh) | `88.23% <100%> (+88.23%)` | :arrow_up: |
| [...core/protocol/transaction/BranchReportRequest.java](https://codecov.io/gh/alibaba/fescar/pull/276/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL3RyYW5zYWN0aW9uL0JyYW5jaFJlcG9ydFJlcXVlc3QuamF2YQ==) | `81.94% <100%> (+81.94%)` | :arrow_up: |
| [...a/com/alibaba/fescar/core/protocol/ResultCode.java](https://codecov.io/gh/alibaba/fescar/pull/276/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL1Jlc3VsdENvZGUuamF2YQ==) | `75% <0%> (+12.5%)` | :arrow_up: |
| [...va/com/alibaba/fescar/core/model/BranchStatus.java](https://codecov.io/gh/alibaba/fescar/pull/276/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL21vZGVsL0JyYW5jaFN0YXR1cy5qYXZh) | `90.47% <0%> (+14.28%)` | :arrow_up: |
| [...ba/fescar/core/protocol/AbstractResultMessage.java](https://codecov.io/gh/alibaba/fescar/pull/276/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL0Fic3RyYWN0UmVzdWx0TWVzc2FnZS5qYXZh) | `58.92% <0%> (+21.42%)` | :arrow_up: |
| [...re/protocol/transaction/GlobalRollbackRequest.java](https://codecov.io/gh/alibaba/fescar/pull/276/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL3RyYW5zYWN0aW9uL0dsb2JhbFJvbGxiYWNrUmVxdWVzdC5qYXZh) | `33.33% <0%> (+33.33%)` | :arrow_up: |
| [...ore/protocol/transaction/GlobalCommitResponse.java](https://codecov.io/gh/alibaba/fescar/pull/276/diff?src=pr&el=tree#diff-Y29yZS9zcmMvbWFpbi9qYXZhL2NvbS9hbGliYWJhL2Zlc2Nhci9jb3JlL3Byb3RvY29sL3RyYW5zYWN0aW9uL0dsb2JhbENvbW1pdFJlc3BvbnNlLmphdmE=) | `50% <0%> (+50%)` | :arrow_up: |
| ... and [4 more](https://codecov.io/gh/alibaba/fescar/pull/276/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/alibaba/fescar/pull/276?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/alibaba/fescar/pull/276?src=pr&el=footer). Last update [ceb1fc5...5e6ef71](https://codecov.io/gh/alibaba/fescar/pull/276?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractGlobalEndRequest.java b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractGlobalEndRequest.java
index be008e279..b41b4a00a 100644
--- a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractGlobalEndRequest.java
+++ b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractGlobalEndRequest.java
@@ -16,10 +16,10 @@
 
 package com.alibaba.fescar.core.protocol.transaction;
 
-import java.nio.ByteBuffer;
-
 import com.alibaba.fescar.core.protocol.MergedMessage;
 
+import java.nio.ByteBuffer;
+
 public abstract class AbstractGlobalEndRequest extends AbstractTransactionRequestToTC implements MergedMessage {
 
     protected long transactionId;
@@ -72,4 +72,16 @@ public abstract class AbstractGlobalEndRequest extends AbstractTransactionReques
             this.setExtraData(new String(bs, UTF8));
         }
     }
+
+    @Override
+    public String toString() {
+        StringBuilder result = new StringBuilder();
+        result.append("transactionId=");
+        result.append(transactionId);
+        result.append(",");
+        result.append("extraData=");
+        result.append(extraData);
+
+        return result.toString();
+    }
 }
diff --git a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractGlobalEndResponse.java b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractGlobalEndResponse.java
index 28767a384..2e94e380e 100644
--- a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractGlobalEndResponse.java
+++ b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/AbstractGlobalEndResponse.java
@@ -16,10 +16,10 @@
 
 package com.alibaba.fescar.core.protocol.transaction;
 
-import java.nio.ByteBuffer;
-
 import com.alibaba.fescar.core.model.GlobalStatus;
 
+import java.nio.ByteBuffer;
+
 public abstract class AbstractGlobalEndResponse extends AbstractTransactionResponse {
 
     protected GlobalStatus globalStatus;
@@ -45,4 +45,18 @@ public abstract class AbstractGlobalEndResponse extends AbstractTransactionRespo
         globalStatus = GlobalStatus.get(byteBuffer.get());
     }
 
+    @Override
+    public String toString() {
+        StringBuilder result = new StringBuilder();
+        result.append("globalStatus=");
+        result.append(globalStatus);
+        result.append(",");
+        result.append("ResultCode=");
+        result.append(getResultCode());
+        result.append(",");
+        result.append("Msg=");
+        result.append(getMsg());
+
+        return result.toString();
+    }
 }
diff --git a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/BranchReportRequest.java b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/BranchReportRequest.java
index 4fdc53cc3..896028554 100644
--- a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/BranchReportRequest.java
+++ b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/BranchReportRequest.java
@@ -16,12 +16,12 @@
 
 package com.alibaba.fescar.core.protocol.transaction;
 
-import java.nio.ByteBuffer;
-
 import com.alibaba.fescar.core.model.BranchStatus;
 import com.alibaba.fescar.core.protocol.MergedMessage;
 import com.alibaba.fescar.core.rpc.RpcContext;
 
+import java.nio.ByteBuffer;
+
 public class BranchReportRequest extends AbstractTransactionRequestToTC implements MergedMessage {
 
     private long transactionId;
@@ -146,4 +146,25 @@ public class BranchReportRequest extends AbstractTransactionRequestToTC implemen
     public AbstractTransactionResponse handle(RpcContext rpcContext) {
         return handler.handle(this, rpcContext);
     }
+
+    @Override
+    public String toString() {
+        StringBuilder result = new StringBuilder();
+        result.append("transactionId=");
+        result.append(transactionId);
+        result.append(",");
+        result.append("branchId=");
+        result.append(branchId);
+        result.append(",");
+        result.append("resourceId=");
+        result.append(resourceId);
+        result.append(",");
+        result.append("status=");
+        result.append(status);
+        result.append(",");
+        result.append("applicationData=");
+        result.append(applicationData);
+
+        return result.toString();
+    }
 }
diff --git a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/GlobalBeginRequest.java b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/GlobalBeginRequest.java
index c6f4d6faa..af589f9bd 100644
--- a/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/GlobalBeginRequest.java
+++ b/core/src/main/java/com/alibaba/fescar/core/protocol/transaction/GlobalBeginRequest.java
@@ -16,11 +16,11 @@
 
 package com.alibaba.fescar.core.protocol.transaction;
 
-import java.nio.ByteBuffer;
-
 import com.alibaba.fescar.core.protocol.MergedMessage;
 import com.alibaba.fescar.core.rpc.RpcContext;
 
+import java.nio.ByteBuffer;
+
 public class GlobalBeginRequest extends AbstractTransactionRequestToTC implements MergedMessage {
 
     private static final long serialVersionUID = 7236162274218388376L;
@@ -87,4 +87,16 @@ public class GlobalBeginRequest extends AbstractTransactionRequestToTC implement
     public AbstractTransactionResponse handle(RpcContext rpcContext) {
         return handler.handle(this, rpcContext);
     }
+
+    @Override
+    public String toString() {
+        StringBuilder result = new StringBuilder();
+        result.append("timeout=");
+        result.append(timeout);
+        result.append(",");
+        result.append("transactionName=");
+        result.append(transactionName);
+
+        return result.toString();
+    }
 }


Test patch:
diff --git a/core/src/test/java/com/alibaba/fescar/core/message/BranchReportRequestTest.java b/core/src/test/java/com/alibaba/fescar/core/message/BranchReportRequestTest.java
new file mode 100644
index 000000000..ccc6b0422
--- /dev/null
+++ b/core/src/test/java/com/alibaba/fescar/core/message/BranchReportRequestTest.java
@@ -0,0 +1,92 @@
+/*
+ *  Copyright 1999-2018 Alibaba Group Holding Ltd.
+ *
+ *  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 com.alibaba.fescar.core.message;
+
+import com.alibaba.fescar.core.model.BranchStatus;
+import com.alibaba.fescar.core.protocol.transaction.BranchReportRequest;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+/**
+ * @author xiajun.0706@163.com
+ * @since 2019/1/24
+ */
+public class BranchReportRequestTest {
+
+  @Test
+  public void testToString() throws Exception {
+    BranchReportRequest branchReportRequest = new BranchReportRequest();
+
+    branchReportRequest.setTransactionId(1249853);
+    branchReportRequest.setBranchId(3);
+    branchReportRequest.setResourceId("resource003");
+    branchReportRequest.setStatus(BranchStatus.PhaseOne_Timeout);
+    branchReportRequest.setApplicationData("test app data");
+
+    Assert.assertEquals("transactionId=1249853,branchId=3,resourceId=resource003,status=PhaseOne_Timeout,applicationData=test app data",
+                        branchReportRequest.toString());
+  }
+
+
+  @Test
+  public void testEncode() throws Exception{
+    BranchReportRequest branchReportRequest = new BranchReportRequest();
+
+    branchReportRequest.setTransactionId(1249853);
+    branchReportRequest.setBranchId(3);
+    branchReportRequest.setResourceId("resource003");
+    branchReportRequest.setStatus(BranchStatus.PhaseOne_Timeout);
+    branchReportRequest.setApplicationData("test app data");
+
+    byte[] encodeResult = branchReportRequest.encode();
+    System.out.println(encodeResult);
+    String encodeResultStr = Arrays.toString(encodeResult);
+    System.out.println(encodeResultStr);
+
+
+    Assert.assertEquals("[0, 0, 0, 0, 0, 19, 18, 61, 0, 0, 0, 0, 0, 0, 0, 3, 4, 0, 11, 114, 101, 115, 111, 117, 114, 99, 101, 48, 48, 51, 0, 0, 0, 13, 116, 101, 115, 116, 32, 97, 112, 112, 32, 100, 97, 116, 97]", encodeResultStr);
+  }
+
+  @Test
+  public void testDecode() throws Exception{
+    BranchReportRequest branchReportRequest = new BranchReportRequest();
+
+    branchReportRequest.setTransactionId(1249853);
+    branchReportRequest.setBranchId(3);
+    branchReportRequest.setResourceId("resource003");
+    branchReportRequest.setStatus(BranchStatus.PhaseOne_Timeout);
+    branchReportRequest.setApplicationData("test app data");
+
+    byte[] encodeResult = branchReportRequest.encode();
+
+    ByteBuffer byteBuffer = ByteBuffer.allocate(encodeResult.length);
+    byteBuffer.put(encodeResult);
+    byteBuffer.flip();
+
+    BranchReportRequest decodeBranchReportRequest = new BranchReportRequest();
+    decodeBranchReportRequest.decode(byteBuffer);
+    System.out.println(decodeBranchReportRequest);
+    Assert.assertEquals(branchReportRequest.getTransactionId(), decodeBranchReportRequest.getTransactionId());
+    Assert.assertEquals(branchReportRequest.getBranchId(), decodeBranchReportRequest.getBranchId());
+    Assert.assertEquals(branchReportRequest.getResourceId(), decodeBranchReportRequest.getResourceId());
+    Assert.assertEquals(branchReportRequest.getStatus(), decodeBranchReportRequest.getStatus());
+    Assert.assertEquals(branchReportRequest.getApplicationData(), decodeBranchReportRequest.getApplicationData());
+  }
+}
\ No newline at end of file
diff --git a/core/src/test/java/com/alibaba/fescar/core/message/GlobalBeginRequestTest.java b/core/src/test/java/com/alibaba/fescar/core/message/GlobalBeginRequestTest.java
new file mode 100644
index 000000000..0d6ec9ed1
--- /dev/null
+++ b/core/src/test/java/com/alibaba/fescar/core/message/GlobalBeginRequestTest.java
@@ -0,0 +1,69 @@
+/*
+ *  Copyright 1999-2018 Alibaba Group Holding Ltd.
+ *
+ *  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 com.alibaba.fescar.core.message;
+
+import com.alibaba.fescar.core.protocol.transaction.GlobalBeginRequest;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+/**
+ * @author xiajun.0706@163.com
+ * @since 2019/1/24
+ */
+public class GlobalBeginRequestTest {
+
+  @Test
+  public void testToString() throws Exception{
+    GlobalBeginRequest globalBeginRequest = new GlobalBeginRequest();
+    globalBeginRequest.setTransactionName("tran 1");
+    System.out.println(globalBeginRequest.toString());
+
+    Assert.assertEquals("timeout=60000,transactionName=tran 1", globalBeginRequest.toString());
+  }
+
+  @Test
+  public void testEncode() throws Exception{
+    GlobalBeginRequest globalBeginRequest = new GlobalBeginRequest();
+    globalBeginRequest.setTransactionName("tran 1");
+
+    byte[] encodeResult = globalBeginRequest.encode();
+    String encodeResultStr = Arrays.toString(encodeResult);
+
+    Assert.assertEquals("[0, 0, -22, 96, 0, 6, 116, 114, 97, 110, 32, 49]", encodeResultStr);
+  }
+
+  @Test
+  public void testDecode() throws Exception{
+    GlobalBeginRequest globalBeginRequest = new GlobalBeginRequest();
+    globalBeginRequest.setTransactionName("tran 1");
+
+    byte[] encodeResult = globalBeginRequest.encode();
+
+    ByteBuffer byteBuffer = ByteBuffer.allocate(encodeResult.length);
+    byteBuffer.put(encodeResult);
+    byteBuffer.flip();
+
+    GlobalBeginRequest decodeGlobalBeginRequest = new GlobalBeginRequest();
+    decodeGlobalBeginRequest.decode(byteBuffer);
+    System.out.println(decodeGlobalBeginRequest);
+    Assert.assertEquals(globalBeginRequest.getTimeout(), decodeGlobalBeginRequest.getTimeout());
+    Assert.assertEquals(globalBeginRequest.getTransactionName(), decodeGlobalBeginRequest.getTransactionName());
+  }
+}
\ No newline at end of file
diff --git a/core/src/test/java/com/alibaba/fescar/core/message/GlobalCommitResponseTest.java b/core/src/test/java/com/alibaba/fescar/core/message/GlobalCommitResponseTest.java
new file mode 100644
index 000000000..c0d2bc22f
--- /dev/null
+++ b/core/src/test/java/com/alibaba/fescar/core/message/GlobalCommitResponseTest.java
@@ -0,0 +1,117 @@
+/*
+ *  Copyright 1999-2018 Alibaba Group Holding Ltd.
+ *
+ *  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 com.alibaba.fescar.core.message;
+
+import com.alibaba.fescar.core.model.GlobalStatus;
+import com.alibaba.fescar.core.protocol.ResultCode;
+import com.alibaba.fescar.core.protocol.transaction.GlobalCommitResponse;
+
+import org.apache.commons.lang.StringUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+/**
+ * @author xiajun.0706@163.com
+ * @since 2019/1/24
+ */
+public class GlobalCommitResponseTest {
+
+  @Test
+  public void testToString() throws Exception{
+    GlobalCommitResponse globalCommitResponse = new GlobalCommitResponse();
+
+    globalCommitResponse.setGlobalStatus(GlobalStatus.Committed);
+    globalCommitResponse.setResultCode(ResultCode.Success);
+    globalCommitResponse.setMsg("OK");
+
+    System.out.println(globalCommitResponse.toString());
+
+    Assert.assertEquals("globalStatus=Committed,ResultCode=Success,Msg=OK", globalCommitResponse.toString());
+  }
+
+  @Test
+  public void testEncode() throws Exception{
+    GlobalCommitResponse globalCommitResponse = new GlobalCommitResponse();
+
+    globalCommitResponse.setGlobalStatus(GlobalStatus.Committed);
+    globalCommitResponse.setResultCode(ResultCode.Success);
+    globalCommitResponse.setMsg("OK");
+
+    System.out.println(globalCommitResponse.toString());
+
+    byte[] encodeResult = globalCommitResponse.encode();
+    System.out.println(encodeResult);
+    String encodeResultStr = Arrays.toString(encodeResult);
+    System.out.println(encodeResultStr);
+
+
+    Assert.assertEquals("[1, 0, 8]", encodeResultStr);
+  }
+
+  @Test
+  public void testDecodeNormal() throws Exception{
+    GlobalCommitResponse globalCommitResponse = new GlobalCommitResponse();
+
+    globalCommitResponse.setGlobalStatus(GlobalStatus.Committed);
+    globalCommitResponse.setResultCode(ResultCode.Success);
+    globalCommitResponse.setMsg("OK");
+
+    System.out.println(globalCommitResponse.toString());
+
+    byte[] encodeResult = globalCommitResponse.encode();
+
+    ByteBuffer byteBuffer = ByteBuffer.allocate(encodeResult.length);
+    byteBuffer.put(encodeResult);
+    byteBuffer.flip();
+    GlobalCommitResponse decodeGlobalCommitResponse = new GlobalCommitResponse();
+    decodeGlobalCommitResponse.decode(byteBuffer);
+
+    System.out.println(decodeGlobalCommitResponse.toString());
+
+    Assert.assertEquals(globalCommitResponse.getGlobalStatus(), decodeGlobalCommitResponse.getGlobalStatus());
+    Assert.assertEquals(globalCommitResponse.getResultCode(), decodeGlobalCommitResponse.getResultCode());
+    //success response do not have msg
+    Assert.assertTrue(StringUtils.isBlank(decodeGlobalCommitResponse.getMsg()));
+  }
+
+  @Test
+  public void testDecodeException() throws Exception{
+    GlobalCommitResponse globalCommitResponse = new GlobalCommitResponse();
+
+    globalCommitResponse.setGlobalStatus(GlobalStatus.CommitFailed);
+    globalCommitResponse.setResultCode(ResultCode.Failed);
+    globalCommitResponse.setMsg("error happened");
+
+    System.out.println(globalCommitResponse.toString());
+
+    byte[] encodeResult = globalCommitResponse.encode();
+
+    ByteBuffer byteBuffer = ByteBuffer.allocate(encodeResult.length);
+    byteBuffer.put(encodeResult);
+    byteBuffer.flip();
+    GlobalCommitResponse decodeGlobalCommitResponse = new GlobalCommitResponse();
+    decodeGlobalCommitResponse.decode(byteBuffer);
+
+    System.out.println(decodeGlobalCommitResponse.toString());
+
+    Assert.assertEquals(globalCommitResponse.getGlobalStatus(), decodeGlobalCommitResponse.getGlobalStatus());
+    Assert.assertEquals(globalCommitResponse.getResultCode(), decodeGlobalCommitResponse.getResultCode());
+    Assert.assertEquals(globalCommitResponse.getMsg(), decodeGlobalCommitResponse.getMsg());
+  }
+}
\ No newline at end of file
diff --git a/core/src/test/java/com/alibaba/fescar/core/message/GlobalRollbackRequestTest.java b/core/src/test/java/com/alibaba/fescar/core/message/GlobalRollbackRequestTest.java
new file mode 100644
index 000000000..23217ee02
--- /dev/null
+++ b/core/src/test/java/com/alibaba/fescar/core/message/GlobalRollbackRequestTest.java
@@ -0,0 +1,81 @@
+/*
+ *  Copyright 1999-2018 Alibaba Group Holding Ltd.
+ *
+ *  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 com.alibaba.fescar.core.message;
+
+import com.alibaba.fescar.core.protocol.transaction.GlobalRollbackRequest;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+/**
+ * @author xiajun.0706@163.com
+ * @since 2019/1/24
+ */
+public class GlobalRollbackRequestTest {
+
+  @Test
+  public void testToString() throws Exception{
+    GlobalRollbackRequest globalRollbackRequest = new GlobalRollbackRequest();
+
+    globalRollbackRequest.setTransactionId(1249853);
+    globalRollbackRequest.setExtraData("test_extra_data");
+
+    System.out.println(globalRollbackRequest.toString());
+
+    Assert.assertEquals("transactionId=1249853,extraData=test_extra_data", globalRollbackRequest.toString());
+  }
+
+  @Test
+  public void testEncode() throws Exception{
+    GlobalRollbackRequest globalRollbackRequest = new GlobalRollbackRequest();
+
+    globalRollbackRequest.setTransactionId(1249853);
+    globalRollbackRequest.setExtraData("test_extra_data");
+
+    System.out.println(globalRollbackRequest.toString());
+
+    byte[] encodeResult = globalRollbackRequest.encode();
+    System.out.println(encodeResult);
+    String encodeResultStr = Arrays.toString(encodeResult);
+    System.out.println(encodeResultStr);
+
+
+    Assert.assertEquals("[0, 0, 0, 0, 0, 19, 18, 61, 0, 15, 116, 101, 115, 116, 95, 101, 120, 116, 114, 97, 95, 100, 97, 116, 97]", encodeResultStr);
+  }
+
+  @Test
+  public void testDecode() throws Exception{
+    GlobalRollbackRequest globalRollbackRequest = new GlobalRollbackRequest();
+
+    globalRollbackRequest.setTransactionId(1249853L);
+    globalRollbackRequest.setExtraData("test_extra_data");
+
+    byte[] encodeResult = globalRollbackRequest.encode();
+
+    ByteBuffer byteBuffer = ByteBuffer.allocate(encodeResult.length);
+    byteBuffer.put(encodeResult);
+    byteBuffer.flip();
+
+    GlobalRollbackRequest decodeGlobalRollbackRequest = new GlobalRollbackRequest();
+    decodeGlobalRollbackRequest.decode(byteBuffer);
+    System.out.println(decodeGlobalRollbackRequest);
+    Assert.assertEquals(globalRollbackRequest.getTransactionId(), decodeGlobalRollbackRequest.getTransactionId());
+    Assert.assertEquals(globalRollbackRequest.getExtraData(), decodeGlobalRollbackRequest.getExtraData());
+  }
+}
\ No newline at end of file