You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/01/31 09:04:36 UTC

[camel] 01/02: CAMEL-16103: Added unit test.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit cb2ae5d0447249697352ce46138ed9a99dd4accd
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Jan 31 09:32:02 2021 +0100

    CAMEL-16103: Added unit test.
---
 .../interceptor/TransactedStackSizeTest.java       | 72 ++++++++++++++++++++++
 .../src/test/resources/log4j2.properties           |  1 +
 2 files changed, 73 insertions(+)

diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactedStackSizeTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactedStackSizeTest.java
new file mode 100644
index 0000000..69e0206
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/TransactedStackSizeTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.spring.interceptor;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+public class TransactedStackSizeTest extends TransactionClientDataSourceSupport {
+
+    private static final boolean PRINT_STACK_TRACE = true;
+
+    @Test
+    public void testStackSize() throws Exception {
+        getMockEndpoint("mock:line").expectedMessageCount(10);
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("seda:start", "A,B,C,D,E,F,G,H,I,J");
+
+        assertMockEndpointsSatisfied();
+
+        int[] sizes = new int[11];
+        for (int i = 0; i < 10; i++) {
+            int size = getMockEndpoint("mock:line").getReceivedExchanges().get(i).getMessage().getHeader("stackSize",
+                    int.class);
+            sizes[i] = size;
+            log.info("#{} size {}", i, size);
+        }
+        int size = getMockEndpoint("mock:result").getReceivedExchanges().get(0).getMessage().getHeader("stackSize", int.class);
+        sizes[10] = size;
+        log.info("#{} size {}", 10, size);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("seda:start")
+                    .transacted()
+                    .split(body())
+                        .setHeader("stackSize", TransactedStackSizeTest::currentStackSize)
+                        .to("mock:line")
+                    .end()
+                    .setHeader("stackSize", TransactedStackSizeTest::currentStackSize)
+                    .to("mock:result");
+            }
+        };
+    }
+
+    public static int currentStackSize() {
+        int depth = Thread.currentThread().getStackTrace().length;
+        if (PRINT_STACK_TRACE) {
+            new Throwable("Printing Stacktrace depth: " + depth).printStackTrace(System.err);
+        }
+        return depth;
+    }
+
+}
diff --git a/components/camel-spring/src/test/resources/log4j2.properties b/components/camel-spring/src/test/resources/log4j2.properties
index 6e7bfa8..75b6bed 100644
--- a/components/camel-spring/src/test/resources/log4j2.properties
+++ b/components/camel-spring/src/test/resources/log4j2.properties
@@ -26,3 +26,4 @@ appender.out.layout.type = PatternLayout
 appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
 rootLogger.level = INFO
 rootLogger.appenderRef.file.ref = file
+#rootLogger.appenderRef.out.ref = out