Search in sources :

Example 1 with BackgroundCommandExecutionFromBackgroundCommandServiceJdo

use of org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo in project estatio by estatio.

the class FakeScheduler method runBackgroundCommands.

@Action(semantics = SemanticsOf.NON_IDEMPOTENT)
public void runBackgroundCommands(@ParameterLayout(named = "Wait for (ms)") final Integer waitFor) throws InterruptedException {
    List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    if (commands.isEmpty()) {
        throw new IllegalStateException("There are no commands not yet started");
    }
    transactionService.nextTransaction();
    BackgroundCommandExecutionFromBackgroundCommandServiceJdo backgroundExec = new BackgroundCommandExecutionFromBackgroundCommandServiceJdo();
    final SimpleSession session = new SimpleSession("scheduler_user", new String[] { "admin_role" });
    final Thread thread = new Thread(() -> backgroundExec.execute(session, null));
    thread.start();
    thread.join(waitFor);
    commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    if (!commands.isEmpty()) {
        throw new IllegalStateException("There are still " + commands.size() + " not yet started");
    }
}
Also used : CommandJdo(org.isisaddons.module.command.dom.CommandJdo) BackgroundCommandExecutionFromBackgroundCommandServiceJdo(org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo) SimpleSession(org.apache.isis.core.runtime.authentication.standard.SimpleSession) Action(org.apache.isis.applib.annotation.Action)

Example 2 with BackgroundCommandExecutionFromBackgroundCommandServiceJdo

use of org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo in project estatio by estatio.

the class RunBackgroundCommandsService method runBackgroundCommands.

@Programmatic
public void runBackgroundCommands() throws InterruptedException {
    List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    assertThat(commands).hasSize(1);
    transactionService.nextTransaction();
    BackgroundCommandExecutionFromBackgroundCommandServiceJdo backgroundExec = new BackgroundCommandExecutionFromBackgroundCommandServiceJdo();
    final SimpleSession session = new SimpleSession("scheduler_user", new String[] { "admin_role" });
    final Thread thread = new Thread(() -> backgroundExec.execute(session, null));
    thread.start();
    thread.join(5000L);
    commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    assertThat(commands).isEmpty();
}
Also used : CommandJdo(org.isisaddons.module.command.dom.CommandJdo) BackgroundCommandExecutionFromBackgroundCommandServiceJdo(org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo) SimpleSession(org.apache.isis.core.runtime.authentication.standard.SimpleSession) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 3 with BackgroundCommandExecutionFromBackgroundCommandServiceJdo

use of org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo in project estatio by estatio.

the class FakeScheduler method runBackgroundCommands.

@Action(semantics = SemanticsOf.NON_IDEMPOTENT)
public void runBackgroundCommands(@ParameterLayout(named = "Wait for (ms)") final Integer waitFor) throws InterruptedException {
    List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    if (commands.isEmpty()) {
        throw new IllegalStateException("There are no commands not yet started");
    }
    transactionService.nextTransaction();
    BackgroundCommandExecutionFromBackgroundCommandServiceJdo backgroundExec = new BackgroundCommandExecutionFromBackgroundCommandServiceJdo();
    final SimpleSession session = new SimpleSession("scheduler_user", new String[] { "admin_role" });
    final Thread thread = new Thread(() -> backgroundExec.execute(session, null));
    thread.start();
    thread.join(waitFor);
    commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    if (!commands.isEmpty()) {
        throw new IllegalStateException("There are still " + commands.size() + " not yet started");
    }
}
Also used : CommandJdo(org.isisaddons.module.command.dom.CommandJdo) BackgroundCommandExecutionFromBackgroundCommandServiceJdo(org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo) SimpleSession(org.apache.isis.core.runtime.authentication.standard.SimpleSession) Action(org.apache.isis.applib.annotation.Action)

Aggregations

SimpleSession (org.apache.isis.core.runtime.authentication.standard.SimpleSession)3 BackgroundCommandExecutionFromBackgroundCommandServiceJdo (org.isisaddons.module.command.dom.BackgroundCommandExecutionFromBackgroundCommandServiceJdo)3 CommandJdo (org.isisaddons.module.command.dom.CommandJdo)3 Action (org.apache.isis.applib.annotation.Action)2 Programmatic (org.apache.isis.applib.annotation.Programmatic)1