Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
Fix concurrency issue in RetryTransactionalPollingIntegrationTests
Browse files Browse the repository at this point in the history
  • Loading branch information
fmbenhassine committed Feb 1, 2019
1 parent 797fe1b commit ffe158c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -42,12 +43,12 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
bus = (Lifecycle) applicationContext;
}

private static volatile int count = 0;
private static AtomicInteger count = new AtomicInteger(0);

@Before
public void clearLists() {
list.clear();
count = 0;
count.set(0);
}

public String input() {
Expand All @@ -61,7 +62,7 @@ public String input() {
}

public void output(String message) {
count++;
count.incrementAndGet();
logger.debug("Handled: " + message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -18,7 +19,7 @@ public class SimpleService implements Service {

private List<String> expected = new ArrayList<>();

private int count = 0;
private AtomicInteger count = new AtomicInteger(0);

public void setExpected(List<String> expected) {
this.expected = expected;
Expand All @@ -34,9 +35,9 @@ public List<String> getProcessed() {

@ServiceActivator(inputChannel = "requests", outputChannel = "replies")
public String process(String message) {
String result = message + ": " + (count++);
String result = message + ": " + count.incrementAndGet();
logger.debug("Handling: " + message);
if (count <= expected.size()) {
if (count.get() <= expected.size()) {
processed.add(message);
}
if ("fail".equals(message)) {
Expand Down

0 comments on commit ffe158c

Please sign in to comment.