You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by nas reg <na...@hotmail.com> on 2018/12/12 19:19:01 UTC

@DirtiesContext not resetting counters

Hi,


I believe I have found a bug with the @DirtiesContext cleanup of the CamelContext.

I have tried every permutation of all the Spring test annotations and the result was always the same


A NullPointerException on getRouteDefinition(String routeId)


(The camel test is extremely fragmented across versions, examples and deprecations by the way. It can be hugely time consuming to get a test running from scratch using spring, due to all the permutations of attempts online. It’d be lovely if the doc page was updated. But I digress).


A NullPointerException!

Really, I should have realised what the NPE meant quicker, rather than bashing my head against the screen trying to get the right test configuration, when that (i have concluded) isn't the problem.


THE ISSUE: The counters aren’t reset in the CamelContext. I found this problem when two separate test classes interfered with each other.


My solution:


@Before

public void setup() throws Exception {

//I found this class with some digging around

TestSupportNodeIdFactory.resetCounters();



context.getRouteDefinition("route2").adviceWith(context, new AdviceWithRouteBuilder() {



@Override

public void configure() throws Exception { }


}

}



I think this reset command needs to be added somewhere to a SpringTestExecutionListener (or whichever class ties into the DirtiesContext cleanup somewhere

TestSupportNodeIdFactory.resetCounters();




————————————


Second issue: The @MockEndpoints annotation and the @UseAdviceWith result duplicate work when injecting a mock, so you get 2 mocks instead of one, and you don’t get a handle on the one receiving the traffic. It’s necessary to use a pattern to exclude the adviced mockendpoint. I guess this could be documented somewhere useful, as a solution.



@UseAdviceWith

@MockEndpoints(value = "/^myMock$/“)

Public class StopDoubleMockInjection {


@EndpointInject(uri = “mock:myMock")

MockEndpoint output;


@EndpointInject(uri = "mock:output”) // <— Let UseAdviceWith take care of this one.

MockEndpoint output;


context.getRouteDefinition("route3").adviceWith(context, new AdviceWithRouteBuilder() {


@Override

public void configure() throws Exception {


interceptSendToEndpoint(RouteNames.POST_MESSAGE_DIRECT)

.skipSendToOriginalEndpoint()

.to("mock:output");

}

});



Many thanks,

Naseem


Get Outlook for Android<https://aka.ms/ghei36>