Package org.apache.niolex.commons.test

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


  /**
   * Test method for {@link org.apache.niolex.commons.seda.Stage#adjustThreadPool()}.
   */
  @Test
  public final void testAdjustTremble() throws Exception {
    SleepStage ss = new SleepStage("abc", dispatcher, 600);
    Field f = Stage.class.getDeclaredField("lastAdjustTime");
    f.setAccessible(true);
    TInput in = mock(TInput.class);
    ss.processRate = 0.030;
    // Prepare ready.
    // stage 1.
    for (int i = 0; i < 100; ++i) {
      ss.addInput(in);
    }
    ss.exeCnt.addAndGet(3);
    this.startAdjust(ss, f);
    int psize = ss.currentPoolSize;
    System.out.println("stage1 " + ss.currentPoolSize);
    assertEquals(psize, 2);
    // stage 2. we drop fast.
    ss.exeCnt.addAndGet(60);
    ss.inputQueue.clear();
    for (int i = 0; i < 41; ++i) {
            ss.addInput(in);
        }
    this.startAdjust(ss, f);
    psize = ss.currentPoolSize;
    System.out.println("stage2 " + ss.currentPoolSize);
    assertEquals(psize, 1);
    // stage 3. we rise very fast.
    ss.exeCnt.addAndGet(30);
    for (int i = 0; i < 100; ++i) {
      ss.addInput(in);
    }
    this.startAdjust(ss, f);
    psize = ss.currentPoolSize;
    System.out.println("stage3 " + ss.currentPoolSize);
    assertEquals(psize, 2);
    // stage 4. we drop slowly.
    ss.exeCnt.addAndGet(70);
    for (int i = 0; i < 30; ++i) {
      ss.addInput(in);
    }
    this.startAdjust(ss, f);
    psize = ss.currentPoolSize;
    System.out.println("stage4 " + ss.currentPoolSize);
    assertEquals(psize, 3);
    // stage 5. we drop faster.
    ss.exeCnt.addAndGet(70);
    for (int i = 0; i < 10; ++i) {
      ss.inputQueue.poll();
    }
    this.startAdjust(ss, f);
    psize = ss.currentPoolSize;
    System.out.println("stage5 " + ss.currentPoolSize);
    assertEquals(psize, 3);
    // stage 6. we rise slowly.
    ss.exeCnt.addAndGet(70);
    for (int i = 0; i < 15; ++i) {
      ss.addInput(in);
    }
    this.startAdjust(ss, f);
    psize = ss.currentPoolSize;
    System.out.println("stage6 " + ss.currentPoolSize);
    assertEquals(psize, 3);
    // stage 7. we have nothing.
    this.startAdjust(ss, f);
    psize = ss.currentPoolSize;
    System.out.println("stage7 " + ss.currentPoolSize);
    assertEquals(psize, 1);
    // done.
    ss.shutdown();
  }
View Full Code Here

TOP

Related Classes of org.apache.niolex.commons.test.SleepStage

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.