Java 类org.apache.hadoop.mapred.StatisticsCollector.Stat 实例源码

项目:hadoop    文件:TestStatisticsCollector.java   
@SuppressWarnings("rawtypes")
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

  //  test Stat class 
  Map updaters= collector.getUpdaters();
  assertEquals(updaters.size(),2);
  Map<String, Stat> ststistics=collector.getStatistics();
  assertNotNull(ststistics.get("m1"));

 Stat newStat= collector.createStat("m2"); 
  assertEquals(newStat.name, "m2");
  Stat st=collector.removeStat("m1");
  assertEquals(st.name, "m1");
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
   st=collector.removeStat("m1");
   // try to remove stat again
  assertNull(st);
  collector.start();
  // waiting 2,5 sec
  Thread.sleep(2500);
  assertEquals(69, stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

}
项目:aliyun-oss-hadoop-fs    文件:TestStatisticsCollector.java   
@SuppressWarnings("rawtypes")
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

  //  test Stat class 
  Map updaters= collector.getUpdaters();
  assertEquals(updaters.size(),2);
  Map<String, Stat> ststistics=collector.getStatistics();
  assertNotNull(ststistics.get("m1"));

 Stat newStat= collector.createStat("m2"); 
  assertEquals(newStat.name, "m2");
  Stat st=collector.removeStat("m1");
  assertEquals(st.name, "m1");
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
   st=collector.removeStat("m1");
   // try to remove stat again
  assertNull(st);
  collector.start();
  // waiting 2,5 sec
  Thread.sleep(2500);
  assertEquals(69, stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

}
项目:big-c    文件:TestStatisticsCollector.java   
@SuppressWarnings("rawtypes")
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

  //  test Stat class 
  Map updaters= collector.getUpdaters();
  assertEquals(updaters.size(),2);
  Map<String, Stat> ststistics=collector.getStatistics();
  assertNotNull(ststistics.get("m1"));

 Stat newStat= collector.createStat("m2"); 
  assertEquals(newStat.name, "m2");
  Stat st=collector.removeStat("m1");
  assertEquals(st.name, "m1");
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
   st=collector.removeStat("m1");
   // try to remove stat again
  assertNull(st);
  collector.start();
  // waiting 2,5 sec
  Thread.sleep(2500);
  assertEquals(69, stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestStatisticsCollector.java   
@SuppressWarnings("rawtypes")
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

  //  test Stat class 
  Map updaters= collector.getUpdaters();
  assertEquals(updaters.size(),2);
  Map<String, Stat> ststistics=collector.getStatistics();
  assertNotNull(ststistics.get("m1"));

 Stat newStat= collector.createStat("m2"); 
  assertEquals(newStat.name, "m2");
  Stat st=collector.removeStat("m1");
  assertEquals(st.name, "m1");
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
   st=collector.removeStat("m1");
   // try to remove stat again
  assertNull(st);
  collector.start();
  // waiting 2,5 sec
  Thread.sleep(2500);
  assertEquals(69, stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestStatisticsCollector.java   
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestStatisticsCollector.java   
public void testBucketing() throws Exception {
  StatisticsCollector collector = new StatisticsCollector();
  TimeWindow window = new TimeWindow("test", 33, 11);
  // We'll collect 3 buckets before we start removing: 33 / 11 = 3
  // We'll do 2 updates per bucket (5 is default period): 11 / 5 = 2
  TimeWindow[] windows = {window};
  Stat stat1 = collector.createStat("TaskTracker A", windows);

  // TT A starts out with 0 buckets
  assertEquals(0, stat1.getValues().get(window).getValue());
  stat1.inc(1);
  collector.update();
  assertEquals(0, stat1.getValues().get(window).getValue());
  stat1.inc(1);
  collector.update();
  assertEquals(2, stat1.getValues().get(window).getValue());
  stat1.inc(1);
  collector.update();
  assertEquals(2, stat1.getValues().get(window).getValue());
  stat1.inc(2);
  collector.update();
  assertEquals(2+3, stat1.getValues().get(window).getValue());
  stat1.inc(0);
  collector.update();
  assertEquals(2+3, stat1.getValues().get(window).getValue());
  stat1.inc(1);
  // At the next update, we now have 3 buckets for TT 1
  collector.update();
  assertEquals(2+3+1, stat1.getValues().get(window).getValue());
  stat1.inc(4);
  collector.update();
  assertEquals(2+3+1, stat1.getValues().get(window).getValue());
  // At the next update, we're going to drop the earliest bucket for TT A and
  // keep a max of 3 buckets forever
  collector.update();
  assertEquals(3+1+4, stat1.getValues().get(window).getValue());

  // A new TaskTracker connects and gets a Stat allocated for it
  Stat stat2 = collector.createStat("TaskTracker B", windows);

  // TT B starts out with 0 buckets even though TT A already has 3
  assertEquals(0, stat2.getValues().get(window).getValue());
  stat2.inc(10);
  collector.update();
  assertEquals(3+1+4, stat1.getValues().get(window).getValue());
  assertEquals(0, stat2.getValues().get(window).getValue());
  stat1.inc(3);
  stat2.inc(2);
  // At the next update, we're going to drop the earliest bucket for TT A
  // but we shouldn't drop the earliest bucket for TT B because it only
  // has one bucket so far (which would result in a value of 0 instead of 12)
  collector.update();
  assertEquals(1+4+3, stat1.getValues().get(window).getValue());
  assertEquals(12, stat2.getValues().get(window).getValue());
}
项目:hadoop-EAR    文件:TestStatisticsCollector.java   
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
}
项目:hadoop-plus    文件:TestStatisticsCollector.java   
@SuppressWarnings("rawtypes")
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

  //  test Stat class 
  Map updaters= collector.getUpdaters();
  assertEquals(updaters.size(),2);
  Map<String, Stat> ststistics=collector.getStatistics();
  assertNotNull(ststistics.get("m1"));

 Stat newStat= collector.createStat("m2"); 
  assertEquals(newStat.name, "m2");
  Stat st=collector.removeStat("m1");
  assertEquals(st.name, "m1");
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
   st=collector.removeStat("m1");
   // try to remove stat again
  assertNull(st);
  collector.start();
  // waiting 2,5 sec
  Thread.sleep(2500);
  assertEquals(69, stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

}
项目:FlexMap    文件:TestStatisticsCollector.java   
@SuppressWarnings("rawtypes")
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

  //  test Stat class 
  Map updaters= collector.getUpdaters();
  assertEquals(updaters.size(),2);
  Map<String, Stat> ststistics=collector.getStatistics();
  assertNotNull(ststistics.get("m1"));

 Stat newStat= collector.createStat("m2"); 
  assertEquals(newStat.name, "m2");
  Stat st=collector.removeStat("m1");
  assertEquals(st.name, "m1");
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
   st=collector.removeStat("m1");
   // try to remove stat again
  assertNull(st);
  collector.start();
  // waiting 2,5 sec
  Thread.sleep(2500);
  assertEquals(69, stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

}
项目:hops    文件:TestStatisticsCollector.java   
@SuppressWarnings("rawtypes")
@Test
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

  //  test Stat class 
  Map updaters= collector.getUpdaters();
  assertEquals(updaters.size(),2);
  Map<String, Stat> ststistics=collector.getStatistics();
  assertNotNull(ststistics.get("m1"));

 Stat newStat= collector.createStat("m2"); 
  assertEquals(newStat.name, "m2");
  Stat st=collector.removeStat("m1");
  assertEquals(st.name, "m1");
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
   st=collector.removeStat("m1");
   // try to remove stat again
  assertNull(st);
  collector.start();
  // waiting 2,5 sec
  Thread.sleep(2500);
  assertEquals(69, stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

}
项目:hadoop-TCP    文件:TestStatisticsCollector.java   
@SuppressWarnings("rawtypes")
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

  //  test Stat class 
  Map updaters= collector.getUpdaters();
  assertEquals(updaters.size(),2);
  Map<String, Stat> ststistics=collector.getStatistics();
  assertNotNull(ststistics.get("m1"));

 Stat newStat= collector.createStat("m2"); 
  assertEquals(newStat.name, "m2");
  Stat st=collector.removeStat("m1");
  assertEquals(st.name, "m1");
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
   st=collector.removeStat("m1");
   // try to remove stat again
  assertNull(st);
  collector.start();
  // waiting 2,5 sec
  Thread.sleep(2500);
  assertEquals(69, stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

}
项目:hadoop-on-lustre    文件:TestStatisticsCollector.java   
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
}
项目:hardfs    文件:TestStatisticsCollector.java   
@SuppressWarnings("rawtypes")
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

  //  test Stat class 
  Map updaters= collector.getUpdaters();
  assertEquals(updaters.size(),2);
  Map<String, Stat> ststistics=collector.getStatistics();
  assertNotNull(ststistics.get("m1"));

 Stat newStat= collector.createStat("m2"); 
  assertEquals(newStat.name, "m2");
  Stat st=collector.removeStat("m1");
  assertEquals(st.name, "m1");
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
   st=collector.removeStat("m1");
   // try to remove stat again
  assertNull(st);
  collector.start();
  // waiting 2,5 sec
  Thread.sleep(2500);
  assertEquals(69, stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

}
项目:hadoop-on-lustre2    文件:TestStatisticsCollector.java   
@SuppressWarnings("rawtypes")
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

  //  test Stat class 
  Map updaters= collector.getUpdaters();
  assertEquals(updaters.size(),2);
  Map<String, Stat> ststistics=collector.getStatistics();
  assertNotNull(ststistics.get("m1"));

 Stat newStat= collector.createStat("m2"); 
  assertEquals(newStat.name, "m2");
  Stat st=collector.removeStat("m1");
  assertEquals(st.name, "m1");
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
   st=collector.removeStat("m1");
   // try to remove stat again
  assertNull(st);
  collector.start();
  // waiting 2,5 sec
  Thread.sleep(2500);
  assertEquals(69, stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());

}
项目:RDFS    文件:TestStatisticsCollector.java   
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
}
项目:hanoi-hadoop-2.0.0-cdh    文件:TestStatisticsCollector.java   
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
}
项目:hanoi-hadoop-2.0.0-cdh    文件:TestStatisticsCollector.java   
public void testBucketing() throws Exception {
  StatisticsCollector collector = new StatisticsCollector();
  TimeWindow window = new TimeWindow("test", 33, 11);
  // We'll collect 3 buckets before we start removing: 33 / 11 = 3
  // We'll do 2 updates per bucket (5 is default period): 11 / 5 = 2
  TimeWindow[] windows = {window};
  Stat stat1 = collector.createStat("TaskTracker A", windows);

  // TT A starts out with 0 buckets
  assertEquals(0, stat1.getValues().get(window).getValue());
  stat1.inc(1);
  collector.update();
  assertEquals(0, stat1.getValues().get(window).getValue());
  stat1.inc(1);
  collector.update();
  assertEquals(2, stat1.getValues().get(window).getValue());
  stat1.inc(1);
  collector.update();
  assertEquals(2, stat1.getValues().get(window).getValue());
  stat1.inc(2);
  collector.update();
  assertEquals(2+3, stat1.getValues().get(window).getValue());
  stat1.inc(0);
  collector.update();
  assertEquals(2+3, stat1.getValues().get(window).getValue());
  stat1.inc(1);
  // At the next update, we now have 3 buckets for TT 1
  collector.update();
  assertEquals(2+3+1, stat1.getValues().get(window).getValue());
  stat1.inc(4);
  collector.update();
  assertEquals(2+3+1, stat1.getValues().get(window).getValue());
  // At the next update, we're going to drop the earliest bucket for TT A and
  // keep a max of 3 buckets forever
  collector.update();
  assertEquals(3+1+4, stat1.getValues().get(window).getValue());

  // A new TaskTracker connects and gets a Stat allocated for it
  Stat stat2 = collector.createStat("TaskTracker B", windows);

  // TT B starts out with 0 buckets even though TT A already has 3
  assertEquals(0, stat2.getValues().get(window).getValue());
  stat2.inc(10);
  collector.update();
  assertEquals(3+1+4, stat1.getValues().get(window).getValue());
  assertEquals(0, stat2.getValues().get(window).getValue());
  stat1.inc(3);
  stat2.inc(2);
  // At the next update, we're going to drop the earliest bucket for TT A
  // but we shouldn't drop the earliest bucket for TT B because it only
  // has one bucket so far (which would result in a value of 0 instead of 12)
  collector.update();
  assertEquals(1+4+3, stat1.getValues().get(window).getValue());
  assertEquals(12, stat2.getValues().get(window).getValue());
}
项目:mapreduce-fork    文件:TestStatisticsCollector.java   
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
}
项目:hortonworks-extension    文件:TestStatisticsCollector.java   
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
}
项目:hortonworks-extension    文件:TestStatisticsCollector.java   
public void testMovingWindow() throws Exception {
  StatisticsCollector collector = new StatisticsCollector(1);
  TimeWindow window = new TimeWindow("test", 6, 2);
  TimeWindow sincStart = StatisticsCollector.SINCE_START;
  TimeWindow[] windows = {sincStart, window};

  Stat stat = collector.createStat("m1", windows);

  stat.inc(3);
  collector.update();
  assertEquals(0, stat.getValues().get(window).getValue());
  assertEquals(3, stat.getValues().get(sincStart).getValue());

  stat.inc(3);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(6, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3), stat.getValues().get(window).getValue());
  assertEquals(16, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10), stat.getValues().get(window).getValue());
  assertEquals(26, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(46, stat.getValues().get(sincStart).getValue());

  stat.inc(10);
  collector.update();
  assertEquals((3+3+10+10+10+10), stat.getValues().get(window).getValue());
  assertEquals(56, stat.getValues().get(sincStart).getValue());

  stat.inc(12);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(68, stat.getValues().get(sincStart).getValue());

  stat.inc(13);
  collector.update();
  assertEquals((10+10+10+10+10+12), stat.getValues().get(window).getValue());
  assertEquals(81, stat.getValues().get(sincStart).getValue());

  stat.inc(14);
  collector.update();
  assertEquals((10+10+10+12+13+14), stat.getValues().get(window).getValue());
  assertEquals(95, stat.getValues().get(sincStart).getValue());
}