Package test.shell.base

Examples of test.shell.base.BaseProcessContext


  }

  public void testAsyncEvaluation() throws InterruptedException {
    AsyncShell connector = new AsyncShell(Executors.newSingleThreadExecutor(), lifeCycle.createShell());
    status = 0;
    BaseProcessContext ctx = BaseProcessContext.create(connector, "invoke " + AsyncShellTestCase.class.getName() + " bilto");
    ctx.execute();
    ShellResponse resp = ctx.getResponse();
    assertTrue("Was not expecting response to be " + resp.getMessage(), resp instanceof ShellResponse.Ok);
    assertEquals(1, status);
    ctx.getResponse();
  }
View Full Code Here


  public void testDirect() throws Exception {
    Shell shell = new BaseShell(BaseProcessFactory.ECHO);
    AsyncShell  asyncShell = new AsyncShell(MoreExecutors.sameThreadExecutor(), shell);

    //
    BaseProcessContext ctx = BaseProcessContext.create(asyncShell, "hello").execute();
    assertEquals(Status.TERMINATED, ((AsyncProcess)ctx.getProcess()).getStatus());
    assertInstance(ShellResponse.Ok.class, ctx.getResponse());
    assertEquals("hello", ctx.getOutput());
  }
View Full Code Here

  public void testExecute() throws Exception {
    Shell shell = new BaseShell();
    CommandQueue commands = new CommandQueue();
    AsyncShell  asyncShell = new AsyncShell(commands, shell);
    BaseProcessContext ctx = BaseProcessContext.create(asyncShell, "foo");
    asyncShell.close();
    ctx.execute();
    assertEquals(Status.TERMINATED, ((AsyncProcess)ctx.getProcess()).getStatus());
    assertEquals(ShellResponse.Cancelled.class, ctx.getResponse().getClass());
    assertEquals(0, commands.getSize());
  }
View Full Code Here

    Shell shell = new BaseShell(factory);
    CommandQueue commands = new CommandQueue();
    AsyncShell  asyncShell = new AsyncShell(commands, shell);

    //
    BaseProcessContext ctx = BaseProcessContext.create(asyncShell, "foo").execute();
    Future<?> future = commands.executeAsync();
    latch1.await();
    assertEquals(Status.EVALUATING, ((AsyncProcess)ctx.getProcess()).getStatus());

    //
    asyncShell.close();
    assertEquals(Status.CANCELED, ((AsyncProcess)ctx.getProcess()).getStatus());
    assertEquals(ShellResponse.Cancelled.class, ctx.getResponse().getClass());
  }
View Full Code Here

    Shell shell = new BaseShell(factory);
    CommandQueue commands = new CommandQueue();
    AsyncShell  asyncShell = new AsyncShell(commands, shell);

    //
    BaseProcessContext ctx = BaseProcessContext.create(asyncShell, "foo").execute();
    assertEquals(Status.QUEUED, ((AsyncProcess)ctx.getProcess()).getStatus());
    assertEquals(0, cancelCount.get());
    assertEquals(1, commands.getSize());

    // Execute the command
    // And wait until the other thread is waiting
    Future<?> future = commands.executeAsync();
    future.get();

    //
    assertEquals(ShellResponse.Error.class, ctx.getResponse().getClass());
  }
View Full Code Here

    Shell shell = new BaseShell(factory);
    CommandQueue commands = new CommandQueue();
    AsyncShell  asyncShell = new AsyncShell(commands, shell);

    //
    BaseProcessContext ctx = BaseProcessContext.create(asyncShell, "foo").execute();
    assertEquals(Status.QUEUED, ((AsyncProcess)ctx.getProcess()).getStatus());
    assertEquals(0, cancelCount.get());
    assertEquals(1, commands.getSize());

    // Execute the command
    // And wait until the other thread is waiting
    Future<?> future = commands.executeAsync();
    latch1.await();
    assertEquals(Status.EVALUATING, ((AsyncProcess)ctx.getProcess()).getStatus());
    assertEquals(0, cancelCount.get());

    //
    ctx.getProcess().cancel();
    assertEquals(Status.CANCELED, ((AsyncProcess)ctx.getProcess()).getStatus());
    assertEquals(1, cancelCount.get());

    //
    ctx.getProcess().cancel();
    assertEquals(Status.CANCELED, ((AsyncProcess)ctx.getProcess()).getStatus());
    assertEquals(1, cancelCount.get());

    // Wait until it's done
    latch2.countDown();
    future.get();

    // Test we received a cancelled response even though we provided an OK result
    assertEquals(ShellResponse.Cancelled.class, ctx.getResponse().getClass());
    assertEquals(Status.TERMINATED, ((AsyncProcess)ctx.getProcess()).getStatus());
    assertEquals(1, cancelCount.get());

    //
    safeFail(failure.get());
  }
View Full Code Here

    Shell shell = new BaseShell(factory);
    CommandQueue commands = new CommandQueue();
    AsyncShell  asyncShell = new AsyncShell(commands, shell);

    //
    BaseProcessContext ctx = BaseProcessContext.create(asyncShell, "foo").execute();
    assertEquals(Status.QUEUED, ((AsyncProcess)ctx.getProcess()).getStatus());
    assertEquals(1, commands.getSize());

    //
    ctx.getProcess().cancel();
    assertEquals(Status.CANCELED, ((AsyncProcess)ctx.getProcess()).getStatus());

    // Execute the command
    Future<?> future = commands.executeAsync();
    future.get();

    // Test we get terminated status and the callback was done
    assertEquals(Status.TERMINATED, ((AsyncProcess)ctx.getProcess()).getStatus());
    assertEquals(ShellResponse.Cancelled.class, ctx.getResponse().getClass());
    safeFail(failure.get());
  }
View Full Code Here

    ArrayBlockingQueue<int[]> queue = new ArrayBlockingQueue<int[]>(1);
    groovyShell.setVariable("queue", queue);
    groovyShell.setVariable("latch1", latch1);
    groovyShell.setVariable("latch2", new CountDownLatch(1));
    lifeCycle.bindGroovy("foo", command);
    final BaseProcessContext process = create("foo");
    new Thread() {
      @Override
      public void run() {
        process.execute();
      }
    }.start();
    latch1.await(10, TimeUnit.SECONDS);
    process.on(null, new int[]{'a'});
    ShellResponse response = process.getResponse();
    assertInstance(ShellResponse.Ok.class, response);
    int[] event = queue.poll(10, TimeUnit.SECONDS);
    assertEquals(1, event.length);
    assertEquals('a', event[0]);
  }
View Full Code Here

TOP

Related Classes of test.shell.base.BaseProcessContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.