[icedtea-web][rfc] Basic closing listeners implementation and example
Adam Domurad
adomurad at redhat.com
Thu Sep 20 07:21:49 PDT 2012
On Thu, 2012-09-20 at 12:22 +0200, Jiri Vanek wrote:
> As discussed here: http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2012-September/020293.html
> this is interface, integration and first and probably most useful implementation (and example) of
> closing listener idea:
>
> * tests/reproducers/signed/AppletTestSigned/resources/AppletTestSigned.html: removed unnecessary XslowX
> * tests/reproducers/signed/AppletTestSigned/resources/AppletTestSigned2.html: aded missinf XslowX
> * tests/reproducers/signed/AppletTestSigned/srcs/AppletTestSigned.java: added standard closing sentence
> * tests/reproducers/signed/AppletTestSigned/testcases/AppletTestSignedTests.java: used auto*clsoing
> listeners
> * tests/test-extensions/net/sourceforge/jnlp/ClosingListener.java: interface for identifying closing
> listeners
> * tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java: added possibility to set timeout n
> the fly
> * tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java: (executeBrowser) added shortcut for
> autoclosing listeners, (setUpClosingListener) method for setting properties of ClosingListener
> (executeBrowser) add logic to handle ClosingListeners
> * tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoAllClosingListener.java: listener
> closing on "APPLET FINISHED" string
> * tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoErrorClosingListener.java:
> listener closing on "xception" match
> * tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoOkClosingListener.java:
> listener closing on both xception and finished string.
>
>
Thanks for exploring so many possibilities! I'm liking what I see,
comments inline.
> diff -r 9d46cc3428eb
> tests/reproducers/signed/AppletTestSigned/resources/AppletTestSigned.html
> ---
> a/tests/reproducers/signed/AppletTestSigned/resources/AppletTestSigned.html Mon Sep 17 16:40:25 2012 -0400
> +++
> b/tests/reproducers/signed/AppletTestSigned/resources/AppletTestSigned.html Thu Sep 20 10:20:52 2012 +0200
> @@ -37,7 +37,7 @@
> -->
> <html><head></head><body bgcolor="red">
> <p>
> - <applet code="AppletTestSigned.class"
> archive="XslowXAppletTestSigned.jar" codebase="." width="100"
> height="100">
> + <applet code="AppletTestSigned.class"
> archive="AppletTestSigned.jar" codebase="." width="100" height="100">
> <param name="key1" value="value1">
> <param name="key2" value="#value2">
> </applet>
> diff -r 9d46cc3428eb
> tests/reproducers/signed/AppletTestSigned/resources/AppletTestSigned2.html
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++
> b/tests/reproducers/signed/AppletTestSigned/resources/AppletTestSigned2.html Thu Sep 20 10:20:52 2012 +0200
> @@ -0,0 +1,46 @@
> +<!--
> +
> +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.
> +
> + -->
> +<html><head></head><body bgcolor="red">
> +<p>
> + <applet code="AppletTestSigned.class"
> archive="XslowXAppletTestSigned.jar" codebase="." width="100"
> height="100">
> + <param name="key1" value="value1">
> + <param name="key2" value="#value2">
> + </applet>
> +</p>
> +</body>
> +</html>
> diff -r 9d46cc3428eb
> tests/reproducers/signed/AppletTestSigned/srcs/AppletTestSigned.java
> ---
> a/tests/reproducers/signed/AppletTestSigned/srcs/AppletTestSigned.java Mon Sep 17 16:40:25 2012 -0400
> +++
> b/tests/reproducers/signed/AppletTestSigned/srcs/AppletTestSigned.java Thu Sep 20 10:20:52 2012 +0200
> @@ -48,6 +48,7 @@
> try {
> Thread.sleep(n);
> System.out.println("AppletTestSigned killing himself
> after " + n + " ms of life");
> + System.out.println("*** APPLET FINISHED ***");
> System.exit(0);
> } catch (Exception ex) {
> }
> diff -r 9d46cc3428eb
> tests/reproducers/signed/AppletTestSigned/testcases/AppletTestSignedTests.java
> ---
> a/tests/reproducers/signed/AppletTestSigned/testcases/AppletTestSignedTests.java Mon Sep 17 16:40:25 2012 -0400
> +++
> b/tests/reproducers/signed/AppletTestSigned/testcases/AppletTestSignedTests.java Thu Sep 20 10:20:52 2012 +0200
> @@ -84,15 +84,24 @@
>
> @Test
> @TestInBrowsers(testIn = {Browsers.all})
> - public void AppletTestSignedFirefoxTest() throws Exception {
> + public void AppletTestSignedFirefoxTestXslowX() throws Exception
> {
> ServerAccess.PROCESS_TIMEOUT = 30 * 1000;
> try {
> - ProcessResult pr =
> server.executeBrowser("/AppletTestSigned.html");
> + ProcessResult pr =
> server.executeBrowser("/AppletTestSigned2.html");
> evaluateSignedApplet(pr, false);
> - Assert.assertTrue(pr.wasTerminated);
> + //Assert.assertTrue(pr.wasTerminated);
> //Assert.assertEquals((Integer) 0, pr.returnValue); due
> to destroy is null
> } finally {
> ServerAccess.PROCESS_TIMEOUT = 20 * 1000; //back to
> normal
> }
> }
> +
> + @Test
> + @TestInBrowsers(testIn = {Browsers.all})
> + public void AppletTestSignedFirefoxTest() throws Exception {
> + ProcessResult pr =
> server.executeBrowser("/AppletTestSigned.html",
> ServerAccess.AutoClose.CLOSE_ON_CORRECT_END);
> + evaluateSignedApplet(pr, false);
> + //Assert.assertTrue(pr.wasTerminated);
> + //Assert.assertEquals((Integer) 0, pr.returnValue); due to
> destroy is null
> + }
> }
> diff -r 9d46cc3428eb
> tests/test-extensions/net/sourceforge/jnlp/ClosingListener.java
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++
> b/tests/test-extensions/net/sourceforge/jnlp/ClosingListener.java Thu Sep 20 10:20:52 2012 +0200
> @@ -0,0 +1,55 @@
> +/* ClosingListener.java
> +Copyright (C) 2012 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.
> + */
> +package net.sourceforge.jnlp;
> +
> +public abstract class ClosingListener implements
> ContentReaderListener {
> +
> + private ThreadedProcess process;
> + private ProcessAssasin assasin;
> +
> + void setProcess(ThreadedProcess p) {
> + this.process = p;
> + }
> +
> + void setAssasin(ProcessAssasin assasin) {
> + this.assasin = assasin;
> + }
> +
> + public void terminate() {
> + assasin.setTimeout(Long.MIN_VALUE);
> + }
> +}
> diff -r 9d46cc3428eb
> tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java
> ---
> a/tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java Mon Sep 17 16:40:25 2012 -0400
> +++
> b/tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java Thu Sep 20 10:20:52 2012 +0200
> @@ -98,6 +98,11 @@
> return skipInstedOfDesroy;
> }
>
> + void setTimeout(long timeout) {
> + this.timeout = timeout;
> + }
> +
> +
> @Override
> public void run() {
> long startTime = System.nanoTime() /
> ServerAccess.NANO_TIME_DELIMITER;
> diff -r 9d46cc3428eb
> tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java
> ---
> a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java Mon Sep 17 16:40:25 2012 -0400
> +++
> b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java Thu Sep 20 10:20:52 2012 +0200
> @@ -1,5 +1,5 @@
> /* ServerAccess.java
> -Copyright (C) 2011 Red Hat, Inc.
> +Copyright (C) 2011, 2012 Red Hat, Inc.
>
> This file is part of IcedTea.
>
> @@ -58,6 +58,8 @@
> import net.sourceforge.jnlp.browsertesting.Browser;
> import net.sourceforge.jnlp.browsertesting.BrowserFactory;
> import net.sourceforge.jnlp.browsertesting.Browsers;
> +import
> net.sourceforge.jnlp.closinglisteners.AutoErrorClosingListener;
> +import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener;
> import org.junit.Assert;
>
> /**
> @@ -77,6 +79,11 @@
> */
> public class ServerAccess {
>
> + public static enum AutoClose {
> +
> + CLOSE_ON_EXCEPTION, CLOSE_ON_CORRECT_END, CLOSE_ON_BOTH
Maybe I'm being pedantic but CLOSE_ON_BOTH to me isn't as meaningful in
isolation as I'd like it to be.
Seeing as it's going to be the most common option, I would prefer if it
was something like AutoClose.CLOSE_ON_EXIT, CLOSE_ON_EXCEPTION_EXIT,
CLOSE_ON_CORRECT_EXIT. It should be readable in isolation, methinks.
> + }
> +
> public static final long NANO_TIME_DELIMITER=1000000l;
> /**
> * java property which value containing path to default (makefile
> by) directory with deployed resources
> @@ -545,6 +552,20 @@
> public ProcessResult executeJavaws(String
> resource,ContentReaderListener stdoutl,ContentReaderListener stderrl)
> throws Exception {
> return executeJavaws(null, resource,stdoutl,stderrl);
> }
> +
> + public net.sourceforge.jnlp.ProcessResult executeBrowser(String
> string, AutoClose autoClose) throws Exception {
Good idea putting the autoclose parameter here, looks convenient.
> + ClosingListener errClosing = null;
> + ClosingListener outClosing = null;
> + if (autoClose == AutoClose.CLOSE_ON_BOTH || autoClose ==
> AutoClose.CLOSE_ON_EXCEPTION){
> + errClosing=new AutoErrorClosingListener();
> + }
> + if (autoClose == AutoClose.CLOSE_ON_BOTH || autoClose ==
> AutoClose.CLOSE_ON_CORRECT_END){
> + outClosing=new AutoOkClosingListener();
> + }
> + return executeBrowser(string, outClosing, errClosing);
> + }
> +
> +
> public ProcessResult executeBrowser(String resource) throws
> Exception {
> return executeBrowser(getBrowserParams(), resource);
> }
> @@ -797,6 +818,8 @@
> log(connectionMesaage, true, true);
> }
> ProcessAssasin pa = new ProcessAssasin(t, PROCESS_TIMEOUT);
> + setUpClosingListener(stdoutl, pa, t);
> + setUpClosingListener(stderrl, pa, t);
> pa.start();
> t.start();
> while (t.getP() == null && t.deadlyException == null) {
> @@ -834,6 +857,13 @@
> return pr;
> }
>
> + private static void setUpClosingListener(ContentReaderListener
> listener, ProcessAssasin pa, ThreadedProcess t) {
> + if (listener != null && (listener instanceof
> ClosingListener)) {
> + ((ClosingListener) listener).setAssasin(pa);
> + ((ClosingListener) listener).setProcess(t);
> + }
> + }
> +
> /**
> * this is temprary solution until refactoring is fully done
> * Use net.sourceforge.jnlp.ProcessResult instead
> diff -r 9d46cc3428eb
> tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoAllClosingListener.java
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++
> b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoAllClosingListener.java Thu Sep 20 10:20:52 2012 +0200
> @@ -0,0 +1,57 @@
> +/* CountingClosingListener.java
> +Copyright (C) 2012 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.
> + */
> +package net.sourceforge.jnlp.closinglisteners;
> +
> +import net.sourceforge.jnlp.ClosingListener;
> +
> +public class AutoAllClosingListener extends ClosingListener {
Seems like these 3 classes (Auto*ClosingListener) could be turned into a
single class that takes a String[] argument. I would prefer that, but if
you have reasons against this its fine.
> +
> +
> +
> + @Override
> + public void charReaded(char ch) {
> +
> + }
> +
> + @Override
> + public void lineReaded(String s) {
> + if
> (s.contains(AutoErrorClosingListener.MAGICAL_ERROR_CLOSING_STRING) ||
> s.contains(AutoOkClosingListener.MAGICAL_OK_CLOSING_STRING)){
> + terminate();
> + }
> + }
> +
> +}
> diff -r 9d46cc3428eb
> tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoErrorClosingListener.java
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++
> b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoErrorClosingListener.java Thu Sep 20 10:20:52 2012 +0200
> @@ -0,0 +1,57 @@
> +/* AutoErrorClosingListener.java
> +Copyright (C) 2012 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.
> + */
> +package net.sourceforge.jnlp.closinglisteners;
> +
> +import net.sourceforge.jnlp.ClosingListener;
> +
> +public class AutoErrorClosingListener extends ClosingListener {
> +
> + public static final String MAGICAL_ERROR_CLOSING_STRING =
> "xception";
> +
> + @Override
> + public void charReaded(char ch) {
> +
> + }
> +
> + @Override
> + public void lineReaded(String s) {
> + if (s.contains(MAGICAL_ERROR_CLOSING_STRING)){
> + terminate();
> + }
> + }
> +
> +}
> diff -r 9d46cc3428eb
> tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoOkClosingListener.java
> --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> +++
> b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoOkClosingListener.java Thu Sep 20 10:20:52 2012 +0200
> @@ -0,0 +1,57 @@
> +/* CountingClosingListener.java
> +Copyright (C) 2012 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.
> + */
> +package net.sourceforge.jnlp.closinglisteners;
> +
> +import net.sourceforge.jnlp.ClosingListener;
> +
> +public class AutoOkClosingListener extends ClosingListener {
> +
> + public static final String MAGICAL_OK_CLOSING_STRING = "***
> APPLET FINISHED ***";
> +
> + @Override
> + public void charReaded(char ch) {
> +
> + }
> +
> + @Override
> + public void lineReaded(String s) {
> + if (s.contains(MAGICAL_OK_CLOSING_STRING)){
> + terminate();
> + }
> + }
> +
> +}
>
>
Good patch! It should allow for a speed up of much of the tests without
a terrible amount of effort.
Thanks,
- Adam
More information about the distro-pkg-dev
mailing list