Skip to content

Commit

Permalink
add unit test for some request class (#239)
Browse files Browse the repository at this point in the history
* add toString method

* add toString method

* add toString method

* add toString method

* fix

* add unit test

* fix
  • Loading branch information
summerjava authored and slievrly committed Jan 23, 2019
1 parent e10063c commit d176782
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,25 @@ public boolean decode(ByteBuf in) {

return true;
}

@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append("xid=");
result.append(xid);
result.append(",");
result.append("branchId=");
result.append(branchId);
result.append(",");
result.append("branchType=");
result.append(branchType);
result.append(",");
result.append("resourceId=");
result.append(resourceId);
result.append(",");
result.append("applicationData=");
result.append(applicationData);

return result.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,19 @@ public boolean decode(ByteBuf in) {
branchStatus = BranchStatus.get(in.readByte());
return true;
}

@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append("branchStatus=");
result.append(branchStatus);
result.append(",");
result.append("result code =");
result.append(getResultCode());
result.append(",");
result.append("getMsg =");
result.append(getMsg());

return result.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,22 @@ public void decode(ByteBuffer byteBuffer) {
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("branchType=");
result.append(branchType);
result.append(",");
result.append("resourceId=");
result.append(resourceId);
result.append(",");
result.append("lockKey=");
result.append(lockKey);

return result.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.alibaba.fescar.core.message;

import com.alibaba.fescar.core.model.BranchType;
import com.alibaba.fescar.core.protocol.transaction.BranchCommitRequest;

import org.junit.Assert;
import org.junit.Test;

/**
* @author xiajun.0706@163.com
* @since 2019/1/23
*/
public class BranchCommitRequestTest {

@Test
public void toStringTest() throws Exception{
BranchCommitRequest branchCommitRequest = new BranchCommitRequest();

branchCommitRequest.setXid("127.0.0.1:9999:39875642");
branchCommitRequest.setBranchId(1);
branchCommitRequest.setBranchType(BranchType.AT);
branchCommitRequest.setResourceId("resource1");
branchCommitRequest.setApplicationData("app1");

Assert.assertEquals("xid=127.0.0.1:9999:39875642,branchId=1,branchType=AT,"
+ "resourceId=resource1,applicationData=app1", branchCommitRequest.toString());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.alibaba.fescar.core.message;

import com.alibaba.fescar.core.model.BranchStatus;
import com.alibaba.fescar.core.protocol.ResultCode;
import com.alibaba.fescar.core.protocol.transaction.BranchCommitResponse;

import org.junit.Assert;
import org.junit.Test;

/**
* @author xiajun.0706@163.com
* @since 2019/1/23
*/
public class BranchCommitResponseTest {
@Test
public void toStringTest() throws Exception{
BranchCommitResponse branchCommitResponse = new BranchCommitResponse();

branchCommitResponse.setBranchStatus(BranchStatus.PhaseOne_Done);
branchCommitResponse.setResultCode(ResultCode.Success);
branchCommitResponse.setMsg("");

System.out.println(branchCommitResponse.toString());

Assert.assertEquals("branchStatus=PhaseOne_Done,result code =Success,getMsg =", branchCommitResponse.toString());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.alibaba.fescar.core.message;

import com.alibaba.fescar.core.model.BranchType;
import com.alibaba.fescar.core.protocol.transaction.BranchRegisterRequest;

import org.junit.Assert;
import org.junit.Test;

/**
* @author xiajun.0706@163.com
* @since 2019/1/23
*/
public class BranchRegisterRequestTest {
@Test
public void toStringTest() throws Exception{
BranchRegisterRequest branchRegisterRequest = new BranchRegisterRequest();

branchRegisterRequest.setTransactionId(123456);
branchRegisterRequest.setBranchType(BranchType.AT);
branchRegisterRequest.setResourceId("resource1");
branchRegisterRequest.setLockKey("lock_key_1");

System.out.println(branchRegisterRequest.toString());

Assert.assertEquals("transactionId=123456,branchType=AT,resourceId=resource1,lockKey=lock_key_1", branchRegisterRequest.toString());

}
}

0 comments on commit d176782

Please sign in to comment.