basedistributedscript.java

来自「cqME :java framework for TCK test.」· Java 代码 · 共 171 行

JAVA
171
字号
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program 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 version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.j2me.javatest;import java.io.PrintWriter;import java.util.Set;import com.sun.javatest.Script;import com.sun.javatest.Status;import com.sun.javatest.TestDescription;import com.sun.javatest.TestEnvironment;import com.sun.tck.j2me.services.messagingService.MessagingService;/** * Convenient base class that contains shared functionality needed to execute * distributed tests. */public class BaseDistributedScript extends DelegatingScript {    /**     * Creates a Script instance and sets the script to be used to run     * non-distributed tests.     *     * @param delegateScript     *            The delegate script.     */    public BaseDistributedScript(Script delegateScript) {        super(delegateScript);    }    /**     * Initializes the test description, and extracts keywords.     */    public void initTestDescription(TestDescription td) {        super.initTestDescription(td);        Set keys = td.getKeywordTable();        interactiveKey = keys.contains("interactive");        distributedKey = isTestDistributed(td);    }    /**     * Determines whether the test is distributed or not.     * <p>     * By default, the test is considered distributed if it is marked with     * keyword <code>"distributed"</code>.     * <p>     * Subclasses may provide additional behavior by overriding this method.     *     * @param td     *            The test.     * @return <code>true</code> if the test is distributed,     *         <code>false</code> otherwise.     */    protected boolean isTestDistributed(TestDescription td) {        return td.getKeywordTable().contains("distributed");    }    /**     * Executes distributed test or delegates the execution     * of non-distributed test to the super implementation.     *     * @param args   Any script-specific options     * @param td      The test description for the test to be performed     * @param env    The test environment giving the details of how to run the test     * @return            The result of running the script     */    public Status run(String[] args, TestDescription td, TestEnvironment env) {        PrintWriter trOut = getTestResult().getTestCommentWriter();        // Exercise the test component...        String executeClass = td.getParameter("executeClass");        Status executeStatus;        if (executeClass != null) {            if (!isTestDistributed(td)) {                // classic simple runtime test                trOut.println("Executing test class...");                executeStatus = super.run(args, td, env);            } else {                RemoteManager rMgr = null;                try {                    String remServAddress = MessagingService.getInstance().getJ2SERemoteServerAddress();                    String testPrefix = "<" + td.getRootRelativeURL() + ">";                    String remote = td.getParameter("remote");                    if (remote != null) {                        trOut.println("Starting remote classes...");                        TestEnvironment rEnv = env.copy();                        // "testMsgSwitch" for J2SEDistributedTest should                        // contain an address where to connect to and a test                        // prefix (to distinguish between different tests.                        rEnv.put("testMsgSwitch", remServAddress                                + "/prefix=" + testPrefix);                        rMgr = new RemoteManager(remote, rEnv, getTestResult());                    } else {                        trOut.println("The \"remote\" entry is not present "                                + "in the test description, "                                + "RemoteManager will not be started.");                    }                    // "testMsgSwitch" for J2MEDistributedTest should contain                    // testPrefix only. There is no need to provide an address                    // where to connect to. New distributed tests use                    // commService for communications.                    env.put("testMsgSwitch", testPrefix);                    trOut.println("testMsgSwitch: " + testPrefix);                    trOut.println("Executing test class...");                    executeStatus = super.run(args, td, env);                    // Send "Terminate" message to all distributed components                    // whose name starts with testPrefix                    MessagingService.getInstance().sendTerminate(testPrefix);                    if (remote != null) {                        String s = td.getParameter("timeout");                        int t = (s == null ? 2 * 60 : Integer.parseInt(s));                        rMgr.waitUntilDone(                                interactiveKey ? t : getTestTimeout());                        Status rms = rMgr.getStatus();                        executeStatus = RemoteManager.mergeStatus(                                executeStatus, rms);                    }                } catch (InterruptedException e) {                    executeStatus = Status.error(                            "timeout waiting for remote classes to exit");                } catch (RemoteManager.Fault e) {                    executeStatus = Status.error(e.getMessage());                } finally {                    if (rMgr != null) {                        rMgr.dispose();                    }                }            }        } else {            return error_noExecuteClass;        }        return executeStatus;    }    /**     * @deprecated Use {@link #isTestDistributed(TestDescription)}     */    protected boolean distributedKey;    protected boolean interactiveKey;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?