Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix_#2188] Enhance readability of waitForEvent method in Kafka IT class #2189

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
*/
package org.kie.kogito.it.jobs;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.AfterEach;
Expand All @@ -30,8 +29,6 @@

import io.restassured.path.json.JsonPath;

import static org.assertj.core.api.Assertions.assertThat;

public class KafkaBaseSwitchStateTimeoutsIT extends BaseSwitchStateTimeoutsIT {

private KafkaTestClient kafkaClient;
Expand All @@ -49,15 +46,9 @@ void cleanUp() {
}

private static JsonPath waitForEvent(KafkaTestClient kafkaClient, String topic, long seconds) throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(1);
final AtomicReference<String> cloudEvent = new AtomicReference<>();
kafkaClient.consume(topic, rawCloudEvent -> {
cloudEvent.set(rawCloudEvent);
countDownLatch.countDown();
});
// give some time to consume the event.
assertThat(countDownLatch.await(seconds, TimeUnit.SECONDS)).isTrue();
return new JsonPath(cloudEvent.get());
CompletableFuture<String> cloudEvent = new CompletableFuture<>();
kafkaClient.consume(topic, cloudEvent::complete);
return new JsonPath(cloudEvent.orTimeout(seconds, TimeUnit.SECONDS).get());
}

@Override
Expand Down