You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2023/02/22 06:18:53 UTC
[camel] branch main updated: CAMEL-19065: camel-kafka - Add KafkaSagaIT test
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 0b80eeea45b CAMEL-19065: camel-kafka - Add KafkaSagaIT test
0b80eeea45b is described below
commit 0b80eeea45bab7d862e98aae6d60a074228ebbc1
Author: Zheng Feng <zh...@gmail.com>
AuthorDate: Fri Feb 17 23:18:59 2023 +0800
CAMEL-19065: camel-kafka - Add KafkaSagaIT test
---
.../component/kafka/integration/KafkaSagaIT.java | 82 ++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaSagaIT.java b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaSagaIT.java
new file mode 100644
index 00000000000..8b5ca605b90
--- /dev/null
+++ b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/integration/KafkaSagaIT.java
@@ -0,0 +1,82 @@
+/*
+ * 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.component.kafka.integration;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.model.SagaCompletionMode;
+import org.apache.camel.model.SagaPropagation;
+import org.apache.camel.saga.InMemorySagaService;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.camel.component.kafka.integration.common.TestProducerUtil.sendMessagesInRoute;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class KafkaSagaIT extends BaseEmbeddedKafkaTestSupport {
+
+ @Test
+ public void testSaga() throws Exception {
+ MockEndpoint result = contextExtension.getMockEndpoint("mock:result");
+ result.expectedMessageCount(1);
+
+ sendMessagesInRoute("direct:saga", 1, contextExtension.getProducerTemplate(), "Hello sag");
+
+ result.assertIsSatisfied();
+ assertTrue(SagaBean.isSame);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ getCamelContext().addService(new InMemorySagaService());
+
+ from("direct:saga")
+ .saga()
+ .completionMode(SagaCompletionMode.MANUAL)
+ .bean(SagaBean.class, "checkId")
+ .to("kafka:saga");
+
+ from("kafka:saga?autoOffsetReset=earliest&autoCommitIntervalMs=1000&pollTimeoutMs=1000&autoCommitEnable=true")
+ .saga()
+ .propagation(SagaPropagation.MANDATORY)
+ .bean(SagaBean.class, "checkId")
+ .to("mock:result")
+ .to("saga:complete");
+ }
+ };
+ }
+}
+
+final class SagaBean {
+ public static String id;
+ public static Boolean isSame = false;
+
+ private SagaBean() {
+ }
+
+ public static void checkId(Exchange exchange) {
+ String sagaId = exchange.getIn().getHeader(Exchange.SAGA_LONG_RUNNING_ACTION, String.class);
+ if (id == null) {
+ id = sagaId;
+ } else {
+ isSame = id.equals(sagaId);
+ }
+ }
+}