Return-Path: X-Original-To: apmail-aries-commits-archive@www.apache.org Delivered-To: apmail-aries-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BF5DC18D3C for ; Thu, 25 Feb 2016 14:08:32 +0000 (UTC) Received: (qmail 20304 invoked by uid 500); 25 Feb 2016 14:08:26 -0000 Delivered-To: apmail-aries-commits-archive@aries.apache.org Received: (qmail 20200 invoked by uid 500); 25 Feb 2016 14:08:23 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 18797 invoked by uid 99); 25 Feb 2016 14:08:18 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Feb 2016 14:08:18 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 09014C0476 for ; Thu, 25 Feb 2016 14:08:18 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.671 X-Spam-Level: X-Spam-Status: No, score=0.671 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.329] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 7rYIyXtozrMl for ; Thu, 25 Feb 2016 14:08:16 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id D62CE5F3FF for ; Thu, 25 Feb 2016 14:08:15 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id BD3B8E0285 for ; Thu, 25 Feb 2016 14:08:14 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id C0D7A3A0113 for ; Thu, 25 Feb 2016 14:08:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1732308 - /aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SimpleTransactionTest.java Date: Thu, 25 Feb 2016 14:08:14 -0000 To: commits@aries.apache.org From: timothyjward@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160225140814.C0D7A3A0113@svn01-us-west.apache.org> Author: timothyjward Date: Thu Feb 25 14:08:14 2016 New Revision: 1732308 URL: http://svn.apache.org/viewvc?rev=1732308&view=rev Log: [tx-control] Testing of nested transactions Modified: aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SimpleTransactionTest.java Modified: aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SimpleTransactionTest.java URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SimpleTransactionTest.java?rev=1732308&r1=1732307&r2=1732308&view=diff ============================================================================== --- aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SimpleTransactionTest.java (original) +++ aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SimpleTransactionTest.java Thu Feb 25 14:08:14 2016 @@ -29,6 +29,7 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Arrays; import java.util.Properties; import javax.inject.Inject; @@ -120,6 +121,105 @@ public class SimpleTransactionTest exten })); } + @Test + public void testNestedTx() { + txControl.required(() -> { + connection.createStatement() + .execute("Insert into TEST_TABLE values ( 'Hello World!' )"); + + txControl.requiresNew(() -> connection.createStatement() + .execute("Insert into TEST_TABLE values ( 'Hello Nested World!' )")); + + return null; + }); + + String[] results = txControl.notSupported(() -> { + Statement s = connection.createStatement(); + + ResultSet rs = s.executeQuery("Select count(*) from TEST_TABLE"); + rs.next(); + int count = rs.getInt(1); + + rs = s.executeQuery("Select message from TEST_TABLE ORDER BY message"); + + String[] result = new String[2]; + rs.next(); + result[0] = "" + count + ": " + rs.getString(1); + rs.next(); + result[1] = "" + count + ": " + rs.getString(1); + return result; + }); + + System.out.println(Arrays.toString(results)); + + assertEquals("2: Hello Nested World!", results[0]); + assertEquals("2: Hello World!", results[1]); + } + + @Test + public void testNestedTxOuterRollback() { + txControl.required(() -> { + // This will not end up in the database + connection.createStatement() + .execute("Insert into TEST_TABLE values ( 'Hello World!' )"); + + // This should only apply to the current transaction level + txControl.setRollbackOnly(); + + // This nested transaction will commit + txControl.requiresNew(() -> connection.createStatement() + .execute("Insert into TEST_TABLE values ( 'Hello Nested World!' )")); + + return null; + }); + + assertEquals("1: Hello Nested World!", txControl.notSupported(() -> { + Statement s = connection.createStatement(); + + ResultSet rs = s.executeQuery("Select count(*) from TEST_TABLE"); + rs.next(); + int count = rs.getInt(1); + + rs = s.executeQuery("Select message from TEST_TABLE ORDER BY message"); + + rs.next(); + return "" + count + ": " + rs.getString(1); + })); + } + + @Test + public void testNestedTxInnerRollback() { + txControl.required(() -> { + // This will end up in the database + connection.createStatement() + .execute("Insert into TEST_TABLE values ( 'Hello World!' )"); + + + // This nested transaction not commit + txControl.requiresNew(() -> { + connection.createStatement() + .execute("Insert into TEST_TABLE values ( 'Hello Nested World!' )"); + txControl.setRollbackOnly(); + return null; + }); + + return null; + }); + + assertEquals("1: Hello World!", txControl.notSupported(() -> { + Statement s = connection.createStatement(); + + ResultSet rs = s.executeQuery("Select count(*) from TEST_TABLE"); + rs.next(); + int count = rs.getInt(1); + + rs = s.executeQuery("Select message from TEST_TABLE ORDER BY message"); + + rs.next(); + return "" + count + ": " + rs.getString(1); + })); + } + @Configuration public Option[] configuration() { String localRepo = System.getProperty("maven.repo.local");