Skip to content

Commit 835cf46

Browse files
fix: callback thread safe
1 parent 21015b6 commit 835cf46

File tree

1 file changed

+10
-6
lines changed
  • src/integration-test/java/com/commercetools/sync/integration/ctpprojectsource/categories

1 file changed

+10
-6
lines changed

src/integration-test/java/com/commercetools/sync/integration/ctpprojectsource/categories/CategorySyncIT.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@
3333
class CategorySyncIT {
3434
private CategorySync categorySync;
3535

36-
private List<String> callBackErrorResponses = new ArrayList<>();
37-
private List<Throwable> callBackExceptions = new ArrayList<>();
38-
private List<String> callBackWarningResponses = new ArrayList<>();
36+
// Use thread-safe lists because callbacks are called from parallel threads
37+
private List<String> callBackErrorResponses =
38+
java.util.Collections.synchronizedList(new ArrayList<>());
39+
private List<Throwable> callBackExceptions =
40+
java.util.Collections.synchronizedList(new ArrayList<>());
41+
private List<String> callBackWarningResponses =
42+
java.util.Collections.synchronizedList(new ArrayList<>());
3943
private ReferenceIdToKeyCache referenceIdToKeyCache;
4044

4145
/**
@@ -68,9 +72,9 @@ void setupTest() {
6872
CategoryITUtils.ensureCategories(
6973
TestClientUtils.CTP_TARGET_CLIENT, CategoryITUtils.getCategoryDrafts(null, 2, true));
7074

71-
callBackErrorResponses = new ArrayList<>();
72-
callBackExceptions = new ArrayList<>();
73-
callBackWarningResponses = new ArrayList<>();
75+
callBackErrorResponses = java.util.Collections.synchronizedList(new ArrayList<>());
76+
callBackExceptions = java.util.Collections.synchronizedList(new ArrayList<>());
77+
callBackWarningResponses = java.util.Collections.synchronizedList(new ArrayList<>());
7478
categorySync = new CategorySync(buildCategorySyncOptions(50));
7579
referenceIdToKeyCache = new CaffeineReferenceIdToKeyCacheImpl();
7680
}

0 commit comments

Comments
 (0)