Skip to content

Commit

Permalink
Intermittent SubscriberPublMsgToPaylRetComplVoidBean test fix
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kec <[email protected]>
  • Loading branch information
danielkec authored and barchetta committed Mar 4, 2024
1 parent 9990916 commit e28c849
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
* Copyright (c) 2020 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;

import javax.enterprise.context.ApplicationScoped;
Expand All @@ -42,6 +43,7 @@
public class SubscriberPublMsgToPaylRetComplVoidBean implements AssertableTestBean, AsyncTestBean {

CopyOnWriteArraySet<String> resultData = new CopyOnWriteArraySet<>();
private final CountDownLatch countDownLatch = new CountDownLatch(TEST_DATA.size());
private final ExecutorService executor = createExecutor();

@Outgoing("cs-void-payload")
Expand All @@ -53,11 +55,15 @@ public Publisher<Message<String>> sourceForCsVoidPayload() {

@Incoming("cs-void-payload")
public CompletionStage<Void> consumePayloadAndReturnCompletionStageOfVoid(String payload) {
return CompletableFuture.runAsync(() -> resultData.add(payload), executor);
return CompletableFuture.runAsync(() -> {
resultData.add(payload);
countDownLatch.countDown();
}, executor);
}

@Override
public void assertValid() {
await("Messages not delivered in time!", countDownLatch);
assertWithOrigin("Result doesn't match", resultData, is(TEST_DATA));
}

Expand Down

0 comments on commit e28c849

Please sign in to comment.