NoClassDefFoundError with Jenkins and Versant - ant

Currently, I have an application which uses a Versant DB. I can build this application in ant and have an ant-task for unit testing. When I run the testing task from command line, all of the test cases will run correctly. However, when I try to run the ant testing task through Jenkins/Hudson, some of the test cases throw a NoClassDefFoundError looking for one of the Versant files. Can anyone tell me what I'm missing in Jenkins to fix this?
Stack Trace:
[junit] Testcase: warning(junit.framework.TestSuite$1): FAILED
[junit] Exception in constructor: testGetTransactionWithStubSelector (java.lang.NoClassDefFoundError: Could not initialize class com.versant.trans.TransSession
[junit] at com.projectName.database.SessionPool.createPooledObject(SessionPool.java:45)
[junit] at com.projectName.util.pooling.PoolManager$ReflectivePooledObjectHandler.createPooledObject(PoolManager.java:210)
[junit] at com.projectName.util.pooling.PoolManager.init(PoolManager.java:58)
[junit] at com.projectName.database.SessionPool.<init>(SessionPool.java:20)
[junit] at com.projectName.database.DB.<init>(DB.java:507)
[junit] at com.projectName.database.DB.get(DB.java:62)

Related

building cassandra test cases failing

I am trying to build cassandra binaries from source and when I try to compile unit test cases, some of them give me errors. I tried versions 2.0.14, 2.1.4 and 2.1.5 with ubuntu 14.04 and Java 7 as well as Java 8. This is the message I get after building the test cases:
BUILD FAILED
/opt/cassandra/build.xml:1139: Some test bucket 0 test(s) failed.
Total time: 17 minutes 13 seconds
Buildfile: `/opt/cassandra/build.xml`
Am I doing something wrong? This is how I am trying to build:
ant
ant build
ant build-test
ant test
ant artifacts
[junit] Testsuite: org.apache.cassandra.utils.BitSetTest
[junit] Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.075 sec
[junit]
[junit] Testcase: compareBitSets(org.apache.cassandra.utils.BitSetTest): Caused an ERROR
[junit] java.io.FileNotFoundException: /usr/share/dict/words (No such file or directory)
[junit] java.lang.RuntimeException: java.io.FileNotFoundException: /usr/share/dict/words (No such file or directory)
[junit] at org.apache.cassandra.utils.KeyGenerator$WordGenerator.reset(KeyGenerator.java:137)
[junit] at org.apache.cassandra.utils.KeyGenerator$WordGenerator.<init>(KeyGenerator.java:126)
[junit] at org.apache.cassandra.utils.BitSetTest.compareBitSets(BitSetTest.java:50)
[junit] Caused by: java.io.FileNotFoundException: /usr/share/dict/words (No such file or directory)
[junit] at java.io.FileInputStream.open(Native Method)
[junit] at java.io.FileInputStream.<init>(FileInputStream.java:146)
[junit] at java.io.FileInputStream.<init>(FileInputStream.java:101)
[junit] at org.apache.cassandra.utils.KeyGenerator$WordGenerator.reset(KeyGenerator.java:135)
[junit]
[junit]
[junit] Test org.apache.cassandra.utils.BitSetTest FAILED
There's your error. The test is looking for /usr/share/dict/words.
apt-get install wamerican

compiling cassandra test cases failing

I am trying to build cassandra binaries from source and when I try to compile unit test cases, one of them fails. I am build cassandra-2.1.4 with Java 8.
These are the commands I run:
ant -Dfile.encoding="UTF-8"
ant test
ant artifacts
Failure details:
[junit] Testsuite: org.apache.cassandra.tools.SSTableExportTest
[junit] Tests run: 8, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 5.903 sec
[junit]
[junit] ------------- Standard Output ---------------
[junit] WARN 17:48:26 No host ID found, created eeaaa375-22f0-4a4c-845a-31decd240218 (Note: This should happen exactly once per node).
[junit] WARN 17:48:26 No host ID found, created eeaaa375-22f0-4a4c-845a-31decd240218 (Note: This should happen exactly once per node).
[junit] Importing 1 keys...
[junit] 1 keys imported successfully.
[junit] ------------- ---------------- ---------------
[junit] Testcase: testExportColumnsWithMetadata(org.apache.cassandra.tools.SSTableExportTest): FAILED
[junit] unexpected serialization format for topLevelDeletion expected:<{"[markedForDeleteAt":0,"localDeletionTime]":0}> but was:<{"[localDeletionTime":0,"markedForDeleteAt]":0}>
[junit] junit.framework.AssertionFailedError: unexpected serialization format for topLevelDeletion expected:<{"[markedForDeleteAt":0,"localDeletionTime]":0}> but was:<{"[localDeletionTime":0,"markedForDeleteAt]":0}>
[junit] at org.apache.cassandra.tools.SSTableExportTest.testExportColumnsWithMetadata(SSTableExportTest.java:298)
[junit]
[junit]
[junit] Test org.apache.cassandra.tools.SSTableExportTest FAILED
[junit] Testsuite: org.apache.cassandra.tools.SSTableImportTest
[junit] Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.759 sec
This is a known issue and has been fixed in Apache Cassandra's trunk (will become 2.2) branch. https://issues.apache.org/jira/browse/CASSANDRA-9065

JUnit/Ant in Hudson: How to start tests in headless mode?

I am having trouble with setting up unit tests for a project developed under Netbeans in Hudson. So far, Hudson is running fine, monitoring my git repository, and automatically starting builds.
But when building is finished, Hudson starts the unit tests. And here lies the problem: Some classes use awt, and when started from within Hudson, the tests fail like this:
[junit] Testcase: testParse_SimpleTextAndSymbols(com.dua3.util.text.LatexParserTest): Caused an ERROR
[junit] Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
[junit] java.lang.InternalError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
[junit] at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
[junit] at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
[junit] at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:110)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:190)
[junit] at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:102)
[junit] at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
[junit] at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:119)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:190)
[junit] at java.awt.Toolkit$2.run(Toolkit.java:868)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:860)
[junit] at sun.swing.SwingUtilities2.getSystemMnemonicKeyMask(SwingUtilities2.java:1877)
[junit] at javax.swing.plaf.basic.BasicLookAndFeel.initComponentDefaults(BasicLookAndFeel.java:752)
[junit] at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:434)
[junit] at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:148)
[junit] at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1589)
[junit] at javax.swing.UIManager.setLookAndFeel(UIManager.java:536)
[junit] at javax.swing.UIManager.setLookAndFeel(UIManager.java:576)
[junit] at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1345)
[junit] at javax.swing.UIManager.initialize(UIManager.java:1455)
[junit] at javax.swing.UIManager.maybeInitialize(UIManager.java:1422)
[junit] at javax.swing.UIManager.getLookAndFeelDefaults(UIManager.java:1034)
[junit] at com.dua3.util.graph.javase.swing.SwingFont$SwingFontProvider.getDefaultFont(SwingFont.java:50)
[junit] at com.dua3.util.graph.Font.getDefault(Font.java:52)
[junit] at com.dua3.util.text.LatexParser$Settings.<init>(LatexParser.java:39)
[junit] at com.dua3.util.text.LatexParser.parse(LatexParser.java:61)
[junit] at com.dua3.util.text.LatexParserTest.testParse_SimpleTextAndSymbols(LatexParserTest.java:49)
I thought it should be enough to check GraphicsEnvironment.isHeadless(), but obviously it isn't. This is the code snippet were it goes wrong:
if(!GraphicsEnvironment.isHeadless()) {
final UIDefaults lookAndFeelDefaults = UIManager.getLookAndFeelDefaults(); // SwingFont.java:50
if (lookAndFeelDefaults!=null) {
swingFont = lookAndFeelDefaults.getFont("defaultFont");
}
}
I tried in the following in Hudson:
Setting Java Options to -Djava.awt.headless=true in the "Build" section
Entering a line "java.awt.headless=true" in the Build Properties
All of that doesn't work. It seems those are only passed on to ant, but not onwards when invoking java to run the JUnit tests.
Is there any way to tell ant that I want my tests be run in headless mode?
I spend some time looking for this and finally found the answer. In short: setting java.awt.headless=true is not enough on linux. You have to unset DISPLAY. So, go to "Manage Hudson", "Configure System", make sure "Environment variables" is checked under "Global Properties" and add a new variable of name DISPLAY (leave the value field blank).

hsqldb inmemory ant target junit test

I have defined an Ant target containing in-memory HSQLDB:
<target name="create.tables" depends="-prepare.test">
<property name="db.connection.url" value="jdbc:hsqldb:mem:adb"/>
<property name="db.driver" value="org.hsqldb.jdbcDriver"/>
<property name="db.username" value="a"/>
<property name="db.password" value="a"/>
<echo>Creating tables using: ${db.driver} ${db.connection.url} ${product.mysql-connector.jar}</echo>
<sql driver="${db.driver}"
url="${db.connection.url}"
userid="${db.username}"
password="${db.password}"
onerror="stop"
src="/create-schema.sql">
<classpath refid="test.classpath" />
</sql>
</target>
The prepare.test only contains basic things such as fileset etc.
When I print the SQL inserts everything is OK. But how can I access the in-memory HSQLDB from a JUnit testcase?
I tried:
Class.forName("org.hsqldb.jdbcDriver");
connection = DriverManager.getConnection("jdbc:hsqldb:mem:adb",
"a", "a");
but there was only an empty database. Is it possible to use HSQLDB with the insert statements from the Ant target in JUnit testcases?
The exception in the junit test is as follows. The table exists because it is created in the ant task:
[junit] java.lang.Exception: user lacks privilege or object not found: MYTABLE
[junit] at com.inmemorytests.InMemoryTest.testSomething(InMemoryTest.java:116)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] at java.lang.reflect.Method.invoke(Method.java:601)
[junit] at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
[junit] at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
[junit] at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
[junit] at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
[junit] at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
[junit] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
[junit] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
[junit] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
[junit] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
[junit] at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
[junit] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
[junit] at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
[junit] at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:518)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1052)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:906)
This is your connection URL in Ant:
<property name="db.connection.url" value="jdbc:hsqldb:mem:adb"/>
You must use the same URL and the same username and password for a connection:
connection = DriverManager.getConnection("jdbc:hsqldb:mem:adb", "a", "a");
Update: When using a memory database, the Ant target and the JUnit tests must run in the same JVM. If you are running the two in separate JVM's, start an HSQLDB server before the tests and connect to this server from each test. The server connection URL's are different and described in the HSQLDB Guide.

How to integrate SWTBot test in Jenkins CI?

I've got a SWT application (not Eclipse RCP based) and I currently test it using SWTBot. This works fine while running the tests from Eclipse. I'm using ant as buildsystem.
On Jenkins the tests fail - an exception is thrown
[junit] Testcase: testPasswordChange(de.rssit.kgepc.swtbot.ChangePasswordTest): Caused an ERROR
[junit] null
[junit] java.lang.ExceptionInInitializerError
[junit] at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeCharacter(Keyboard.java:100)
[junit] at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Keyboard.java:89)
[junit] at org.eclipse.swtbot.swt.finder.widgets.SWTBotText.typeText(SWTBotText.java:92)
[junit] at org.eclipse.swtbot.swt.finder.widgets.SWTBotText.typeText(SWTBotText.java:78)
[junit] at de.foo.swtbot.pages.PasswordDialogPage.setText(PasswordDialogPage.java:70)
[junit] at de.foo.swtbot.pages.PasswordDialogPage.setOldPassword(PasswordDialogPage.java:30)
[junit] at de.foo.swtbot.ChangePasswordTest.testPasswordChange(ChangePasswordTest.java:43)
[junit] at org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.getKeyboardLayout(KeyboardLayout.java:89)
[junit] at org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.getDefaultKeyboardLayout(KeyboardLayout.java:75)
[junit] at org.eclipse.swtbot.swt.finder.keyboard.Keystrokes.<clinit>(Keystrokes.java:110)
Searching for this specific problem did not result in any helpful solution.
Edit:
Adding the jvm args to set US english fixes this isse and makes some tests run; all other bring the following stacktrace:
[junit] Running foo.bar.swtbot.ChangePasswordTest
[junit] Testsuite: foo.bar.swtbot.ChangePasswordTest
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 1.453 sec
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 1.453 sec
[junit]
[junit] Testcase: testPasswordChange(foo.bar.swtbot.ChangePasswordTest): FAILED
[junit] null
[junit] junit.framework.AssertionFailedError: null
[junit] at foo.bar.swtbot.ChangePasswordTest.testPasswordChange(ChangePasswordTest.java:46)
[junit]
[junit]
[junit] Cobertura: Loaded information on 219 classes.
[junit] Cobertura: Saved information on 219 classes.
[junit] Test foo.bar.swtbot.ChangePasswordTest FAILED
[junit] Running foo.bar.swtbot.LoginDialogTest
[junit] Testsuite: foo.bar.swtbot.LoginDialogTest
[junit] Exception in thread "UIThread" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
[junit] at org.eclipse.swt.SWT.error(SWT.java:4282)
[junit] at org.eclipse.swt.SWT.error(SWT.java:4197)
[junit] at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
[junit] at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
[junit] at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
[junit] at foo.bar.swtbot.UIThread$1.run(UIThread.java:79)
[junit] at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
[junit] at foo.bar.swtbot.UIThread.startEventLoop(UIThread.java:74)
[junit] at foo.bar.swtbot.UIThread.run(UIThread.java:59)
[junit] Caused by: org.eclipse.swt.SWTException: Widget is disposed
[junit] at org.eclipse.swt.SWT.error(SWT.java:4282)
[junit] at org.eclipse.swt.SWT.error(SWT.java:4197)
[junit] at org.eclipse.swt.SWT.error(SWT.java:4168)
[junit] at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
[junit] at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
[junit] at org.eclipse.swt.widgets.Control.setVisible(Control.java:3725)
[junit] at foo.bar.gui.Main.tryLogin(Main.java:142)
[junit] at foo.bar.gui.Main.open(Main.java:117)
[junit] at foo.bar.swtbot.AbstractMainTest$1.run(AbstractMainTest.java:46)
[junit] at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
[junit] at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
[junit] ... 6 more
[junit] Exception in thread "Timer-0" org.eclipse.swt.SWTException: Widget is disposed
[junit] at org.eclipse.swt.SWT.error(SWT.java:4282)
[junit] at org.eclipse.swt.SWT.error(SWT.java:4197)
[junit] at org.eclipse.swt.SWT.error(SWT.java:4168)
[junit] at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
[junit] at org.eclipse.swt.widgets.Widget.getDisplay(Widget.java:582)
[junit] at foo.bar.gui.AbstractKGEAdminDialog$1.run(AbstractKGEAdminDialog.java:46)
[junit] at java.util.TimerThread.mainLoop(Timer.java:512)
[junit] at java.util.TimerThread.run(Timer.java:462)
Regarding java.lang.ExceptionInInitializerError
I notice that there are / have been Eclipse bugs relating to missing keyboard layout for DE_DE locale. Could I suggest you check the locale settings of the process running the junit tests. If you set the locale to en_US, does the problem still arise?
Apart from setting the locale for the server process (e.g. LC_ALL environment variable?), perhaps you could use explicit locale in your junit task, e.g.
<junit fork="yes">
<jvmarg value="-Duser.language=en"/>
<jvmarg value="-Duser.region=US"/>
Regarding org.eclipse.swt.SWTException: Widget is disposed
Maybe this is exposing a real bug in your UI code, but I suspect you need to look at your unit tests. Are they stateless, or do they depend on a certain execution order to work reliably? Perhaps this error can arise if the tests are executed in a different order than you expect.

Resources