Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
*/
public class RejectedPoliciesTest {

private final int DEFAULT_CORE_POOL_SIZE = 1;
private final int DEFAULT_KEEP_ALIVE_TIME = 10;
private final int MAX_QUEUE_SIZE = 1;
private final int defaultCorePoolSize = 1;
Comment thread
slievrly marked this conversation as resolved.
Outdated
private final int defaultKeepAliveTime = 10;
private final int maxQueueSize = 1;

/**
* Test runs oldest task policy.
Expand All @@ -44,12 +44,12 @@ public class RejectedPoliciesTest {
public void testRunsOldestTaskPolicy() throws Exception {
AtomicInteger atomicInteger = new AtomicInteger();
ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
DEFAULT_CORE_POOL_SIZE,
DEFAULT_CORE_POOL_SIZE,
DEFAULT_KEEP_ALIVE_TIME,
defaultCorePoolSize,
defaultCorePoolSize,
defaultKeepAliveTime,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(MAX_QUEUE_SIZE),
new NamedThreadFactory("OldestRunsPolicy", DEFAULT_CORE_POOL_SIZE),
new LinkedBlockingQueue<>(maxQueueSize),
new NamedThreadFactory("OldestRunsPolicy", defaultCorePoolSize),
RejectedPolicies.runsOldestTaskPolicy());
CountDownLatch downLatch1 = new CountDownLatch(1);
CountDownLatch downLatch2 = new CountDownLatch(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
public class ZstdUtilTest {

private final int MAX_COMPRESSED_SIZE = 4 * 1024 * 1024; // 4MB
private final int maxCompressedSize = 4 * 1024 * 1024; // 4MB

@Test
public void test_compress() {
Expand Down Expand Up @@ -65,14 +65,14 @@ public void test_decompress_with_len_illegal() {
@Test
public void test_decompress_with_len() {
Assertions.assertDoesNotThrow(() -> {
byte[] data = new byte[MAX_COMPRESSED_SIZE + 1];
byte[] data = new byte[maxCompressedSize + 1];
for (int i = 0; i < data.length; i++) {
data[i] = (byte) ('A' + i % 26);
}
byte[] compressedData = Zstd.compress(data);
ZstdUtil.decompress(compressedData);
});
int len = MAX_COMPRESSED_SIZE / 2;
int len = maxCompressedSize / 2;
byte[] data = new byte[len];
for (int i = 0; i < data.length; i++) {
data[i] = (byte) ('A' + i % 26);
Expand Down Expand Up @@ -106,6 +106,6 @@ public void test_decompress_with_fake_frame_content_size_oom() {
frameHeaderDescriptor.length + frameContentSize.length,
fakeContent.length);
Assertions.assertThrows(IllegalArgumentException.class, () -> ZstdUtil.decompress(frameContent));
Assertions.assertTrue(Zstd.decompressedSize(frameContent) > MAX_COMPRESSED_SIZE);
Assertions.assertTrue(Zstd.decompressedSize(frameContent) > maxCompressedSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ApolloMockServer {
private MockWebServer server;
private final ObjectMapper mapper = new ObjectMapper();

private final String CONFIG_PREFIX_PATH = "/configs";
private final String configPrefixPath = "/configs";

/**
* Instantiates a new Apollo mock server.
Expand All @@ -53,7 +53,7 @@ public ApolloMockServer(int port) throws IOException {
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().startsWith(CONFIG_PREFIX_PATH)) {
if (request.getPath().startsWith(configPrefixPath)) {
List<String> pathSegments = request.getRequestUrl().pathSegments();
String appId = pathSegments.get(1);
String cluster = pathSegments.get(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@
*/
public class ContextCoreTest {

private final String FIRST_KEY = "first_key";
private final String FIRST_VALUE = "first_value";
private final String SECOND_KEY = "second_key";
private final String SECOND_VALUE = "second_value";
private final String NOT_EXIST_KEY = "not_exist_key";
private final String firstKey = "first_key";
private final String firstValue = "first_value";
private final String secondKey = "second_key";
private final String secondValue = "second_value";
private final String notExistKey = "not_exist_key";

/**
* Test put.
*/
@Test
public void testPut() {
ContextCore load = ContextCoreLoader.load();
assertThat(load.put(FIRST_KEY, FIRST_VALUE)).isNull();
assertThat(load.put(SECOND_KEY, SECOND_VALUE)).isNull();
assertThat(load.put(FIRST_KEY, SECOND_VALUE)).isEqualTo(FIRST_VALUE);
assertThat(load.put(SECOND_KEY, FIRST_VALUE)).isEqualTo(SECOND_VALUE);
assertThat(load.put(firstKey, firstValue)).isNull();
assertThat(load.put(secondKey, secondValue)).isNull();
assertThat(load.put(firstKey, secondValue)).isEqualTo(firstValue);
assertThat(load.put(secondKey, firstValue)).isEqualTo(secondValue);
// clear keys
load.remove(FIRST_KEY);
load.remove(SECOND_KEY);
load.remove(firstKey);
load.remove(secondKey);
}

/**
Expand All @@ -55,19 +55,19 @@ public void testPut() {
@Test
public void testGet() {
ContextCore load = ContextCoreLoader.load();
load.put(FIRST_KEY, FIRST_VALUE);
load.put(SECOND_KEY, FIRST_VALUE);
assertThat(load.get(FIRST_KEY)).isEqualTo(FIRST_VALUE);
assertThat(load.get(SECOND_KEY)).isEqualTo(FIRST_VALUE);
load.put(FIRST_KEY, SECOND_VALUE);
load.put(SECOND_KEY, SECOND_VALUE);
assertThat(load.get(FIRST_KEY)).isEqualTo(SECOND_VALUE);
assertThat(load.get(SECOND_KEY)).isEqualTo(SECOND_VALUE);
assertThat(load.get(NOT_EXIST_KEY)).isNull();
load.put(firstKey, firstValue);
load.put(secondKey, firstValue);
assertThat(load.get(firstKey)).isEqualTo(firstValue);
assertThat(load.get(secondKey)).isEqualTo(firstValue);
load.put(firstKey, secondValue);
load.put(secondKey, secondValue);
assertThat(load.get(firstKey)).isEqualTo(secondValue);
assertThat(load.get(secondKey)).isEqualTo(secondValue);
assertThat(load.get(notExistKey)).isNull();
// clear keys
load.remove(FIRST_KEY);
load.remove(SECOND_KEY);
load.remove(NOT_EXIST_KEY);
load.remove(firstKey);
load.remove(secondKey);
load.remove(notExistKey);
}

/**
Expand All @@ -76,14 +76,14 @@ public void testGet() {
@Test
public void testEntries() {
ContextCore load = ContextCoreLoader.load();
load.put(FIRST_KEY, FIRST_VALUE);
load.put(SECOND_KEY, FIRST_VALUE);
load.put(firstKey, firstValue);
load.put(secondKey, firstValue);
Map<String, Object> entries = load.entries();
assertThat(entries.get(FIRST_KEY)).isEqualTo(FIRST_VALUE);
assertThat(entries.get(SECOND_KEY)).isEqualTo(FIRST_VALUE);
load.remove(FIRST_KEY);
load.remove(SECOND_KEY);
load.remove(NOT_EXIST_KEY);
assertThat(entries.get(firstKey)).isEqualTo(firstValue);
assertThat(entries.get(secondKey)).isEqualTo(firstValue);
load.remove(firstKey);
load.remove(secondKey);
load.remove(notExistKey);
}

/**
Expand All @@ -92,10 +92,10 @@ public void testEntries() {
@Test
public void testRemove() {
ContextCore load = ContextCoreLoader.load();
load.put(FIRST_KEY, FIRST_VALUE);
load.put(SECOND_KEY, SECOND_VALUE);
assertThat(load.remove(FIRST_KEY)).isEqualTo(FIRST_VALUE);
assertThat(load.remove(SECOND_KEY)).isEqualTo(SECOND_VALUE);
assertThat(load.remove(NOT_EXIST_KEY)).isNull();
load.put(firstKey, firstValue);
load.put(secondKey, secondValue);
assertThat(load.remove(firstKey)).isEqualTo(firstValue);
assertThat(load.remove(secondKey)).isEqualTo(secondValue);
assertThat(load.remove(notExistKey)).isNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
*/
public class RootContextTest {

private final String DEFAULT_XID = "default_xid";
private final String defaultXid = "default_xid";

private final BranchType DEFAULT_BRANCH_TYPE = BranchType.AT;
private final BranchType defaultBranchType = BranchType.AT;

/**
* Test bind and unbind.
*/
@Test
public void testBind_And_Unbind() {
assertThat(RootContext.unbind()).isNull();
RootContext.bind(DEFAULT_XID);
assertThat(RootContext.unbind()).isEqualTo(DEFAULT_XID);
RootContext.bind(defaultXid);
assertThat(RootContext.unbind()).isEqualTo(defaultXid);

RootContext.unbind();
assertThat(RootContext.getXID()).isNull();
Expand All @@ -53,9 +53,9 @@ public void testBind_And_Unbind() {
*/
@Test
public void testGetXID() {
RootContext.bind(DEFAULT_XID);
assertThat(RootContext.getXID()).isEqualTo(DEFAULT_XID);
assertThat(RootContext.unbind()).isEqualTo(DEFAULT_XID);
RootContext.bind(defaultXid);
assertThat(RootContext.getXID()).isEqualTo(defaultXid);
assertThat(RootContext.unbind()).isEqualTo(defaultXid);
assertThat(RootContext.getXID()).isNull();
RootContext.unbind();
}
Expand Down Expand Up @@ -118,9 +118,9 @@ public void testRequireGlobalLock() {
*/
@Test
public void testEntries() {
RootContext.bind(DEFAULT_XID);
RootContext.bind(defaultXid);
Map<String, Object> entries = RootContext.entries();
assertThat(entries.get(RootContext.KEY_XID)).isEqualTo(DEFAULT_XID);
assertThat(entries.get(RootContext.KEY_XID)).isEqualTo(defaultXid);
RootContext.unbind();
}

Expand All @@ -130,18 +130,18 @@ public void testEntries() {
@Test
public void testBind_And_Unbind_BranchType() {
assertThat(RootContext.unbindBranchType()).isNull();
RootContext.bindBranchType(DEFAULT_BRANCH_TYPE);
RootContext.bindBranchType(defaultBranchType);

// before bind xid, branchType is null
assertThat(RootContext.getBranchType()).isNull();
// after bind xid, branchType is not null
RootContext.bind(DEFAULT_XID);
assertThat(RootContext.getBranchType()).isEqualTo(DEFAULT_BRANCH_TYPE);
RootContext.bind(defaultXid);
assertThat(RootContext.getBranchType()).isEqualTo(defaultBranchType);

// unbind xid and branchType
assertThat(RootContext.unbind()).isEqualTo(DEFAULT_XID);
assertThat(RootContext.unbind()).isEqualTo(defaultXid);
assertThat(RootContext.getBranchType()).isNull();
assertThat(RootContext.unbindBranchType()).isEqualTo(DEFAULT_BRANCH_TYPE);
assertThat(RootContext.unbindBranchType()).isEqualTo(defaultBranchType);
assertThat(RootContext.getBranchType()).isNull();

Assertions.assertThrows(IllegalArgumentException.class, () -> RootContext.bindBranchType(null));
Expand All @@ -152,16 +152,16 @@ public void testBind_And_Unbind_BranchType() {
*/
@Test
public void testGetBranchType() {
RootContext.bindBranchType(DEFAULT_BRANCH_TYPE);
RootContext.bindBranchType(defaultBranchType);

// before bind xid, branchType is null
assertThat(RootContext.getBranchType()).isNull();
// after bind xid, branchType is not null
RootContext.bind(DEFAULT_XID);
assertThat(RootContext.getBranchType()).isEqualTo(DEFAULT_BRANCH_TYPE);
RootContext.bind(defaultXid);
assertThat(RootContext.getBranchType()).isEqualTo(defaultBranchType);

RootContext.unbind();
assertThat(RootContext.unbindBranchType()).isEqualTo(DEFAULT_BRANCH_TYPE);
assertThat(RootContext.unbindBranchType()).isEqualTo(defaultBranchType);
assertThat(RootContext.getBranchType()).isNull();
}

Expand All @@ -171,7 +171,7 @@ public void testGetBranchType() {
@Test
public void testInGlobalTransaction() {
assertThat(RootContext.inGlobalTransaction()).isFalse();
RootContext.bind(DEFAULT_XID);
RootContext.bind(defaultXid);
assertThat(RootContext.inGlobalTransaction()).isTrue();
RootContext.unbind();
assertThat(RootContext.inGlobalTransaction()).isFalse();
Expand All @@ -183,7 +183,7 @@ public void testInGlobalTransaction() {
*/
@Test
public void testInTccBranch() {
RootContext.bind(DEFAULT_XID);
RootContext.bind(defaultXid);
assertThat(RootContext.inTccBranch()).isFalse();
RootContext.bindBranchType(BranchType.TCC);
assertThat(RootContext.inTccBranch()).isTrue();
Expand All @@ -197,7 +197,7 @@ public void testInTccBranch() {
*/
@Test
public void testInSagaBranch() {
RootContext.bind(DEFAULT_XID);
RootContext.bind(defaultXid);
assertThat(RootContext.inSagaBranch()).isFalse();
RootContext.bindBranchType(BranchType.SAGA);
assertThat(RootContext.inSagaBranch()).isTrue();
Expand All @@ -214,7 +214,7 @@ public void testAssertNotInGlobalTransactionWithException() {
Assertions.assertThrows(ShouldNeverHappenException.class, () -> {
try {
RootContext.assertNotInGlobalTransaction();
RootContext.bind(DEFAULT_XID);
RootContext.bind(defaultXid);
RootContext.assertNotInGlobalTransaction();
} finally {
// clear
Expand All @@ -237,8 +237,8 @@ public void testAssertNotInGlobalTransaction() {
public void testBindBranchType_And_UnbindBranchType() {
assertThat(RootContext.getBranchType()).isNull();
assertThat(RootContext.unbindBranchType()).isNull();
RootContext.bindBranchType(DEFAULT_BRANCH_TYPE);
assertThat(RootContext.unbindBranchType()).isEqualTo(DEFAULT_BRANCH_TYPE);
RootContext.bindBranchType(defaultBranchType);
assertThat(RootContext.unbindBranchType()).isEqualTo(defaultBranchType);
assertThat(RootContext.getBranchType()).isNull();
assertThat(RootContext.unbindBranchType()).isNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
*
**/
public class GlobalBeginResponseTest {
private final String XID = "test_xid";
private final String EXTRA_DATA = "test_extra_data";
private final ResultCode RESULT_CODE = ResultCode.Success;
private final String xid = "test_xid";
private final String extraData = "test_extra_data";
private final ResultCode resultCode = ResultCode.Success;

@Test
public void testGetSetXid() {
GlobalBeginResponse globalBeginResponse = new GlobalBeginResponse();
globalBeginResponse.setXid(XID);
Assertions.assertEquals(XID, globalBeginResponse.getXid());
globalBeginResponse.setXid(xid);
Assertions.assertEquals(xid, globalBeginResponse.getXid());
}

@Test
public void testGetSetExtraData() {
GlobalBeginResponse globalBeginResponse = new GlobalBeginResponse();
globalBeginResponse.setExtraData(EXTRA_DATA);
Assertions.assertEquals(EXTRA_DATA, globalBeginResponse.getExtraData());
globalBeginResponse.setExtraData(extraData);
Assertions.assertEquals(extraData, globalBeginResponse.getExtraData());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class GrpcTest {

private final ServerInterceptor mockServerInterceptor =
mock(ServerInterceptor.class, delegatesTo(new ServerTransactionInterceptor()));
private final String XID = "192.168.0.1:8091:10086";
private final String xid = "192.168.0.1:8091:10086";

@Test
public void clientHeaderDeliveredToServer() throws Exception {
Expand Down Expand Up @@ -101,7 +101,7 @@ public void contextRpc(Request request, StreamObserver<Response> responseObserve
.build());
ContextRpcGrpc.ContextRpcFutureStub stub =
ContextRpcGrpc.newFutureStub(ClientInterceptors.intercept(channel, new ClientTransactionInterceptor()));
RootContext.bind(XID);
RootContext.bind(xid);
RootContext.bindBranchType(BranchType.TCC);
ListenableFuture<Response> future =
stub.contextRpc(Request.newBuilder().setName("seata").build());
Expand All @@ -110,11 +110,11 @@ public void contextRpc(Request request, StreamObserver<Response> responseObserve
ArgumentCaptor<Metadata> metadataCaptor = ArgumentCaptor.forClass(Metadata.class);
verify(mockServerInterceptor)
.interceptCall(ArgumentMatchers.any(), metadataCaptor.capture(), ArgumentMatchers.any());
assertEquals(XID, metadataCaptor.getValue().get(GrpcHeaderKey.XID_HEADER_KEY));
assertEquals(xid, metadataCaptor.getValue().get(GrpcHeaderKey.XID_HEADER_KEY));
assertEquals(BranchType.TCC.name(), metadataCaptor.getValue().get(GrpcHeaderKey.BRANCH_HEADER_KEY));

countDownLatch.await();
assertEquals(XID, context[0]);
assertEquals(xid, context[0]);
assertEquals(BranchType.TCC.name(), context[1]);
}
}
Loading