Skip to content

Commit

Permalink
[JBTM-3376] clean CMRIntegrationTest to be more transparent and get m…
Browse files Browse the repository at this point in the history
…ore when fails
  • Loading branch information
ochaloup committed Oct 23, 2020
1 parent ed79025 commit b3e22db
Showing 1 changed file with 28 additions and 61 deletions.
Expand Up @@ -40,9 +40,9 @@
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;

import org.h2.jdbcx.JdbcDataSource;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
Expand All @@ -51,7 +51,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import com.arjuna.ats.arjuna.exceptions.ObjectStoreException;
import com.arjuna.ats.arjuna.recovery.RecoveryManager;
import com.arjuna.ats.arjuna.recovery.RecoveryModule;
import com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule;
Expand All @@ -62,6 +61,7 @@

@RunWith(Arquillian.class)
public class CMRIntegrationTest {
private static final Logger log = Logger.getLogger(CMRIntegrationTest.class);

private static final String DEPENDENCIES = "Dependencies: com.h2database.h2, org.jboss.jts, org.jboss.jboss-transaction-spi\n";

Expand Down Expand Up @@ -110,7 +110,7 @@ public void testCMR1() throws Exception {

userTransaction.commit();
} catch (Exception e) {
System.out.printf("XXX txn excp: %s%n", e.getCause());
log.infof(e, "XXX txn exception cause: %s", e.getCause());
} finally {
try {
if (userTransaction.getStatus() == Status.STATUS_ACTIVE
Expand All @@ -122,12 +122,12 @@ public void testCMR1() throws Exception {
}
}

private int threadCount = 5;
private int iterationCount = 20;
private final int threadCount = 5;
private final int iterationCount = 20;
private int waiting;
private boolean go;
private final Object waitLock = new Object();
private AtomicInteger totalExecuted = new AtomicInteger();
private final AtomicInteger totalExecuted = new AtomicInteger();

public void doTest(final DataSource dataSource) throws Exception {

Expand All @@ -145,17 +145,15 @@ public void run() {
while (!go) {
try {
CMRIntegrationTest.this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InterruptedException ie) {
log.error("Interrupted exception on waiting for a notification at CMRIntegrationTest", ie);
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 {
Expand All @@ -169,60 +167,40 @@ public void run() {
.createStatement();
createStatement
.execute("INSERT INTO foo (bar) VALUES (1)");
// System.out.printf("XXX txn close%n");

if (faultType == 1)
Runtime.getRuntime().halt(0);

userTransaction.commit();
connection.close(); // This wouldn't work for a
// 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();
}
log.errorf(e, "Error while invoking insertion to a database table with CMR resource");
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();
log.errorf("Next SQLException chained", nextException);
nextException = nextException.getNextException();
}
try {
userTransaction.rollback();
} catch (IllegalStateException | SecurityException
| SystemException e1) {
e1.printStackTrace();
log.error("Problem with transaction", e1);
fail("Problem with transaction");
}
} catch (NotSupportedException | SystemException
| IllegalStateException | RollbackException
| SecurityException | HeuristicMixedException
| HeuristicRollbackException e) {
e.printStackTrace();
log.error("Problem with UserTransaction", e);
fail("Problem with transaction");
} finally {
if (connection != null)
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace(); // To change body of
// catch statement
// use File |
// Settings | File
// Templates.
} catch (SQLException sqle) {
log.error("Error on closing failed CMR resource connection", sqle);
}
}

Expand All @@ -239,31 +217,27 @@ public void run() {
waitLock.wait();
}
}
long startTime = -1;
long startTime;
synchronized (CMRIntegrationTest.this) {
go = true;
CMRIntegrationTest.this.notifyAll();
startTime = System.currentTimeMillis();
}

for (int i = 0; i < threads.length; i++) {
threads[i].join();
for (Thread thread : threads) {
thread.join();
}

long endTime = System.currentTimeMillis();

System.out.println(new Date() + " Number of transactions: "
+ totalExecuted.intValue());
log.infof("%T Number of transactions: %d", new Date(), totalExecuted.intValue());

long additionalCleanuptime = 0L; // postRunCleanup(dataSource);

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))));
log.infof(" Total time millis: %d%n", timeInMillis);
log.infof(" Average transaction time: %d%n", timeInMillis / totalExecuted.intValue());
log.infof(" Transactions per second: %d%n", Math.round((totalExecuted.intValue() / (timeInMillis / 1000d))));

checkFooSize(dataSource);
}
Expand Down Expand Up @@ -292,15 +266,14 @@ public void checkFooSize(DataSource dataSource) throws SQLException,
}

private CommitMarkableResourceRecordRecoveryModule getCRRRM() {
CommitMarkableResourceRecordRecoveryModule crrrm = null;
RecoveryManager recMan = RecoveryManager.manager();
Vector recoveryModules = recMan.getModules();
Vector<RecoveryModule> recoveryModules = recMan.getModules();

if (recoveryModules != null) {
Enumeration modules = recoveryModules.elements();
Enumeration<RecoveryModule> modules = recoveryModules.elements();

while (modules.hasMoreElements()) {
RecoveryModule m = (RecoveryModule) modules.nextElement();
RecoveryModule m = modules.nextElement();

if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
return (CommitMarkableResourceRecordRecoveryModule) m;
Expand All @@ -311,9 +284,7 @@ private CommitMarkableResourceRecordRecoveryModule getCRRRM() {
return null;
}

public long postRunCleanup(DataSource dataSource) throws SQLException,
ObjectStoreException {

public long postRunCleanup(DataSource dataSource) throws SQLException {
Connection connection = dataSource.getConnection();
CommitMarkableResourceRecordRecoveryModule crrrm = getCRRRM();

Expand All @@ -330,8 +301,6 @@ public long postRunCleanup(DataSource dataSource) throws SQLException,

if (expectedReapableConnectableResourceRecords > 0) {
// The recovery module has to perform lookups
// new InitialContext().rebind("connectableresource",
// recoveryDataSource);
long startTime = System.currentTimeMillis();
crrrm.periodicWorkFirstPass();
crrrm.periodicWorkSecondPass();
Expand All @@ -340,10 +309,8 @@ public long postRunCleanup(DataSource dataSource) throws SQLException,
checkSize("xids", statement, 0);
statement.close();

System.out.println(" Total cleanup time: "
+ (endTime - startTime) + " Average cleanup time: "
+ (endTime - startTime)
/ expectedReapableConnectableResourceRecords);
log.infof(" Total cleanup time: %d Average cleanup time: %s",
(endTime - startTime),(endTime - startTime) / expectedReapableConnectableResourceRecords);

return endTime - startTime;
} else {
Expand Down

0 comments on commit b3e22db

Please sign in to comment.