dev@glassfish.java.net

EmbeddedTest needs to assert on test conditions

From: Vivek Pandey <Vivek.Pandey_at_Sun.COM>
Date: Thu, 20 Aug 2009 13:33:03 -0700

I ran in to a problem dealing with my own tests for embedded glassfish
for Grails. To verify if everything is working I checked EmbeddedTest at
distribution/web and I saw same failures but the test reported SUCCESS.

I think this test needs to assert on the test condition. I noticed there
are try/catch block in this test. try/catch blocks in junit tests is
pointless unless you either want to do Assert.assertTrue(false) or you
want to ignore the exception. The later is undesirable as it can mask
serious issues.

Anyway, the error is:

SEVERE: doSelect IOException
java.net.BindException: Address already in use:
8080=com.sun.enterprise.v3.services.impl.monitor.MonitorableSelectorHandler_at_
    at
com.sun.grizzly.TCPSelectorHandler.initSelector(TCPSelectorHandler.java:445)
    at
com.sun.grizzly.TCPSelectorHandler.preSelect(TCPSelectorHandler.java:392)
    at
com.sun.grizzly.SelectorHandlerRunner.doSelect(SelectorHandlerRunner.java:182)
    at
com.sun.grizzly.SelectorHandlerRunner.run(SelectorHandlerRunner.java:129)
    at
com.sun.grizzly.util.FixedThreadPool$BasicWorker.dowork(FixedThreadPool.java:379)
    at
com.sun.grizzly.util.FixedThreadPool$BasicWorker.run(FixedThreadPool.java:360)
    at java.lang.Thread.run(Thread.java:637)
Aug 20, 2009 12:06:03 PM
com.sun.enterprise.transaction.JavaEETransactionManagerSimplified
initDelegates


Following patch for testWeb() fails the test correctly:

-vivek.

Index: src/test/java/org/glassfish/distributions/test/EmbeddedTest.java
===================================================================
--- src/test/java/org/glassfish/distributions/test/EmbeddedTest.java
(revision 30620)
+++ src/test/java/org/glassfish/distributions/test/EmbeddedTest.java
(working copy)
@@ -182,31 +182,20 @@

         System.out.println("Deploying " + p);
         String appName = null;
- try {
- appName = deployer.deploy(builder.buildWar(), dp);
-
- try {
- URL servlet = new
URL("http://localhost:8080/test-classes/hello");
- URLConnection yc = servlet.openConnection();
- BufferedReader in = new BufferedReader(
- new InputStreamReader(
- yc.getInputStream()));
- String inputLine;
-
- while ((inputLine = in.readLine()) != null)
- System.out.println(inputLine);
- in.close();
- } catch(Exception e) {
- e.printStackTrace();
- throw e;
- }
- } catch(Exception e) {
- // mask exceptions for now
- // e.printStackTrace();
- }
- if (appName!=null)
- deployer.undeploy(appName);
-
+ appName = deployer.deploy(builder.buildWar(), dp);
+ Assert.assertTrue(appName != null);
+ URL servlet = new URL("http://localhost:8080/test-classes/hello");
+ URLConnection yc = servlet.openConnection();
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(
+ yc.getInputStream()));
+ String inputLine;
+
+ while ((inputLine = in.readLine()) != null)
+ System.out.println(inputLine);
+ Assert.assertEquals(inputLine.trim(), "Hello World !");
+ in.close();
+ deployer.undeploy(appName);
     }

     @Test