use of javax.transaction.NotSupportedException in project narayana by jbosstm.
the class CMRIntegrationTest method doTest.
public void doTest(final DataSource dataSource) throws Exception {
// Test code
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(new Runnable() {
public void run() {
synchronized (waitLock) {
waiting++;
waitLock.notify();
}
synchronized (CMRIntegrationTest.this) {
while (!go) {
try {
CMRIntegrationTest.this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
return;
}
}
}
int success = 0;
Connection connection = null;
int faultType = Integer.getInteger("com.hp.mwtests.ts.jta.commitmarkable.integration.CMRIntegrationTest", 0);
for (int i = 0; i < iterationCount; i++) {
try {
userTransaction.begin();
tm.getTransaction().enlistResource(new DummyXAResource());
connection = dataSource.getConnection();
Statement createStatement = connection.createStatement();
createStatement.execute("INSERT INTO foo (bar) VALUES (1)");
if (faultType == 1)
Runtime.getRuntime().halt(0);
userTransaction.commit();
// This wouldn't work for a
connection.close();
// none-JCA code as commit has
// closed the connection - it
// helps us though as JCA seems
// to rely on finalize
// System.out
// .printf("committed txn iteration %d%n", i);
success++;
} catch (SQLException e) {
System.err.println("boom");
e.printStackTrace();
if (e.getCause() != null) {
e.getCause().printStackTrace();
}
SQLException nextException = e.getNextException();
while (nextException != null) {
nextException.printStackTrace();
nextException = nextException.getNextException();
}
Throwable[] suppressed = e.getSuppressed();
for (int j = 0; j < suppressed.length; j++) {
suppressed[j].printStackTrace();
}
try {
userTransaction.rollback();
} catch (IllegalStateException | SecurityException | SystemException e1) {
e1.printStackTrace();
fail("Problem with transaction");
}
} catch (NotSupportedException | SystemException | IllegalStateException | RollbackException | SecurityException | HeuristicMixedException | HeuristicRollbackException e) {
e.printStackTrace();
fail("Problem with transaction");
} finally {
if (connection != null)
try {
connection.close();
} catch (SQLException e) {
// To change body of
e.printStackTrace();
// catch statement
// use File |
// Settings | File
// Templates.
}
}
}
totalExecuted.addAndGet(success);
}
});
threads[i].start();
}
synchronized (waitLock) {
while (waiting < threads.length) {
waitLock.wait();
}
}
long startTime = -1;
synchronized (CMRIntegrationTest.this) {
go = true;
CMRIntegrationTest.this.notifyAll();
startTime = System.currentTimeMillis();
}
for (int i = 0; i < threads.length; i++) {
threads[i].join();
}
long endTime = System.currentTimeMillis();
System.out.println(new Date() + " Number of transactions: " + totalExecuted.intValue());
// postRunCleanup(dataSource);
long additionalCleanuptime = 0L;
long timeInMillis = (endTime - startTime) + additionalCleanuptime;
System.out.printf(" Total time millis: %d%n", timeInMillis);
System.out.printf(" Average transaction time: %d%n", timeInMillis / totalExecuted.intValue());
System.out.printf(" Transactions per second: %d%n", Math.round((totalExecuted.intValue() / (timeInMillis / 1000d))));
checkFooSize(dataSource);
}
use of javax.transaction.NotSupportedException in project narayana by jbosstm.
the class PerformanceTestCommitMarkableResource method doTest.
public void doTest(final Handler xaHandler, String testName) throws Exception {
String fullTestName = getClass().getName() + testName;
Worker<Void> worker = new Worker<Void>() {
javax.transaction.TransactionManager tm = null;
@Override
public void init() {
tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
}
@Override
public void fini() {
// totalExecuted.addAndGet(success);
}
@Override
public void finishWork(Measurement<Void> measurement) {
try {
xaHandler.finishWork();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public Void doWork(Void context, int batchSize, Measurement<Void> measurement) {
for (int i = 0; i < batchSize; i++) {
try {
tm.begin();
tm.getTransaction().enlistResource(new DummyXAResource());
xaHandler.enlistResource(tm.getTransaction());
tm.commit();
// System.out.println("done");
totalExecuted.incrementAndGet();
} catch (SQLException e) {
measurement.incrementErrorCount();
if (measurement.getNumberOfErrors() == 1) {
System.err.println("boom");
e.printStackTrace();
if (e.getCause() != null) {
e.getCause().printStackTrace();
}
SQLException nextException = e.getNextException();
while (nextException != null) {
nextException.printStackTrace();
nextException = nextException.getNextException();
}
Throwable[] suppressed = e.getSuppressed();
for (int j = 0; j < suppressed.length; j++) {
suppressed[j].printStackTrace();
}
try {
tm.rollback();
} catch (IllegalStateException | SecurityException | SystemException e1) {
e1.printStackTrace();
fail("Problem with transaction");
}
}
} catch (NotSupportedException | SystemException | IllegalStateException | RollbackException | SecurityException | HeuristicMixedException | HeuristicRollbackException e) {
measurement.incrementErrorCount();
e.printStackTrace();
fail("Problem with transaction");
}
}
return context;
}
};
// TODO if non zero then make sure the db is reset after the warm up loop
int warmUpCount = 0;
int batchSize = 50;
int threadCount = 20;
Measurement measurement = new Measurement.Builder(fullTestName).maxTestTime(0L).numberOfCalls(batchSize * threadCount).numberOfThreads(threadCount).batchSize(batchSize).numberOfWarmupCalls(warmUpCount).build().measure(worker, worker);
System.out.printf("%s%n", measurement.getInfo());
System.out.println(new Date() + " Number of transactions: " + totalExecuted.intValue());
long additionalCleanuptime = xaHandler.postRunCleanup(measurement.getNumberOfMeasurements(), measurement.getNumberOfCalls(), measurement.getNumberOfThreads());
long timeInMillis = measurement.getTotalMillis() + additionalCleanuptime;
long throughput = Math.round((totalExecuted.intValue() / (timeInMillis / 1000d)));
System.out.println(" Total transactions: " + totalExecuted.intValue());
System.out.println(" Total time millis: " + timeInMillis);
System.out.println(" Average transaction time: " + timeInMillis / totalExecuted.intValue());
System.out.println(" Transactions per second: " + throughput);
xaHandler.checkFooSize(measurement.getNumberOfMeasurements(), measurement.getBatchSize(), measurement.getNumberOfThreads());
Assert.assertEquals(0, measurement.getNumberOfErrors());
Assert.assertFalse(measurement.getInfo(), measurement.shouldFail());
}
use of javax.transaction.NotSupportedException in project narayana by jbosstm.
the class XATerminatorImple method doRecover.
/**
* <p>
* Recovering /JCA section of object store.
* The filtering functionality on xid or parentNodeName is not permitted and throws {@link NotSupportedException}.<br>
* Expected to be called only with null parameters <code>doRecover(null, null)</code>
*
* @param xid has to be null
* @param parentNodeName has to be null
* @return array of subordinate recovered xids
* @throws XAException if recovery operation fails for the XA protocol reason
* @throws NotSupportedException if not null params are passes as method parameters
*/
@Override
public Xid[] doRecover(Xid xid, String parentNodeName) throws XAException, NotSupportedException {
if (xid != null || parentNodeName != null)
throw new NotSupportedException("doRecover method works only with null arguments");
Xid[] indoubt = null;
try {
RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
InputObjectState states = new InputObjectState();
// only look in the JCA section of the object store
if (recoveryStore.allObjUids(ServerTransaction.getType(), states) && (states.notempty())) {
Stack<Transaction> values = new Stack<Transaction>();
boolean finished = false;
do {
Uid uid = null;
try {
uid = UidHelper.unpackFrom(states);
} catch (IOException ex) {
jtsLogger.i18NLogger.info_fail_to_read_subordinate_uid(recoveryStore, states, ex);
finished = true;
}
if (uid.notEquals(Uid.nullUid())) {
Transaction tx = SubordinationManager.getTransactionImporter().recoverTransaction(uid);
if (tx != null)
values.push(tx);
} else
finished = true;
} while (!finished);
if (values.size() > 0) {
int index = 0;
indoubt = new Xid[values.size()];
while (!values.empty()) {
TransactionImple id = (TransactionImple) values.pop();
indoubt[index] = id.baseXid();
index++;
}
}
}
} catch (Exception ex) {
jtsLogger.i18NLogger.info_fail_to_dorecover(xid, parentNodeName, ex);
}
return indoubt;
}
use of javax.transaction.NotSupportedException in project narayana by jbosstm.
the class BaseTransaction method createSubordinate.
public TransactionImple createSubordinate() throws javax.transaction.NotSupportedException, javax.transaction.SystemException {
if (jtaLogger.logger.isTraceEnabled()) {
jtaLogger.logger.trace("BaseTransaction.createSubordinate");
}
try {
checkTransactionState();
} catch (IllegalStateException e1) {
NotSupportedException notSupportedException = new NotSupportedException();
notSupportedException.initCause(e1);
throw notSupportedException;
} catch (Exception e2) {
javax.transaction.SystemException systemException = new javax.transaction.SystemException(e2.toString());
systemException.initCause(e2);
throw systemException;
}
Integer value = _timeouts.get();
// if not set then assume 0. What else can we do?
int v = 0;
if (value != null) {
v = value.intValue();
}
return new com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.TransactionImple(v);
}
use of javax.transaction.NotSupportedException in project narayana by jbosstm.
the class SimpleNestedDisabledTest method testDisabled.
@Test
public void testDisabled() throws Exception {
ORB myORB = null;
RootOA myOA = null;
myORB = ORB.getInstance("test");
myOA = OA.getRootOA(myORB);
myORB.initORB(new String[] {}, null);
myOA.initOA();
ORBManager.setORB(myORB);
ORBManager.setPOA(myOA);
jtaPropertyManager.getJTAEnvironmentBean().setTransactionManagerClassName(com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple.class.getName());
jtaPropertyManager.getJTAEnvironmentBean().setUserTransactionClassName(com.arjuna.ats.internal.jta.transaction.jts.UserTransactionImple.class.getName());
jtaPropertyManager.getJTAEnvironmentBean().setSupportSubtransactions(false);
javax.transaction.TransactionManager transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager();
transactionManager.begin();
try {
transactionManager.begin();
fail();
} catch (final NotSupportedException ex) {
}
transactionManager.commit();
myOA.destroy();
myORB.shutdown();
}
Aggregations