Testing java ee applications – the server side java symposium

This session was also fast moving and information filled, but it didn’t feel as overwhelming as the Spring session. The presenter included demos of some of the technologies.  He did use the term “unit test” for things that test through the web and database. I would rather these be called integration/functional tests. I wish the testing industry would use one set of definitions. I subscribe to the one where a unit test doesn’t involve the database or the server

Servlet layer

  • Junit – need to build on
  • httpunit – higher level api on http level – the demo shows creating requests and responses using the java api. This technology is preferred over htmlunit because you are usually not generating raw html if you are using a servlet.  [you should be using MVC]
  • htmlunit – higher level api on html level
  • Cactus – in container tests, good for functional testing
  • Selenium – can be used for acceptance testing by users, no coding required
  • Servletunit gives you a simulated container or can mock the request/response objects for simple cases

JSF

  • Jsf 2 project stages help for debugging and testing. This helps because you can easily specify different web.xml settings.
  • Selenium – for simple cases
  • jsfunit – uses cactus, junit, httpnit and htmlunit behind the scenes

Tip: define ids in your jsf tags so not randomly generated. That way you can refer to them

CDI/EJB 3.1

  • Arquillian – lets you say you do not want your whole aoo to be deployed. You use @RunAs(Arquillian.class). Then you can createDeployment() with the classes you want deployed. the ShrinkWrap API lets you add specific classes which lets you test one EJB or injected element.  The demo used embedded glassfish as specified by a Maven profile.  Also lets you inject into the unit test
  • Apace myfaces codi testing is a competing choice
  • For simple cases mock objects are sufficient, not testing production environment [that is why you test logic in unit tests and environment in integration tests which are in container]
  • @RunWith(ResinBeanContainerRunner) starts a very light container. Only supports CDI and EJB 3.1 lite

JPA

  • Embedded database – derby, hsql, java db
  • Embedded container like arquillian
  • Dbunit – helps with data consistency [and setup]
  • ejb3junit, mocks or pure junit again works for simple cases

Web Services

  • Soapui – good for complex cases with either SOAP or REST. Same level as Selenium
  • Can use junit and arquillian if want test to be self contained
  • Can use jersey test framework

Static analysis for performance – the server side java symposium

Overall, I was disappointed by the session. Most of it was about the performance anti-patterns and i was expecting more about the static analysis tool. There was only one slide with an example of how to detect a pattern using static analysis and I found it hard to understand,  It is easy to say to tell new developers not to do something.  It is hard to detect programatically.   Nevertheless, the points made are valid and here are the notes.

Is Java slow? Not on Intel for C at least.

What are root causes of performance issues?

  • Bad architecture, code or design
  • Configuration
  • [or database/network and not java at all, but that’s out of scope here]
  • Many ways to write incorrect code. Static analysis is not a replacement for traditional performance tuning

Types of analysis:

  • Code query systems – Explore relationships among program elements, Codequest and jquery in this space
  • Semantic code query systens – focus on behavior in addition to structure.  Yonita is in this space.  Yonita starts with bytecode to capture all detail. Then query in sql or prolog to find anti-patterns
  • Note that yonita is a prototype and not yet publicly available

Redundant work
Examples

  • JSF calling output text and the getXXX<> method makes a database call each time
  • get value for key several time.  Ok if took like Hibernate is caching it for you
  • make the same ajax call twice and then do something different than the result

Fix by caching the value
Showed patterns for detecting, it looks complicated!

Other anti-patterns

  • Fine grained remote calls – entity beans versions 1 and 2
  • One by one processing – adding one at a time instead of batching so the transaction, authorization and database all happen repeatedly
  • Return a lot of records and discard the results

I asked if the static analysis tools could detect all of the anti-patterns shown. The answer was that it is library specific. I didn’t get a clear yes or no as to whether one could write a rule.

Someone asked about complex configurations. The answer was the tools struggle with dynamic configuration like Spring and specific support of the tool is required.

Live from TSSJS – PostgreSQL with Tom

Live blogging from TheServerSide Java Symposium with Tom Kincaid at his vendor presentation “Introduction to PostgreSQL for Development and Deployment”.  Tom spends a lot of time contrasing Postgres with MySQL, and commenting how since Oracle’s aquisition of MySQL, the licensing of MySQL is now much more restrictive. Tom says the licensing of Postgres is basically “Do what you want with the code but don’t bother us”.

1. Why has it not the most adopted open source DB?
Tom talks about some of the limitation of Postgres that prevented it from becoming one of the most adopted DBMS software including:

  • Early versions were Linux only with Windows support coming later
  • Installation was difficult
  • Default configuration was not neccessarily the best, and was designed for widest platform adoption
  • Lacked bundled distribution tools

Tom points out that originally, developers “first 20 mins” of using the product was often frustrating and would turn people off to the software.

2. Today’s Postgres
Postgres has made a number of changes in the last few years to grow Postgres has a more developer-friendly and easier-to-use product.  It also has been extended to work with all major IDEs, object-relational mapping tools such as JDBC, ODBC drivers, and stored procedures based in Java.  They have also spent time improving the GUI tools to compete with other major DBMS providers.  The GUI also shows performance tools and query plans.

Conclusion
The vendor sessions were abridged compared to the normal sessions so there was a lot Tom did not get to.  He did peak my interest in learning more about Postgres, now that it has grown to a more substational platform.  Tom’s belief is that everyone should use Postgres given its power and hands-off licensing, especially compared to the direction MySQL may be going.