/hg/icedtea-web: added xnofork tests and applet tests

jvanek at icedtea.classpath.org jvanek at icedtea.classpath.org
Wed Jan 25 07:42:24 PST 2012


changeset b901442e9ba4 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=b901442e9ba4
author: Jiri Vanek <jvanek at redhat.com>
date: Wed Jan 25 16:42:27 2012 +0100

	added xnofork tests and applet tests


diffstat:

 ChangeLog                                                            |   16 +
 tests/jnlp_tests/simple/AppletTest/resources/AppletTest.jnlp         |   63 ++++
 tests/jnlp_tests/simple/AppletTest/srcs/AppletTest.java              |   82 +++++
 tests/jnlp_tests/simple/AppletTest/testcases/AppletTestTests.java    |   73 ++++
 tests/jnlp_tests/simple/deadlocktest/resources/deadlocktest_1.jnlp   |   53 +++
 tests/jnlp_tests/simple/deadlocktest/srcs/DeadlockTest.java          |   25 +-
 tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java |  151 +++++++++-
 tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java   |    8 +-
 8 files changed, 449 insertions(+), 22 deletions(-)

diffs (truncated from 564 to 500 lines):

diff -r 21183f821dd4 -r b901442e9ba4 ChangeLog
--- a/ChangeLog	Tue Jan 24 15:33:51 2012 -0500
+++ b/ChangeLog	Wed Jan 25 16:42:27 2012 +0100
@@ -1,3 +1,19 @@
+2012-01-25  Jiri Vanek  <jvanek at redhat.com>
+
+	Added test for -Xnofork option and for applet launching by jnlp
+	* tests/jnlp_tests/simple/deadlocktest/resources/deadlocktest_1.jnlp: new file
+	By specifying new max heap size, should invoke jvm to fork when launched
+	* tests/jnlp_tests/simple/deadlocktest/srcs/DeadlockTest.java:
+	improved indentation, added debug output that main method was lunched
+	* tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java:
+	small refactoring, add lunching  of deadlocktest_1.jnlp with and
+	without -Xnofork, and counting java instances during runtime
+	* tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java
+	(ThreadedProcess.run) fixed situation, when process ended, but not all
+	the output was read by its stdout/stderr readers
+	(ContentReader.run) enabled exception printing to stderr.
+	* tests/jnlp_tests/simple/AppletTest/ : test for loading applets by jnlp file
+
 2012-01-06  Danesh Dadachanji  <ddadacha at redhat.com>
 
 	Use the JNLP file's information section for the Name and
diff -r 21183f821dd4 -r b901442e9ba4 tests/jnlp_tests/simple/AppletTest/resources/AppletTest.jnlp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/jnlp_tests/simple/AppletTest/resources/AppletTest.jnlp	Wed Jan 25 16:42:27 2012 +0100
@@ -0,0 +1,63 @@
+<!--
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+
+ -->
+<?xml version="1.0" encoding="utf-8"?>
+<jnlp spec="1.0" href="AppletTest.jnlp" codebase=".">
+    <information>
+        <title>AppletTest</title>
+        <vendor>NetX</vendor>
+        <homepage href="http://jnlp.sourceforge.net/netx/"/>
+        <description>AppletTest</description>
+        <offline/>
+    </information>
+    <resources>
+        <j2se version="1.4+"/>
+        <jar href="AppletTest.jar"/>
+    </resources>
+    <applet-desc
+      documentBase="."
+      name="AppletTest"
+      main-class="AppletTest"
+      width="100"
+      height="100">
+        <param name="key1" value="value1"/>
+        <param name="key2" value="value2"/>
+    </applet-desc>
+</jnlp>
+
+
+</applet-desc>
diff -r 21183f821dd4 -r b901442e9ba4 tests/jnlp_tests/simple/AppletTest/srcs/AppletTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/jnlp_tests/simple/AppletTest/srcs/AppletTest.java	Wed Jan 25 16:42:27 2012 +0100
@@ -0,0 +1,82 @@
+
+import java.applet.Applet;
+
+/* AppletTest.java
+Copyright (C) 2011 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+ */
+public class AppletTest extends Applet {
+
+    private class Killer extends Thread {
+
+        public int n = 2000;
+
+        @Override
+        public void run() {
+            try {
+                Thread.sleep(n);
+                System.out.println("Aplet killing himself after " + n + " ms of life");
+                System.exit(0);
+            } catch (Exception ex) {
+            }
+        }
+    }
+    private Killer killer;
+
+    @Override
+    public void init() {
+        System.out.println("applet was initialised");
+        killer = new Killer();
+    }
+
+    @Override
+    public void start() {
+        System.out.println("applet was started");
+        System.out.println(getParameter("key1"));
+        System.out.println(getParameter("key2"));
+        killer.start();
+        System.out.println("killer was started");
+    }
+
+    @Override
+    public void stop() {
+        System.out.println("applet was stopped");
+    }
+
+    @Override
+    public void destroy() {
+        System.out.println("applet will be destroyed");
+    }
+}
diff -r 21183f821dd4 -r b901442e9ba4 tests/jnlp_tests/simple/AppletTest/testcases/AppletTestTests.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/jnlp_tests/simple/AppletTest/testcases/AppletTestTests.java	Wed Jan 25 16:42:27 2012 +0100
@@ -0,0 +1,73 @@
+/* AppletTestTests.java
+Copyright (C) 2011 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+ */
+
+import net.sourceforge.jnlp.ServerAccess;
+import org.junit.Assert;
+
+import org.junit.Test;
+
+public class AppletTestTests {
+
+    private static ServerAccess server = new ServerAccess();
+
+    @Test
+    public void AppletTest() throws Exception {
+        System.out.println("connecting AppletTest request");
+        System.err.println("connecting AppletTest request");
+        ServerAccess.ProcessResult pr = server.executeJavawsHeadless(null, "/AppletTest.jnlp");
+        System.out.println(pr.stdout);
+        System.err.println(pr.stderr);
+        String s3 = "applet was initialised";
+        Assert.assertTrue("AppletTest stdout should contains " + s3 + " bud didn't", pr.stdout.contains(s3));
+        String s0 = "applet was started";
+        Assert.assertTrue("AppletTest stdout should contains " + s0 + " bud didn't", pr.stdout.contains(s0));
+        String s1 = "value1";
+        Assert.assertTrue("AppletTest stdout should contains " + s1 + " bud didn't", pr.stdout.contains(s1));
+        String s2 = "value2";
+        Assert.assertTrue("AppletTest stdout should contains " + s2 + " bud didn't", pr.stdout.contains(s2));
+        String s4 = "applet was stopped";
+        Assert.assertFalse("AppletTest stdout shouldn't contains " + s4 + " bud did", pr.stdout.contains(s4));
+        String s5 = "applet will be destroyed";
+        Assert.assertFalse("AppletTest stdout shouldn't contains " + s5 + " bud did", pr.stdout.contains(s5));
+        String ss = "xception";
+        Assert.assertFalse("AppletTest stderr should not contains " + ss + " but did", pr.stderr.contains(ss));
+        String s7 = "Aplet killing himself after 2000 ms of life";
+        Assert.assertTrue("AppletTest stdout should contains " + s7 + " bud didn't", pr.stdout.contains(s7));
+        Assert.assertFalse(pr.wasTerminated);
+        Assert.assertEquals((Integer) 0, pr.returnValue);
+    }
+}
diff -r 21183f821dd4 -r b901442e9ba4 tests/jnlp_tests/simple/deadlocktest/resources/deadlocktest_1.jnlp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/jnlp_tests/simple/deadlocktest/resources/deadlocktest_1.jnlp	Wed Jan 25 16:42:27 2012 +0100
@@ -0,0 +1,53 @@
+<!--
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+
+ -->
+<?xml version="1.0" encoding="utf-8"?>
+<jnlp spec="1.0" href="deadlocktest_1.jnlp" codebase="." java-vm-args="-Xmx1g" >
+    <information>
+        <title>simpletest1</title>
+        <vendor>NetX</vendor>
+        <homepage href="http://jnlp.sourceforge.net/netx/"/>
+        <description>simpletest1</description>
+        <offline/>
+    </information>
+    <resources>
+        <j2se version="1.4+" max-heap-size="1024m"/>
+        <jar href="deadlocktest.jar"/>
+    </resources>
+    <application-desc main-class="DeadlockTest">
+    </application-desc>
+</jnlp>
diff -r 21183f821dd4 -r b901442e9ba4 tests/jnlp_tests/simple/deadlocktest/srcs/DeadlockTest.java
--- a/tests/jnlp_tests/simple/deadlocktest/srcs/DeadlockTest.java	Tue Jan 24 15:33:51 2012 -0500
+++ b/tests/jnlp_tests/simple/deadlocktest/srcs/DeadlockTest.java	Wed Jan 25 16:42:27 2012 +0100
@@ -35,17 +35,20 @@
 exception statement from your version.
  */
 
-public class DeadlockTest{
+public class DeadlockTest {
 
-    public static void main(String[] args) throws Exception{
-        long startTime=System.nanoTime()/1000000l;
-while(true){
-long now=System.nanoTime()/1000000l;
-Thread.sleep(10);
-if (now-startTime>30000){
-    System.out.println("This process is hanging more then 30s. Should be killed");
-    System.exit(5);
-}
-}
+    private static final int DEADLOCK_TEST_TIME_OF_LIFE=30000;
+
+    public static void main(String[] args) throws Exception {
+        long startTime = System.nanoTime() / 1000000l;
+        System.out.println("Deadlock test started");
+        while (true) {
+            long now = System.nanoTime() / 1000000l;
+            Thread.sleep(10);
+            if (now - startTime > DEADLOCK_TEST_TIME_OF_LIFE) {
+                System.out.println("This process is hanging more then "+DEADLOCK_TEST_TIME_OF_LIFE/1000+"s. Should be killed");
+                System.exit(5);
+            }
+        }
     }
 }
diff -r 21183f821dd4 -r b901442e9ba4 tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java
--- a/tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java	Tue Jan 24 15:33:51 2012 -0500
+++ b/tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java	Wed Jan 25 16:42:27 2012 +0100
@@ -36,30 +36,165 @@
  */
 
 import net.sourceforge.jnlp.ServerAccess;
+import net.sourceforge.jnlp.ServerAccess.ProcessResult;
 import org.junit.Assert;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.junit.BeforeClass;
 
 import org.junit.Test;
 
 public class DeadLockTestTest {
 
     private static ServerAccess server = new ServerAccess();
+    private static String deadlocktest_1 = "/deadlocktest_1.jnlp";
+    private static String deadlocktest = "/deadlocktest.jnlp";
 
-  
+    @BeforeClass
+    public static void printJavas() throws Exception {
+        System.out.println("Currently runnng javas1 " + countJavaInstances());
 
-   @Test
+    }
+
+    @Test
     public void testDeadLockTestTerminated() throws Exception {
-        System.out.println("connecting deadlocktest request");
-        System.err.println("connecting deadlocktest request");
-        ServerAccess.ProcessResult pr=server.executeJavawsHeadless(null,"/deadlocktest.jnlp");
+        testDeadLockTestTerminatedBody(deadlocktest);
+        System.out.println("Currently runnng javas2 " + countJavaInstances());
+    }
+
+    @Test
+    public void testDeadLockTestTerminated2() throws Exception {
+        testDeadLockTestTerminatedBody(deadlocktest_1);
+        System.out.println("Currently runnng javas3 " + countJavaInstances());
+    }
+
+    public void testDeadLockTestTerminatedBody(String jnlp) throws Exception {
+        System.out.println("connecting " + jnlp + " request");
+        System.err.println("connecting " + jnlp + " request");
+        ServerAccess.ProcessResult pr = server.executeJavawsHeadless(null, jnlp);
         System.out.println(pr.stdout);
         System.err.println(pr.stderr);
+        assertDeadlockTestLaunched(pr);
         Assert.assertFalse(pr.stdout.contains("This process is hanging more then 30s. Should be killed"));
 //        Assert.assertTrue(pr.stderr.contains("xception"));, exception is thrown by engine,not by application
-        Assert.assertTrue("testDeadLockTestTerminated should be terminated, but wasn't",pr.wasTerminated);
+        Assert.assertTrue("testDeadLockTestTerminated should be terminated, but wasn't", pr.wasTerminated);
         Assert.assertEquals(null, pr.returnValue);//killed process have no value
     }
 
- 
-
+    @Test
+    public void ensureAtLeasOneJavaIsRunning() throws Exception {
+        Assert.assertTrue("at least one java should be running, but isnt! Javas are probably counted badly", countJavaInstances() > 0);
+        ;
 
     }
+
+    @Test
+    public void testSimpletest1lunchFork() throws Exception {
+        System.out.println("connecting " + deadlocktest_1 + " request");
+        System.err.println("connecting " + deadlocktest_1 + " request");
+        int before = countJavaInstances();
+        System.out.println("java4: " + before);
+        BackgroundDeadlock bd = new BackgroundDeadlock(deadlocktest_1, null);
+        bd.start();
+        Thread.sleep(ServerAccess.PROCESS_TIMEOUT * 2 / 3);
+        int during = +countJavaInstances();
+        System.out.println("java5: " + during);
+        waitForBackgroundDeadlock(bd);
+        Thread.sleep(500);
+        int after = countJavaInstances();
+        System.out.println("java6: " + after);
+        Assert.assertNotNull("proces inside background deadlock cant be null. Was.", bd.getPr());
+        System.out.println(bd.getPr().stdout);
+        System.err.println(bd.getPr().stderr);
+        assertDeadlockTestLaunched(bd.getPr());
+        Assert.assertEquals("lunched JVMs must be exactly 2, was " + (during - before), 2, during - before);
+    }
+
+    @Test
+    public void testSimpletest1lunchNoFork() throws Exception {
+        System.out.println("connecting " + deadlocktest_1 + " Xnofork request");
+        System.err.println("connecting " + deadlocktest_1 + " Xnofork request");
+        int before = countJavaInstances();
+        System.out.println("java7: " + before);
+        BackgroundDeadlock bd = new BackgroundDeadlock(deadlocktest_1, Arrays.asList(new String[]{"-Xnofork"}));
+        bd.start();
+        Thread.sleep(ServerAccess.PROCESS_TIMEOUT * 2 / 3);
+        int during = +countJavaInstances();
+        System.out.println("java8: " + during);
+        waitForBackgroundDeadlock(bd);
+        Thread.sleep(500);
+        int after = countJavaInstances();
+        System.out.println("java9: " + after);
+        Assert.assertNotNull("proces inside background deadlock cant be null. Was.", bd.getPr());
+        System.out.println(bd.getPr().stdout);
+        System.err.println(bd.getPr().stderr);
+        assertDeadlockTestLaunched(bd.getPr());
+        Assert.assertEquals("lunched JVMs must be exactly 1, was  " + (during - before), 1, during - before);
+        ;
+    }
+
+    private static int countJavaInstances() throws Exception {
+        String os = System.getProperty("os.name").toLowerCase();
+        if (!(os.contains("linux") || os.contains("unix"))) {
+            throw new IllegalStateException("This test can be procesed only on linux like machines");
+        }
+        ServerAccess.ProcessResult pr = ServerAccess.executeProcess(Arrays.asList(new String[]{"ps", "-A"}));
+        Matcher m = Pattern.compile("\\s+java\\s+").matcher(pr.stdout);
+        //System.out.println(pr.stdout);
+        int i = 0;
+        while (m.find()) {
+            i++;
+        }
+        return i;
+
+    }
+
+    private void assertDeadlockTestLaunched(ProcessResult pr) {
+        String s = "Deadlock test started";
+        Assert.assertTrue("Deadlock test should print out " + s + ", but did not", pr.stdout.contains(s));
+        String ss = "xception";
+        Assert.assertFalse("Deadlock test should not stderr " + ss + " but did", pr.stderr.contains(ss));
+    }
+
+    private void waitForBackgroundDeadlock(final BackgroundDeadlock bd) throws InterruptedException {
+        while (!bd.isFinished()) {
+            Thread.sleep(500);
+
+        }
+    }
+
+    private static class BackgroundDeadlock extends Thread {
+
+        private boolean finished = false;
+        private ProcessResult pr = null;
+        String jnlp;
+        List<String> args;
+
+        public BackgroundDeadlock(String jnlp, List<String> args) {
+            this.jnlp = jnlp;
+            this.args = args;
+        }



More information about the distro-pkg-dev mailing list