Skip to content

Commit

Permalink
fix(core): SourceType enum order
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez authored and lburgazzoli committed Apr 13, 2021
1 parent 5909f6d commit 76c64d8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
public enum SourceType {
// Order matters. We want the sources to be loaded following this enum order.
errorHandler,
source,
template
template,
source
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.camel.k.listener;

import java.util.Arrays;

import org.apache.camel.k.Runtime;
import org.apache.camel.k.SourceDefinition;
import org.apache.camel.k.SourceType;
Expand All @@ -25,8 +27,6 @@
import org.apache.camel.spi.Configurer;
import org.apache.camel.util.ObjectHelper;

import java.util.Arrays;

@Configurer
public class SourcesConfigurer extends AbstractPhaseListener {
public static final String CAMEL_K_PREFIX = "camel.k.";
Expand Down Expand Up @@ -99,7 +99,7 @@ static void sortSources(SourceDefinition[] sources) {
if (sources == null) {
return;
}
// We must ensure the following source type order: errorHandler, source, template
// We must ensure the source order as defined in SourceType enum
Arrays.sort(sources,
(a, b) -> {
if (a.getType() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
package org.apache.camel.k.support;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.List;

import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.RuntimeCamelException;
Expand All @@ -35,10 +39,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.util.Collection;
import java.util.List;

public final class SourcesSupport {
private static final Logger LOGGER = LoggerFactory.getLogger(SourcesConfigurer.class);

Expand Down Expand Up @@ -148,7 +148,7 @@ public void afterConfigure(RouteBuilder builder) {
throw new IllegalArgumentException("There should not be any template, got " + templates.size());
}

if (existErrorHandler(builder)) {
if (hasErrorHandlerBuilder(builder)) {
LOGGER.debug("Setting default error handler builder factory as {}", builder.getErrorHandlerBuilder());
runtime.getCamelContext().adapt(ExtendedCamelContext.class).setErrorHandlerFactory(builder.getErrorHandlerBuilder());
}
Expand All @@ -173,7 +173,7 @@ public void afterConfigure(RouteBuilder builder) {
}
}

static boolean existErrorHandler(RouteBuilder builder) {
static boolean hasErrorHandlerBuilder(RouteBuilder builder) {
//return builder.hasErrorHandlerBuilder();
// TODO We need to replace the following workaround with the statement above once we switch to camel-3.10.0 or above
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void shouldLoadMultipleSources() {
"camel.k.sources[0].location", "classpath:MyTemplate1.java",
"camel.k.sources[0].type", "template",
"camel.k.sources[1].name", "err1",
"camel.k.sources[1.location", "classpath:MyTemplate2.java",
"camel.k.sources[1].location", "classpath:MyTemplate2.java",
"camel.k.sources[2].name", "err2",
"camel.k.sources[2].location", "classpath:Err2.java",
"camel.k.sources[2].type", "errorHandler"
Expand All @@ -60,7 +60,7 @@ public void shouldFailOnMultipleErrorHandlers() {
"camel.k.sources[0].location", "classpath:MyTemplate1.java",
"camel.k.sources[0].type", "template",
"camel.k.sources[1].name", "err1",
"camel.k.sources[1.location", "classpath:Err1.java",
"camel.k.sources[1].location", "classpath:Err1.java",
"camel.k.sources[1].type", "errorHandler",
"camel.k.sources[2].name", "err2",
"camel.k.sources[2].location", "classpath:Err2.java",
Expand Down Expand Up @@ -104,12 +104,11 @@ public void shouldOrderSourcesByType() {
SourcesConfigurer.sortSources(configuration.getSources());

assertThat(configuration.getSources().length).isEqualTo(4);

assertThat(configuration.getSources()[0].getName()).isEqualTo("errorHandler1");
assertThat(configuration.getSources()[1].getName()).isEqualTo("template1");
// Order for the same type does not matter
assertThat(configuration.getSources()[1].getName()).contains("source");
assertThat(configuration.getSources()[2].getName()).contains("source");
assertThat(configuration.getSources()[3].getName()).isEqualTo("template1");
assertThat(configuration.getSources()[3].getName()).contains("source");
}

@Test
Expand Down

0 comments on commit 76c64d8

Please sign in to comment.