From: <fd...@us...> - 2008-11-10 22:09:31
|
Revision: 4698 http://jnode.svn.sourceforge.net/jnode/?rev=4698&view=rev Author: fduminy Date: 2008-11-10 22:09:27 +0000 (Mon, 10 Nov 2008) Log Message: ----------- initial version of JTestServer Added Paths: ----------- trunk/core/descriptors/org.jtestserver.server.xml trunk/core/src/test/org/jtestserver/ trunk/core/src/test/org/jtestserver/client/ trunk/core/src/test/org/jtestserver/client/DefaultTestClient.java trunk/core/src/test/org/jtestserver/client/NewProcessLauncher.java trunk/core/src/test/org/jtestserver/client/PipeInputStream.java trunk/core/src/test/org/jtestserver/client/TestClient.java trunk/core/src/test/org/jtestserver/client/TestDriver.java trunk/core/src/test/org/jtestserver/client/TestServerLauncher.java trunk/core/src/test/org/jtestserver/client/TestServerProcess.java trunk/core/src/test/org/jtestserver/common/ trunk/core/src/test/org/jtestserver/common/Status.java trunk/core/src/test/org/jtestserver/common/message/ trunk/core/src/test/org/jtestserver/common/message/Descriptors.java trunk/core/src/test/org/jtestserver/common/message/InputMessage.java trunk/core/src/test/org/jtestserver/common/message/Message.java trunk/core/src/test/org/jtestserver/common/message/MessageDescriptor.java trunk/core/src/test/org/jtestserver/common/message/NullValueException.java trunk/core/src/test/org/jtestserver/common/message/OutputMessage.java trunk/core/src/test/org/jtestserver/common/protocol/ trunk/core/src/test/org/jtestserver/common/protocol/Protocol.java trunk/core/src/test/org/jtestserver/common/protocol/ProtocolException.java trunk/core/src/test/org/jtestserver/common/protocol/TimeoutException.java trunk/core/src/test/org/jtestserver/common/protocol/UDPProtocol.java trunk/core/src/test/org/jtestserver/server/ trunk/core/src/test/org/jtestserver/server/TestFailureException.java trunk/core/src/test/org/jtestserver/server/TestServer.java trunk/core/src/test/org/jtestserver/server/TestServerCommand.java trunk/core/src/test/org/jtestserver/server/commands/ trunk/core/src/test/org/jtestserver/server/commands/AbstractTestServerCommand.java trunk/core/src/test/org/jtestserver/server/commands/GetStatusCommand.java trunk/core/src/test/org/jtestserver/server/commands/MauveTestRunner.java trunk/core/src/test/org/jtestserver/server/commands/RunMauveTestCommand.java trunk/core/src/test/org/jtestserver/server/commands/ShutdownCommand.java trunk/core/src/test/org/jtestserver/server/commands/TestRunner.java trunk/core/src/test/org/jtestserver/tests/ trunk/core/src/test/org/jtestserver/tests/AllTests.java trunk/core/src/test/org/jtestserver/tests/TestInputMessage.java trunk/core/src/test/org/jtestserver/tests/TestOutputMessage.java trunk/core/src/test/org/jtestserver/tests/TestProtocol.java trunk/core/src/test/org/jtestserver/tests/TestUDPProtocol.java trunk/core/src/test/org/jtestserver/tests/TestUtils.java trunk/core/src/test/org/jtestserver/tests/mauve-tests.txt Added: trunk/core/descriptors/org.jtestserver.server.xml =================================================================== --- trunk/core/descriptors/org.jtestserver.server.xml (rev 0) +++ trunk/core/descriptors/org.jtestserver.server.xml 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plugin SYSTEM "jnode.dtd"> + +<plugin id="org.jtestserver.server" + name="JTestServer" + version="0.1" + provider-name="JNode.org" + provider-url="http://www.jnode.org/" + license-name="gpl"> + + <requires> + <import plugin="gnu.mauve"/> + <import plugin="org.jnode.test"/> + </requires> + + <runtime> + <library name="jnode-core.jar"> + <export name="org.jtestserver.server.*"/> + <export name="org.jtestserver.server.commands.*"/> + <export name="org.jtestserver.common.*"/> + <export name="org.jtestserver.common.message.*"/> + <export name="org.jtestserver.common.protocol.*"/> + </library> + </runtime> + + <extension point="org.jnode.security.permissions"> + <permission class="java.security.AllPermission" /> + </extension> + + <extension point="org.jnode.shell.aliases"> + <alias name="TestServer" class="org.jtestserver.server.TestServer"/> + </extension> + +</plugin> \ No newline at end of file Added: trunk/core/src/test/org/jtestserver/client/DefaultTestClient.java =================================================================== --- trunk/core/src/test/org/jtestserver/client/DefaultTestClient.java (rev 0) +++ trunk/core/src/test/org/jtestserver/client/DefaultTestClient.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,65 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.client; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.jtestserver.common.Status; +import org.jtestserver.common.message.Descriptors; +import org.jtestserver.common.message.Message; +import org.jtestserver.common.protocol.Protocol; +import org.jtestserver.common.protocol.ProtocolException; +import org.jtestserver.common.protocol.TimeoutException; + +public class DefaultTestClient implements TestClient { + private static final Logger LOGGER = Logger.getLogger(DefaultTestClient.class.getName()); + + private final Protocol protocol; + + public DefaultTestClient(Protocol protocol) { + this.protocol = protocol; + } + + @Override + public Status runMauveTest(String test) throws ProtocolException, TimeoutException { + return (Status) Message.send(protocol, Descriptors.RUN_MAUVE_TEST, test); + } + + @Override + public Status getStatus() throws ProtocolException, TimeoutException { + return (Status) Message.send(protocol, Descriptors.GET_STATUS); + } + + @Override + public void shutdown() throws ProtocolException, TimeoutException { + Message.send(protocol, Descriptors.SHUTDOWN); + } + + @Override + public void close() throws ProtocolException { + try { + shutdown(); + } catch (TimeoutException e) { + LOGGER.log(Level.SEVERE, "error in close", e); + } + protocol.close(); + } +} Added: trunk/core/src/test/org/jtestserver/client/NewProcessLauncher.java =================================================================== --- trunk/core/src/test/org/jtestserver/client/NewProcessLauncher.java (rev 0) +++ trunk/core/src/test/org/jtestserver/client/NewProcessLauncher.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,45 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.client; + +import java.io.File; +import java.io.IOException; +import java.util.logging.Logger; + +import org.jtestserver.server.TestServer; + +public class NewProcessLauncher implements TestServerLauncher { + private static final Logger LOGGER = Logger.getLogger(NewProcessLauncher.class.getName()); + + @Override + public Process launch() throws IOException { + String javaHome = "/home/fabien/apps/java/"; + String java = javaHome + "bin/java"; + String jnodeCore = "/home/fabien/data/Projets/JNode/jnode/core/"; + String classesDir = jnodeCore + "build/classes"; + String mainClass = TestServer.class.getName(); + String classpath = "." + File.pathSeparatorChar + jnodeCore + "lib/mauve.jar"; + String command = java + " -cp " + classpath + " " + mainClass; + + LOGGER.finer("command: " + command); + return Runtime.getRuntime().exec(command, new String[0], new File(classesDir)); + } + +} Added: trunk/core/src/test/org/jtestserver/client/PipeInputStream.java =================================================================== --- trunk/core/src/test/org/jtestserver/client/PipeInputStream.java (rev 0) +++ trunk/core/src/test/org/jtestserver/client/PipeInputStream.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,68 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.client; + +import java.io.BufferedReader; +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class PipeInputStream { + private final InputStream input; + private final Logger logger; + private final Level level; + + private PipeThread pipeThread; + + public PipeInputStream(final InputStream input, final Logger logger, Level level) { + this.level = level; + this.input = input; + this.logger = logger; + this.pipeThread = new PipeThread(); + } + + public void start() { + pipeThread.start(); + } + + private class PipeThread extends Thread { + public void run() { + final InputStreamReader isr = new InputStreamReader(input); + final BufferedReader br = new BufferedReader(isr, 100); + String line; + try { + try { + while ((line = br.readLine()) != null) { + logger.log(level, line); + } + } catch (EOFException e) { + // ignore + } + br.close(); + } catch (IOException e) { + // ignore + + } + } + } +} Added: trunk/core/src/test/org/jtestserver/client/TestClient.java =================================================================== --- trunk/core/src/test/org/jtestserver/client/TestClient.java (rev 0) +++ trunk/core/src/test/org/jtestserver/client/TestClient.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,31 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.client; + +import org.jtestserver.common.Status; +import org.jtestserver.common.protocol.ProtocolException; +import org.jtestserver.common.protocol.TimeoutException; + +public interface TestClient { + Status runMauveTest(String test) throws ProtocolException, TimeoutException; + Status getStatus() throws ProtocolException, TimeoutException; + void shutdown() throws ProtocolException, TimeoutException; + void close() throws ProtocolException; +} Added: trunk/core/src/test/org/jtestserver/client/TestDriver.java =================================================================== --- trunk/core/src/test/org/jtestserver/client/TestDriver.java (rev 0) +++ trunk/core/src/test/org/jtestserver/client/TestDriver.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,119 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.jtestserver.common.Status; +import org.jtestserver.common.protocol.Protocol; +import org.jtestserver.common.protocol.ProtocolException; +import org.jtestserver.common.protocol.TimeoutException; +import org.jtestserver.common.protocol.UDPProtocol; + +public class TestDriver { + private static final Logger LOGGER = Logger.getLogger(TestDriver.class.getName()); + + public static void main(String[] args) throws ProtocolException, IOException { + TestDriver testDriver = createUDPTestDriver(InetAddress.getByName("localhost")); + + if ((args.length > 0) && "kill".equals(args[0])) { + testDriver.killRunningServers(); + } else { + testDriver.start(); + } + } + + private static TestDriver createUDPTestDriver(InetAddress serverAddress) throws ProtocolException { + UDPProtocol protocol = UDPProtocol.createClient(serverAddress); + protocol.setTimeout(10000); + + return new TestDriver(protocol, new NewProcessLauncher()); + } + + private final TestClient client; + private final TestServerProcess serverProcess; + private final List<String> tests = new ArrayList<String>(); + + private TestDriver(Protocol protocol, TestServerLauncher launcher) { + this.client = new DefaultTestClient(protocol); + this.serverProcess = new TestServerProcess(launcher); + } + + public void killRunningServers() throws ProtocolException { + try { + // kill server that might still be running + client.shutdown(); + } catch (Throwable t) { + LOGGER.log(Level.SEVERE, "unexpected error", t); + } + + boolean killed = false; + while (!killed) { + try { + client.getStatus(); + } catch (TimeoutException e) { + LOGGER.log(Level.SEVERE, "a timeout happened", e); + killed = true; + } + } + } + + public void start() throws IOException, ProtocolException { + //killRunningServers(); + + //serverProcess.start(); + + readTests(); + + for (String test : tests) { + try { + Status status = client.runMauveTest(test); + LOGGER.info(((status == null) ? "null" : status.toString()) + ": " + test); + } catch (TimeoutException e) { + LOGGER.log(Level.SEVERE, "a timeout happened", e); + } + } + + //killRunningServers(); + } + + private void readTests() throws IOException { + if (tests.isEmpty()) { + InputStream in = TestDriver.class.getResourceAsStream("/org/jnode/test/jtestserver/tests/mauve-tests.txt"); + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + String test = null; + while ((test = reader.readLine()) != null) { + if (!test.startsWith("#")) { + tests.add(test); + } + } + LOGGER.info("" + tests.size() + " tests"); + } + } + +} Added: trunk/core/src/test/org/jtestserver/client/TestServerLauncher.java =================================================================== --- trunk/core/src/test/org/jtestserver/client/TestServerLauncher.java (rev 0) +++ trunk/core/src/test/org/jtestserver/client/TestServerLauncher.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,26 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.client; + +import java.io.IOException; + +public interface TestServerLauncher { + Process launch() throws IOException; +} Added: trunk/core/src/test/org/jtestserver/client/TestServerProcess.java =================================================================== --- trunk/core/src/test/org/jtestserver/client/TestServerProcess.java (rev 0) +++ trunk/core/src/test/org/jtestserver/client/TestServerProcess.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,89 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.client; + +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + + +public class TestServerProcess { + private static final Logger LOGGER = Logger.getLogger(TestServerProcess.class.getName()); + + private static final Logger SERVER_LOGGER = Logger.getLogger("Server"); + + private final TestServerLauncher launcher; + private PipeInputStream outputPipe; + private PipeInputStream errorPipe; + + private Process process; + private WatchDog watchDog; + + public TestServerProcess(TestServerLauncher launcher) { + this.launcher = launcher; + + } + + public void start() throws IOException { + process = launcher.launch(); + + outputPipe = new PipeInputStream(process.getInputStream(), SERVER_LOGGER, Level.INFO); + outputPipe.start(); + + errorPipe = new PipeInputStream(process.getErrorStream(), SERVER_LOGGER, Level.SEVERE); + errorPipe.start(); + + watchDog = new WatchDog(); + watchDog.start(); + + LOGGER.finer("process = " + process); + } + + public boolean isAlive() { + boolean alive = false; + + try { + process.exitValue(); + } catch (IllegalThreadStateException e) { + alive = true; + } + return alive; + } + + private class WatchDog extends Thread { + public WatchDog() { + setDaemon(true); + } + + @Override + public void run() { + while (true) { + while (TestServerProcess.this.isAlive()) { + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + // ignore + } + + } + } + } + } +} Added: trunk/core/src/test/org/jtestserver/common/Status.java =================================================================== --- trunk/core/src/test/org/jtestserver/common/Status.java (rev 0) +++ trunk/core/src/test/org/jtestserver/common/Status.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,26 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.common; + +public enum Status { + READY, + ERROR, + RUNNING; +} Added: trunk/core/src/test/org/jtestserver/common/message/Descriptors.java =================================================================== --- trunk/core/src/test/org/jtestserver/common/message/Descriptors.java (rev 0) +++ trunk/core/src/test/org/jtestserver/common/message/Descriptors.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,33 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.common.message; + +import org.jtestserver.common.Status; + +public interface Descriptors { + public static final MessageDescriptor RUN_MAUVE_TEST = + new MessageDescriptor(Status.class, "RUN_MAUVE_TEST", String.class); + + public static final MessageDescriptor SHUTDOWN = + new MessageDescriptor(null, "SHUTDOWN"); + + public static final MessageDescriptor GET_STATUS = + new MessageDescriptor(Status.class, "GET_STATUS"); +} Added: trunk/core/src/test/org/jtestserver/common/message/InputMessage.java =================================================================== --- trunk/core/src/test/org/jtestserver/common/message/InputMessage.java (rev 0) +++ trunk/core/src/test/org/jtestserver/common/message/InputMessage.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,90 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.common.message; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import javax.net.ssl.SSLEngineResult.Status; + +import org.jtestserver.common.protocol.Protocol; +import org.jtestserver.common.protocol.ProtocolException; +import org.jtestserver.common.protocol.TimeoutException; + +public class InputMessage extends Message { + private final StringTokenizer message; + + public static InputMessage create(Protocol protocol) throws ProtocolException, TimeoutException { + return new InputMessage(protocol.receive()); + } + + private InputMessage(String message) { + this.message = new StringTokenizer(message, SEPARATOR, false); + } + + public final Object[] parseParameters(MessageDescriptor desc) { + List<Object> parameters = new ArrayList<Object>(); + + for (Class<?> paramClass : desc.getParamClasses()) { + parameters.add(parse(paramClass)); + } + + return parameters.toArray(); + } + + final Object parse(Class<?> type) { + Object result = null; + + try { + if (int.class.equals(type) || Integer.class.equals(type)) { + result = getInt(); + } else if (String.class.equals(type)) { + result = getString(); + } else if (Status.class.equals(type)) { + result = getStatus(); + } else { + //TODO throw exception + } + } catch (NullValueException nve) { + // the parsed value is equals to the NULL constant + result = null; + } + + return result; + } + + public String getString() { + String str = message.nextToken(); + if (NULL.equals(str)) { + throw new NullValueException(); + } + + return str; + } + + public Status getStatus() { + return Status.valueOf(getString()); + } + + public int getInt() { + return Integer.parseInt(getString()); + } +} Added: trunk/core/src/test/org/jtestserver/common/message/Message.java =================================================================== --- trunk/core/src/test/org/jtestserver/common/message/Message.java (rev 0) +++ trunk/core/src/test/org/jtestserver/common/message/Message.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,44 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.common.message; + + +import org.jtestserver.common.protocol.Protocol; +import org.jtestserver.common.protocol.ProtocolException; +import org.jtestserver.common.protocol.TimeoutException; + +public abstract class Message { + + public static Object send(Protocol protocol, MessageDescriptor desc, Object... params) + throws ProtocolException, TimeoutException { + OutputMessage output = OutputMessage.createOutputMessage(desc, params); + output.sendWith(protocol); + + Object result = null; + if (desc.getResultClass() != null) { + InputMessage input = InputMessage.create(protocol); + result = input.parse(desc.getResultClass()); + } + return result; + } + + static final String SEPARATOR = ";"; + static final String NULL = "NULL"; +} Added: trunk/core/src/test/org/jtestserver/common/message/MessageDescriptor.java =================================================================== --- trunk/core/src/test/org/jtestserver/common/message/MessageDescriptor.java (rev 0) +++ trunk/core/src/test/org/jtestserver/common/message/MessageDescriptor.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,45 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.common.message; + + +public class MessageDescriptor { + private final Class<?> resultClass; + private final String name; + private final Class<?>[] paramClasses; + + MessageDescriptor(Class<?> resultClass, String name, Class<?>... paramClasses) { + this.resultClass = resultClass; + this.name = name; + this.paramClasses = paramClasses; + } + + public final String getName() { + return name; + } + + final Class<?> getResultClass() { + return resultClass; + } + + final Class<?>[] getParamClasses() { + return paramClasses; + } +} Added: trunk/core/src/test/org/jtestserver/common/message/NullValueException.java =================================================================== --- trunk/core/src/test/org/jtestserver/common/message/NullValueException.java (rev 0) +++ trunk/core/src/test/org/jtestserver/common/message/NullValueException.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,45 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.common.message; + +public class NullValueException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public NullValueException() { + super(); + } + + public NullValueException(String message, Throwable cause) { + super(message, cause); + } + + public NullValueException(String message) { + super(message); + } + + public NullValueException(Throwable cause) { + super(cause); + } + +} Added: trunk/core/src/test/org/jtestserver/common/message/OutputMessage.java =================================================================== --- trunk/core/src/test/org/jtestserver/common/message/OutputMessage.java (rev 0) +++ trunk/core/src/test/org/jtestserver/common/message/OutputMessage.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,91 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.common.message; + +import org.jtestserver.common.Status; +import org.jtestserver.common.protocol.Protocol; +import org.jtestserver.common.protocol.ProtocolException; +import org.jtestserver.common.protocol.TimeoutException; + +public class OutputMessage extends Message { + private final StringBuilder message; + + public static final OutputMessage createResultMessage(MessageDescriptor desc, Object result) { + OutputMessage output = null; + + if (desc.getResultClass() != null) { + output = new OutputMessage(); + output.append(desc.getResultClass(), result); + } + + return output; + } + + public static final OutputMessage createOutputMessage(MessageDescriptor desc, Object... params) { + OutputMessage output = new OutputMessage(); + output.append(desc.getName()); + + int iParam = 0; + for (Class<?> paramClass : desc.getParamClasses()) { + output.append(paramClass, params[iParam]); + iParam++; + } + + return output; + } + + private OutputMessage() { + message = new StringBuilder(); + } + + public void sendWith(Protocol protocol) throws ProtocolException, TimeoutException { + protocol.send(message.toString()); + } + + private OutputMessage append(CharSequence chars) { + if (message.length() > 0) { + message.append(SEPARATOR); + } + + message.append(chars); + + return this; + } + + private OutputMessage append(int i) { + return append(Integer.toString(i)); + } + + private final void append(Class<?> type, Object value) { + if (value == null) { + append(NULL); + } else if (int.class.equals(type)) { + append(int.class.cast(value)); + } else if (Integer.class.equals(type)) { + append(Integer.class.cast(value).intValue()); + } else if (String.class.equals(type)) { + append((String) value); + } else if (Status.class.equals(type)) { + append(((Status) value).toString()); + } else { + //TODO throw exception + } + } +} Added: trunk/core/src/test/org/jtestserver/common/protocol/Protocol.java =================================================================== --- trunk/core/src/test/org/jtestserver/common/protocol/Protocol.java (rev 0) +++ trunk/core/src/test/org/jtestserver/common/protocol/Protocol.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,30 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.common.protocol; + + +public interface Protocol { + public void send(String command) throws ProtocolException, TimeoutException; + + public String receive() throws ProtocolException, TimeoutException; + + public void close() throws ProtocolException; + +} Added: trunk/core/src/test/org/jtestserver/common/protocol/ProtocolException.java =================================================================== --- trunk/core/src/test/org/jtestserver/common/protocol/ProtocolException.java (rev 0) +++ trunk/core/src/test/org/jtestserver/common/protocol/ProtocolException.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,45 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.common.protocol; + +public class ProtocolException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public ProtocolException() { + super(); + } + + public ProtocolException(String message, Throwable cause) { + super(message, cause); + } + + public ProtocolException(String message) { + super(message); + } + + public ProtocolException(Throwable cause) { + super(cause); + } + +} Added: trunk/core/src/test/org/jtestserver/common/protocol/TimeoutException.java =================================================================== --- trunk/core/src/test/org/jtestserver/common/protocol/TimeoutException.java (rev 0) +++ trunk/core/src/test/org/jtestserver/common/protocol/TimeoutException.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,45 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.common.protocol; + +public class TimeoutException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public TimeoutException() { + super(); + } + + public TimeoutException(String message, Throwable cause) { + super(message, cause); + } + + public TimeoutException(String message) { + super(message); + } + + public TimeoutException(Throwable cause) { + super(cause); + } + +} Added: trunk/core/src/test/org/jtestserver/common/protocol/UDPProtocol.java =================================================================== --- trunk/core/src/test/org/jtestserver/common/protocol/UDPProtocol.java (rev 0) +++ trunk/core/src/test/org/jtestserver/common/protocol/UDPProtocol.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,171 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.common.protocol; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.SocketException; +import java.net.SocketTimeoutException; +import java.nio.ByteBuffer; + +public class UDPProtocol implements Protocol { + private static final int DEFAULT_PORT = 10000; + + private static final int INT_SIZE = 4; // size of an int in bytes + + private final DatagramSocket socket; + private InetAddress remoteIp; + private int remotePort; + + /** + * Create an UDPProtocol for a server listening on {@link UDPProtocol#DEFAULT_PORT} + * @return + * @throws ProtocolException + */ + public static UDPProtocol createServer() throws ProtocolException { + return createServer(DEFAULT_PORT); + } + + /** + * Create an UDPProtocol for a server listening on given port + * @param localPort + * @return + * @throws ProtocolException + */ + public static UDPProtocol createServer(int localPort) throws ProtocolException { + return new UDPProtocol(localPort); + } + + /** + * Create an UDPProtocol for a client of the server at specified address + * listening on {@link UDPProtocol#DEFAULT_PORT} + * + * @param serverIp + * @return + * @throws ProtocolException + */ + public static UDPProtocol createClient(InetAddress serverIp) throws ProtocolException { + return createClient(serverIp, DEFAULT_PORT); + } + + /** + * Create an UDPProtocol for a client of the server at specified address and port + * @param serverIp + * @param serverPort + * @return + * @throws ProtocolException + */ + public static UDPProtocol createClient(InetAddress serverIp, int serverPort) throws ProtocolException { + return new UDPProtocol(serverIp, serverPort); + } + + /** + * Create an UDPProtocol for a server listening on given port. + * Note : the constructor should be 'private' but we need it to simulate timeouts in the tests. + * @param localPort + * @throws ProtocolException + */ + protected UDPProtocol(int localPort) throws ProtocolException { + try { + socket = new DatagramSocket(localPort); + } catch (SocketException se) { + throw new ProtocolException(se); + } + } + + /** + * Create an UDPProtocol for a client of the server at specified address and port + * Note : the constructor should be 'private' but we need it to simulate timeouts in the tests. + * @param serverIp + * @param serverPort + * @throws ProtocolException + */ + protected UDPProtocol(InetAddress serverIp, int serverPort) throws ProtocolException { + try { + socket = new DatagramSocket(); + this.remoteIp = serverIp; + this.remotePort = serverPort; + } catch (SocketException se) { + throw new ProtocolException(se); + } + } + + public void setTimeout(int timeout) throws ProtocolException { + try { + socket.setSoTimeout(timeout); + } catch (SocketException se) { + throw new ProtocolException(se); + } + } + + @Override + public void send(String command) throws ProtocolException, TimeoutException { + try { + // send size of data + ByteBuffer byteBuffer = ByteBuffer.allocate(INT_SIZE).putInt(command.length()); + byte[] data = byteBuffer.array(); + DatagramPacket packet = new DatagramPacket(data, data.length, remoteIp, remotePort); + + socket.send(packet); + + // send data + data = command.getBytes(); + packet = new DatagramPacket(data, data.length, remoteIp, remotePort); + socket.send(packet); + } catch (SocketTimeoutException e) { + throw new TimeoutException("timeout in receive", e); + } catch (IOException e) { + throw new ProtocolException("error in receive", e); + } + } + + @Override + public String receive() throws ProtocolException, TimeoutException { + try { + // receive size of data + byte[] data = new byte[INT_SIZE]; + DatagramPacket packet = new DatagramPacket(data, data.length); + socket.receive(packet); + int size = ByteBuffer.wrap(data).getInt(); + + // receive actual data + data = new byte[size]; + packet = new DatagramPacket(data, data.length); + socket.receive(packet); + + remoteIp = packet.getAddress(); + remotePort = packet.getPort(); + + return new String(packet.getData()); + } catch (SocketTimeoutException e) { + throw new TimeoutException("timeout in receive", e); + } catch (IOException e) { + throw new ProtocolException("error in receive", e); + } + } + + @Override + public void close() { + socket.disconnect(); + socket.close(); + } +} Added: trunk/core/src/test/org/jtestserver/server/TestFailureException.java =================================================================== --- trunk/core/src/test/org/jtestserver/server/TestFailureException.java (rev 0) +++ trunk/core/src/test/org/jtestserver/server/TestFailureException.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,45 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.server; + +public class TestFailureException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public TestFailureException() { + super(); + } + + public TestFailureException(String message, Throwable cause) { + super(message, cause); + } + + public TestFailureException(String message) { + super(message); + } + + public TestFailureException(Throwable cause) { + super(cause); + } + +} Added: trunk/core/src/test/org/jtestserver/server/TestServer.java =================================================================== --- trunk/core/src/test/org/jtestserver/server/TestServer.java (rev 0) +++ trunk/core/src/test/org/jtestserver/server/TestServer.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,115 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.server; + +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.jtestserver.common.message.InputMessage; +import org.jtestserver.common.message.OutputMessage; +import org.jtestserver.common.protocol.Protocol; +import org.jtestserver.common.protocol.ProtocolException; +import org.jtestserver.common.protocol.TimeoutException; +import org.jtestserver.common.protocol.UDPProtocol; +import org.jtestserver.server.commands.GetStatusCommand; +import org.jtestserver.server.commands.MauveTestRunner; +import org.jtestserver.server.commands.RunMauveTestCommand; +import org.jtestserver.server.commands.ShutdownCommand; + +public class TestServer { + private static final Logger LOGGER = Logger.getLogger(TestServer.class.getName()); + + public static void main(String[] args) throws ProtocolException { + UDPProtocol protocol = UDPProtocol.createServer(); + //protocol.setTimeout(10000); + + TestServer server = new TestServer(protocol); + server.start(); + } + + private boolean shutdownRequested = false; + private final Protocol protocol; + private final Map<String, TestServerCommand> nameToCommand; + + public TestServer(Protocol protocol) { + this.protocol = protocol; + nameToCommand = new HashMap<String, TestServerCommand>(); + + addCommand(new RunMauveTestCommand()); + addCommand(new ShutdownCommand(this)); + addCommand(new GetStatusCommand()); + } + + private void addCommand(TestServerCommand command) { + nameToCommand.put(command.getName(), command); + } + + public void start() { + while (!shutdownRequested) { + try { + InputMessage input = InputMessage.create(protocol); + String commandName = input.getString(); + TestServerCommand command = nameToCommand.get(commandName); + + OutputMessage output = null; + if (command == null) { + //TODO + } else { + try { + output = command.execute(input); + } catch (Throwable t) { + LOGGER.log(Level.SEVERE, "error in command", t); + } + } + + // if the command returns a result + if (output != null) { + output.sendWith(protocol); + } + + } catch (ProtocolException pe) { + LOGGER.log(Level.SEVERE, "protocol error", pe); + } catch (TimeoutException te) { + // ignore + } catch (Throwable t) { + LOGGER.log(Level.SEVERE, "unexpected error", t); + } + } + + shutdown(); + } + + private void shutdown() { + try { + protocol.close(); + } catch (ProtocolException e) { + LOGGER.log(Level.SEVERE, "error in shutdown", e); + } + MauveTestRunner.getInstance().shutdown(); + LOGGER.info("Server has shutdown"); + } + + public void requestShutdown() { + shutdownRequested = true; + LOGGER.info("shutdown requested"); + } +} Added: trunk/core/src/test/org/jtestserver/server/TestServerCommand.java =================================================================== --- trunk/core/src/test/org/jtestserver/server/TestServerCommand.java (rev 0) +++ trunk/core/src/test/org/jtestserver/server/TestServerCommand.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,30 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.server; + +import org.jtestserver.common.message.InputMessage; +import org.jtestserver.common.message.OutputMessage; +import org.jtestserver.common.protocol.ProtocolException; +import org.jtestserver.common.protocol.TimeoutException; + +public interface TestServerCommand { + String getName(); + OutputMessage execute(InputMessage input) throws ProtocolException, TimeoutException; +} Added: trunk/core/src/test/org/jtestserver/server/commands/AbstractTestServerCommand.java =================================================================== --- trunk/core/src/test/org/jtestserver/server/commands/AbstractTestServerCommand.java (rev 0) +++ trunk/core/src/test/org/jtestserver/server/commands/AbstractTestServerCommand.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,50 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 +of the License, or (at your option) any later version. + +JTestServer 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 this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +package org.jtestserver.server.commands; + +import org.jtestserver.common.message.InputMessage; +import org.jtestserver.common.message.MessageDescriptor; +import org.jtestserver.common.message.OutputMessage; +import org.jtestserver.common.protocol.ProtocolException; +import org.jtestserver.common.protocol.TimeoutException; +import org.jtestserver.server.TestServerCommand; + +public abstract class AbstractTestServerCommand<T> implements TestServerCommand { + private final MessageDescriptor descriptor; + + public AbstractTestServerCommand(MessageDescriptor descriptor) { + this.descriptor = descriptor; + } + + @Override + public final String getName() { + return descriptor.getName(); + } + + @Override + public final OutputMessage execute(InputMessage input) throws ProtocolException, TimeoutException { + Object[] params = input.parseParameters(descriptor); + T result = execute(params); + + return OutputMessage.createResultMessage(descriptor, result); + } + + protected abstract T execute(Object[] params) throws ProtocolException, TimeoutException; +} Added: trunk/core/src/test/org/jtestserver/server/commands/GetStatusCommand.java =================================================================== --- trunk/core/src/test/org/jtestserver/server/commands/GetStatusCommand.java (rev 0) +++ trunk/core/src/test/org/jtestserver/server/commands/GetStatusCommand.java 2008-11-10 22:09:27 UTC (rev 4698) @@ -0,0 +1,36 @@ +/* +JTestServer is a client/server framework for testing any JVM implementation. + +Copyright (C) 2008 Fabien DUMINY (fd...@jn...) + +JTestServer 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 ... [truncated message content] |