Exemplo n.º 1
0
  @Test(dependsOnMethods = "testChildContext")
  public void testContextAwareMeter() {
    ContextAwareMeter jobRecordsProcessRate = this.context.contextAwareMeter(RECORD_PROCESS_RATE);
    Assert.assertEquals(
        this.context.getMeters().get(jobRecordsProcessRate.getName()),
        jobRecordsProcessRate.getInnerMetric());
    Assert.assertEquals(jobRecordsProcessRate.getContext(), this.context);
    Assert.assertEquals(jobRecordsProcessRate.getName(), RECORD_PROCESS_RATE);

    jobRecordsProcessRate.mark();
    jobRecordsProcessRate.mark(3);
    Assert.assertEquals(jobRecordsProcessRate.getCount(), 4l);

    ContextAwareMeter taskRecordsProcessRate =
        this.childContext.contextAwareMeter(RECORD_PROCESS_RATE);
    Assert.assertEquals(
        this.childContext.getMeters().get(taskRecordsProcessRate.getName()),
        taskRecordsProcessRate.getInnerMetric());
    Assert.assertEquals(taskRecordsProcessRate.getContext(), this.childContext);
    Assert.assertEquals(taskRecordsProcessRate.getName(), RECORD_PROCESS_RATE);

    taskRecordsProcessRate.mark(2);
    Assert.assertEquals(taskRecordsProcessRate.getCount(), 2l);
    Assert.assertEquals(jobRecordsProcessRate.getCount(), 6l);
    taskRecordsProcessRate.mark(5);
    Assert.assertEquals(taskRecordsProcessRate.getCount(), 7l);
    Assert.assertEquals(jobRecordsProcessRate.getCount(), 11l);
  }