Tuesday, April 13, 2010

Remote Debugging for Eclipse Test Plugin Running by Tycho

When I report an issue in bug tracking system about a nightly build's JUnit test error I usually get simple answer that it is supposed to be working because it is working on developers workstation. After that routine conversation starts and it turns out that tests were running from development environment under Eclipse. Here I usually have to explain again and again that's not the same running tests from development environment and in build.

The right way to make yourself sure your tests will work in most cases without errors in nightly build is to start tests the same way as nightly build does. It was not easy for JBoss Tools tests until we created experimental branch and switched to Maven Tycho project. That means it is fairly easy to run tests now. Basically you need to change current directory and execute maven install goal. If it runs in development environment and in maven your tests are good and in most cases it should be fine in nightly build. Problems begin if it runs in development environment but it doesn't in maven. In this scenario you need to debug tests running in Tycho somehow and fix it. Fortunately it can be done using Java remote debugging support.

First of all you need to be sure you have built your sources you're going to debug and there is no differences between .java and .class files. If you're going find problem from previous build just get right tagged version and build it before debugging session.

Then open pom.xml for your Eclipse Test Plug-in and add Java VM arguments like it shown below (actual port numbers, server names and other parameters may be different, it depends from your environment)




   org.sonatype.tycho
      maven-osgi-test-plugin
      ${tycho-version}
      
      -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y
      
   


This snipped configured for remote debugging in OpenJDK 6, if your is different you might need to read [1] and configure it right for your java version.

Configure java projects with sources you're going to debug in Eclipse and create Remote Java Application configuration in Eclipse Debug Configuration dialog. Fill 'host' and 'port' fields with the same values from pom.xml argLine element. Press Apply button to save your changes and start your test plug-in from terminal like

$mvn install

It will go through build process and finally you ll see something like

[INFO] Expected eclipse log file: /home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test/target/work/data/.metadata/.log
[INFO] Command line:
/bin/sh -c cd /home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test && /usr/lib/jvm/java-6-openjdk/jre/bin/java -Dosgi.noShutdown=false -Dosgi.os=linux -Dosgi.ws=gtk -Dosgi.arch=x86 -agentlib:jdwp=transport=dt_socket,address=8001,server=y,suspend=y -jar /home/eskimo/.m2/repository/p2/osgi/bundle/org.eclipse.equinox.launcher/1.0.201.R35x_v20090715/org.eclipse.equinox.launcher-1.0.201.R35x_v20090715.jar -data /home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test/target/work/data -dev file:/home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test/target/dev.properties -install /home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test/target/work -configuration /home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test/target/work/configuration -application org.codehaus.tycho.surefire.osgibooter.uitest -testproperties /home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test/target/surefire.properties
Listening for transport dt_socket at address: 8001

At this point build is waiting for you to attach remote debugger to the process because of using

suspend=y

in argLine element of your pom.xml file. So you need to return to eclipse and hit 'Debug' button in dialog opened before.

Build will continue at this point and stop on your break points so you can find out what is wrong with tests during nightly build.

[1] Java Platform Debugger Architecture - http://java.sun.com/javase/technologies/core/toolsapis/jpda/#Invocation

Tuesday, April 6, 2010

How to Use HSQL Database With JBossTools Right Way

There is no perfect software, there is always something you need to know to get things done. Here is an example, an article how to get HSQL rocks in JBoss Tools.

in reference to:

"How to Use HSQL Database With JBossTools Right Way"
- How to Use HSQL Database With JBossTools Right Way - JBoss Community (view on Google Sidewiki)

JBoss Tools Official IRC Chat Log

This page contains full log for official JBoss Tools IRC chat. What is this chat for? It is dedicated for development discussions, but you can get there and ask any technical question about JBoss Tools from why something is not working to I have an idea and I want to make that happend in next release

in reference to: jbosstools IRC logs [April 7 - 2010] (view on Google Sidewiki)

Eclipse Plug-ins for JBoss and related Technology

A lot of helpful information about JBoss Tools and related technologies. You can find here: downloads and updates, documentation, screen-casts, blogs, project activity info and many other resources.

in reference to:

"Eclipse Plugins for JBoss and related Technology" - JBoss Tools | Overview - JBoss Community (view on Google Sidewiki)

JBoss Tools User Forum

All you want to know about JBoss Tools project :) This forum is the best place:

  • to ask question about tools features;
  • to request new feature;
  • to get advice about using tools right way;
  • to get help with issues you got in your installation;
  • to get help with issue reporting and get your issue fixed;
  • to find a way to use tools for your project;
  • to influence to next version's functionality;
  • to get in touch with development team.

Your posts are very welcome :)

in reference to:

- Space: JBoss Tools - JBoss Community (view on Google Sidewiki)

Thursday, April 1, 2010

Run Eclipse UI Test Plug-in without Eclipse Workbench Window Bothering You

In Test Driven Development it happens you need to run Eclipse UI Tests and keep working at the same time. You can start tests but then you'll get Eclipse Workbench window annoying you especially if you have several JUnit Test Suites to run. Eclipse Workbench Window will pop up and grab input focus for each new suite and that's really annoying. After fiddling with my linux I found several ways to solve this issue:
  1. Do not run tests at all, which is not acceptable for TDD;
  2. Run only Eclipse core tests without workbench window, which is not enough to make tests results reliable;
  3. Create new display and force test session to use it.
Firs option isn't reasonable at all. Second is good enough for non UI applications, but has no value for opposite ones. Third is not for none UI applications, but is the best for UI ones. Fortunately, it is amazingly easy to create new display and redirect your tests execution to it. You have couple options to consider for creating new display :
  1. start vncserver
  2. create virtual buffer using Xvfb
After you have created new display just pass display number as local environment variable in your command line like DISPLAY=:N ${your-command-line-here} and you'll never see your eclipse workbench window :) But if you need to follow tests for a while or just check what is going on from time to time you can use vncviewer or xwud for first or second option accordingly.

Friday, March 26, 2010

How to Use HSQL Database With JBoss Tools Right Way

You have several options to start HSQL. I would choose from couple described below:

1. In process - by pointing out to local folder during creating DTP Connection Profile

2. Server - by starting it outside eclipse using command line and then create DTP Connection Profile with local server

In Process Option

If you use "in process" option you have to be aware that it is not enough just point out folder where your database is located in connection properties. You have to add one more segment to it with database name or your DB will be empty (see explanation below).

For example you have HSQL DB somewhere on disk with name "employee". Im my case I have it downloaded from here and just moved all files to local directory /home/eskimo/db/employee. So I have in this folder structure showed below (ignore employee.lck file it will be created after first "In process" start and not needed initially)

hsql-db-structure.png

I assume you you have the same but you need to correct all paths "/home/eskimo/db/employee" and database name "employee" with yours real values.

Then create "Database Connection" in DTP "Data Source Explorer" View by selecting "New..." from context menu on "Database Connections" node like

hsql-new-conn-1.png

Then select "HSQLDB" connection type and enter DB name as "employee"

hsql-new-conn-2.png

Then I assume you already have configured HSQL JDBC Driver and all what you need to do is enter database name again as "employee" and select its location. After that one magic step is needed (it could be DTP issue). Add one more segment "/employee" in "Database Location" like it shown below. Do not forget to clear "Connect when wizard completes" checkbox because it will start "In Process" HSQL after wizard is finished and create employee.lck file in your database folder. This file will be the reason Seam why Seam Entity Generation wizard will fail during execution. Use 'Optional' tab to define hsqldb.lock_file=false to fix this problem like it is shown below

hsql-new-conn-3.png

dtp-connection-props.png

Press Finish and check the "employee" node created under "Database Connections".

Now you're ready to create Seam Web project using "New Seam Web Project" wizard like it is shown below (it shows only first and last steps because all other steps I left unchanged with default values).

seam-new-1.png

Then comes screens I left unchanged and finally you get to last one with seam configuration. You should have seam 2.1 configured and all what you need is to fill Database properties like it shown below and press "Finish".

seam-new-2.png

After wizard is finished you should see two projects prj1 and prj1-test in your workspace. Now to be ready for entities reverse engineering from your database you need to be sure hsqldb.jar is available in your Server classpath container or in prj1/WebContent/WEB-INF/lib folder. If you don't have hsqldb.jar there "Generate Seam Entities" will fail with ClassNotFound Exception, because it will not be able to find HSQL JDBC driver class.

Now you're ready to go. Switch to Seam Perspective and select "Generate Seam Entiies" from context menu on prj1 project

seam-gen-entities-1.png

Leave first step unchanged like it shown below and press "Next"

seam-gen-entities-2.png

On second step press "Refresh" button and make sure it shows all tables form database as it shown below. If there are no tables most likely HSQL connection is not correctly configured. To generate Seam Entities and xhtml pages press "Finish".

seam-gen-entities-3.png

You should get bunch of generated classes in source folder and pages in WebContent.

Server Option

You need to start HSQL as Server first using command line. Open console and change your directory to database directory like

$ cd /home/eskimo/db/employee

Then start HSQL server in Server Mode like

$java -cp /home/eskimo/Java/hsqldb/lib/hsqldb.jar org.hsqldb.Server

You should see output like

[Server@19106c7]: [Thread[main,5,main]]: checkRunning(false) entered [Server@19106c7]: [Thread[main,5,main]]: checkRunning(false) exited [Server@19106c7]: Startup sequence initiated from main() method [Server@19106c7]: Loaded properties from [/home/eskimo/db/employee/server.properties] [Server@19106c7]: Initiating startup sequence... [Server@19106c7]: Server socket opened successfully in 8 ms. [Server@19106c7]: Database [index=0, id=0, db=file:employee, alias=] opened sucessfully in 690 ms. [Server@19106c7]: Startup sequence completed in 699 ms. [Server@19106c7]: 2010-02-25 13:37:54.016 HSQLDB server 1.8.1 is online [Server@19106c7]: To close normally, connect and execute SHUTDOWN SQL [Server@19106c7]: From command line, use [Ctrl]+[C] to abort abruptly

It starts by default in silent mode. If you want to see what's going one just change property server.silent in server.properties file from true to false and your output will look like

[Server@34a1fc]: [Thread[main,5,main]]: checkRunning(false) entered [Server@34a1fc]: [Thread[main,5,main]]: checkRunning(false) exited [Server@34a1fc]: Startup sequence initiated from main() method [Server@34a1fc]: Loaded properties from [/home/eskimo/db/employee/server.properties] [Server@34a1fc]: [Thread[main,5,main]]: start() entered [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: run() entered [Server@34a1fc]: Initiating startup sequence... [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: server.tls=false [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: server.port=1701 [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: server.trace=false [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: server.database.0=employee [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: server.restart_on_shutdown=false [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: server.no_system_exit=false [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: server.silent=false [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: server.default_page=index.html [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: server.address=0.0.0.0 [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: server.dbname.0= [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: server.root=. [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: openServerSocket() entered [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: Got server socket: ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=1701] [Server@34a1fc]: Server socket opened successfully in 4 ms. [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: openServerSocket() exiting [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: openDatabases() entered [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: Opening database: [file:employee] [Server@34a1fc]: Database [index=0, id=0, db=file:employee, alias=] opened sucessfully in 696 ms. [Server@34a1fc]: [Thread[HSQLDB Server @34a1fc,5,main]]: openDatabases() exiting [Server@34a1fc]: Startup sequence completed in 701 ms. [Server@34a1fc]: 2010-02-25 13:41:49.516 HSQLDB server 1.8.1 is online [Server@34a1fc]: To close normally, connect and execute SHUTDOWN SQL [Server@34a1fc]: From command line, use [Ctrl]+[C] to abort abruptly [Server@34a1fc]: [Thread[main,5,main]]: start() exiting

Starting HSQL as Servers you should not worry about employee.lck anymore and can leave "Connect when wizard completes" checkbox selected during creating new HSQL Database Connection, but Database Location should be changed to hsql://localhost:1701 in second step of "New Database Connection" Wizard like

hsql-new-conn-server-mode.png