jamesnetherton commented on code in PR #489:
URL: 
https://github.com/apache/camel-quarkus-examples/pull/489#discussion_r3005908138


##########
saga/saga-integration-tests/src/test/java/org/apache/camel/example/saga/SagaBasicTest.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.example.saga;
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Basic integration tests for Saga example.
+ * Tests verify saga orchestration, service participation, routing, and 
compensation.
+ * Note: Payment service has 15% random failure rate to test compensation 
scenarios.
+ */
+@QuarkusTest
+@QuarkusTestResource(SagaTestResource.class)
+public class SagaBasicTest {
+
+    private static final String LOG_FILE = "target/quarkus.log";
+
+    /**
+     * Test saga orchestration with LRA - accepts both success and 
compensation outcomes.
+     * Payment service has 15% random failure rate, so either scenario is 
valid.
+     */
+    @Test
+    public void testSagaWithLRAAndRandomOutcomes() throws Exception {
+        // Trigger saga asynchronously (may timeout on payment failure, which 
is expected)
+        CompletableFuture.runAsync(() -> {
+            try {
+                RestAssured.given()
+                        .queryParam("id", 1)
+                        .post("/api/saga");
+            } catch (Exception e) {
+                // Expected - request may timeout on payment failure
+            }
+        });
+
+        // Wait for saga to start and process fully
+        // In native mode, we need to wait longer for all messages to be logged
+        await().atMost(60, TimeUnit.SECONDS).untilAsserted(() -> {
+            String log = new String(Files.readAllBytes(Paths.get(LOG_FILE)), 
StandardCharsets.UTF_8);
+            assertTrue(log.contains("Executing saga #1"), "Saga should start 
with LRA");
+
+            // Wait until we see evidence of completion (success or failure)
+            boolean completed = log.contains("done for order #1")
+                    || log.contains("fails!")
+                    || log.contains("cancelled");
+            assertTrue(completed, "Saga should complete with either success or 
compensation");
+        });
+
+        // Give logs a moment to flush (important in native mode)
+        Thread.sleep(1000);

Review Comment:
   Switched to `Awaitility.await`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to