Package com.bluesoft.util.metrics.core

Examples of com.bluesoft.util.metrics.core.Timing


    UnitRoundingTimingMetric rounder = new UnitRoundingTimingMetric( TimeUnit.MINUTES, TimeUnit.MILLISECONDS, mock );

    expect( mock.getCentile( eq( BigDecimal.valueOf( 95.0 ) ) ) )
            .andReturn( new TimingImpl( BigDecimal.valueOf( 1500000000L, 0 ), TimeUnit.NANOSECONDS ) );
    replay( mock );
    Timing timing = rounder.getCentile( BigDecimal.valueOf( 95.0 ) );
    assertEquals( timing.getUnit(), TimeUnit.MILLISECONDS );
    assertEquals( timing.getValue(), BigDecimal.valueOf( 1500000000000L, 9 ) );
    verify( mock );

    reset( mock );
    expect( mock.getCentile( eq( BigDecimal.valueOf( 95.0 ) ) ) )
            .andReturn( new TimingImpl( BigDecimal.valueOf( 1500000000L, 0 ), TimeUnit.MILLISECONDS ) );
    replay( mock );
    timing = rounder.getCentile( BigDecimal.valueOf( 95.0 ) );
    assertEquals( timing.getUnit(), TimeUnit.MILLISECONDS );
    assertEquals( timing.getValue(), BigDecimal.valueOf( 1500000000L, 0 ) );
    verify( mock );
  }
View Full Code Here


  public void testGetMean() {
    TimingMetric mock = createMock( TimingMetric.class );
    UnitRoundingTimingMetric rounder = new UnitRoundingTimingMetric( TimeUnit.MINUTES, TimeUnit.MILLISECONDS, mock );
    expect( mock.getMean() ).andReturn( new TimingImpl( BigDecimal.valueOf( 1500000000L, 0 ), TimeUnit.NANOSECONDS ) );
    replay( mock );
    Timing timing = rounder.getMean();
    assertEquals( timing.getUnit(), TimeUnit.MILLISECONDS );
    assertEquals( timing.getValue(), BigDecimal.valueOf( 1500000000000L, 9 ) );
    verify( mock );

    reset( mock );
    expect( mock.getMean() ).andReturn( new TimingImpl( BigDecimal.valueOf( 1500000000L, 0 ), TimeUnit.MILLISECONDS ) );
    replay( mock );
    timing = rounder.getMean();
    assertEquals( timing.getUnit(), TimeUnit.MILLISECONDS );
    assertEquals( timing.getValue(), BigDecimal.valueOf( 1500000000L, 0 ) );
    verify( mock );
  }
View Full Code Here

  public void testGetStandardDeviation() {
    TimingMetric mock = createMock( TimingMetric.class );
    UnitRoundingTimingMetric rounder = new UnitRoundingTimingMetric( TimeUnit.MINUTES, TimeUnit.MILLISECONDS, mock );
    expect( mock.getStandardDeviation() ).andReturn( new TimingImpl( BigDecimal.valueOf( 1500000000L, 0 ), TimeUnit.NANOSECONDS ) );
    replay( mock );
    Timing timing = rounder.getStandardDeviation();
    assertEquals( timing.getUnit(), TimeUnit.MILLISECONDS );
    assertEquals( timing.getValue(), BigDecimal.valueOf( 1500000000000L, 9 ) );
    verify( mock );

    reset( mock );
    expect( mock.getStandardDeviation() ).andReturn( new TimingImpl( BigDecimal.valueOf( 1500000000L, 0 ), TimeUnit.MILLISECONDS ) );
    replay( mock );
    timing = rounder.getStandardDeviation();
    assertEquals( timing.getUnit(), TimeUnit.MILLISECONDS );
    assertEquals( timing.getValue(), BigDecimal.valueOf( 1500000000L, 0 ) );
    verify( mock );
  }
View Full Code Here

  public void testGetTotal() {
    TimingMetric mock = createMock( TimingMetric.class );
    UnitRoundingTimingMetric rounder = new UnitRoundingTimingMetric( TimeUnit.MINUTES, TimeUnit.MILLISECONDS, mock );
    expect( mock.getTotal() ).andReturn( new TimingImpl( BigDecimal.valueOf( 1500000000L, 0 ), TimeUnit.NANOSECONDS ) );
    replay( mock );
    Timing timing = rounder.getTotal();
    assertEquals( timing.getUnit(), TimeUnit.MILLISECONDS );
    assertEquals( timing.getValue(), BigDecimal.valueOf( 1500000000000L, 9 ) );
    verify( mock );

    reset( mock );
    expect( mock.getTotal() ).andReturn( new TimingImpl( BigDecimal.valueOf( 1500000000L, 0 ), TimeUnit.MILLISECONDS ) );
    replay( mock );
    timing = rounder.getTotal();
    assertEquals( timing.getUnit(), TimeUnit.MILLISECONDS );
    assertEquals( timing.getValue(), BigDecimal.valueOf( 1500000000L, 0 ) );
    verify( mock );
  }
View Full Code Here

    tm.addEvent( new BasicTimingEvent( now - 3, now ) );
    tm.addEvent( new BasicTimingEvent( now - 4, now ) );
    tm.addEvent( new BasicTimingEvent( now - 5, now ) );
    tm.addEvent( new BasicTimingEvent( now - 2, now ) );

    Timing mean = tm.getMean();
    Timing median = tm.getCentile( new BigDecimal( 50L ) );
    BigDecimal stddev = tm.getStandardDeviation().getValue();
    Timing total = tm.getTotal();
    Rate rate = tm.getRate();

    try {
      tm.getCentile( BigDecimal.valueOf( 105.0 ) );
      fail( "failed to trigger expected exception: IllegalArgumentException" );
    } catch ( IllegalArgumentException ex ) {
      // Expected
    }
    try {
      tm.getCentile( BigDecimal.valueOf( -1.0 ) );
      fail( "failed to trigger expected exception: IllegalArgumentException" );
    } catch ( IllegalArgumentException ex ) {
      // Expected
    }
    assertEquals( tm.getCentile( BigDecimal.valueOf( 100L ) ).getValue(), BigDecimal.valueOf( 10L ) );
    assertNotNull( mean );
    assertNotNull( median );
    assertNotNull( stddev );
    assertNotNull( total );
    assertNotNull( rate );
    assertBigDecimalEquals( mean.getValue(), BigDecimal.valueOf( 48333333333L, 10 ) );
    assertBigDecimalEquals( median.getValue(), new BigDecimal( 4 ) );
    assertBigDecimalEquals( stddev, BigDecimal.valueOf( 2786873996L, 9 ) );
    assertBigDecimalEquals( total.getValue(), new BigDecimal( 29 ) );
    assertBigDecimalEquals( rate.getValue(), new BigDecimal( 6 ) );

    TimingMetric<TimingMetric, TimingEvent> snapshot = tm.getSnapshot();
    mean = snapshot.getMean();
    median = snapshot.getCentile( new BigDecimal( 50L ) );
    stddev = snapshot.getStandardDeviation().getValue();
    total = snapshot.getTotal();
    rate = snapshot.getRate();

    assertNotNull( mean );
    assertNotNull( median );
    assertNotNull( stddev );
    assertNotNull( total );
    assertNotNull( rate );
    assertBigDecimalEquals( mean.getValue(), BigDecimal.valueOf( 48333333333L, 10 ) );
    assertBigDecimalEquals( median.getValue(), new BigDecimal( 4 ) );
    assertBigDecimalEquals( stddev, BigDecimal.valueOf( 2786873996L, 9 ) );
    assertBigDecimalEquals( total.getValue(), new BigDecimal( 29 ) );
    assertBigDecimalEquals( rate.getValue(), new BigDecimal( 6 ) );

    snapshot = tm.reset();
    mean = snapshot.getMean();
    median = snapshot.getCentile( new BigDecimal( 50L ) );
    stddev = snapshot.getStandardDeviation().getValue();
    total = snapshot.getTotal();
    rate = snapshot.getRate();

    assertNotNull( mean );
    assertNotNull( median );
    assertNotNull( stddev );
    assertNotNull( total );
    assertNotNull( rate );
    assertBigDecimalEquals( mean.getValue(), BigDecimal.valueOf( 48333333333L, 10 ) );
    assertBigDecimalEquals( median.getValue(), new BigDecimal( 4 ) );
    assertBigDecimalEquals( stddev, BigDecimal.valueOf( 2786873996L, 9 ) );
    assertBigDecimalEquals( total.getValue(), new BigDecimal( 29 ) );
    assertBigDecimalEquals( rate.getValue(), new BigDecimal( 6 ) );

    mean = tm.getMean();
    median = tm.getCentile( new BigDecimal( 50L ) );
    stddev = tm.getStandardDeviation().getValue();
    total = tm.getTotal();
    rate = tm.getRate();

    assertNull( mean );
    assertNull( median );
    assertEquals( stddev, ZERO );
    assertEquals( total.getValue(), ZERO );
    assertNull( rate );
  }
View Full Code Here

   * <p>
   * @return the mean, or null of no data has been collected.
   */
  @Override
  public Timing getMean() {
    Timing t = delegate.getMean();
    if ( t.getUnit() != timeUnit ) {
      return t.convertTo( timeUnit );
    }
    return t;
  }
View Full Code Here

   * <p>
   * @return the total time.
   */
  @Override
  public Timing getTotal() {
    Timing t = delegate.getTotal();
    if ( t.getUnit() != timeUnit ) {
      return t.convertTo( timeUnit );
    }
    return t;
  }
View Full Code Here

   * <p>
   * @return the standard deviation or null if no data has been collected.
   */
  @Override
  public Timing getStandardDeviation() {
    Timing t = delegate.getStandardDeviation();
    if ( t.getUnit() != timeUnit ) {
      return t.convertTo( timeUnit );
    }
    return t;
  }
View Full Code Here

   * <p>
   * @return the percentile requested or null of no data has been collected.
   */
  @Override
  public Timing getCentile( BigDecimal centile ) {
    Timing t = delegate.getCentile( centile );
    if ( t.getUnit() != timeUnit ) {
      return t.convertTo( timeUnit );
    }
    return t;
  }
View Full Code Here

TOP

Related Classes of com.bluesoft.util.metrics.core.Timing

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.