001: /*
002: Copyright (C) 2004 David Bucciarelli (davibu@interfree.it)
003:
004: This program is free software; you can redistribute it and/or
005: modify it under the terms of the GNU General Public License
006: as published by the Free Software Foundation; either version 2
007: of the License, or (at your option) any later version.
008:
009: This program is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: GNU General Public License for more details.
013:
014: You should have received a copy of the GNU General Public License
015: along with this program; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: */
018:
019: package org.homedns.dade.jcgrid.cmd.dummy;
020:
021: import org.apache.log4j.*;
022: import org.apache.commons.cli.*;
023:
024: import org.homedns.dade.jcgrid.*;
025: import org.homedns.dade.jcgrid.cmd.*;
026: import org.homedns.dade.jcgrid.client.*;
027: import org.homedns.dade.jcgrid.message.*;
028: import org.homedns.dade.jcgrid.worker.impl.dummy.*;
029:
030: public class JCGridClient {
031: private final static String className = JCGridClient.class
032: .getName();
033: private static Logger log = Logger.getLogger(className);
034: private static Logger logDetail = Logger.getLogger("DETAIL."
035: + className);
036:
037: private final static int WORKREQUEST_COUNT = 100;
038:
039: public static void main(String[] args) {
040: try {
041: // Setup log4j
042:
043: MainCmd.setUpLog4J("client", true);
044:
045: // Setup GridServer
046:
047: log.warn("-----------------------------------------------");
048: log.warn("-- JCGridClient Dummy v" + Version.RELEASE);
049: log.warn("-----------------------------------------------");
050:
051: GridClient gc = new GridClient();
052:
053: // Parse command line options
054:
055: Options options = new Options();
056: try {
057: CommandLine cmd = MainCmd.parseCommonOptions(options,
058: gc.getNodeConfig(), args);
059:
060: if (cmd.getArgs().length > 0)
061: throw new Exception("Unknown command line option");
062: } catch (Exception ex) {
063: log.warn("Error while parsing command line", ex);
064:
065: HelpFormatter formatter = new HelpFormatter();
066: formatter.printHelp("JCGridClient", options);
067:
068: System.exit(0);
069: }
070:
071: // Start Client
072:
073: gc.start();
074:
075: log.warn("Sending work requests...");
076:
077: boolean[] resultReceived = new boolean[WORKREQUEST_COUNT];
078: DummyWorkRequest[] dwr = new DummyWorkRequest[WORKREQUEST_COUNT];
079: for (int i = 0; i < WORKREQUEST_COUNT; i++) {
080: resultReceived[i] = false;
081: dwr[i] = new DummyWorkRequest(
082: ((GridNodeGenericConfig) gc.getNodeConfig())
083: .getSessionName(), i);
084: gc.send(new GridMessageWorkRequest(dwr[i]));
085: }
086:
087: log.warn("Receiving work results...");
088: for (int i = 0; i < WORKREQUEST_COUNT; i++) {
089: GridMessageWorkResult gmwr = (GridMessageWorkResult) gc
090: .recv();
091: DummyWorkResult dwres = (DummyWorkResult) gmwr
092: .getWorkResult();
093:
094: int id = dwres.getRID();
095: resultReceived[id] = true;
096:
097: if (dwres.getNumber() != dwr[id].getNumber())
098: log.warn("Message " + id + " match failed !");
099: }
100:
101: boolean res = true;
102: for (int i = 0; i < WORKREQUEST_COUNT; i++)
103: res = res && resultReceived[i];
104:
105: gc.stop();
106:
107: if (res)
108: log.warn("Test completed.");
109: else
110: log.warn("Test failed.");
111: } catch (Exception ex) {
112: log.warn("Error", ex);
113: System.exit(0);
114: }
115: }
116: }
|