2009. június 17., szerda
SQLException: OALL8 is in an inconsistent state
I haven't investigated the problem thoroughly, but my gut feeling is that it would be not enough to synchronize the method calls on the Connection instance. Presumably, one should make sure that more complex "activities" (such as: executing a query + accessing its results + closing the result set) carried out by different threads don't overlap. So the simple solution is to have each thread use its own Connection instance.
2009. április 21., kedd
Stack dump from timed-out JUnit tests
ant with JUnit 3 features not whole-heartedly supported in JUnit 4.x), you can create your own junit ant task.What I did was this:
- Copy the content of the org.apache.tools.ant.taskdefs.optional.junit package as mycomapny.test.juice. (I used version 1.7.1 of ant.)
- Retarget references to org.apache.tools.ant.taskdefs.optional.junit to mycomapny.test.juice that classes in the new package.
- Modify the mycomapny.test.juice.JUnitTestRunner class as seen in the diff output below. (Sorry for the host of irrelevant formatting changes. The interesting part start from @@ -265,8 +311,7 @@)
- Start the tests with a default time out specified in the default.test.timeout system property.
- Customize the time-out value for test classes (if needed) using the annotation mycomapny.test.TestTimeOut.
- Declare my own <junit> task with <taskdef> in my ant script and use it as I would use <junit>.
--- apache-ant-1.7.1/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java 2008-06-27 07:05:15.000000000 +0200
+++ main/mypackage/junit/mycomapny/test/juice/JUnitTestRunner.java 2009-04-17 23:44:19.000000000 +0200
@@ -16,12 +16,13 @@
*
*/
-package org.apache.tools.ant.taskdefs.optional.junit;
+package mycomapny.test.juice;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
@@ -32,6 +33,7 @@
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -35,7 +37,9 @@
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Vector;
+
import junit.framework.AssertionFailedError;
+import junit.framework.Protectable;
import junit.framework.Test;
import junit.framework.TestFailure;
import junit.framework.TestListener;
@@ -47,25 +51,37 @@
import org.apache.tools.ant.util.StringUtils;
import org.apache.tools.ant.util.TeeOutputStream;
+import mycomapny.test.TestTimeOut;
+import mycomapny.util.concurrent.util.LogUtil;
+
-public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestRunnerMirror {
+public class JUnitTestRunner implements TestListener,
+ JUnitTaskMirror.JUnitTestRunnerMirror {
+
+ private long timeout = 0;
/**
* Holds the registered formatters.
[...]
@@ -312,10 +356,14 @@
* Run the test.
*/
public void run() {
- res = new TestResult();
- res.addListener(wrapListener(this));
+ final MyTimer timer = new MyTimer();
+
+ res = new TimerCheckingTestResult(timer);
+
+ res.addListener(wrapListener(this, timer));
for (int i = 0; i < errstrm =" new" testclass =" null;" loader ="="" testclass =" Class.forName(junitTest.getName());" testclass =" Class.forName(junitTest.getName()," testclass =" Class.forName(junitTest.getName()," loader ="="" junit4testadapterclass =" -" junit4testadapterclass =" Class.forName(" junit4testadapterclass =" -" junit4testadapterclass =" Class.forName(" suite =" -" suite =" (Test)" starttestsuitesuccess =" true;" i =" 0;" cnts =" findJUnit4FailureErrorCount(res);" retcode =" ERRORS;" retcode =" FAILURES;" sysprop =" System.getProperty(" timeout =" Long.parseLong(sysprop);" testtimeout =" (TestTimeOut)" timeout =" testTimeOut.value();" systemout =" null;" retcode =" ERRORS;" retcode =" FAILURES;" cnts =" findJUnit4FailureErrorCount(res);">A new Test is started.
- * @param t the test.
+ *
+ * A new Test is started.
+ *
+ * @param t
+ * the test.
*/
public void startTest(Test t) {
String testName = JUnitVersionHelper.getTestCaseName(t);
@@ -481,8 +570,11 @@
/**
* Interface TestListener.
*
- *A Test is finished.
- * @param test the test.
+ *
+ * A Test is finished.
+ *
+ * @param test
+ * the test.
*/
public void endTest(Test test) {
String testName = JUnitVersionHelper.getTestCaseName(test);
@@ -493,7 +585,7 @@
PrintStream out = savedOut != null ? savedOut : System.out;
if (logTestListenerEvents) {
out.flush();
- out.println(JUnitTask.TESTLISTENER_PREFIX + msg);
+ out.println(CxJUnitTask.TESTLISTENER_PREFIX + msg);
out.flush();
}
}
@@ -501,13 +593,18 @@
/**
* Interface TestListener for JUnit <= 3.4.
*
- *A Test failed.
- * @param test the test.
- * @param t the exception thrown by the test.
+ *
+ * A Test failed.
+ *
+ * @param test
+ * the test.
+ * @param t
+ * the exception thrown by the test.
*/
public void addFailure(Test test, Throwable t) {
String testName = JUnitVersionHelper.getTestCaseName(test);
- logTestListenerEvent("addFailure(" + testName + ", " + t.getMessage() + ")");
+ logTestListenerEvent("addFailure(" + testName + ", " + t.getMessage()
+ + ")");
if (haltOnFailure) {
res.stop();
}
@@ -516,9 +613,13 @@
/**
* Interface TestListener for JUnit > 3.4.
*
- *A Test failed.
- * @param test the test.
- * @param t the assertion thrown by the test.
+ *
+ * A Test failed.
+ *
+ * @param test
+ * the test.
+ * @param t
+ * the assertion thrown by the test.
*/
public void addFailure(Test test, AssertionFailedError t) {
addFailure(test, (Throwable) t);
@@ -527,13 +628,18 @@
/**
* Interface TestListener.
*
- *An error occurred while running the test.
- * @param test the test.
- * @param t the error thrown by the test.
+ *
+ * An error occurred while running the test.
+ *
+ * @param test
+ * the test.
+ * @param t
+ * the error thrown by the test.
*/
public void addError(Test test, Throwable t) {
String testName = JUnitVersionHelper.getTestCaseName(test);
- logTestListenerEvent("addError(" + testName + ", " + t.getMessage() + ")");
+ logTestListenerEvent("addError(" + testName + ", " + t.getMessage()
+ + ")");
if (haltOnError) {
res.stop();
}
@@ -541,8 +647,10 @@
/**
* Permissions for the test run.
+ *
* @since Ant 1.6
- * @param permissions the permissions to use.
+ * @param permissions
+ * the permissions to use.
*/
public void setPermissions(Permissions permissions) {
perm = permissions;
@@ -550,10 +658,13 @@
/**
* Handle a string destined for standard output.
- * @param output the string to output
+ *
+ * @param output
+ * the string to output
*/
public void handleOutput(String output) {
- if (!logTestListenerEvents && output.startsWith(JUnitTask.TESTLISTENER_PREFIX)) {
+ if (!logTestListenerEvents
+ && output.startsWith(CxJUnitTask.TESTLISTENER_PREFIX)) {
// ignore
} else if (systemOut != null) {
systemOut.print(output);
@@ -562,11 +673,16 @@
/**
* Handle input.
- * @param buffer not used.
- * @param offset not used.
- * @param length not used.
+ *
+ * @param buffer
+ * not used.
+ * @param offset
+ * not used.
+ * @param length
+ * not used.
* @return -1 always.
- * @throws IOException never.
+ * @throws IOException
+ * never.
* @see org.apache.tools.ant.Task#handleInput(byte[], int, int)
*
* @since Ant 1.6
@@ -726,8 +860,8 @@
int returnCode = SUCCESS;
if (multipleTests) {
try {
- java.io.BufferedReader reader =
- new java.io.BufferedReader(new java.io.FileReader(args[0]));
+ java.io.BufferedReader reader = new java.io.BufferedReader(
+ new java.io.FileReader(args[0]));
String testCaseName;
int code = 0;
boolean errorOccurred = false;
@@ -740,9 +874,8 @@
t.setTodir(new File(st.nextToken()));
t.setOutfile(st.nextToken());
t.setProperties(props);
- code = launch(t, haltError, stackfilter, haltFail,
- showOut, outputToFormat,
- logTestListenerEvents);
+ code = launch(t, haltError, stackfilter, haltFail, showOut,
+ outputToFormat, logTestListenerEvents);
errorOccurred = (code == ERRORS);
failureOccurred = (code != SUCCESS);
if (errorOccurred || failureOccurred) {
@@ -765,9 +898,8 @@
} else {
JUnitTest t = new JUnitTest(args[0]);
t.setProperties(props);
- returnCode = launch(
- t, haltError, stackfilter, haltFail,
- showOut, outputToFormat, logTestListenerEvents);
+ returnCode = launch(t, haltError, stackfilter, haltFail, showOut,
+ outputToFormat, logTestListenerEvents);
}
registerNonCrash();
@@ -811,9 +943,8 @@
for (int i = 0; i < fe =" (FormatterElement)" destfile =" -" destfile =" new" fname =" line.indexOf(IGNORED_FILE_NAME);"> -1) {
- fe.setExtension(line
- .substring(fName
+ fe.setExtension(line.substring(fName
+ IGNORED_FILE_NAME.length()));
}
}
@@ -848,9 +978,11 @@
}
/**
- * Returns a filtered stack trace.
- * This is ripped out of junit.runner.BaseTestRunner.
- * @param t the exception to filter.
+ * Returns a filtered stack trace. This is ripped out of
+ * junit.runner.BaseTestRunner.
+ *
+ * @param t
+ * the exception to filter.
* @return the filtered stack trace.
*/
public static String getFilteredTrace(Throwable t) {
@@ -860,7 +992,9 @@
/**
* Filters stack frames from internal JUnit and Ant classes
- * @param stack the stack trace to filter.
+ *
+ * @param stack
+ * the stack trace to filter.
* @return the filtered stack.
*/
public static String filterStack(String stack) {
@@ -898,12 +1032,10 @@
* @since Ant 1.6.2
*/
private static int launch(JUnitTest t, boolean haltError,
- boolean stackfilter, boolean haltFail,
- boolean showOut, boolean outputToFormat,
- boolean logTestListenerEvents) {
- JUnitTestRunner runner =
- new JUnitTestRunner(t, haltError, stackfilter, haltFail, showOut,
- logTestListenerEvents, null);
+ boolean stackfilter, boolean haltFail, boolean showOut,
+ boolean outputToFormat, boolean logTestListenerEvents) {
+ JUnitTestRunner runner = new JUnitTestRunner(t, haltError, stackfilter,
+ haltFail, showOut, logTestListenerEvents, null);
runner.forked = true;
runner.outputToFormatters = outputToFormat;
transferFormatters(runner, t);
@@ -915,8 +1047,7 @@
/**
* @since Ant 1.7
*/
- private static void registerNonCrash()
- throws IOException {
+ private static void registerNonCrash() throws IOException {
if (crashFile != null) {
FileWriter out = null;
try {
@@ -956,24 +1087,46 @@
*
* @since Ant 1.7
*/
- private TestListener wrapListener(final TestListener testListener) {
- return new TestListener() {
+ private TestListener wrapListener(final TestListener testListener,
+ final MyTimer timer) {
+ return new TimerCheckingListenerWrapper(testListener, timer);
+ }
+
+ private class TimerCheckingListenerWrapper implements TestListener {
+ private TestListener testListener;
+ private MyTimer timer;
+
+ public TimerCheckingListenerWrapper(TestListener testListener,
+ MyTimer timer) {
+ super();
+ this.testListener = testListener;
+ this.timer = timer;
+ }
+
public void addError(Test test, Throwable t) {
+ synchronized (timer) {
if (junit4 && t instanceof AssertionFailedError) {
// JUnit 4 does not distinguish between errors and failures
// even in the JUnit 3 adapter.
- // So we need to help it a bit to retain compatibility for JUnit 3 tests.
+ // So we need to help it a bit to retain compatibility for
+ // JUnit 3 tests.
testListener.addFailure(test, (AssertionFailedError) t);
- } else if (junit4 && t.getClass().getName().equals("java.lang.AssertionError")) {
+ } else if (junit4
+ && t.getClass()
+ .getName()
+ .equals("java.lang.AssertionError")) {
// Not strictly necessary but probably desirable.
// JUnit 4-specific test GUIs will show just "failures".
// But Ant's output shows "failures" vs. "errors".
- // We would prefer to show "failure" for things that logically are.
+ // We would prefer to show "failure" for things that
+ // logically are.
try {
String msg = t.getMessage();
AssertionFailedError failure = msg != null
- ? new AssertionFailedError(msg) : new AssertionFailedError();
- // To compile on pre-JDK 4 (even though this should always succeed):
+ ? new AssertionFailedError(msg)
+ : new AssertionFailedError();
+ // To compile on pre-JDK 4 (even though this should
+ // always succeed):
Method initCause = Throwable.class.getMethod(
"initCause", new Class[] {Throwable.class});
initCause.invoke(failure, new Object[] {t});
@@ -987,28 +1140,156 @@
testListener.addError(test, t);
}
}
+ }
+
public void addFailure(Test test, AssertionFailedError t) {
+ synchronized (timer) {
testListener.addFailure(test, t);
}
+ }
+
public void addFailure(Test test, Throwable t) { // pre-3.4
+ synchronized (timer) {
if (t instanceof AssertionFailedError) {
testListener.addFailure(test, (AssertionFailedError) t);
} else {
testListener.addError(test, t);
}
}
+ }
+
public void endTest(Test test) {
+ synchronized (timer) {
testListener.endTest(test);
}
+ }
+
public void startTest(Test test) {
+ synchronized (timer) {
testListener.startTest(test);
}
- };
+ }
+
+ }
+
+ private class TimerCheckingTestResult extends TestResult {
+ TestResult testResult = new TestResult();
+
+ MyTimer timer;
+
+ public TimerCheckingTestResult(MyTimer timer) {
+ this.timer = timer;
+ }
+
+ public void addError(Test test, Throwable t) {
+ synchronized (timer) {
+ testResult.addError(test, t);
+ }
+ }
+
+ public void addFailure(Test test, AssertionFailedError t) {
+ synchronized (timer) {
+ testResult.addFailure(test, t);
+ }
+ }
+
+ public void addListener(TestListener listener) {
+ synchronized (timer) {
+ testResult.addListener(listener);
+ }
+ }
+
+ public void endTest(Test test) {
+ synchronized (timer) {
+ testResult.endTest(test);
+ }
+ }
+
+ public boolean equals(Object obj) {
+ synchronized (timer) {
+ return testResult.equals(obj);
+ }
+ }
+
+ public int errorCount() {
+ synchronized (timer) {
+ return testResult.errorCount();
+ }
+ }
+
+ public Enumeration errors() {
+ synchronized (timer) {
+ return testResult.errors();
+ }
+ }
+
+ public int failureCount() {
+ synchronized (timer) {
+ return testResult.failureCount();
+ }
+ }
+
+ public Enumeration failures() {
+ synchronized (timer) {
+ return testResult.failures();
+ }
+ }
+
+ public int hashCode() {
+ synchronized (timer) {
+ return testResult.hashCode();
+ }
+ }
+
+ public void removeListener(TestListener listener) {
+ synchronized (timer) {
+ testResult.removeListener(listener);
+ }
+ }
+
+ public int runCount() {
+ synchronized (timer) {
+ return testResult.runCount();
+ }
+ }
+
+ public void runProtected(Test test, Protectable p) {
+ testResult.runProtected(test, p);
+ }
+
+ public boolean shouldStop() {
+ synchronized (timer) {
+ return testResult.shouldStop();
+ }
+ }
+
+ public void startTest(Test test) {
+ testResult.startTest(test);
+ }
+
+ public void stop() {
+ synchronized (timer) {
+ testResult.stop();
+ }
+ }
+
+ public String toString() {
+ synchronized (timer) {
+ return testResult.toString();
+ }
+ }
+
+ public boolean wasSuccessful() {
+ synchronized (timer) {
+ return testResult.wasSuccessful();
+ }
+ }
}
/**
- * Use instead of TestResult.get{Failure,Error}Count on JUnit 4,
- * since the adapter claims that all failures are errors.
+ * Use instead of TestResult.get{Failure,Error}Count on JUnit 4, since the
+ * adapter claims that all failures are errors.
+ *
* @since Ant 1.7
*/
private int[] findJUnit4FailureErrorCount(TestResult res) {
@@ -1032,4 +1313,82 @@
return new int[] {failures, errors};
}
+ private class MyTimer {
+
+ long start;
+ boolean expired;
+
+ public void start(final Test test, long start,
+ final ByteArrayOutputStream outStrm,
+ final ByteArrayOutputStream errStrm) {
+ this.start = start;
+
+ Thread t = new Thread() {
+
+ public void run() {
+ synchronized (MyTimer.this) {
+ try {
+ MyTimer.this.wait(timeout);
+ expired = true;
+
+ StringBuilder sb = new StringBuilder();
+ Mapstacks = Thread.getAllStackTraces();
+ for (Thread t : stacks.keySet()) {
+ sb.append(t.toString()).append('\n');
+ for (StackTraceElement ste : t.getStackTrace()) {
+ sb.append("\tat ")
+ .append(ste.toString())
+ .append('\n');
+ }
+ sb.append('\n');
+ }
+ RuntimeException rte = new RuntimeException(
+ "Test timed-out -- \n" + sb.toString());
+
+ res.addError(test, rte);
+
+ for (int i = 0; i < obj =" formatters.elementAt(i);" os =" new">
2008. július 20., vasárnap
EEE PC - Speed - BIOS
Newer BIOS versions don't allow you to change the power saving scheme (and hence the CPU frequency) from the BIOS setup menu. It appears that with recent BIOS versions the only way to change the CPU frequency is for the OS to interact with the BIOS to this effect. As at the time of posting this BLOG entry stock linux distros are unlikely to support this BIOS feature (Fedora 9 doesn't support it for sure at this point), you will be stuck with the default 630MHz frequency.
The little thing is slow anyway already on account of the surprisingly slow SSDisks built into it. As SSDisks are based on flash technology, I had expected secondary storage to be at least as fast as regular HDisks -- if not faster. I haven't done any benchmarks, but my feeling is that the HDisks in EEE PC are about 3 to 4 times slower than regular notebook HDisks.
2008. május 27., kedd
Linux - Laptops - Sex
While Windows XP is said to be much less power-hungry than Windows Vista, it is still more so than Linux for quite a few kinds of jobs. For example, compiling multiple thousands of Java class files takes on a medium category laptop about two times longer on Windows XP than on Linux.
So there are legitimate performance reasons why you would prefer running your laptop on Linux instead of Windows. And on this point, you have to be careful and remember that hardware support for Linux is not yet as universal as for Windows XP. While hardware vendors tumble over each other to provide device driver for Windows, they don't do the same for Linux. Wireless adapters, video and even audio adapters often don't perform as well on Linux as on Windows.
My otherwise fairly decent Compaq (HP) nx6325 laptop had the following problems with Linux:
- either the video driver doesn't make use of hardware acceleration or you cannot easily adjust the display brightness when needed
- wireless connection is unreliable, it sometimes works and sometimes it doesn't
- audio adapter uses both the built-in speakers and the plugged in head-phone at the same time after you wake up the laptop from suspension; the microphone is generally unreliable with Skype
So I decided to replace my nx6325 with an HP 6720s and I am quite satisfied with the Linux support of the new hardware. The only painful surprise is (and this is not related to Linux at all) that the 6720s is part of HP's more cost effective line. And it is painful, because the keyboard of this line is much less comfortable and I already have started experiencing ominous signs of hand/wrist injuries caused by intensive use of a suboptimal keyboard.
2008. május 8., csütörtök
Turning off updatedb et al. in Fedora 8
for f in $(find /etc/cron* -name "*makewhatis*" -o -name "*mlocate*"); do chmod -x $f; done
2008. május 7., szerda
Advanced Wireless Settings With WRT54GL Et Al.
Take the following scenario:
In an attempt to solve some other problem, I changed the advanced wireless settings of my WRT54GL and forgot about it. The new settings worked with the Broadcom adapter of my older laptop flawlessly. Then I a bought a new laptop with an Intel 3945ABG adapter which just refused to work. Originally, I thought that the wireless adapter of my new laptop was broken. Fortunately, I had non-secured APs nearby, to which I could successfully connect with my new laptop, so I knew that the device was not entirely broken. My AP is secured with WPA-PSK, so I set out along that line to find out what might be the problem. (For one, I didn't know how the implementation of the WPA-PSK was partitioned between the device and the OS on the client side -- i.e. whether I needed to suspect a device problem or not.) Fortunately, in my office we use the same Linksys AP, to which I could successfully connect using WPA-PSK and the problem was then trivial to solve.