All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hyperfoil.http.handlers.StatusToStatsHandler Maven / Gradle / Ivy

There is a newer version: 0.27.1
Show newest version
package io.hyperfoil.http.handlers;

import org.kohsuke.MetaInfServices;

import io.hyperfoil.api.config.Name;
import io.hyperfoil.http.api.HttpRequest;
import io.hyperfoil.http.api.StatusHandler;
import io.hyperfoil.api.statistics.IntValue;

public class StatusToStatsHandler implements StatusHandler {
   private static final int FIRST_STATUS = 100;
   private static final int LAST_STATUS = 599;
   private static final String[] statusStrings;

   static {
      statusStrings = new String[LAST_STATUS - FIRST_STATUS + 1];
      for (int i = 0; i <= LAST_STATUS - FIRST_STATUS; ++i) {
         statusStrings[i] = "status_" + (i + FIRST_STATUS);
      }
   }

   @Override
   public void handleStatus(HttpRequest request, int status) {
      String statusString;
      if (status >= FIRST_STATUS && status <= LAST_STATUS) {
         statusString = statusStrings[status - FIRST_STATUS];
      } else {
         statusString = "status_" + status;
      }
      IntValue custom = request.statistics().getCustom(request.startTimestampMillis(), statusString, IntValue::new);
      custom.add(1);
   }

   /**
    * Records number of occurrences of each status counts into custom statistics
    * (these can be displayed in CLI using stats -c).
    */
   @MetaInfServices
   @Name("stats")
   public static class Builder implements StatusHandler.Builder {
      @Override
      public StatusHandler build() {
         return new StatusToStatsHandler();
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy