Repository: alibaba/fescar
Pull request #278 (2019-01-25 01:32:26)

add lock manager test
<!-- Please make sure you have read and understood the contributing guidelines -->

### Ⅰ. Describe what this PR did
add lock manager test

### Ⅱ. Does this pull request fix one issue?
<!-- If that, add "fixes #xxx" below in the next line, for example, fixes #97. -->
fixes##192

### Ⅲ. 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/278?src=pr&el=h1) Report
> Merging [#278](https://codecov.io/gh/alibaba/fescar/pull/278?src=pr&el=desc) into [develop](https://codecov.io/gh/alibaba/fescar/commit/ceb1fc5383df68eb4d11a1d207f54956a14df7a8?src=pr&el=desc) will **increase** coverage by `0.89%`.
> The diff coverage is `n/a`.

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

```diff
@@             Coverage Diff             @@
##           develop     #278      +/-   ##
===========================================
+ Coverage    12.15%   13.05%   +0.89%     
===========================================
  Files          184      184              
  Lines         6834     6834              
  Branches       937      937              
===========================================
+ Hits           831      892      +61     
+ Misses        5924     5855      -69     
- Partials        79       87       +8
```


| [Impacted Files](https://codecov.io/gh/alibaba/fescar/pull/278?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [...m/alibaba/fescar/server/session/BranchSession.java](https://codecov.io/gh/alibaba/fescar/pull/278/diff?src=pr&el=tree#diff-c2VydmVyL3NyYy9tYWluL2phdmEvY29tL2FsaWJhYmEvZmVzY2FyL3NlcnZlci9zZXNzaW9uL0JyYW5jaFNlc3Npb24uamF2YQ==) | `72.05% <0%> (+0.73%)` | :arrow_up: |
| [...alibaba/fescar/server/lock/LockManagerFactory.java](https://codecov.io/gh/alibaba/fescar/pull/278/diff?src=pr&el=tree#diff-c2VydmVyL3NyYy9tYWluL2phdmEvY29tL2FsaWJhYmEvZmVzY2FyL3NlcnZlci9sb2NrL0xvY2tNYW5hZ2VyRmFjdG9yeS5qYXZh) | `50% <0%> (+50%)` | :arrow_up: |
| [...aba/fescar/server/lock/DefaultLockManagerImpl.java](https://codecov.io/gh/alibaba/fescar/pull/278/diff?src=pr&el=tree#diff-c2VydmVyL3NyYy9tYWluL2phdmEvY29tL2FsaWJhYmEvZmVzY2FyL3NlcnZlci9sb2NrL0RlZmF1bHRMb2NrTWFuYWdlckltcGwuamF2YQ==) | `78.08% <0%> (+78.08%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/alibaba/fescar/pull/278?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/278?src=pr&el=footer). Last update [ceb1fc5...e635f6a](https://codecov.io/gh/alibaba/fescar/pull/278?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
diff --git a/server/src/test/java/com/alibaba/fescar/server/lock/LockManagerTest.java b/server/src/test/java/com/alibaba/fescar/server/lock/LockManagerTest.java
new file mode 100644
index 000000000..aa32984e7
--- /dev/null
+++ b/server/src/test/java/com/alibaba/fescar/server/lock/LockManagerTest.java
@@ -0,0 +1,100 @@
+/*
+ *  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.server.lock;
+
+import com.alibaba.fescar.core.model.BranchType;
+import com.alibaba.fescar.server.UUIDGenerator;
+import com.alibaba.fescar.server.session.BranchSession;
+import org.junit.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * @author tianming.xm@gmail.com
+ * @since 2019/1/23
+ */
+public class LockManagerTest {
+
+    @Test(dataProvider = "branchSessionProvider")
+    public void acquireLock_success(BranchSession branchSession) throws Exception{
+        LockManager lockManager = LockManagerFactory.get();
+        Assert.assertTrue(lockManager.acquireLock(branchSession));
+    }
+
+    @Test(dataProvider = "branchSessionsProvider")
+    public void acquireLock_failed(BranchSession branchSession1,BranchSession branchSession2) throws Exception{
+        LockManager lockManager = LockManagerFactory.get();
+        Assert.assertTrue(lockManager.acquireLock(branchSession1));
+        Assert.assertFalse(lockManager.acquireLock(branchSession2));
+    }
+
+    @Test(dataProvider = "branchSessionProvider")
+    public void isLockableTest(BranchSession branchSession) throws Exception{
+        branchSession.setLockKey("t:4");
+        LockManager lockManager = LockManagerFactory.get();
+        Assert.assertTrue(lockManager.isLockable(branchSession.getTransactionId(),branchSession.getResourceId(),branchSession.getLockKey()));
+        lockManager.acquireLock(branchSession);
+        branchSession.setTransactionId(UUIDGenerator.generateUUID());
+        Assert.assertFalse(lockManager.isLockable(branchSession.getTransactionId(),branchSession.getResourceId(),branchSession.getLockKey()));
+    }
+
+    @DataProvider
+    public static Object[][] branchSessionProvider() {
+        BranchSession branchSession = new BranchSession();
+        branchSession.setTransactionId(UUIDGenerator.generateUUID());
+        branchSession.setBranchId(0L);
+        branchSession.setClientId("c1");
+        branchSession.setResourceGroupId("my_test_tx_group");
+        branchSession.setResourceId("tb_1");
+        branchSession.setLockKey("t:0");
+        branchSession.setBranchType(BranchType.AT);
+        branchSession.setApplicationId("demo-child-app");
+        branchSession.setTxServiceGroup("my_test_tx_group");
+        branchSession.setApplicationData("{\"data\":\"test\"}");
+        branchSession.setBranchType(BranchType.AT);
+        return new Object[][] {{ branchSession}};
+    }
+
+    @DataProvider
+    public static Object[][] branchSessionsProvider() {
+        BranchSession branchSession1 = new BranchSession();
+        branchSession1.setTransactionId(UUIDGenerator.generateUUID());
+        branchSession1.setBranchId(1L);
+        branchSession1.setClientId("c1");
+        branchSession1.setResourceGroupId("my_test_tx_group");
+        branchSession1.setResourceId("tb_1");
+        branchSession1.setLockKey("t:1,2");
+        branchSession1.setBranchType(BranchType.AT);
+        branchSession1.setApplicationId("demo-child-app");
+        branchSession1.setTxServiceGroup("my_test_tx_group");
+        branchSession1.setApplicationData("{\"data\":\"test\"}");
+        branchSession1.setBranchType(BranchType.AT);
+
+        BranchSession branchSession2 = new BranchSession();
+        branchSession2.setTransactionId(UUIDGenerator.generateUUID());
+        branchSession2.setBranchId(2L);
+        branchSession2.setClientId("c1");
+        branchSession2.setResourceGroupId("my_test_tx_group");
+        branchSession2.setResourceId("tb_1");
+        branchSession2.setLockKey("t:1,2");
+        branchSession2.setBranchType(BranchType.AT);
+        branchSession2.setApplicationId("demo-child-app");
+        branchSession2.setTxServiceGroup("my_test_tx_group");
+        branchSession2.setApplicationData("{\"data\":\"test\"}");
+        branchSession2.setBranchType(BranchType.AT);
+        return new Object[][] {{ branchSession1,branchSession2}};
+    }
+}
diff --git a/server/src/test/java/com/alibaba/fescar/server/store/FileTransactionStoreManagerTest.java b/server/src/test/java/com/alibaba/fescar/server/store/FileTransactionStoreManagerTest.java
new file mode 100644
index 000000000..e48de1201
--- /dev/null
+++ b/server/src/test/java/com/alibaba/fescar/server/store/FileTransactionStoreManagerTest.java
@@ -0,0 +1,67 @@
+/*
+ *  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.server.store;
+
+import com.alibaba.fescar.server.session.FileBasedSessionManager;
+import com.alibaba.fescar.server.session.GlobalSession;
+import com.alibaba.fescar.server.session.SessionManager;
+import org.junit.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+/**
+ * @author tianming.xm@gmail.com
+ * @since 2019/1/25
+ */
+public class FileTransactionStoreManagerTest {
+    private FileTransactionStoreManager fileTransactionStoreManager;
+
+    @BeforeClass
+    public void setUp() throws Exception{
+        SessionManager sessionManager = new FileBasedSessionManager("default","root.data");
+        fileTransactionStoreManager = new FileTransactionStoreManager("root.data",sessionManager);
+    }
+
+    @AfterClass
+    public void tearDown(){
+        fileTransactionStoreManager.shutdown();
+    }
+
+    @Test(dataProvider = "sessionProvider")
+    public void writeSessionTest(GlobalSession globalSession){
+        boolean result = fileTransactionStoreManager.writeSession(TransactionStoreManager.LogOperation.GLOBAL_ADD,globalSession);
+        Assert.assertTrue(result);
+    }
+
+    @Test(dataProvider = "sessionProvider")
+    public void readWriteStoreFromFileTest(GlobalSession globalSession){
+        fileTransactionStoreManager.writeSession(TransactionStoreManager.LogOperation.GLOBAL_ADD,globalSession);
+        List<TransactionWriteStore> stores = fileTransactionStoreManager.readWriteStoreFromFile(100,false);
+        Assert.assertNotNull(stores);
+        Assert.assertTrue(stores.size() > 0);
+    }
+
+    @DataProvider
+    public static Object[][] sessionProvider() {
+        GlobalSession globalSession = new GlobalSession("demo-app","my_test_tx_group","test",6000);
+        return new Object[][] {{ globalSession}};
+    }
+
+}