use of io.narayana.perf.Worker 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());
}
Aggregations