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 685A310C5A for ; Thu, 6 Jun 2013 20:59:11 +0000 (UTC) Received: (qmail 34678 invoked by uid 500); 6 Jun 2013 20:59:10 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 34634 invoked by uid 500); 6 Jun 2013 20:59:10 -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 34626 invoked by uid 99); 6 Jun 2013 20:59:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Jun 2013 20:59:10 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of christian.mueller@gmail.com designates 209.85.214.171 as permitted sender) Received: from [209.85.214.171] (HELO mail-ob0-f171.google.com) (209.85.214.171) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Jun 2013 20:59:05 +0000 Received: by mail-ob0-f171.google.com with SMTP id dn14so5459139obc.16 for ; Thu, 06 Jun 2013 13:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=V4XKTiLvo8kNOrGc00i7iTAO3NmExGzySdoDWbLjw8c=; b=icZSD2hM6QJX7yFcw8LzusQfsxuUEeRY7AUP/dwgITtGeBXfmz1C4FEEgLnk+n6c2B dajPhw5Q4kVGJuuDNw1jyPd2Y7Wzc+bOqqpuKj8RgP4xNiI3eGAHU9Q9eF2ieDURPOAO yrgxCiPmLsEF+MzIwKjnA9emvtisWus3Pdmh3N2hPOcBMNQ94b/LH7OrshUyJe3y85Zk irMAZS2gDFaia5SEQwvR0zi6b+r5jcWZIGdg5pGbET94pFpZuLXtIxGHCh+sWz6qQbM9 LJnxJbeVAFMgWduh4pxaoOQFpCgeYMSyxD0NmuotRXnA8QLvL+yLxYiu5OQB8qS+qiJG PNpA== MIME-Version: 1.0 X-Received: by 10.60.132.146 with SMTP id ou18mr16992148oeb.36.1370552323907; Thu, 06 Jun 2013 13:58:43 -0700 (PDT) Received: by 10.182.110.100 with HTTP; Thu, 6 Jun 2013 13:58:43 -0700 (PDT) In-Reply-To: References: Date: Thu, 6 Jun 2013 22:58:43 +0200 Message-ID: Subject: Re: Transactional test assertions timing issue From: =?ISO-8859-1?Q?Christian_M=FCller?= To: users@camel.apache.org Content-Type: multipart/alternative; boundary=047d7b4724f469a8a004de8294c6 X-Virus-Checked: Checked by ClamAV on apache.org --047d7b4724f469a8a004de8294c6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable If you have to do it by yourself (as we have to do it some time), you could do it in this way (template is an instance of Springs JDBCTemplate): private void assertDatabaseCount(int count) throws InterruptedException { long timeout =3D System.currentTimeMillis() + 10000; while (timeout > System.currentTimeMillis() && template.queryForInt("SELECT COUNT(*) FROM FOO_TABLE") < count) { Thread.sleep(200); } assertEquals(count, statisticMock.size()); } Best, Christian M=FCller ----------------- Software Integration Specialist Apache Camel committer: https://camel.apache.org/team V.P. Apache Camel: https://www.apache.org/foundation/ Apache Member: https://www.apache.org/foundation/members.html https://www.linkedin.com/pub/christian-mueller/11/551/642 On Tue, Jun 4, 2013 at 5:31 PM, Alex Sherwin wrote= : > When unit (integration) testing a transacted route, such as (pseudo): > > > > > > > > Where "someBeanProcessor" does some DB work and participates in a JTA > transaction with the JMS message on this route > > The problem is, what is a reliable way to apply an assertion on the work > that "someBeanProcessor" has done in the DB? I've tried both of the > following: > > 1. Add , get a MockEn= dpoint > ref and use an expected message count of 1, and wait on > mock.assertIsSatisified() > > 2. Use a NotifyBuilder on the route and use whenComplete(1), and wait on > builder.matchesMockWaitTime() > > Both have the same result, where my test code is told about the success > before the JTA transaction has finished comitting, so when the test threa= d > performs a SQL select, it is doing so too early since the JTA tx of the > route hasn't actually completed. > > This scenario works OK if the end result is something like uri=3D"activemq:out queue"/> and I use a MockEndpoint on the JMS output U= RI, > which makes sense since it'd be waiting on the TX to commit here; but wha= t > about routes where this isn't an option? > > Do I just need to suck it up and use Thread.sleep(..) on the test thread? > > Thanks, > > -- > Alexander Sherwin > --047d7b4724f469a8a004de8294c6--