dev@glassfish.java.net

Re: EmbeddedTest needs to assert on test conditions

From: Vivek Pandey <Vivek.Pandey_at_Sun.COM>
Date: Fri, 21 Aug 2009 09:58:39 -0700
Jerome Dochez wrote:
that's because your classpath contains multiple time the same module resulting in multiple similar @Service running.
I am planning to try to catch those mistakes on startup but so far you need to fix your classpath.

I know about this issue but no, this does not apply to me. I run my tests like this: java -jar embedded-grails.jar. embedded-grails.jar has Class-Path entry in manifest for glassfish-embedded-web.jar. I am not running it from inside maven. So unlike running from inside maven there is no chance of same @Service module present there multiple times.

This might be true for this test  EmbeddedTest in distribution/web which is running under maven. However this test is runing in inplanted mode so I dont see how the same module can appear multiple times in classpath.

Anhyway, it is broken as the IOException was not there and this test should assert on checking if the servlet is deployed and is doing what its supposed to do.

-vivek.



jerome

On Aug 20, 2009, at 1:33 PM, Vivek Pandey wrote:

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@167d912
  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



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: dev-help@glassfish.dev.java.net



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: dev-help@glassfish.dev.java.net