Examples of SleepStage


Examples of org.apache.niolex.commons.test.SleepStage

    latch.await(10, TimeUnit.SECONDS);
    disp.shutdown();

    for (Stage<?>s : disp.getAllStages()) {
      SleepStage ss = (SleepStage)s;
      System.out.println(ss.getStageName() + "\t-> " + ss.getStageStatus() + " -> " + ss.getProcessedCount());
    }
    assertEquals(0, latch.getCount());
  }
View Full Code Here

Examples of org.apache.niolex.commons.test.SleepStage

  public final void testStartAdjust() throws InterruptedException {
    adj.setAdjustInterval(10);
    adj.startAdjust();
    // start again.
    adj.startAdjust();
    adj.addStage(new SleepStage("s10", 10));
    Stage<?> s = mock(Stage.class);
    adj.addStage(s);
    Thread.sleep(100);
    adj.stopAdjust();
    verify(s, atLeast(1)).adjustThreadPool();
View Full Code Here

Examples of org.apache.niolex.commons.test.SleepStage

   *
   * @param args
   * @throws InterruptedException
   */
  public static void main(String[] args) throws InterruptedException {
    SleepStage s = new SleepStage("S1", 6);
    Adjuster adj = new Adjuster();
    adj.addStage(s);
    adj.startAdjust();
    int it = 10000;
    //
    System.out.println("stage 1. send 10 request and sleep 10.");
    while (it-- > 0) {
      s.addInput(new TInput());
      Thread.sleep(1);
    }
    //
    System.out.println("stage 2. send 60 request and sleep 10.");
    it = 5000;
    while (it-- > 0) {
      for (int i = 0; i < 60; ++i) {
        s.addInput(new TInput());
      }
      Thread.sleep(10);
    }
    it = 20000;
    //
    System.out.println("stage 3. send 20 request and sleep 10.");
    while (it-- > 0) {
      s.addInput(new TInput());
      s.addInput(new TInput());
      Thread.sleep(1);
    }
    //
    it = 10000;
    System.out.println("stage 4. send 10 request and sleep 10.");
    while (it-- > 0) {
      s.addInput(new TInput());
      Thread.sleep(1);
    }
    //
    System.out.println("stage 5. shutdown now.");
    Thread.sleep(100);
    s.shutdown();
    adj.stopAdjust();
  }
View Full Code Here

Examples of org.apache.niolex.commons.test.SleepStage

  /**
   * Test method for {@link org.apache.niolex.commons.seda.Dispatcher#register(org.apache.niolex.commons.seda.Stage)}.
   */
  @Test
  public final void testARegister() {
    disp.register(new SleepStage("S10", 10));
    disp.register(new SleepStage("S20", 20));
    Map<String, String> consMap = new HashMap<String, String>();
    consMap.put(null, "S10");
    consMap.put("s10", "S10");
    consMap.put("S20", "S20");
    consMap.put("s20", "S20");
View Full Code Here

Examples of org.apache.niolex.commons.test.SleepStage

  /**
   * Test method for {@link org.apache.niolex.commons.seda.Dispatcher#getStage(java.lang.String)}.
   */
  @Test
  public final void testGetStage() {
      SleepStage sl = disp.getStage("S10");
      assertEquals("S10", sl.getStageName());
  }
View Full Code Here

Examples of org.apache.niolex.commons.test.SleepStage

  /**
   * Test method for {@link org.apache.niolex.commons.seda.Stage#Stage(java.lang.String)}.
   */
  @Test
  public final void testShutdownSend() {
    SleepStage ss = new SleepStage("abc", dispatcher);
    ss.shutdown();
    ss = spy(ss);
    TInput in = mock(TInput.class);
    ss.addInput(in);
    ArgumentCaptor<RejectType> cap = ArgumentCaptor.forClass(RejectType.class);
    verify(ss).reject(cap.capture(), eq("abc"), eq(in));
    assertEquals(RejectType.STAGE_SHUTDOWN, cap.getValue());
    assertEquals(ss.getInputSize(), 0);
  }
View Full Code Here

Examples of org.apache.niolex.commons.test.SleepStage

   */
  @Test
  public final void testProcessError() throws InterruptedException {
      TInput in = mock(TInput.class);
      final One<RejectType> one = One.create(null);
    SleepStage ss = new SleepStage("abc", dispatcher){
        @Override
        public void reject(RejectType type, Object info, Message msg) {
            one.a = type;
        }
    };
    when(in.getTag()).thenReturn(65432);
    ss.addInput(in);
    Thread.sleep(100);
    assertEquals(RejectType.PROCESS_ERROR, one.a);
    assertEquals(ss.getInputSize(), 0);
    ss.shutdown();
    assertNull(ss.takeMessage());
    Thread.sleep(100);
    assertEquals(3, ss.getStageStatus());
    assertNull(ss.takeMessage());
  }
View Full Code Here

Examples of org.apache.niolex.commons.test.SleepStage

  /**
   * Test method for {@link org.apache.niolex.commons.seda.Stage#construct()}.
   */
  @Test
  public final void testWorker() {
    SleepStage ss = new SleepStage("abcdef", 123);
    // Scenario 1. interrupt
    SleepStage.Worker w = ss.getWorker();
    assertTrue(w.isWorking());
    w.setWorking(false);
    w.interrupt();
    assertFalse(w.isWorking());
    ss.construct();
    ss.subtractThread();
    ss.subtractThread();
    ss.subtractThread();
    ss.shutdown();
  }
View Full Code Here

Examples of org.apache.niolex.commons.test.SleepStage

    ss.shutdown();
  }

    @Test
    public void testAdjustThreadPool() throws Exception {
        SleepStage ss = new SleepStage("abcdef", 123);
        ss.adjustThreadPool();
        ss.adjustThreadPool();
        ss.adjustThreadPool();
        ss.shutdown();
        Field f = Stage.class.getDeclaredField("lastAdjustTime");
        f.setAccessible(true);
        f.setLong(ss, 100);
        ss.adjustThreadPool();
        ss.adjustThreadPool();
    }
View Full Code Here

Examples of org.apache.niolex.commons.test.SleepStage

  /**
   * Test method for {@link org.apache.niolex.commons.seda.Stage#addThread()}.
   */
  @Test
  public final void testAddThreadToMax() throws Exception {
    SleepStage ss = new SleepStage("abc", dispatcher);
    Field f = Stage.class.getDeclaredField("lastAdjustTime");
    f.setAccessible(true);
    TInput in = mock(TInput.class);
    // Prepare ready.
    // stage 1.
    for (int i = 0; i < 60; ++i) {
      ss.addInput(in);
    }
    ss.exeCnt.addAndGet(30);
    this.startAdjust(ss, f);
    // stage 2.
    for (int i = 0; i < 210; ++i) {
      ss.addInput(in);
    }
    ss.exeCnt.addAndGet(100);
    this.startAdjust(ss, f);
    // stage 3.
    for (int i = 0; i < 550; ++i) {
      ss.addInput(in);
    }
    ss.exeCnt.addAndGet(200);
    this.startAdjust(ss, f);
    // stage 4.
    for (int i = 0; i < 1300; ++i) {
      ss.addInput(in);
    }
    ss.exeCnt.addAndGet(500);
    this.startAdjust(ss, f);
    // stage 5.
    System.out.println("up stage finished. we start to drop.");
    // No input, But we adjust the executed item.
    for (int i = 0; i < 500; ++i) {
      ss.inputQueue.poll();
    }
    ss.exeCnt.addAndGet(500);
    this.startAdjust(ss, f);
    for (int i = 0; i < 500; ++i) {
      ss.inputQueue.poll();
    }
    ss.exeCnt.addAndGet(500);
    this.startAdjust(ss, f);
    // stage 6.
    // No input, We adjust even more executed item.
    ss.exeCnt.addAndGet(600);
    for (int i = 0; i < 600; ++i) {
      ss.inputQueue.poll();
    }
    System.out.println("stage6 " + ss.currentPoolSize);
    int a = ss.currentPoolSize;
    this.startAdjust(ss, f);
    System.out.println("stage6 " + ss.currentPoolSize);
    a -= ss.currentPoolSize;
    // We are in tremble.
    assertTrue(a == 0);
    // stage 7.
    for (int i = 0; i < 600; ++i) {
      ss.inputQueue.poll();
    }
    ss.exeCnt.addAndGet(600);
    this.startAdjust(ss, f);
    System.out.println("stage7 " + ss.currentPoolSize);
    // stage 8.
    ss.exeCnt.addAndGet(200);
    this.startAdjust(ss, f);
    System.out.println("stage8 " + ss.currentPoolSize);
    // stage 9.
    ss.exeCnt.addAndGet(3);
    this.startAdjust(ss, f);
    System.out.println("stage9 " + ss.currentPoolSize);
    // stage 10.
    ss.exeCnt.addAndGet(3);
    this.startAdjust(ss, f);
    System.out.println("stage10 " + ss.currentPoolSize);
    assertEquals(1, ss.currentPoolSize);
    ss.shutdown();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.