package org.radargun.stages;

import org.radargun.DistStageAck;
import org.radargun.state.MasterState;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * The warmup stage for web session benchmarks.  This ensures the same access paths are used for the warmup and the
 * actual benchmark.
 *
 * @author Manik Surtani
 */
public class WebSessionWarmupStage extends WebSessionBenchmarkStage {

   private static final Set<String> WARMED_UP_CONFIGS = new HashSet<String>(2);

   @Override
   public DistStageAck executeOnSlave() {

      String configName = cacheWrapper.getClass().getName() + " - " + cacheWrapper.getInfo();
      DefaultDistStageAck result = new DefaultDistStageAck(slaveIndex, slaveState.getLocalAddress());
      if (!WARMED_UP_CONFIGS.contains(configName)) {
         this.cacheWrapper = slaveState.getCacheWrapper();
         if (cacheWrapper == null) {
            log.info("Not running test on this slave as the wrapper hasn't been configured.");
            return result;
         }

         try {
            long startTime = System.currentTimeMillis();
            doWork();
            long duration = System.currentTimeMillis() - startTime;
            log.info("The warmup took: " + (duration / 1000) + " seconds.");
            result.setPayload(duration);
            WARMED_UP_CONFIGS.add(configName);
            return result;
         } catch (Exception e) {
            log.warn("Exception while running " + getClass().getSimpleName(), e);
            result.setError(true);
            result.setRemoteException(e);
            return result;
         }
      } else {
         log.info("Skipping warmup, this has already been done for this configuration on this node.");
         return result;
      }
   }

   @Override
   public boolean processAckOnMaster(List<DistStageAck> acks, MasterState masterState) {
      logDurationInfo(acks);
      for (DistStageAck ack : acks) {
         DefaultDistStageAck dAck = (DefaultDistStageAck) ack;
         if (dAck.isError())
            log.warn("Caught error on slave " + dAck.getSlaveIndex() + " when running " + getClass().getSimpleName() + ".  Error details:" + dAck.getErrorMessage());
      }
      return true;
   }

   @Override
   public String toString() {
      return "Warmup for " + super.toString();
   }
}

@@ -552,103 +552,8 @@
 () %7B
-%0A%0A      String configName = cacheWrapper.getClass().getName() + %22 - %22 + cacheWrapper.getInfo();
 %0A   
@@ -655,64 +655,8 @@
 ));%0A
-      if (!WARMED_UP_CONFIGS.contains(configName)) %7B%0A   
     
@@ -703,27 +703,24 @@
 eWrapper();%0A
-   
       if (ca
@@ -742,35 +742,32 @@
 ull) %7B%0A         
-   
 log.info(%22Not ru
@@ -834,35 +834,32 @@
 ed.%22);%0A         
-   
 return result;%0A 
@@ -863,20 +863,166 @@
 ;%0A      
-   %7D
+%7D%0A%0A      String configName = cacheWrapper.getClass().getName() + %22 - %22 + cacheWrapper.getInfo();%0A%0A      if (!WARMED_UP_CONFIGS.contains(configName)) %7B
 %0A%0A      

Fix NPE