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

io.perfana.event.generator.EventScheduleGeneratorDefault Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
package io.perfana.event.generator;

import io.perfana.client.api.TestContext;
import io.perfana.event.EventScheduleGenerator;
import io.perfana.event.ScheduleEvent;

import java.io.BufferedReader;
import java.io.StringReader;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class EventScheduleGeneratorDefault implements EventScheduleGenerator {

    private static final String EVENT_SCHEDULE_TAG = "eventSchedule";

    @Override
    public List generateEvents(TestContext context, GeneratorProperties properties) {
        return createPerfanaTestEvents(properties.getProperty(EVENT_SCHEDULE_TAG));
    }

    public List createPerfanaTestEvents(String eventsAsString) {
        if (eventsAsString != null) {
            BufferedReader eventReader = new BufferedReader(new StringReader(eventsAsString));
            List events = eventReader.lines()
                    .map(String::trim)
                    .filter(e -> !e.isEmpty())
                    .collect(Collectors.toList());
            return parseScheduleEvents(events);
        }
        else {
            return Collections.emptyList();
        }
    }

    private List parseScheduleEvents(List eventSchedule) {
        return eventSchedule.stream()
                .map(ScheduleEvent::createFromLine)
                .collect(Collectors.toList());
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy