-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP FUSETOOLS2-1624 - Support automatic restart
When Automatic restart of Camel route is configured, the JMX connection vanishes for few seconds. Adding code to be able to reconnect. As a first iteration ,allow 5 seconds for the connection to be up again. - how to test it? - How to check we have no potential zombies if reconnection last more than 5 seconds or if it was an abrupt stop? - if automatic reload is done in the one second time between two check of suspended nodes, we won't detect the reload. For now, I do not see a better way than to live with it as it shouldn't occur a lot, with a very simple use case, it is taking always more than a second on my relatively fast machine. Current proposal is working only with Quarkus with a not robust implementation and I cannot manage to write a test for this case. i tis not working with Camel JBangand I do not see how to detect that there was a reload. I'm wondering if the breakpoints are kept on route reload, it would not be enough to work on most cases. Maybe a better approach is to support the "restart" of the debug adapter which is available in VS Code UI when the code has been detected as modified. Signed-off-by: Aurélien Pupier <[email protected]>
- Loading branch information
Showing
4 changed files
with
256 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
src/test/java/com/github/cameltooling/dap/internal/AutomaticReloadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/** | ||
* 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 | ||
* | ||
* https://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 com.github.cameltooling.dap.internal; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.impl.DefaultCamelContext; | ||
import org.apache.camel.impl.engine.DefaultProducerTemplate; | ||
import org.eclipse.lsp4j.debug.SetBreakpointsArguments; | ||
import org.eclipse.lsp4j.debug.StoppedEventArguments; | ||
import org.eclipse.lsp4j.debug.StoppedEventArgumentsReason; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class AutomaticReloadTest extends BaseTest { | ||
|
||
private void addRoute(CamelContext context, String startEndpointUri) throws Exception { | ||
System.out.println("add route"); | ||
context.addRoutes(new RouteBuilder() { | ||
|
||
@Override | ||
public void configure() throws Exception { | ||
from(startEndpointUri) | ||
.log("Log from test 1"); // XXX-breakpoint-XXX | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
void testAutomaticReloadOfRoutes() throws Exception { | ||
try (CamelContext context = new DefaultCamelContext()) { | ||
String startEndpointUri = "direct:testAutoReload"; | ||
|
||
addRoute(context, startEndpointUri); | ||
|
||
context.start(); | ||
initDebugger(); | ||
attach(server); | ||
SetBreakpointsArguments setBreakpointsArguments = createSetBreakpointArgument("XXX-breakpoint-XXX"); | ||
|
||
server.setBreakpoints(setBreakpointsArguments).get(); | ||
|
||
DefaultProducerTemplate producerTemplate = DefaultProducerTemplate.newInstance(context, startEndpointUri); | ||
producerTemplate.start(); | ||
|
||
CompletableFuture<Object> asyncSendBody1 = producerTemplate.asyncSendBody(startEndpointUri, "a body 1"); | ||
waitBreakpointNotification(1); | ||
awaitAllVariablesFilled(0); | ||
StoppedEventArguments stoppedEventArgument = clientProxy.getStoppedEventArguments().get(0); | ||
assertThat(stoppedEventArgument.getReason()).isEqualTo(StoppedEventArgumentsReason.BREAKPOINT); | ||
|
||
//TODO how to trigger/simulate the live reload? stop/remove/add is simulating what is happening with Camel JBang. But not with quarkus:dev which is restarting context. | ||
String routeId = context.getRoutes().get(0).getId(); | ||
context.getRouteController().stopRoute(routeId); | ||
assertThat(context.removeRoute(routeId)).isTrue(); | ||
Thread.sleep(1000); // we have a know hole, if the JMX service is down less than a second | ||
addRoute(context, startEndpointUri); | ||
|
||
Thread.sleep(1000); // find a conditional wait for breakpoint to be added back | ||
|
||
|
||
producerTemplate.asyncSendBody(startEndpointUri, "a body 2"); | ||
waitBreakpointNotification(2); | ||
awaitAllVariablesFilled(1); | ||
StoppedEventArguments stoppedEventArgument2 = clientProxy.getStoppedEventArguments().get(1); | ||
assertThat(stoppedEventArgument2.getReason()).isEqualTo(StoppedEventArgumentsReason.BREAKPOINT); | ||
} | ||
} | ||
|
||
@Test | ||
void testAutomaticReloadOfContext() throws Exception { | ||
String startEndpointUri = "direct:testAutoReload"; | ||
try (CamelContext context = new DefaultCamelContext()) { | ||
|
||
addRoute(context, startEndpointUri); | ||
|
||
context.start(); | ||
initDebugger(); | ||
attach(server); | ||
SetBreakpointsArguments setBreakpointsArguments = createSetBreakpointArgument("XXX-breakpoint-XXX"); | ||
|
||
server.setBreakpoints(setBreakpointsArguments).get(); | ||
|
||
DefaultProducerTemplate producerTemplate = DefaultProducerTemplate.newInstance(context, startEndpointUri); | ||
producerTemplate.start(); | ||
|
||
CompletableFuture<Object> asyncSendBody1 = producerTemplate.asyncSendBody(startEndpointUri, "a body 1"); | ||
waitBreakpointNotification(1); | ||
awaitAllVariablesFilled(0); | ||
StoppedEventArguments stoppedEventArgument = clientProxy.getStoppedEventArguments().get(0); | ||
assertThat(stoppedEventArgument.getReason()).isEqualTo(StoppedEventArgumentsReason.BREAKPOINT); | ||
|
||
// TODO how to trigger/simulate the live reload? stop context/start context/ add route again is simulating | ||
// what is happening with Camel Quarkus. | ||
System.out.println("Will stop context"); | ||
context.stop(); | ||
System.out.println("context stopped"); | ||
Thread.sleep(1000); // we have a known hole, if the JMX service is down less than a second | ||
} | ||
try (CamelContext context = new DefaultCamelContext()) { | ||
addRoute(context, startEndpointUri); | ||
|
||
Thread.sleep(1000); // find a conditional wait for breakpoint to be added back | ||
|
||
DefaultProducerTemplate producerTemplate = DefaultProducerTemplate.newInstance(context, startEndpointUri); | ||
producerTemplate.start(); | ||
producerTemplate.asyncSendBody(startEndpointUri, "a body 2"); | ||
waitBreakpointNotification(2, 5); | ||
awaitAllVariablesFilled(1); | ||
StoppedEventArguments stoppedEventArgument2 = clientProxy.getStoppedEventArguments().get(1); | ||
assertThat(stoppedEventArgument2.getReason()).isEqualTo(StoppedEventArgumentsReason.BREAKPOINT); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters