dev@glassfish.java.net

Re: EmbeddedTest needs to assert on test conditions

From: Jerome Dochez <Jerome.Dochez_at_Sun.COM>
Date: Fri, 21 Aug 2009 09:25:29 -0700

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.

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_at_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_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>