Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 82EEB1037C for ; Thu, 14 Nov 2013 10:31:17 +0000 (UTC) Received: (qmail 43632 invoked by uid 500); 14 Nov 2013 10:31:14 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 43592 invoked by uid 500); 14 Nov 2013 10:31:13 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 43580 invoked by uid 99); 14 Nov 2013 10:31:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Nov 2013 10:31:11 +0000 X-ASF-Spam-Status: No, hits=0.6 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of claus.ibsen@gmail.com designates 209.85.223.173 as permitted sender) Received: from [209.85.223.173] (HELO mail-ie0-f173.google.com) (209.85.223.173) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Nov 2013 10:31:05 +0000 Received: by mail-ie0-f173.google.com with SMTP id x13so2454050ief.32 for ; Thu, 14 Nov 2013 02:30:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=6HLsXG/dbii8O27qRxLXDOhPI4yzd1Hp8ttD8AVGmB0=; b=mimITH+uNJYgeCKPhwCF1/tAA8uypG/o8YQK+OZwI/SrMIXE4d3eG2JQWWkOhMPiO2 SdkLqGADpd6JNHQC6/7HjtheC7uwOLG7URNHAtyZhT2VIVYvjxUh+0da6O0TivYNSNHh vYkP9i6Rb5zDlTPcSVnn9h5lXIvEQwJwCea/5WbjVr5pn0So0fFWftyCm1LLh+462SNP dgFbXF3jRzdrXv+Nt+b0IlviOYGKu7Ds7wBeV6Z/LD2C8m4pAZy9oQ49xTORr6vwC1dd LI2l7wm/fwk25tRaO8lMIjhMx4iYRDjih1FDa1Eo4OVZ06Dl167FywuBEfoZEMAd+bEj O3Sw== X-Received: by 10.50.136.200 with SMTP id qc8mr927281igb.52.1384425044369; Thu, 14 Nov 2013 02:30:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.168.38 with HTTP; Thu, 14 Nov 2013 02:30:24 -0800 (PST) In-Reply-To: <1384415901331-5743249.post@n5.nabble.com> References: <1384334475270-5743163.post@n5.nabble.com> <1384368528945-5743207.post@n5.nabble.com> <1384415901331-5743249.post@n5.nabble.com> From: Claus Ibsen Date: Thu, 14 Nov 2013 11:30:24 +0100 Message-ID: Subject: Re: onCompletion not triggerd in testing To: "users@camel.apache.org" Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org What Camel version do you use? And as always try making simpler unit tests to get it working, eg just a plain onCompletion etc. And in the past there was an bug with using onWhen with onCompletion. So try with latest release of Camel. On Thu, Nov 14, 2013 at 8:58 AM, cristisor wrote: > Hello, > > I'm back with some code. > The mock route builder: > @Component > public class MockedTransactionToDBPublisherRouteBuilder extends > TransactionToDBPublisherRouteBuilder { > > /** > * @throws java.sql.SQLException > */ > public MockedTransactionToDBPublisherRouteBuilder(DataSource datasource, > TransactionTemplate transactionTemplate, String > redeliveryPolicy, ProducerTemplate producer, > ConsumerTemplate consumer) { > super(datasource, transactionTemplate, redeliveryPolicy, producer, > consumer); > } > > /** > * {@inheritDoc} > */ > @Override > protected String getExceptionEndpoint() { > return "mock:exception"; > } > > /** > * {@inheritDoc} > */ > @Override > protected String getDeadLetterEndpoint() { > return "mock:deadletter"; > } > > /** > * {@inheritDoc} > */ > @Override > protected String getInputEndpoint() { > return "direct:input"; > } > > /** > * {@inheritDoc} > */ > @Override > protected String getOutputEndpoint() { > return "mock:output"; > } > } > > > The route initialized in TransactionToDBPublisherRouteBuilder: > protected void createRoute(Processor processor) { > from(getInputEndpoint()) > // when the exchange is a TRANSACTION and is completed > update the number of passed transactions > .onCompletion() > .onCompleteOnly() > > .onWhen(TransactionPredicates.isMessageType(MessageType.TRANSACTION)) > .process(endOfDaySyncProcessor) > .end() > // the onCompletion callback ended and normal processing is > back > .choice() > // the End Of Day must be handled separately since it is > processed after all the TRANSACTIONs > > .when(TransactionPredicates.isMessageType(MessageType.END_OF_DAY)) > .process(endOfDaySyncProcessor) > // let all the other exchanges follow the standard route > // this path can't go through the endOfDaySync route because > we need to intercept the callback > .otherwise() > .process(processor) > .to(getOutputEndpoint()) > .end(); > > // this is the route where the End Of Day go after all the > transactions have been integrated > from(getSyncEndOfDayEndpoint()) > .process(processor) > .to(getOutputEndpoint()); > } > > > The base test class: > @ContextConfiguration(locations = { "transactionToDb-context.xml" }) > abstract public class AbstractTransactionToDBPublisherRouteBuilderTest > extends AbstractJUnit4SpringContextTests { > protected static final String CHARSET = "UTF-8"; > > @Autowired > protected CamelContext camelContext; > > @Autowired > protected DataSource DATA_SOURCE; > > @Autowired > protected TransactionTemplate TRANSACTION_TEMPLATE; > > @EndpointInject(uri = "mock:output") > protected MockEndpoint resultEndpoint; > > @EndpointInject(uri = "mock:exception") > protected MockEndpoint exceptionEndpoint; > > @Produce(uri = "direct:input") > protected ProducerTemplate template; > > @BeforeClass > public static void beforeClass() { > // force jibx to use the staxReaderFactory > System.setProperty("org.jibx.runtime.impl.parser", > "org.jibx.runtime.impl.StAXReaderFactory"); > } > > @Before > public void setUp() throws Exception { > // delete all records from the database > TestUtil.clearDatabase(DATA_SOURCE.getConnection()); > } > > protected Exchange createExchangeWithBodyAndHeader(Object body, > MessageType type) { > Exchange exchange = new DefaultExchange(camelContext); > Message message = exchange.getIn(); > message.setHeader("testClass", getClass().getName()); > message.setHeader(MessageConstant.ERES_CONTENT_TYPE, > type.toString()); > message.setBody(body); > return exchange; > } > } > > > The test: > @Test > public void testRouteWithPendingTransactions() throws Exception { > resultEndpoint.setExpectedMessageCount(4); > > // sending Transaction 1 > InputStream is = > getClass().getClassLoader().getResourceAsStream("Transaction1.xml"); > String msg = TestUtil.getInputStreamAsString(is, CHARSET); > is.close(); > > Exchange exchange = createExchangeWithBodyAndHeader(msg, > MessageType.TRANSACTION); > template.send(exchange); > > // sending Transaction 2 > is = > getClass().getClassLoader().getResourceAsStream("Transaction2.xml"); > msg = TestUtil.getInputStreamAsString(is, CHARSET); > is.close(); > > exchange = createExchangeWithBodyAndHeader(msg, > MessageType.TRANSACTION); > template.send(exchange); > > // sending End Of Process which must wait for 3 transactions to be > processed > is = > getClass().getClassLoader().getResourceAsStream("endBusinessDate.xml"); > msg = TestUtil.getInputStreamAsString(is, CHARSET); > is.close(); > > // turn the End Of Day into Exchange and send them to the Direct > Input > exchange = createExchangeWithBodyAndHeader(msg, > MessageType.END_OF_DAY); > template.send(exchange); > > resultEndpoint.assertIsNotSatisfied(1000); > > // sending Transaction 3, which should trigger the processing of the > End Of Process also > is = > getClass().getClassLoader().getResourceAsStream("Transaction3.xml"); > msg = TestUtil.getInputStreamAsString(is, CHARSET); > is.close(); > > exchange = createExchangeWithBodyAndHeader(msg, > MessageType.TRANSACTION); > template.send(exchange); > > // assert that we got all the messages > resultEndpoint.assertIsSatisfied(1000); > } > > > The syncProcessor is working fine but none of the onCompletion events get to > it. > > Thanks for your support. > > > > -- > View this message in context: http://camel.465427.n5.nabble.com/onCompletion-not-triggerd-in-testing-tp5743163p5743249.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen ----------------- Red Hat, Inc. Email: cibsen@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen