Search in sources :

Example 1 with SimpleActivity

use of io.engineblock.activityimpl.SimpleActivity in project engineblock by engineblock.

the class ActivityExecutorTest method testNewActivityExecutor.

@Test(enabled = true)
public void testNewActivityExecutor() {
    ActivityDef ad = ActivityDef.parseActivityDef("type=diag;alias=test;cycles=1000;");
    Optional<ActivityType> activityType = ActivityType.FINDER.get(ad.getActivityType());
    Input longSupplier = new TargetRateInput(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);
    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 : TargetRateInput(io.engineblock.activityimpl.input.TargetRateInput) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) CoreInputDispenser(io.engineblock.activityimpl.input.CoreInputDispenser) ActivityDef(io.engineblock.activityimpl.ActivityDef) CoreMotorDispenser(io.engineblock.activityimpl.motor.CoreMotorDispenser) CoreInputDispenser(io.engineblock.activityimpl.input.CoreInputDispenser) InputDispenser(io.engineblock.activityapi.input.InputDispenser) CoreActionDispenser(io.engineblock.activityimpl.action.CoreActionDispenser) TargetRateInput(io.engineblock.activityimpl.input.TargetRateInput) Input(io.engineblock.activityapi.input.Input) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) CoreMotorDispenser(io.engineblock.activityimpl.motor.CoreMotorDispenser) CoreActionDispenser(io.engineblock.activityimpl.action.CoreActionDispenser) OutputDispenser(io.engineblock.activityapi.output.OutputDispenser) Test(org.testng.annotations.Test)

Example 2 with SimpleActivity

use of io.engineblock.activityimpl.SimpleActivity in project engineblock by engineblock.

the class CoreMotorTest method testBasicActivityMotor.

@Test
public void testBasicActivityMotor() {
    BlockingSegmentInput lockstepper = new BlockingSegmentInput();
    Activity activity = new SimpleActivity(ActivityDef.parseActivityDef("alias=foo"));
    Motor cm = new CoreMotor(activity, 5L, lockstepper);
    AtomicLong observableAction = new AtomicLong(-3L);
    cm.setAction(getTestConsumer(observableAction));
    cm.getSlotStateTracker().enterState(RunState.Starting);
    Thread t = new Thread(cm);
    t.setName("TestMotor");
    t.start();
    try {
        // allow action time to be waiting in monitor for test fixture
        Thread.sleep(1000);
    } catch (InterruptedException ignored) {
    }
    lockstepper.publishSegment(5L);
    boolean result = awaitCondition(atomicInteger -> (atomicInteger.get() == 5L), observableAction, 5000, 100);
    assertThat(observableAction.get()).isEqualTo(5L);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) BlockingSegmentInput(io.engineblock.activitycore.fortesting.BlockingSegmentInput) CoreMotor(io.engineblock.activityimpl.motor.CoreMotor) Motor(io.engineblock.activityapi.core.Motor) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) Activity(io.engineblock.activityapi.core.Activity) CoreMotor(io.engineblock.activityimpl.motor.CoreMotor) Test(org.testng.annotations.Test)

Example 3 with SimpleActivity

use of io.engineblock.activityimpl.SimpleActivity in project engineblock by engineblock.

the class CoreMotorTest method testIteratorStride.

@Test
public void testIteratorStride() {
    BlockingSegmentInput lockstepper = new BlockingSegmentInput();
    Motor cm1 = new CoreMotor(new SimpleActivity("stride=3"), 1L, lockstepper);
    AtomicLongArray ary = new AtomicLongArray(10);
    Action a1 = getTestArrayConsumer(ary);
    cm1.setAction(a1);
    cm1.getSlotStateTracker().enterState(RunState.Starting);
    Thread t1 = new Thread(cm1);
    t1.setName("cm1");
    t1.start();
    try {
        // allow action time to be waiting in monitor for test fixture
        Thread.sleep(500);
    } catch (InterruptedException ignored) {
    }
    lockstepper.publishSegment(11L, 12L, 13L);
    boolean result = awaitAryCondition(ala -> (ala.get(2) == 13L), ary, 5000, 100);
    assertThat(ary.get(0)).isEqualTo(11L);
    assertThat(ary.get(1)).isEqualTo(12L);
    assertThat(ary.get(2)).isEqualTo(13L);
    assertThat(ary.get(3)).isEqualTo(0L);
}
Also used : Action(io.engineblock.activityapi.core.Action) BlockingSegmentInput(io.engineblock.activitycore.fortesting.BlockingSegmentInput) CoreMotor(io.engineblock.activityimpl.motor.CoreMotor) Motor(io.engineblock.activityapi.core.Motor) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) AtomicLongArray(java.util.concurrent.atomic.AtomicLongArray) CoreMotor(io.engineblock.activityimpl.motor.CoreMotor) Test(org.testng.annotations.Test)

Example 4 with SimpleActivity

use of io.engineblock.activityimpl.SimpleActivity in project engineblock by engineblock.

the class ActivityExecutorTest method getActivityMotorFactory.

private MotorDispenser getActivityMotorFactory(final ActivityDef ad, Action lc, final Input ls) {
    MotorDispenser cmf = new MotorDispenser() {

        @Override
        public Motor getMotor(ActivityDef activityDef, int slotId) {
            Activity activity = new SimpleActivity(activityDef);
            Motor cm = new CoreMotor(activity, slotId, ls);
            cm.setAction(lc);
            return cm;
        }
    };
    return cmf;
}
Also used : CoreMotor(io.engineblock.activityimpl.motor.CoreMotor) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) CoreMotorDispenser(io.engineblock.activityimpl.motor.CoreMotorDispenser) SimpleActivity(io.engineblock.activityimpl.SimpleActivity) ActivityDef(io.engineblock.activityimpl.ActivityDef) CoreMotor(io.engineblock.activityimpl.motor.CoreMotor)

Aggregations

SimpleActivity (io.engineblock.activityimpl.SimpleActivity)4 CoreMotor (io.engineblock.activityimpl.motor.CoreMotor)3 Test (org.testng.annotations.Test)3 Motor (io.engineblock.activityapi.core.Motor)2 BlockingSegmentInput (io.engineblock.activitycore.fortesting.BlockingSegmentInput)2 ActivityDef (io.engineblock.activityimpl.ActivityDef)2 CoreMotorDispenser (io.engineblock.activityimpl.motor.CoreMotorDispenser)2 Action (io.engineblock.activityapi.core.Action)1 Activity (io.engineblock.activityapi.core.Activity)1 Input (io.engineblock.activityapi.input.Input)1 InputDispenser (io.engineblock.activityapi.input.InputDispenser)1 OutputDispenser (io.engineblock.activityapi.output.OutputDispenser)1 CoreActionDispenser (io.engineblock.activityimpl.action.CoreActionDispenser)1 CoreInputDispenser (io.engineblock.activityimpl.input.CoreInputDispenser)1 TargetRateInput (io.engineblock.activityimpl.input.TargetRateInput)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicLongArray (java.util.concurrent.atomic.AtomicLongArray)1