コード例 #1
0
  @Test
  public void testPathology() throws InterruptedException {
    ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);
    JavaUtilActionSequenceExecutor x = new JavaUtilActionSequenceExecutor(ses);
    assertSame(ses, x.getService());

    assertNull(found);
    Monitor m =
        new Monitor() {
          @Override
          public void failed(ActionSequence seq, Runnable action, Throwable e, long elpasedMillis) {
            found = e;
          }

          @Override
          public void completed(ActionSequence seq, Runnable action, long elapsedMillis) {
            completedCount++;
          }

          @Override
          public void slept(ActionSequence seq, long intendedAmount, long actualAmount) {
            sleptCount++;
          }
        };
    x.setMonitor(m);
    assertSame(m, x.getMonitor());
    PathologicalTestActionSequenceFactory pfac = new PathologicalTestActionSequenceFactory();
    pfac.setDelayTime(10);
    pfac.setDelayDeviation(2);
    x.addActionSequence(pfac.create());
    Thread.sleep(20);
    assertNotNull(found);
    x.shutdown();
    Thread.sleep(20);
    assertTrue(x.isShutdown());

    ActionSequenceExecutor stupid =
        new ActionSequenceExecutor() {

          @Override
          protected void schedule(Runnable r, long delay, TimeUnit unit) {}
        };

    // unimplemented
    stupid.shutdown();
    assertFalse(stupid.isShutdown());
  }
コード例 #2
0
 @Test
 public void testTwentySlower() throws Exception {
   factory.setDelayTime(50);
   factory.setDelayDeviation(5);
   for (int i = 0; i < 20; i++) {
     TestActionSequence seq = factory.create();
     exec.addActionSequence(seq);
     Thread.sleep(3);
   }
   Thread.sleep(8000);
   for (TestActionSequence t : factory.getSequences()) {
     assertEquals(10, t.getTimesRun().size());
     assertAllInRange(
         "requestedDelays",
         t.getRequestedDelays(),
         factory.getDelayTime(),
         factory.getDelayDeviation());
     assertAllInRange("diffs", t.getDelayDiffs().subList(1, t.getDelayDiffs().size() - 2), 0, 5);
   }
 }
コード例 #3
0
  @Test
  public void testOne() throws Exception {
    TestActionSequence seq = factory.create();
    exec.addActionSequence(seq);
    Thread.sleep(350);
    ArrayList<Long> rd = new ArrayList<Long>(seq.getRequestedDelays());
    assertAllInRange("", rd, factory.getDelayTime(), factory.getDelayDeviation());
    ArrayList<Long> md = new ArrayList<Long>(seq.getMeasuredDelays());
    assertAllInRange("", rd, factory.getDelayTime(), 5);
    System.out.println(rd);
    System.out.println(md);
    Collections.sort(md);
    System.out.println(md);
    assertEquals(factory.getDelayTime(), md.get(0), 4);
    assertEquals(factory.getDelayTime(), md.get(rd.size() - 1), 4);

    assertEquals(factory.getDelayTime(), rd.get(0), 5);
    assertEquals(factory.getDelayTime(), rd.get(rd.size() - 1), 5);
    assertEquals(10, seq.getTimesRun().size());
    assertEquals(1, factory.getSequences().size());
    assertSame(seq, factory.getSequences().get(0));
  }