davsclaus commented on code in PR #26742:
URL: https://github.com/apache/camel/pull/26742#discussion_r4071517855
##########
dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/RouteReloadRollbackTest.groovy:
##########
@@ -66,6 +73,120 @@ class RouteReloadRollbackTest extends YamlTestSupport {
dir.toFile().deleteDir()
}
+ def 'the only route file keeps its previous version when the save is
broken'() {
+ setup:
+ def solo = Files.createTempDirectory("camel-reload-solo")
+ def only = solo.resolve("only.camel.yaml")
+ Files.writeString(only, """
+ - route:
+ id: only
+ from:
+ uri: direct:only
+ steps:
+ - to:
+ uri: mock:only
+ """)
+ def context2 = new org.apache.camel.impl.DefaultCamelContext()
+ context2.start()
+ org.apache.camel.support.PluginHelper.getRoutesLoader(context2)
+ .loadRoutes(ResourceHelper.resolveResource(context2,
"file:" + only))
+ def strategy = new RouteWatcherReloadStrategy(solo.toString())
+ strategy.setCamelContext(context2)
+ strategy.setPattern("*.yaml")
+ strategy.doStart()
+ // one successful reload, so the content that runs is remembered
+ strategy.getResourceReload().onReload(only.toString(),
ResourceHelper.resolveResource(context2, "file:" + only))
+ assert context2.getRouteController().getRouteStatus("only") ==
ServiceStatus.Started
+ when: 'the only route file is saved with a mistake (pollEnrich takes
an expression, not a uri)'
+ Files.writeString(only, """
+ - route:
+ id: only
+ from:
+ uri: direct:only
+ steps:
+ - pollEnrich:
+ uri: file:./order.json
+ """)
+ def failure = null
+ try {
+ strategy.getResourceReload().onReload(only.toString(),
ResourceHelper.resolveResource(context2, "file:" + only))
+ } catch (Exception e) {
+ failure = e
+ }
+ then: 'the reload fails and the version that ran before is still
running'
+ failure != null
+ context2.getRouteController().getRouteStatus("only") ==
ServiceStatus.Started
+ when: 'the file is fixed'
+ Files.writeString(only, """
+ - route:
+ id: only
+ from:
+ uri: direct:only
+ steps:
+ - to:
+ uri: mock:fixed
+ """)
+ strategy.getResourceReload().onReload(only.toString(),
ResourceHelper.resolveResource(context2, "file:" + only))
+ then: 'the fixed version runs, not the remembered one'
+ context2.getRouteController().getRouteStatus("only") ==
ServiceStatus.Started
+
context2.getRoute("only").getEndpoint().getEndpointUri().startsWith("direct://only")
Review Comment:
Right, the `from` endpoint is `direct:only` in both versions, so that line
proved nothing. The step now sends a message and checks where it lands:
```groovy
def fixed = context2.getEndpoint("mock:fixed", MockEndpoint)
fixed.expectedMessageCount(1)
def stale = context2.getEndpoint("mock:only", MockEndpoint)
stale.expectedMessageCount(0)
context2.createProducerTemplate().sendBody("direct:only", "x")
MockEndpoint.assertIsSatisfied(context2)
```
I checked it catches the case it is meant to: with the loader patched to
serve the remembered content instead of the file, the test fails.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]