aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1732984 - in /aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests: AbstractTransactionTest.java SimpleTransactionTest.java SpringJdbcTemplateTransactionTest.java
Date Tue, 01 Mar 2016 00:36:37 GMT
Author: timothyjward
Date: Tue Mar  1 00:36:37 2016
New Revision: 1732984

URL: http://svn.apache.org/viewvc?rev=1732984&view=rev
Log:
[tx-control] Test using remote H2 in addition to local embedded, also test tx suspension

Modified:
    aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java
    aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SimpleTransactionTest.java
    aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SpringJdbcTemplateTransactionTest.java

Modified: aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java?rev=1732984&r1=1732983&r2=1732984&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java
(original)
+++ aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/AbstractTransactionTest.java
Tue Mar  1 00:36:37 2016
@@ -32,6 +32,7 @@ import java.util.Properties;
 import javax.inject.Inject;
 
 import org.apache.aries.itest.AbstractIntegrationTest;
+import org.h2.tools.Server;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.runner.RunWith;
@@ -49,6 +50,8 @@ import org.osgi.service.transaction.cont
 @ExamReactorStrategy(PerClass.class)
 public abstract class AbstractTransactionTest extends AbstractIntegrationTest {
 
+	private static final String REMOTE_DB_PROPERTY = "org.apache.aries.tx.control.itests.remotedb";
+
 	@Inject
 	protected TransactionControl txControl;
 
@@ -60,14 +63,27 @@ public abstract class AbstractTransactio
 	
 	protected Connection connection;
 
+	private Server server;
+
 	@Before
-	public void setUp() {
+	public void setUp() throws Exception {
 		Properties jdbc = new Properties();
 		
-		jdbc.setProperty(DataSourceFactory.JDBC_URL, "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
+		Boolean external = Boolean.parseBoolean(REMOTE_DB_PROPERTY);
 		
-		connection = resourceProviderFactory.getProviderFor(dsf, jdbc, null).getResource(txControl);
+		String jdbcUrl;
+		if(external) {
+			server = Server.createTcpServer("-tcpPort", "0");
+			server.start();
+			
+			jdbcUrl = "jdbc:h2:tcp://127.0.0.1:" + server.getPort() + "/target/test/db1";
+		} else {
+			jdbcUrl = "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1";
+		}
 		
+		jdbc.setProperty(DataSourceFactory.JDBC_URL, jdbcUrl);
+		
+		connection = resourceProviderFactory.getProviderFor(dsf, jdbc, null).getResource(txControl);
 		
 		txControl.required(() -> {
 				Statement s = connection.createStatement();
@@ -84,11 +100,14 @@ public abstract class AbstractTransactio
 
 		txControl.required(() -> connection.createStatement()
 				.execute("DROP TABLE TEST_TABLE"));
-
+		
+		if(server != null) {
+			server.stop();
+		}
 	}
 
 	@Configuration
-	public Option[] configuration() {
+	public Option[] localH2Configuration() {
 		String localRepo = System.getProperty("maven.repo.local");
 		if (localRepo == null) {
 			localRepo = System.getProperty("org.ops4j.pax.url.mvn.localRepository");
@@ -113,6 +132,34 @@ public abstract class AbstractTransactio
 		 */
 		);
 	}
+
+	@Configuration
+	public Option[] serverH2Configuration() {
+		String localRepo = System.getProperty("maven.repo.local");
+		if (localRepo == null) {
+			localRepo = System.getProperty("org.ops4j.pax.url.mvn.localRepository");
+		}
+		
+		Option testSpecificOptions = testSpecificOptions();
+		
+		return options(junitBundles(), systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+				when(localRepo != null)
+				.useOptions(CoreOptions.vmOption("-Dorg.ops4j.pax.url.mvn.localRepository=" + localRepo)),
+				mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit").versionAsInProject(),
+				localTxControlService(),
+				localJdbcResourceProviderWithH2(),
+				systemProperty(REMOTE_DB_PROPERTY).value("true"),
+				when(testSpecificOptions != null).useOptions(testSpecificOptions),
+				mavenBundle("org.ops4j.pax.logging", "pax-logging-api").versionAsInProject(),
+				mavenBundle("org.ops4j.pax.logging", "pax-logging-service").versionAsInProject()
+				
+				/*
+				 * vmOption
+				 * ("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+				 * waitForFrameworkStartup(),
+				 */
+				);
+	}
 	
 	public Option localTxControlService() {
 		return CoreOptions.composite(

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=1732984&r1=1732983&r2=1732984&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
Tue Mar  1 00:36:37 2016
@@ -200,4 +200,23 @@ public class SimpleTransactionTest exten
 		assertEquals("2: Hello Nested World!", results[0]);
 		assertEquals("2: Hello World!", results[1]);
 	}
+
+	@Test
+	public void testSuspendedTx() {
+		txControl.required(() -> {        
+			
+			connection.createStatement()
+				.execute("Insert into TEST_TABLE values ( 'Hello World!' )");
+			
+			assertEquals(Integer.valueOf(0), txControl.notSupported(() -> {
+				ResultSet rs = connection.createStatement()
+						.executeQuery("Select count(*) from TEST_TABLE");
+				rs.next();
+				return rs.getInt(1);
+			}));                
+			
+			return null;            
+			
+		});   
+	}
 }

Modified: aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SpringJdbcTemplateTransactionTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SpringJdbcTemplateTransactionTest.java?rev=1732984&r1=1732983&r2=1732984&view=diff
==============================================================================
--- aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SpringJdbcTemplateTransactionTest.java
(original)
+++ aries/trunk/tx-control/tx-control-itests/src/test/java/org/apache/aries/tx/control/itests/SpringJdbcTemplateTransactionTest.java
Tue Mar  1 00:36:37 2016
@@ -40,7 +40,7 @@ public class SpringJdbcTemplateTransacti
 	JdbcTemplate jdbcTemplate; 
 
 	@Before
-	public void setUp() {
+	public void setUp() throws Exception {
 		super.setUp();
 		
 		jdbcTemplate = new JdbcTemplate(new SingleConnectionDataSource(connection, false));



Mime
View raw message