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

io.hyperfoil.core.parser.StepParser Maven / Gradle / Ivy

There is a newer version: 0.27.1
Show newest version
package io.hyperfoil.core.parser;

import org.yaml.snakeyaml.events.Event;
import org.yaml.snakeyaml.events.MappingEndEvent;
import org.yaml.snakeyaml.events.MappingStartEvent;
import org.yaml.snakeyaml.events.ScalarEvent;
import org.yaml.snakeyaml.events.SequenceStartEvent;

import io.hyperfoil.api.config.BaseSequenceBuilder;
import io.hyperfoil.api.config.BenchmarkDefinitionException;
import io.hyperfoil.core.builders.ServiceLoadedContract;
import io.hyperfoil.api.config.StepBuilder;
import io.hyperfoil.core.builders.ServiceLoadedBuilderProvider;

class StepParser extends BaseReflectionParser implements Parser {
   private static final StepParser INSTANCE = new StepParser();

   public static StepParser instance() {
      return INSTANCE;
   }

   private StepParser() {}

   @Override
   public void parse(Context ctx, BaseSequenceBuilder target) throws ParserException {
      Event firstEvent = ctx.next();
      ServiceLoadedBuilderProvider provider = new ServiceLoadedBuilderProvider<>(StepBuilder.class, target.createLocator(), target::stepBuilder);
      if (firstEvent instanceof ScalarEvent) {
         ServiceLoadedContract slc;
         String name = ((ScalarEvent) firstEvent).getValue();
         try {
            slc = provider.forName(name, null);
         } catch (BenchmarkDefinitionException e) {
            throw new ParserException(firstEvent, "Failed to instantiate step builder " + name, e);
         }
         slc.complete();
         return;
      } else if (!(firstEvent instanceof MappingStartEvent)) {
         throw ctx.unexpectedEvent(firstEvent);
      }

      ScalarEvent stepEvent = ctx.expectEvent(ScalarEvent.class);
      if (!ctx.hasNext()) {
         throw ctx.noMoreEvents(ScalarEvent.class, MappingStartEvent.class, MappingEndEvent.class, SequenceStartEvent.class);
      }
      fillSLBP(ctx, stepEvent, provider);
      ctx.expectEvent(MappingEndEvent.class);
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy