Search in sources :

Example 1 with PeriodicTrigger

use of org.springframework.scheduling.support.PeriodicTrigger in project webofneeds by researchstudio-sat.

the class BAAtomicCCActiveExitingBotTest method before.

@Before
public void before() {
    if (!run) {
        // create a bot instance and auto-wire it
        AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
        bot = (MyBot) beanFactory.autowire(MyBot.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
        Object botBean = beanFactory.initializeBean(bot, "mybot");
        bot = (MyBot) botBean;
        // the bot also needs a trigger so its act() method is called regularly.
        // (there is no trigger bean in the context)
        PeriodicTrigger trigger = new PeriodicTrigger(ACT_LOOP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        trigger.setInitialDelay(ACT_LOOP_INITIAL_DELAY_MILLIS);
        bot.setTrigger(trigger);
        logger.info("starting test case testBAAtomicCCActiveExitingBot");
        // adding the bot to the bot manager will cause it to be initialized.
        // at that point, the trigger starts.
        botManager.setShutdownApplicationContextIfWorkDone(false);
        botManager.addBot(bot);
        staticBotManager = botManager;
        // and both threads continue.
        try {
            bot.getBarrier().await();
        } catch (InterruptedException e) {
            // To change body of catch statement use File | Settings | File Templates.
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            // To change body of catch statement use File | Settings | File Templates.
            e.printStackTrace();
        }
        run = true;
    }
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Before(org.junit.Before)

Example 2 with PeriodicTrigger

use of org.springframework.scheduling.support.PeriodicTrigger in project webofneeds by researchstudio-sat.

the class BAAtomicCCActiveFailingBotTest method before.

@Before
public void before() {
    if (!run) {
        // create a bot instance and auto-wire it
        AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
        bot = (MyBot) beanFactory.autowire(MyBot.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
        Object botBean = beanFactory.initializeBean(bot, "mybot");
        bot = (MyBot) botBean;
        // the bot also needs a trigger so its act() method is called regularly.
        // (there is no trigger bean in the context)
        PeriodicTrigger trigger = new PeriodicTrigger(ACT_LOOP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        trigger.setInitialDelay(ACT_LOOP_INITIAL_DELAY_MILLIS);
        bot.setTrigger(trigger);
        logger.info("starting test case testBAAtomicCCActiveFailingBot");
        // adding the bot to the bot manager will cause it to be initialized.
        // at that point, the trigger starts.
        botManager.setShutdownApplicationContextIfWorkDone(false);
        botManager.addBot(bot);
        staticBotManager = botManager;
        // and both threads continue.
        try {
            bot.getBarrier().await();
        } catch (InterruptedException e) {
            // To change body of catch statement use File | Settings | File Templates.
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            // To change body of catch statement use File | Settings | File Templates.
            e.printStackTrace();
        }
        run = true;
    }
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Before(org.junit.Before)

Example 3 with PeriodicTrigger

use of org.springframework.scheduling.support.PeriodicTrigger in project webofneeds by researchstudio-sat.

the class BAAtomicPCActiveExitingBotTest method before.

@Before
public void before() {
    if (!run) {
        // create a bot instance and auto-wire it
        AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
        bot = (MyBot) beanFactory.autowire(MyBot.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
        Object botBean = beanFactory.initializeBean(bot, "mybot");
        bot = (MyBot) botBean;
        // the bot also needs a trigger so its act() method is called regularly.
        // (there is no trigger bean in the context)
        PeriodicTrigger trigger = new PeriodicTrigger(ACT_LOOP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        trigger.setInitialDelay(ACT_LOOP_INITIAL_DELAY_MILLIS);
        bot.setTrigger(trigger);
        logger.info("starting test case testBAAtomicPCActiveExitingBot");
        // adding the bot to the bot manager will cause it to be initialized.
        // at that point, the trigger starts.
        botManager.setShutdownApplicationContextIfWorkDone(false);
        botManager.addBot(bot);
        staticBotManager = botManager;
        // and both threads continue.
        try {
            bot.getBarrier().await();
        } catch (InterruptedException e) {
            // To change body of catch statement use File | Settings | File Templates.
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            // To change body of catch statement use File | Settings | File Templates.
            e.printStackTrace();
        }
        run = true;
    }
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Before(org.junit.Before)

Example 4 with PeriodicTrigger

use of org.springframework.scheduling.support.PeriodicTrigger in project webofneeds by researchstudio-sat.

the class SecurityBotTests method runBot.

private void runBot(Class botClass) throws ExecutionException, InterruptedException {
    IntegrationtestBot bot = null;
    // create a bot instance and auto-wire it
    AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
    bot = (IntegrationtestBot) beanFactory.autowire(botClass, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    Object botBean = beanFactory.initializeBean(bot, "theBot");
    bot = (IntegrationtestBot) botBean;
    // the bot also needs a trigger so its act() method is called regularly.
    // (there is no trigger bean in the context)
    PeriodicTrigger trigger = new PeriodicTrigger(500, TimeUnit.MILLISECONDS);
    trigger.setInitialDelay(100);
    ((TriggeredBot) bot).setTrigger(trigger);
    // adding the bot to the bot manager will cause it to be initialized.
    // at that point, the trigger starts.
    botManager.addBot(bot);
    final SettableListenableFuture<TestFinishedEvent> futureTestResult = new SettableListenableFuture();
    final EventListenerContext ctx = bot.getExposedEventListenerContext();
    // action for setting the future when we get a test result
    EventBotAction setFutureAction = new SetFutureAction(ctx, futureTestResult);
    // action for setting the future when an error occurs
    EventBotAction setFutureFromErrorAction = new SetFutureFromErrorEventAction(ctx, futureTestResult, bot);
    // add a listener for test success
    ctx.getEventBus().subscribe(TestPassedEvent.class, new ActionOnEventListener(ctx, setFutureAction));
    // add a listener for test failure
    ctx.getEventBus().subscribe(TestFailedEvent.class, new ActionOnEventListener(ctx, setFutureAction));
    // add a listener for errors
    ctx.getEventBus().subscribe(ErrorEvent.class, new ActionOnEventListener(ctx, setFutureFromErrorAction));
    // wait for the result
    TestFinishedEvent result = futureTestResult.get();
    if (result instanceof TestFailedEvent) {
        Assert.fail(((TestFailedEvent) result).getMessage());
    }
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) SettableListenableFuture(org.springframework.util.concurrent.SettableListenableFuture) IntegrationtestBot(won.bot.IntegrationtestBot) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) TriggeredBot(won.bot.framework.bot.base.TriggeredBot) PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) TestFailedEvent(won.bot.framework.eventbot.event.impl.test.TestFailedEvent) TestFinishedEvent(won.bot.framework.eventbot.event.impl.test.TestFinishedEvent) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) EventBotAction(won.bot.framework.eventbot.action.EventBotAction) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction)

Example 5 with PeriodicTrigger

use of org.springframework.scheduling.support.PeriodicTrigger in project webofneeds by researchstudio-sat.

the class BAAtomicPCActiveFailingBotTest method before.

@Before
public void before() {
    if (!run) {
        // create a bot instance and auto-wire it
        AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
        bot = (MyBot) beanFactory.autowire(MyBot.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
        Object botBean = beanFactory.initializeBean(bot, "mybot");
        bot = (MyBot) botBean;
        // the bot also needs a trigger so its act() method is called regularly.
        // (there is no trigger bean in the context)
        PeriodicTrigger trigger = new PeriodicTrigger(ACT_LOOP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        trigger.setInitialDelay(ACT_LOOP_INITIAL_DELAY_MILLIS);
        bot.setTrigger(trigger);
        logger.info("starting test case testBAAtomicPCActiveFailingBot");
        // adding the bot to the bot manager will cause it to be initialized.
        // at that point, the trigger starts.
        botManager.setShutdownApplicationContextIfWorkDone(false);
        botManager.addBot(bot);
        staticBotManager = botManager;
        // and both threads continue.
        try {
            bot.getBarrier().await();
        } catch (InterruptedException e) {
            // To change body of catch statement use File | Settings | File Templates.
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            // To change body of catch statement use File | Settings | File Templates.
            e.printStackTrace();
        }
        run = true;
    }
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Before(org.junit.Before)

Aggregations

PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)42 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)20 Before (org.junit.Before)19 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)14 Test (org.junit.Test)14 QueueChannel (org.springframework.integration.channel.QueueChannel)10 PollerMetadata (org.springframework.integration.scheduling.PollerMetadata)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 BeanFactory (org.springframework.beans.factory.BeanFactory)6 Message (org.springframework.messaging.Message)6 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)5 GenericMessage (org.springframework.messaging.support.GenericMessage)5 NullChannel (org.springframework.integration.channel.NullChannel)4 TestApplicationContext (org.springframework.integration.test.util.TestUtils.TestApplicationContext)4 Trigger (org.springframework.scheduling.Trigger)4 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)4 ArrayList (java.util.ArrayList)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)3 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)3