Clover coverage report -
Coverage timestamp: Sat Jul 7 2007 16:41:13 CEST
file stats: LOC: 362   Methods: 32
NCLOC: 175   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbstractWsRunner.java 80% 52.4% 31.2% 48.6%
coverage coverage
 1    /**
 2    * JTRunner is free software; you can redistribute it and/or modify it under the
 3    * terms of the GNU General Public License as published by the Free Software
 4    * Foundation; either version 2, or (at your option) any later version.
 5    */
 6   
 7    package jtr.runners;
 8   
 9    import java.util.concurrent.Future;
 10   
 11    import jtr.config.RegisteredFactories;
 12    import jtr.config.ws.Binding;
 13    import jtr.config.ws.WebServiceConfig;
 14    import jtr.ws.IWsHelper;
 15    import jtr.ws.IWsHelperFactory;
 16    import jtr.ws.IWsResponse;
 17    import jtr.ws.IWsResponseListener;
 18    import jtr.ws.WsMsgType;
 19    import jtr.ws.WsProviderException;
 20    import org.apache.log4j.Logger;
 21   
 22    /**
 23    * This abstract class is the base class every application-level <code>IRunner</code> implementation
 24    * should extend when the ability to access webservices is required.<br>
 25    * This class provides facilities for invoking webservices according to what has been specified in the
 26    * <code>jtr.xml</code> configuration file.<br>
 27    *
 28    * @author Francesco Russo (frusso@dev.java.net)
 29    * @version 4.0
 30    * @since 3.0
 31    */
 32    public abstract class AbstractWsRunner extends AbstractRunnerAncestor implements IRunnerWs {
 33    /**
 34    * Default constructor.
 35    */
 36  34 public AbstractWsRunner() {
 37  34 wsHelper = ((IWsHelperFactory) RegisteredFactories.getFactory(RegisteredFactories.IWSHELPER_FACTORY)).getInstance();
 38    }
 39   
 40    /**
 41    * @see jtr.runners.IRunnerWs#getWsConfig()
 42    */
 43  0 public WebServiceConfig getWsConfig() {
 44  0 return wsConfig;
 45    }
 46   
 47    /**
 48    * @see jtr.runners.IRunnerWs#setWsConfig(jtr.config.ws.WebServiceConfig)
 49    */
 50  6014 public void setWsConfig(WebServiceConfig wsConfig) {
 51  6014 this.wsConfig = wsConfig;
 52    }
 53   
 54    /**
 55    * @throws WsProviderException
 56    * @see jtr.ws.IWsHelper#setMessageObjectPart(Binding, String, Object, WsMsgType)
 57    * @deprecated
 58    */
 59  0 @Deprecated
 60    protected void setMessageObjectPart(Binding binding, String partName, Object part, WsMsgType msgType) throws WsProviderException {
 61  0 wsHelper.setMessageObjectPart(binding, partName, part, msgType);
 62    }
 63   
 64    /**
 65    * @see jtr.ws.IWsHelper#setMessageIntPart(Binding, String, int, WsMsgType)
 66    * @deprecated
 67    */
 68  0 @Deprecated
 69    protected void setMessageIntPart(Binding binding, String partName, int part, WsMsgType msgType) {
 70  0 wsHelper.setMessageIntPart(binding, partName, part, msgType);
 71    }
 72   
 73    /**
 74    * @see jtr.ws.IWsHelper#setMessageBooleanPart(Binding, String, boolean, WsMsgType)
 75    * @deprecated
 76    */
 77  0 @Deprecated
 78    protected void setMessageBooleanPart(Binding binding, String partName, boolean part, WsMsgType msgType) {
 79  0 wsHelper.setMessageBooleanPart(binding, partName, part, msgType);
 80    }
 81   
 82    /**
 83    * @see jtr.ws.IWsHelper#setMessageBytePart(Binding, String, byte, WsMsgType)
 84    * @deprecated
 85    */
 86  0 @Deprecated
 87    protected void setMessageBytePart(Binding binding, String partName, byte part, WsMsgType msgType) {
 88  0 wsHelper.setMessageBytePart(binding, partName, part, msgType);
 89    }
 90   
 91    /**
 92    * @see jtr.ws.IWsHelper#setMessageCharPart(Binding, String, char, WsMsgType)
 93    * @deprecated
 94    */
 95  0 @Deprecated
 96    protected void setMessageCharPart(Binding binding, String partName, char part, WsMsgType msgType) {
 97  0 wsHelper.setMessageCharPart(binding, partName, part, msgType);
 98    }
 99   
 100    /**
 101    * @see jtr.ws.IWsHelper#setMessageDoublePart(Binding, String, double, WsMsgType)
 102    * @deprecated
 103    */
 104  0 @Deprecated
 105    protected void setMessageDoublePart(Binding binding, String partName, double part, WsMsgType msgType) {
 106  0 wsHelper.setMessageDoublePart(binding, partName, part, msgType);
 107    }
 108   
 109    /**
 110    * @see jtr.ws.IWsHelper#setMessageFloatPart(Binding, String, float, WsMsgType)
 111    * @deprecated
 112    */
 113  0 @Deprecated
 114    protected void setMessageFloatPart(Binding binding, String partName, float part, WsMsgType msgType) {
 115  0 wsHelper.setMessageFloatPart(binding, partName, part, msgType);
 116    }
 117   
 118    /**
 119    * @see jtr.ws.IWsHelper#setMessageLongPart(Binding, String, long, WsMsgType)
 120    * @deprecated
 121    */
 122  0 @Deprecated
 123    protected void setMessageLongPart(Binding binding, String partName, long part, WsMsgType msgType) {
 124  0 wsHelper.setMessageLongPart(binding, partName, part, msgType);
 125    }
 126   
 127    /**
 128    * @throws WsProviderException
 129    * @see jtr.ws.IWsHelper#getMessageObjectPart(Binding, String, WsMsgType)
 130    * @deprecated
 131    */
 132  0 @Deprecated
 133    protected Object getMessageObjectPart(Binding binding, String partName, WsMsgType msgType) throws WsProviderException {
 134  0 return wsHelper.getMessageObjectPart(binding, partName, msgType);
 135    }
 136   
 137    /**
 138    * @throws WsProviderException
 139    * @see jtr.ws.IWsHelper#getMessageIntPart(Binding, String, WsMsgType)
 140    * @deprecated
 141    */
 142  0 @Deprecated
 143    protected int getMessageIntPart(Binding binding, String partName, WsMsgType msgType) throws WsProviderException {
 144  0 return wsHelper.getMessageIntPart(binding, partName, msgType);
 145    }
 146   
 147    /**
 148    * @throws WsProviderException
 149    * @see jtr.ws.IWsHelper#getMessageBooleanPart(Binding, String, WsMsgType)
 150    * @deprecated
 151    */
 152  0 @Deprecated
 153    protected boolean getMessageBooleanPart(Binding binding, String partName, WsMsgType msgType) throws WsProviderException {
 154  0 return wsHelper.getMessageBooleanPart(binding, partName, msgType);
 155    }
 156   
 157    /**
 158    * @throws WsProviderException
 159    * @see jtr.ws.IWsHelper#getMessageBytePart(Binding, String, WsMsgType)
 160    * @deprecated
 161    */
 162  0 @Deprecated
 163    protected byte getMessageBytePart(Binding binding, String partName, WsMsgType msgType) throws WsProviderException {
 164  0 return wsHelper.getMessageBytePart(binding, partName, msgType);
 165    }
 166   
 167    /**
 168    * @throws WsProviderException
 169    * @see jtr.ws.IWsHelper#getMessageCharPart(Binding, String, WsMsgType)
 170    * @deprecated
 171    */
 172  0 @Deprecated
 173    protected char getMessageCharPart(Binding binding, String partName, WsMsgType msgType) throws WsProviderException {
 174  0 return wsHelper.getMessageCharPart(binding, partName, msgType);
 175    }
 176   
 177    /**
 178    * @throws WsProviderException
 179    * @see jtr.ws.IWsHelper#getMessageDoublePart(Binding, String, WsMsgType)
 180    * @deprecated
 181    */
 182  0 @Deprecated
 183    protected double getMessageDoublePart(Binding binding, String partName, WsMsgType msgType) throws WsProviderException {
 184  0 return wsHelper.getMessageDoublePart(binding, partName, msgType);
 185    }
 186   
 187    /**
 188    * @throws WsProviderException
 189    * @see jtr.ws.IWsHelper#getMessageFloatPart(Binding, String, WsMsgType)
 190    * @deprecated
 191    */
 192  0 @Deprecated
 193    protected float getMessageFloatPart(Binding binding, String partName, WsMsgType msgType) throws WsProviderException {
 194  0 return wsHelper.getMessageFloatPart(binding, partName, msgType);
 195    }
 196   
 197    /**
 198    * @throws WsProviderException
 199    * @see jtr.ws.IWsHelper#getMessageLongPart(Binding, String, WsMsgType)
 200    * @deprecated
 201    */
 202  0 @Deprecated
 203    protected long getMessageLongPart(Binding binding, String partName, WsMsgType msgType) throws WsProviderException {
 204  0 return wsHelper.getMessageLongPart(binding, partName, msgType);
 205    }
 206   
 207    /**
 208    * @see jtr.ws.IWsHelper#getFaultMessageAsString(Binding)
 209    * @deprecated
 210    */
 211  0 @Deprecated
 212    protected String getFaultMessageAsString(Binding binding) {
 213  0 return wsHelper.getFaultMessageAsString(binding);
 214    }
 215   
 216    /**
 217    * @see jtr.ws.IWsHelper#getFaultCause(Binding)
 218    * @deprecated
 219    */
 220  0 @Deprecated
 221    protected Throwable getFaultCause(Binding binding) {
 222  0 return wsHelper.getFaultCause(binding);
 223    }
 224   
 225    /**
 226    * This method performs a synchronous invocation of the webservice following a request/response pattern.
 227    * @param binding The webservice binding in use
 228    * @return boolean The outcome of the invocation
 229    * @throws Throwable
 230    * @see jtr.ws.IWsHelper#synchronousInvoke(Binding)
 231    * @deprecated
 232    */
 233  0 @Deprecated
 234    protected boolean synchronousInvoke(Binding binding) throws Throwable {
 235  0 boolean res = false;
 236  0 res = wsHelper.synchronousInvoke(binding);
 237  0 if(!res) {
 238  0 String faultMsg = getFaultMessageAsString(binding);
 239  0 logger.error("The synchronous invocation of "+binding.getNameSpace()+"-"+binding.getName()+"-"+binding.getPortName()+"-"+binding.getOperationName()+" returned the following fault message: \n"+faultMsg);
 240  0 logger.error("Follows the cause: ",getFaultCause(binding));
 241    }
 242  0 return res;
 243    }
 244   
 245    /**
 246    * This method performs an asynchronous invocation of the webservice, following a one-way messaging pattern.
 247    * @param binding The webservice binding in use
 248    * @throws Throwable
 249    * @deprecated
 250    */
 251  0 @Deprecated
 252    public void asynchronousInputOnlyInvoke(Binding binding) throws Throwable {
 253  0 wsHelper.asynchronousInputOnlyInvoke(binding);
 254    }
 255   
 256    /**
 257    * This method sets the configured webservice binding.
 258    * @param binding
 259    */
 260  6014 public void setBinding(Binding binding) {
 261  6014 this.binding = binding;
 262    }
 263   
 264    /**
 265    * This method returns the set of configured webservice bindings.
 266    * @return Bindings
 267    */
 268  36995 public Binding getBinding() {
 269  36997 return binding;
 270    }
 271   
 272  0 @Deprecated
 273    public String[] getMessageParts(Binding binding, WsMsgType msgType) {
 274  0 return wsHelper.getMessageParts(binding, msgType);
 275    }
 276   
 277    /**
 278    * This method wraps the <code>test()</code> method implemented by
 279    * application developed runners.<br>
 280    * It manages the execution of the <code>test()</code> method according to
 281    * the sleep time interval associated with the wrapped <code>IRunner</code>
 282    * instance, according to the declared number of required runs and so on.<br>
 283    * Furthermore there is a fundamental exception accounting feature which
 284    * enables JTR to collect information about each single <code>IRunner</code>
 285    * run and the handling of boring/complex tasks such as the reinitialization
 286    * of each runner parameters according to the associated
 287    * <code>IAssignmentPolicy</code>.
 288    */
 289  1700 public final void run() {
 290  1700 logger = Logger.getLogger(this.getClass().getName());
 291  1700 logger.debug("Running client thread...");
 292  1700 for (currentRun = 0; currentRun < getRuns(); currentRun++) {
 293    // let's start the test logic...
 294  9499 try {
 295  9500 logger.debug("Starting run " + currentRun + " in epoch " + epoch);
 296  9498 if (epoch == 0 && currentRun == 0 || paramsAssigner.requiresReinitialization()) {
 297  6014 logger.debug("Generating WS runtime configuration...");
 298  6014 wsHelper.generateRuntimeConfig(wsConfig);
 299    }
 300  9500 doRunTest();
 301    } catch (Throwable t) {
 302  2000 handleFailure(currentRun, t);
 303    }
 304    // it's now time for a sleep
 305  9500 try {
 306  9500 if (currentRun < getRuns() - 1) {
 307  7800 logger.debug("Completed, going to bed for a while... [" + getSleepTime() + " mSecs.]");
 308  7799 Thread.sleep(getSleepTime());
 309  7798 logger.debug("Awaken");
 310    // we have some runs left, let's check for reinitialization
 311  7797 logger.debug("Check for reinitialization");
 312  7798 if (paramsAssigner.requiresReinitialization()) {
 313    // re-initialization required...
 314  5000 logger.debug("Reinitialization required...");
 315  5000 paramsAssigner.reAssign(clean());
 316  5000 logger.debug("... reinitialized");
 317    } else {
 318    // nop
 319  2799 logger.debug("Reinitialization not required");
 320    }
 321    }
 322    } catch (InterruptedException e) {
 323  0 String msg = "The current test-thread " + Thread.currentThread().getName() + " received an interrupt while sleeping";
 324  0 logger.warn(msg, e);
 325    }
 326    }
 327    // runs are over... back into the pool
 328  1700 logger.debug("Completed all the runs [" + getRuns() + "], going back into the pool");
 329  1700 logger.debug("Getting IPoolManager instance...");
 330  1700 pool.getPoolManager().backIntoPool(this);
 331    }
 332   
 333  7494 public Object invoke(Binding binding, Object input) throws WsProviderException {
 334  7500 return wsHelper.invoke(this, binding, input);
 335    }
 336   
 337  4000 public void invokeOneWay(Binding binding, Object input) throws WsProviderException {
 338  4000 wsHelper.invokeOneWay(this, binding, input);
 339    }
 340   
 341  2000 public Future<?> invokeAsync(Binding binding, Object input, IWsResponseListener rl) throws WsProviderException {
 342  2000 return wsHelper.invokeAsync(this, binding, input, rl);
 343    }
 344   
 345  2000 public IWsResponse invokeAsync(Binding binding, Object input) throws WsProviderException {
 346  2000 return wsHelper.invokeAsync(this, binding, input);
 347    }
 348   
 349    /**
 350    * Return the current run assigned to the <code>IRunner</code>
 351    *
 352    * @return int The current run
 353    */
 354  9500 public int getCurrentRun() {
 355  9500 return currentRun;
 356    }
 357   
 358    private int currentRun;
 359    private WebServiceConfig wsConfig;
 360    private Binding binding;
 361    private IWsHelper wsHelper;
 362    }