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

io.hyperfoil.cli.commands.BenchmarkCommand Maven / Gradle / Ivy

There is a newer version: 0.27.1
Show newest version
package io.hyperfoil.cli.commands;

import org.aesh.command.CommandException;
import org.aesh.command.option.Argument;

import io.hyperfoil.cli.context.HyperfoilCliContext;
import io.hyperfoil.cli.context.HyperfoilCommandInvocation;
import io.hyperfoil.controller.Client;

public abstract class BenchmarkCommand extends ServerCommand {
   @Argument(description = "Name of the benchmark.", completer = BenchmarkCompleter.class)
   public String benchmark;

   protected Client.BenchmarkRef ensureBenchmark(HyperfoilCommandInvocation invocation) throws CommandException {
      ensureConnection(invocation);
      HyperfoilCliContext ctx = invocation.context();
      Client.BenchmarkRef benchmarkRef;
      if (benchmark == null || benchmark.isEmpty()) {
         benchmarkRef = ctx.serverBenchmark();
         if (benchmarkRef == null) {
            invocation.println("No benchmark was set. Available benchmarks: ");
            printList(invocation, invocation.context().client().benchmarks(), 15);
            throw new CommandException("Use " + getClass().getSimpleName().toLowerCase() + " ");
         }
      } else {
         benchmarkRef = ctx.client().benchmark(benchmark);
         if (benchmarkRef == null) {
            invocation.println("Available benchmarks: ");
            printList(invocation, invocation.context().client().benchmarks(), 15);
            throw new CommandException("No such benchmark: '" + benchmark + "'");
         }
      }
      ctx.setServerBenchmark(benchmarkRef);
      return benchmarkRef;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy