mirror of https://github.com/apache/openjpa.git
OPENJPA-1234:
AllowFailure checks for system property before running or logging exceptions from test methods. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@802587 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3ec9136da7
commit
fb2a45a739
|
@ -57,7 +57,7 @@ public class SimpleEntity implements Serializable {
|
|||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "ID")
|
||||
@Column(name = "ID",columnDefinition="")
|
||||
private long id;
|
||||
|
||||
@Basic
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
<dbcp.args>MaxActive=${dbcp.maxActive},MaxIdle=${dbcp.maxIdle},MinIdle=${dbcp.minIdle},MaxWait=${dbcp.maxWait}</dbcp.args>
|
||||
<derby.locks.waitTimeout>60</derby.locks.waitTimeout>
|
||||
<derby.locks.deadlockTimeout>5</derby.locks.deadlockTimeout>
|
||||
<tests.openjpa.allowfailure>ignore</tests.openjpa.allowfailure>
|
||||
</properties>
|
||||
<profiles>
|
||||
|
||||
|
@ -80,6 +81,10 @@
|
|||
<name>openjpa.ConnectionProperties</name>
|
||||
<value>DriverClassName=${connection.driver.name},Url=${connection.url},Username=${connection.username},Password=${connection.password},${dbcp.args}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>tests.openjpa.allowfailure</name>
|
||||
<value>${tests.openjpa.allowfailure}</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -855,6 +860,10 @@
|
|||
<name>openjpa.ConnectionProperties</name>
|
||||
<value>DriverClassName=${connection.driver.name},Url=${connection.url},Username=${connection.username},Password=${connection.password},${dbcp.args}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>tests.openjpa.allowfailure</name>
|
||||
<value>${tests.openjpa.allowfailure}</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
|
|
@ -66,6 +66,12 @@ public abstract class PersistenceTestCase
|
|||
public static final String RETAIN_DATA = "Retain data after test run";
|
||||
private boolean retainDataOnTearDown;
|
||||
protected boolean _fresh = false;
|
||||
|
||||
public static String ALLOW_FAILURE_LOG = "log";
|
||||
public static String ALLOW_FAILURE_IGNORE = "ignore";
|
||||
public static String ALLOW_FAILURE_SYS_PROP= "tests.openjpa.allowfailure";
|
||||
|
||||
private static String allowFailureConfig = System.getProperty(ALLOW_FAILURE_SYS_PROP, ALLOW_FAILURE_IGNORE);
|
||||
/**
|
||||
* Marker object you pass to {@link #setUp} to indicate that the
|
||||
* database table rows should be cleared.
|
||||
|
@ -469,21 +475,35 @@ public abstract class PersistenceTestCase
|
|||
*/
|
||||
@Override
|
||||
public void runBare() throws Throwable {
|
||||
if (!isRunsOnCurrentPlatform())
|
||||
if (!isRunsOnCurrentPlatform()) {
|
||||
return;
|
||||
try {
|
||||
super.runBare();
|
||||
} catch (Throwable t) {
|
||||
AllowFailure allowFailure = getAllowFailure();
|
||||
if ( allowFailure != null && allowFailure.value()==true) {
|
||||
System.err.println("*** FAILED (but ignored): " + this);
|
||||
System.err.println("*** Reason : "
|
||||
+ allowFailure.message());
|
||||
System.err.println("Stacktrace of failure");
|
||||
t.printStackTrace();
|
||||
} else {
|
||||
throw t;
|
||||
}
|
||||
runBare(getAllowFailure());
|
||||
}
|
||||
|
||||
protected void runBare(AllowFailure allowFailureAnnotation) throws Throwable {
|
||||
boolean allowFailureValue = allowFailureAnnotation == null ? false : allowFailureAnnotation.value();
|
||||
|
||||
if(allowFailureValue) {
|
||||
if(ALLOW_FAILURE_IGNORE.equalsIgnoreCase(allowFailureConfig)){
|
||||
return; // skip this test
|
||||
}
|
||||
else {
|
||||
try {
|
||||
super.runBare();
|
||||
} catch (Throwable t) {
|
||||
if (ALLOW_FAILURE_LOG.equalsIgnoreCase(allowFailureConfig)) {
|
||||
System.err.println("*** FAILED (but ignored): " + this);
|
||||
System.err.println("*** Reason : " + allowFailureAnnotation.message());
|
||||
System.err.println("Stacktrace of failure");
|
||||
t.printStackTrace();
|
||||
} else {
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.runBare();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue