squakez commented on a change in pull request #648:
URL: https://github.com/apache/camel-k-runtime/pull/648#discussion_r612514690



##########
File path: 
camel-k-core/support/src/main/java/org/apache/camel/k/listener/SourcesConfigurer.java
##########
@@ -64,14 +67,49 @@ protected void accept(Runtime runtime) {
         // property that can't be bound to this configurer.
         //
         PropertiesSupport.bindProperties(
-            runtime.getCamelContext(),
-            this,
-            k -> k.startsWith(CAMEL_K_SOURCES_PREFIX),
-            CAMEL_K_PREFIX);
+                runtime.getCamelContext(),
+                this,
+                k -> k.startsWith(CAMEL_K_SOURCES_PREFIX),
+                CAMEL_K_PREFIX);
+
+        checkUniqueErrorHandler();
+        sortSources();
 
         if (ObjectHelper.isNotEmpty(this.getSources())) {
             SourcesSupport.loadSources(runtime, this.getSources());
         }
     }
 
+    private void checkUniqueErrorHandler() {
+        checkUniqueErrorHandler(this.sources);
+    }
+
+    static void checkUniqueErrorHandler(SourceDefinition[] sources) {
+        long errorHandlers = sources == null ? 0 : 
Arrays.stream(sources).filter(s -> s.getType() == 
SourceType.errorHandler).count();
+        if (errorHandlers > 1) {
+            throw new IllegalArgumentException("Expected only one error 
handler source type, got " + errorHandlers);
+        }
+    }
+
+    private void sortSources() {
+        sortSources(this.getSources());
+    }
+
+    static void sortSources(SourceDefinition[] sources) {
+        if (sources == null) {
+            return;
+        }
+        // We must ensure the source order as defined in SourceType enum
+        Arrays.sort(sources,

Review comment:
       I agree. I had to introduce those checks because there were a few unit 
test failing and also the real integration. I think the root cause may be 
within camel k which leaves that field blank. However, it will need a bit more 
of investigation. Are you okey if I open a follow up issue and we keep this 
ahead?




-- 
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.

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


Reply via email to