gnodet-bot commented on code in PR #26742:
URL: https://github.com/apache/camel/pull/26742#discussion_r4071464902


##########
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:
   ⚠️ **Weak assertion — does not distinguish remembered vs fixed version**
   
   `route.getEndpoint()` returns the `from` endpoint — `direct:only` in both 
the remembered version (→ `mock:only`) and the fixed version (→ `mock:fixed`). 
If the implementation accidentally served the cached content instead of the new 
file, this assertion still passes.
   
   Add a check on the route's consumer output URI to confirm the *fixed* 
version is running:
   
   ```suggestion
               
context2.getRoute("only").getEndpoint().getEndpointUri().startsWith("direct://only")
               context2.endpoints.find { 
it.endpointUri.contains("mock://fixed") } != null
               context2.endpoints.find { it.endpointUri.contains("mock://only") 
} == null
   ```



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

Reply via email to