On Thu, Mar 5, 2009 at 2:52 AM, Willem Jiang <[email protected]> wrote: > Hi Claus, > > Does this change need to be merge in to 1.x branch ? No as the code change in StreamCachingInterceptor does not exists in 1.x. It was using a TypeConverterRegistry which does not exist in 1.x.
The other change to only wait 2 sec instead of 20 sec will of course cut 18 sec on unit testing + // wait at most 2 sec to speedup unit testing + resultEndpoint.setResultWaitTime(2000); And the last change to support Object instead of only String values for expected header is fine only on trunk. > > Thanks, > > Willem > > [email protected] wrote: >> Author: davsclaus >> Date: Wed Mar 4 12:06:11 2009 >> New Revision: 749973 >> >> URL: http://svn.apache.org/viewvc?rev=749973&view=rev >> Log: >> CAMEL-1417: Fixed failing unit test as we can not use the lookup in type >> converter registry. Improved expectedHeader to allow all types instead of >> only string values. So now you can compare real numbers and whatelse. >> >> Modified: >> >> camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java >> >> camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCachingInterceptor.java >> >> camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java >> >> camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePerformanceTest.java >> >> Modified: >> camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java >> URL: >> http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java?rev=749973&r1=749972&r2=749973&view=diff >> ============================================================================== >> --- >> camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java >> (original) >> +++ >> camel/trunk/camel-core/src/main/java/org/apache/camel/component/mock/MockEndpoint.java >> Wed Mar 4 12:06:11 2009 >> @@ -74,7 +74,7 @@ >> private List actualBodyValues; >> private PropertyChangeSupport propertyChangeSupport = new >> PropertyChangeSupport(this); >> private String headerName; >> - private String headerValue; >> + private Object headerValue; >> private Object actualHeader; >> private Processor reporter; >> >> @@ -308,7 +308,7 @@ >> * Adds an expectation that the given header name & value are received >> by this >> * endpoint >> */ >> - public void expectedHeaderReceived(String name, String value) { >> + public void expectedHeaderReceived(final String name, final Object >> value) { >> this.headerName = name; >> this.headerValue = value; >> >> @@ -316,7 +316,8 @@ >> public void run() { >> assertTrue("No header with name " + headerName + " found.", >> actualHeader != null); >> >> - assertEquals("Header of message", headerValue, >> actualHeader.toString()); >> + Object actualValue = >> getCamelContext().getTypeConverter().convertTo(actualHeader.getClass(), >> headerValue); >> + assertEquals("Header of message", actualValue, >> actualHeader); >> } >> }); >> } >> >> Modified: >> camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCachingInterceptor.java >> URL: >> http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCachingInterceptor.java?rev=749973&r1=749972&r2=749973&view=diff >> ============================================================================== >> --- >> camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCachingInterceptor.java >> (original) >> +++ >> camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCachingInterceptor.java >> Wed Mar 4 12:06:11 2009 >> @@ -24,7 +24,6 @@ >> import org.apache.camel.NoTypeConversionAvailableException; >> import org.apache.camel.Processor; >> import org.apache.camel.StreamCache; >> -import org.apache.camel.TypeConverter; >> import org.apache.camel.model.InterceptorRef; >> import org.apache.camel.model.InterceptorType; >> import org.apache.camel.processor.DelegateProcessor; >> @@ -64,39 +63,28 @@ >> } >> } >> } >> - >> + >> �...@override >> public void process(Exchange exchange) throws Exception { >> AsyncProcessorHelper.process(this, exchange); >> } >> >> public boolean process(Exchange exchange, AsyncCallback callback) { >> - // Change the body to StreamCache if possible >> - // important to lookup for the type converter to avoid excessive >> overhead of trying to covnert if not possible >> - // as Camel will throw NoTypeConversionAvailableException that we >> just ignores. So we want to avoid this >> - // exception handling as it hurts performance dramatically for high >> throughput >> - // See also MessageSupport#getBody and CAMEL-1417 >> - Object body = exchange.getIn().getBody(); >> - if (body != null) { >> - TypeConverter tc = >> exchange.getContext().getTypeConverterRegistry().lookup(StreamCache.class, >> body.getClass()); >> - if (tc != null) { >> - try { >> - StreamCache newBody = tc.convertTo(StreamCache.class, >> exchange, body); >> - if (newBody != null) { >> - exchange.getIn().setBody(newBody); >> - } >> - MessageHelper.resetStreamCache(exchange.getIn()); >> - } catch (NoTypeConversionAvailableException ex) { >> - // ignore if in is not of StreamCache type >> - } >> + try { >> + StreamCache newBody = >> exchange.getIn().getBody(StreamCache.class); >> + if (newBody != null) { >> + exchange.getIn().setBody(newBody); >> } >> + MessageHelper.resetStreamCache(exchange.getIn()); >> + } catch (NoTypeConversionAvailableException ex) { >> + // ignore if in is not of StreamCache type >> } >> >> return proceed(exchange, callback); >> } >> >> - public boolean proceed(Exchange exchange, AsyncCallback callback) { >> - if (getProcessor() instanceof AsyncProcessor) { >> + public boolean proceed(Exchange exchange, AsyncCallback callback) { >> + if (getProcessor() instanceof AsyncProcessor) { >> return ((AsyncProcessor) getProcessor()).process(exchange, >> callback); >> } else { >> try { >> >> Modified: >> camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java >> URL: >> http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java?rev=749973&r1=749972&r2=749973&view=diff >> ============================================================================== >> --- >> camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java >> (original) >> +++ >> camel/trunk/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTest.java >> Wed Mar 4 12:06:11 2009 >> @@ -112,6 +112,8 @@ >> >> MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); >> resultEndpoint.expectedMessageCount(6); >> + // wait at most 2 sec to speedup unit testing >> + resultEndpoint.setResultWaitTime(2000); >> resultEndpoint.assertIsNotSatisfied(); >> } >> >> @@ -141,7 +143,6 @@ >> resultEndpoint.assertIsSatisfied(); >> >> resultEndpoint.reset(); >> - >> // assert failure when value is different >> resultEndpoint.expectedHeaderReceived("header", "value1"); >> sendHeader("header", "value"); >> @@ -162,10 +163,21 @@ >> resultEndpoint.assertIsNotSatisfied(); >> } >> >> + public void testExpectationOfHeaderWithNumber() throws >> InterruptedException { >> + MockEndpoint resultEndpoint = getMockEndpoint("mock:result"); >> + resultEndpoint.reset(); >> + >> + // assert we can assert using other than string, eg numbers >> + resultEndpoint.expectedHeaderReceived("number", 123); >> + sendHeader("number", 123); >> + resultEndpoint.assertIsSatisfied(); >> + >> + resultEndpoint.assertIsNotSatisfied(); >> + } >> + >> protected void sendMessages(int... counters) { >> for (int counter : counters) { >> - template.sendBodyAndHeader("direct:a", >> createTestMessage(counter), >> - "counter", counter); >> + template.sendBodyAndHeader("direct:a", >> createTestMessage(counter), "counter", counter); >> } >> } >> >> @@ -181,7 +193,7 @@ >> return list; >> } >> >> - protected void sendHeader(String name, String value) { >> + protected void sendHeader(String name, Object value) { >> template.sendBodyAndHeader("direct:a", "body", name, value); >> } >> >> >> Modified: >> camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePerformanceTest.java >> URL: >> http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePerformanceTest.java?rev=749973&r1=749972&r2=749973&view=diff >> ============================================================================== >> --- >> camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePerformanceTest.java >> (original) >> +++ >> camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RoutePerformanceTest.java >> Wed Mar 4 12:06:11 2009 >> @@ -38,6 +38,7 @@ >> >> MockEndpoint endpoint = getMockEndpoint("mock:results"); >> endpoint.expectedMessageCount((int) dataSet.getSize()); >> + endpoint.expectedHeaderReceived("foo", 123); >> >> assertMockEndpointsSatisfied(); >> >> >> >> > > -- Claus Ibsen Apache Camel Committer Open Source Integration: http://fusesource.com Blog: http://davsclaus.blogspot.com/
