Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBTM-3376] clean CMRIntegrationTest to be more transparent and get more info when it fails #1702

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much more friendly than boom :-)

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();
mmusgrov marked this conversation as resolved.
Show resolved Hide resolved
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