diff options
author | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
---|---|---|
committer | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
commit | bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch) | |
tree | 38a92061c0793434c4be189f1d70c3458b6bc41d /branches/sca-java-1.2/itest/transaction/src/test |
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.2/itest/transaction/src/test')
2 files changed, 172 insertions, 0 deletions
diff --git a/branches/sca-java-1.2/itest/transaction/src/test/java/org/apache/tuscany/sca/itest/transaction/ConcurrentXAResourceTestCase.java b/branches/sca-java-1.2/itest/transaction/src/test/java/org/apache/tuscany/sca/itest/transaction/ConcurrentXAResourceTestCase.java new file mode 100644 index 0000000000..c23628ff91 --- /dev/null +++ b/branches/sca-java-1.2/itest/transaction/src/test/java/org/apache/tuscany/sca/itest/transaction/ConcurrentXAResourceTestCase.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.itest.transaction; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.logging.Logger; + +import javax.sql.XAConnection; +import javax.transaction.Transaction; +import javax.transaction.TransactionManager; + +import junit.framework.TestCase; + +import org.apache.derby.jdbc.EmbeddedXADataSource; +import org.apache.tuscany.sca.policy.transaction.TransactionManagerHelper; +import org.apache.tuscany.sca.policy.transaction.TransactionManagerWrapper; + +public class ConcurrentXAResourceTestCase extends TestCase { + class TestThread extends Thread { + private int counter; + + TestThread(int i) { + counter = i; + } + + public void run() { + log.info(this + " running..."); + + EmbeddedXADataSource xads = new EmbeddedXADataSource(); + xads.setDatabaseName("target/test" + counter); + xads.setCreateDatabase("create"); + Connection conn = null; + try { + + Transaction trans = helper.managedGlobalTransactionPreInvoke(); + + XAConnection xaconn = xads.getXAConnection(); + + trans.enlistResource(xaconn.getXAResource()); + + conn = xaconn.getConnection(); + try { + conn.prepareStatement("create table T1(col1 char(100))").execute(); + } catch (SQLException ex) { + log.info("table T1 exists"); + } + conn.prepareStatement("insert into T1 values('kkkkkkkk')").execute(); + ResultSet rs = conn.prepareStatement("select count(*) from T1").executeQuery(); + rs.next(); + log.info(String.valueOf(rs.getInt(1))); + + helper.managedGlobalTransactionPostInvoke(trans, false); + + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + try { + conn.close(); + } catch (Exception _ex) { + _ex.printStackTrace(); + } + } + } + + } + private TransactionManagerWrapper activator; + private TransactionManagerHelper helper; + + private Logger log = Logger.getLogger(this.getClass().getName()); + + public void setUp() throws Exception { + activator = new TransactionManagerWrapper(); + activator.start(); + TransactionManager tm = activator.getTransactionManager(); + helper = new TransactionManagerHelper(tm); + } + + public void tearDown() throws Exception { + activator.stop(); + + } + + public void testConcurrent() { + TestThread[] tts = new TestThread[5]; + for (int i = 0; i < tts.length; i++) { + tts[i] = new TestThread(i); + tts[i].start(); + // log.info("one TestThread started..."); + } + try { + for (TestThread tt : tts) { + while (tt != null && tt.isAlive()) { + // log.info("wait for..."); + Thread.sleep(200); + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/branches/sca-java-1.2/itest/transaction/src/test/java/org/apache/tuscany/sca/itest/transaction/TransactionTestCase.java b/branches/sca-java-1.2/itest/transaction/src/test/java/org/apache/tuscany/sca/itest/transaction/TransactionTestCase.java new file mode 100644 index 0000000000..36884f6098 --- /dev/null +++ b/branches/sca-java-1.2/itest/transaction/src/test/java/org/apache/tuscany/sca/itest/transaction/TransactionTestCase.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.itest.transaction; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TransactionTestCase { + private static SCADomain domain; + + @BeforeClass + public static void init() throws Exception { + domain = SCADomain.newInstance("accounts.composite"); + } + + @AfterClass + public static void destroy() throws Exception { + if (domain != null) { + domain.close(); + } + } + + @Test + public void testTransaction() throws Exception { + TransferService service = domain.getService(TransferService.class, "TransferServiceComponent"); + String[] accounts = service.getAccounts(); + for (int i = 0; i < accounts.length; i++) { + float balance = service.getBalance(accounts[i]); + System.out.println("[" + i + "] " + accounts[i] + ":" + balance); + } + service.transfer(accounts[0], accounts[2], 200.0f); + } + +} |