diff options
author | Jiri Vanek <[email protected]> | 2012-01-25 16:42:27 +0100 |
---|---|---|
committer | Jiri Vanek <[email protected]> | 2012-01-25 16:42:27 +0100 |
commit | 8f98160184cfe24c20677937db590da40ea1926f (patch) | |
tree | b07ffa3ac61b68e12f22c6dbab872cdeccdf6180 | |
parent | 11870d80cfacf0d71875905c5d9720c3dec8e827 (diff) |
added xnofork tests and applet tests
8 files changed, 449 insertions, 22 deletions
@@ -1,3 +1,19 @@ +2012-01-25 Jiri Vanek <[email protected]> + + 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 <[email protected]> Use the JNLP file's information section for the Name and diff --git a/tests/jnlp_tests/simple/AppletTest/resources/AppletTest.jnlp b/tests/jnlp_tests/simple/AppletTest/resources/AppletTest.jnlp new file mode 100644 index 0000000..f691a61 --- /dev/null +++ b/tests/jnlp_tests/simple/AppletTest/resources/AppletTest.jnlp @@ -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 --git a/tests/jnlp_tests/simple/AppletTest/srcs/AppletTest.java b/tests/jnlp_tests/simple/AppletTest/srcs/AppletTest.java new file mode 100644 index 0000000..bac629a --- /dev/null +++ b/tests/jnlp_tests/simple/AppletTest/srcs/AppletTest.java @@ -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 --git a/tests/jnlp_tests/simple/AppletTest/testcases/AppletTestTests.java b/tests/jnlp_tests/simple/AppletTest/testcases/AppletTestTests.java new file mode 100644 index 0000000..9d83915 --- /dev/null +++ b/tests/jnlp_tests/simple/AppletTest/testcases/AppletTestTests.java @@ -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 --git a/tests/jnlp_tests/simple/deadlocktest/resources/deadlocktest_1.jnlp b/tests/jnlp_tests/simple/deadlocktest/resources/deadlocktest_1.jnlp new file mode 100644 index 0000000..b193447 --- /dev/null +++ b/tests/jnlp_tests/simple/deadlocktest/resources/deadlocktest_1.jnlp @@ -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 --git a/tests/jnlp_tests/simple/deadlocktest/srcs/DeadlockTest.java b/tests/jnlp_tests/simple/deadlocktest/srcs/DeadlockTest.java index 01ecb7d..c473ef4 100644 --- a/tests/jnlp_tests/simple/deadlocktest/srcs/DeadlockTest.java +++ b/tests/jnlp_tests/simple/deadlocktest/srcs/DeadlockTest.java @@ -35,17 +35,20 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ -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); -} -} +public class DeadlockTest { + + 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 --git a/tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java b/tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java index fa823f0..a542f13 100644 --- a/tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java +++ b/tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java @@ -36,30 +36,165 @@ exception statement from your version. */ 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; + } + + @Override + public void run() { + try { + pr = server.executeJavawsHeadless(args, jnlp); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + finished = true; + } + + } + public ProcessResult getPr() { + return pr; + } + public boolean isFinished() { + return finished; + } } +} diff --git a/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java b/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java index e3cd92e..4391215 100644 --- a/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java +++ b/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java @@ -82,6 +82,7 @@ import org.junit.Test; */ public class ServerAccess { + public static final long NANO_TIME_DELIMITER=1000000l; /** * java property which value containig path to default (makefile by) directory with deployed resources */ @@ -684,6 +685,7 @@ public class ServerAccess { p = r.exec(args.toArray(new String[0]),new String[0], dir); } exitCode = p.waitFor(); + Thread.sleep(500);//this is giving to fastly done proecesses's e/o readers time to read all. I would like to know better solution :-/ } catch (Exception ex) { if (ex instanceof InterruptedException) { //add to the set of terminated threadedproceses @@ -885,11 +887,11 @@ public class ServerAccess { @Override public void run() { - long startTime = System.nanoTime() / 1000000l; + long startTime = System.nanoTime() / NANO_TIME_DELIMITER; while (canRun) { try { - long time = System.nanoTime() / 1000000l; + long time = System.nanoTime() / NANO_TIME_DELIMITER; //System.out.println(time - startTime); //System.out.println((time - startTime) > timeout); if ((time - startTime) > timeout) { @@ -992,7 +994,7 @@ public class ServerAccess { } //do not want to bother output with terminations } catch (Exception ex) { - //ex.printStackTrace(); + ex.printStackTrace(); } finally { try { is.close(); |