This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git

commit 2cb6e7257585db70061338c8c18064417bb28b88
Author: Lei Zhang <[email protected]>
AuthorDate: Tue Aug 6 19:46:33 2019 +0800

    SCB-1423 Use the AtomInteger counter instead of ConcurrentLinkedQueue.size()
---
 .../servicecomb/pack/alpha/server/AlphaIntegrationTest.java  | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git 
a/alpha/alpha-server/src/test/java/org/apache/servicecomb/pack/alpha/server/AlphaIntegrationTest.java
 
b/alpha/alpha-server/src/test/java/org/apache/servicecomb/pack/alpha/server/AlphaIntegrationTest.java
index 4d9a778..fa501c3 100644
--- 
a/alpha/alpha-server/src/test/java/org/apache/servicecomb/pack/alpha/server/AlphaIntegrationTest.java
+++ 
b/alpha/alpha-server/src/test/java/org/apache/servicecomb/pack/alpha/server/AlphaIntegrationTest.java
@@ -42,6 +42,7 @@ import java.util.Queue;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Consumer;
 import javax.annotation.PostConstruct;
 
@@ -124,6 +125,7 @@ public class AlphaIntegrationTest {
   @Autowired
   private TxConsistentService consistentService;
 
+  private static final AtomicInteger receivedCommandsCounter = new 
AtomicInteger();
   private static final Queue<GrpcCompensateCommand> receivedCommands = new 
ConcurrentLinkedQueue<>();
 
   private final CompensationStreamObserver compensateResponseObserver = new 
CompensationStreamObserver(
@@ -145,6 +147,7 @@ public class AlphaIntegrationTest {
     System.out.println(" globalTxId " + globalTxId);
     eventRepo.deleteAll();
     receivedCommands.clear();
+    receivedCommandsCounter.set(0);
   }
 
   @After
@@ -271,7 +274,7 @@ public class AlphaIntegrationTest {
     blockingStub.onTxEvent(eventOf(TxEndedEvent, localTxId1, parentTxId1, new 
byte[0], "method b"));
 
     blockingStub.onTxEvent(someGrpcEvent(TxAbortedEvent));
-    await().atMost(1, SECONDS).until(() -> receivedCommands.size() > 1);
+    await().atMost(1, SECONDS).until(() -> receivedCommandsCounter.get() > 1);
 
     assertThat(receivedCommands, contains(
         
GrpcCompensateCommand.newBuilder().setGlobalTxId(globalTxId).setLocalTxId(localTxId1).setParentTxId(parentTxId1)
@@ -317,7 +320,7 @@ public class AlphaIntegrationTest {
     blockingStub.onTxEvent(someGrpcEvent(TxAbortedEvent));
     await().atMost(1, SECONDS).until(() -> !receivedCommands.isEmpty());
 
-    assertThat(receivedCommands.size(), is(1));
+    assertThat(receivedCommandsCounter.get(), is(1));
     assertThat(receivedCommands.poll().getGlobalTxId(), is(globalTxId));
 
     anotherBlockingStub.onDisconnected(anotherServiceConfig);
@@ -332,7 +335,7 @@ public class AlphaIntegrationTest {
 
     blockingStub.onTxEvent(someGrpcEvent(TxAbortedEvent));
 
-    await().atMost(1, SECONDS).until(() -> receivedCommands.size() == 1);
+    await().atMost(1, SECONDS).until(() -> receivedCommandsCounter.get() == 1);
 
     String localTxId1 = UUID.randomUUID().toString();
     String parentTxId1 = UUID.randomUUID().toString();
@@ -361,7 +364,7 @@ public class AlphaIntegrationTest {
     blockingStub.onTxEvent(someGrpcEvent(TxAbortedEvent, globalTxId, 
anotherLocalTxId2));
     await().atMost(1, SECONDS).until(() -> !receivedCommands.isEmpty());
 
-    assertThat(receivedCommands.size(), is(1));
+    assertThat(receivedCommandsCounter.get(), is(1));
     assertThat(receivedCommands.poll().getGlobalTxId(), is(globalTxId));
   }
 
@@ -574,6 +577,7 @@ public class AlphaIntegrationTest {
       // intercept received command
       consumer.accept(command);
       receivedCommands.add(command);
+      receivedCommandsCounter.incrementAndGet();
     }
 
     @Override

Reply via email to