Skip to content

Commit

Permalink
Intermittent SubscriberPublMsgToMsgRetComplBean 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 e28c849 commit 437baae
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 SubscriberPublMsgToMsgRetComplBean implements AssertableTestBean, AsyncTestBean {

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

private final ExecutorService executor = createExecutor();

Expand All @@ -54,11 +56,15 @@ public Publisher<Message<String>> sourceForCsVoidMessage() {

@Incoming("cs-void-message")
public CompletionStage<Void> consumeMessageAndReturnCompletionStageOfVoid(Message<String> message) {
return CompletableFuture.runAsync(() -> resultData.add(message.getPayload()), executor);
return CompletableFuture.runAsync(() -> {
resultData.add(message.getPayload());
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 437baae

Please sign in to comment.