Search in sources :

Example 1 with InputDispenser

use of io.nosqlbench.engine.api.activityapi.input.InputDispenser in project nosqlbench by nosqlbench.

the class CoreInputDispenser method createInput.

private synchronized Input createInput(long slot) {
    SimpleConfig conf = new SimpleConfig(activity, "input");
    String inputType = conf.getString("type").orElse("atomicseq");
    InputType inputTypeImpl = InputType.FINDER.getOrThrow(inputType);
    InputDispenser inputDispenser = inputTypeImpl.getInputDispenser(activity);
    if (inputDispenser instanceof ActivitiesAware) {
        ((ActivitiesAware) inputDispenser).setActivitiesMap(activities);
    }
    Input input = inputDispenser.getInput(slot);
    return input;
}
Also used : SimpleConfig(io.nosqlbench.engine.api.util.SimpleConfig) Input(io.nosqlbench.engine.api.activityapi.input.Input) InputType(io.nosqlbench.engine.api.activityapi.input.InputType) InputDispenser(io.nosqlbench.engine.api.activityapi.input.InputDispenser) ActivitiesAware(io.nosqlbench.engine.api.activityapi.core.ActivitiesAware)

Example 2 with InputDispenser

use of io.nosqlbench.engine.api.activityapi.input.InputDispenser in project nosqlbench by nosqlbench.

the class ActivityType method getAssembledActivity.

/**
 * Create an instance of an activity that ties together all the components into a usable
 * activity instance. This is the method that should be called by executor classes.
 *
 * @param activityDef the definition that initializez and controlls the activity.
 * @param activities  a map of existing activities
 * @return a distinct activity instance for each call
 */
default Activity getAssembledActivity(ActivityDef activityDef, Map<String, Activity> activities) {
    A activity = getActivity(activityDef);
    InputDispenser inputDispenser = getInputDispenser(activity);
    if (inputDispenser instanceof ActivitiesAware) {
        ((ActivitiesAware) inputDispenser).setActivitiesMap(activities);
    }
    activity.setInputDispenserDelegate(inputDispenser);
    ActionDispenser actionDispenser = getActionDispenser(activity);
    if (actionDispenser instanceof ActivitiesAware) {
        ((ActivitiesAware) actionDispenser).setActivitiesMap(activities);
    }
    activity.setActionDispenserDelegate(actionDispenser);
    OutputDispenser outputDispenser = getOutputDispenser(activity).orElse(null);
    if (outputDispenser != null && outputDispenser instanceof ActivitiesAware) {
        ((ActivitiesAware) outputDispenser).setActivitiesMap(activities);
    }
    activity.setOutputDispenserDelegate(outputDispenser);
    MotorDispenser motorDispenser = getMotorDispenser(activity, inputDispenser, actionDispenser, outputDispenser);
    if (motorDispenser instanceof ActivitiesAware) {
        ((ActivitiesAware) motorDispenser).setActivitiesMap(activities);
    }
    activity.setMotorDispenserDelegate(motorDispenser);
    return activity;
}
Also used : CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) CoreMotorDispenser(io.nosqlbench.engine.api.activityimpl.motor.CoreMotorDispenser) OutputDispenser(io.nosqlbench.engine.api.activityapi.output.OutputDispenser) InputDispenser(io.nosqlbench.engine.api.activityapi.input.InputDispenser)

Example 3 with InputDispenser

use of io.nosqlbench.engine.api.activityapi.input.InputDispenser in project nosqlbench by nosqlbench.

the class ActivityExecutorTest method testNewActivityExecutor.

@Test
public void testNewActivityExecutor() {
    ActivityDef ad = ActivityDef.parseActivityDef("driver=diag;alias=test;cycles=1000;");
    Optional<ActivityType> activityType = new ActivityTypeLoader().load(ad);
    Input longSupplier = new AtomicInput(ad);
    MotorDispenser<?> cmf = getActivityMotorFactory(ad, motorActionDelay(999), longSupplier);
    Activity a = new SimpleActivity(ad);
    InputDispenser idisp = new CoreInputDispenser(a);
    ActionDispenser adisp = new CoreActionDispenser(a);
    OutputDispenser tdisp = CoreServices.getOutputDispenser(a).orElse(null);
    MotorDispenser<?> mdisp = new CoreMotorDispenser(a, idisp, adisp, tdisp);
    a.setActionDispenserDelegate(adisp);
    a.setInputDispenserDelegate(idisp);
    a.setMotorDispenserDelegate(mdisp);
    ActivityExecutor ae = new ActivityExecutor(a, "test-new-executor");
    ad.setThreads(5);
    ae.startActivity();
    int[] speeds = new int[] { 1, 2000, 5, 2000, 2, 2000 };
    for (int offset = 0; offset < speeds.length; offset += 2) {
        int threadTarget = speeds[offset];
        int threadTime = speeds[offset + 1];
        logger.info("Setting thread level to " + threadTarget + " for " + threadTime + " seconds.");
        ad.setThreads(threadTarget);
        try {
            Thread.sleep(threadTime);
        } catch (InterruptedException ignored) {
        }
    }
    ad.setThreads(0);
}
Also used : AtomicInput(io.nosqlbench.engine.api.activityimpl.input.AtomicInput) SimpleActivity(io.nosqlbench.engine.api.activityimpl.SimpleActivity) CoreInputDispenser(io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) CoreMotorDispenser(io.nosqlbench.engine.api.activityimpl.motor.CoreMotorDispenser) InputDispenser(io.nosqlbench.engine.api.activityapi.input.InputDispenser) CoreInputDispenser(io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser) CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) AtomicInput(io.nosqlbench.engine.api.activityimpl.input.AtomicInput) Input(io.nosqlbench.engine.api.activityapi.input.Input) ActivityExecutor(io.nosqlbench.engine.core.lifecycle.ActivityExecutor) SimpleActivity(io.nosqlbench.engine.api.activityimpl.SimpleActivity) CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) OutputDispenser(io.nosqlbench.engine.api.activityapi.output.OutputDispenser) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader) Test(org.junit.jupiter.api.Test)

Example 4 with InputDispenser

use of io.nosqlbench.engine.api.activityapi.input.InputDispenser in project nosqlbench by nosqlbench.

the class ActivityExecutorTest method testDelayedStartSanity.

@Test
public void testDelayedStartSanity() {
    ActivityDef ad = ActivityDef.parseActivityDef("driver=diag;alias=test;cycles=1000;initdelay=5000;");
    Optional<ActivityType> activityType = new ActivityTypeLoader().load(ad);
    Activity a = new DelayedInitActivity(ad);
    InputDispenser idisp = new CoreInputDispenser(a);
    ActionDispenser adisp = new CoreActionDispenser(a);
    OutputDispenser tdisp = CoreServices.getOutputDispenser(a).orElse(null);
    MotorDispenser<?> mdisp = new CoreMotorDispenser(a, idisp, adisp, tdisp);
    a.setActionDispenserDelegate(adisp);
    a.setOutputDispenserDelegate(tdisp);
    a.setInputDispenserDelegate(idisp);
    a.setMotorDispenserDelegate(mdisp);
    ActivityExecutor ae = new ActivityExecutor(a, "test-delayed-start");
    ad.setThreads(1);
    ae.startActivity();
    ae.awaitCompletion(15000);
    assertThat(idisp.getInput(10).getInputSegment(3)).isNull();
}
Also used : SimpleActivity(io.nosqlbench.engine.api.activityimpl.SimpleActivity) CoreInputDispenser(io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) CoreMotorDispenser(io.nosqlbench.engine.api.activityimpl.motor.CoreMotorDispenser) InputDispenser(io.nosqlbench.engine.api.activityapi.input.InputDispenser) CoreInputDispenser(io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser) CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) ActivityExecutor(io.nosqlbench.engine.core.lifecycle.ActivityExecutor) CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) OutputDispenser(io.nosqlbench.engine.api.activityapi.output.OutputDispenser) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader) Test(org.junit.jupiter.api.Test)

Example 5 with InputDispenser

use of io.nosqlbench.engine.api.activityapi.input.InputDispenser in project nosqlbench by nosqlbench.

the class ActivityExecutorTest method testRestart.

@Test
public void testRestart() {
    ActivityDef ad = ActivityDef.parseActivityDef("driver=diag;alias=test;cycles=1000;initdelay=5000;");
    Optional<ActivityType> activityType = new ActivityTypeLoader().load(ad);
    Activity a = new DelayedInitActivity(ad);
    InputDispenser idisp = new CoreInputDispenser(a);
    ActionDispenser adisp = new CoreActionDispenser(a);
    OutputDispenser tdisp = CoreServices.getOutputDispenser(a).orElse(null);
    MotorDispenser<?> mdisp = new CoreMotorDispenser(a, idisp, adisp, tdisp);
    a.setActionDispenserDelegate(adisp);
    a.setOutputDispenserDelegate(tdisp);
    a.setInputDispenserDelegate(idisp);
    a.setMotorDispenserDelegate(mdisp);
    ActivityExecutor ae = new ActivityExecutor(a, "test-restart");
    ad.setThreads(1);
    ae.startActivity();
    ae.stopActivity();
    ae.startActivity();
    ae.awaitCompletion(15000);
    assertThat(idisp.getInput(10).getInputSegment(3)).isNull();
}
Also used : SimpleActivity(io.nosqlbench.engine.api.activityimpl.SimpleActivity) CoreInputDispenser(io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser) ActivityDef(io.nosqlbench.engine.api.activityimpl.ActivityDef) CoreMotorDispenser(io.nosqlbench.engine.api.activityimpl.motor.CoreMotorDispenser) InputDispenser(io.nosqlbench.engine.api.activityapi.input.InputDispenser) CoreInputDispenser(io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser) CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) ActivityExecutor(io.nosqlbench.engine.core.lifecycle.ActivityExecutor) CoreActionDispenser(io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser) OutputDispenser(io.nosqlbench.engine.api.activityapi.output.OutputDispenser) ActivityTypeLoader(io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader) Test(org.junit.jupiter.api.Test)

Aggregations

InputDispenser (io.nosqlbench.engine.api.activityapi.input.InputDispenser)6 OutputDispenser (io.nosqlbench.engine.api.activityapi.output.OutputDispenser)4 CoreActionDispenser (io.nosqlbench.engine.api.activityimpl.action.CoreActionDispenser)4 CoreMotorDispenser (io.nosqlbench.engine.api.activityimpl.motor.CoreMotorDispenser)4 ActivityDef (io.nosqlbench.engine.api.activityimpl.ActivityDef)3 SimpleActivity (io.nosqlbench.engine.api.activityimpl.SimpleActivity)3 CoreInputDispenser (io.nosqlbench.engine.api.activityimpl.input.CoreInputDispenser)3 ActivityExecutor (io.nosqlbench.engine.core.lifecycle.ActivityExecutor)3 ActivityTypeLoader (io.nosqlbench.engine.core.lifecycle.ActivityTypeLoader)3 Test (org.junit.jupiter.api.Test)3 Input (io.nosqlbench.engine.api.activityapi.input.Input)2 InputType (io.nosqlbench.engine.api.activityapi.input.InputType)2 SimpleConfig (io.nosqlbench.engine.api.util.SimpleConfig)2 ActivitiesAware (io.nosqlbench.engine.api.activityapi.core.ActivitiesAware)1 AtomicInput (io.nosqlbench.engine.api.activityimpl.input.AtomicInput)1 Predicate (java.util.function.Predicate)1