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 2019/05/22 07:54:29 UTC
[camel] branch camel-2.24.x updated: CAMEL-13554: Fixed auto assign
route id can go into looping if using fixed route1 as id.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-2.24.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.24.x by this push:
new 5fedbaa CAMEL-13554: Fixed auto assign route id can go into looping if using fixed route1 as id.
5fedbaa is described below
commit 5fedbaa8f57d60eae678a2b839fa5c50bd789dd0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed May 22 09:51:26 2019 +0200
CAMEL-13554: Fixed auto assign route id can go into looping if using fixed route1 as id.
---
.../apache/camel/model/RouteDefinitionHelper.java | 14 ++++++-
.../issues/RouteIdAnonymousAndFixedClashTest.java | 48 ++++++++++++++++++++++
2 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
index 3089861..f109d4b 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
@@ -165,9 +165,19 @@ public final class RouteDefinitionHelper {
boolean done = false;
String id = null;
- while (!done) {
+ int attempts = 0;
+ while (!done && attempts < 1000) {
+ attempts++;
id = route.idOrCreate(context.getNodeIdFactory());
- done = !customIds.contains(id);
+ if (customIds.contains(id)) {
+ // reset id and try again
+ route.setId(null);
+ } else {
+ done = true;
+ }
+ }
+ if (!done) {
+ throw new IllegalArgumentException("Cannot auto assign id to route: " + route);
}
route.setId(id);
ProcessorDefinitionHelper.addPropertyPlaceholdersChangeRevertAction(new Runnable() {
diff --git a/camel-core/src/test/java/org/apache/camel/issues/RouteIdAnonymousAndFixedClashTest.java b/camel-core/src/test/java/org/apache/camel/issues/RouteIdAnonymousAndFixedClashTest.java
new file mode 100644
index 0000000..3ddd0aa
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/issues/RouteIdAnonymousAndFixedClashTest.java
@@ -0,0 +1,48 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class RouteIdAnonymousAndFixedClashTest extends ContextTestSupport {
+
+ @Test
+ public void testClash() throws Exception {
+ // should create the 2 routes
+ assertEquals(2, context.getRoutes().size());
+
+ assertNotNull("Should have route1 (fixed id", context.getRoute("route1"));
+ assertNotNull("Should have route2 (auto assigned id)", context.getRoute("route2"));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:in1")
+ .id("route1") // Note the name
+ .to("mock:test1");
+
+ from("direct:in2")
+ .to("mock:test2");
+ }
+ };
+ }
+}