Package com.bluesoft.util.metrics.core.impl

Examples of com.bluesoft.util.metrics.core.impl.BasicTimingMetric


  private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger( RecorderTest.class );

  @Test
  public void testTryTimer() throws Exception {
    TimingMetric metric = new BasicTimingMetric( "test" );
    TimingMetric exMetric = new BasicTimingMetric( "exTest" );
    DistributingMetric distMetric = new DistributingMetric( "distTest",
                                                            map( pairOf( Conditions.all(), "test" ), pairOf( Conditions.exception(), "exTest" ) ),
                                                            metric, exMetric );

    try ( Recorder t = Recorder.recordFor( distMetric ) ) {
      Thread.sleep( 100L );
    }

    assertEquals( metric.getCount(), BigInteger.ONE );
    assertEquals( exMetric.getCount(), BigInteger.ZERO );

    try ( Recorder t = Recorder.recordFor( distMetric, "foo", "bar", "snafu" ) ) {
      Thread.sleep( 100L );
    }

    assertEquals( metric.getCount(), BigInteger.valueOf( 2 ) );
    assertEquals( exMetric.getCount(), BigInteger.ZERO );
    Recorder t = Recorder.recordFor( distMetric );
    try {
      Thread.sleep( 100L );
      throw new RuntimeException( "test exception" );
    } catch ( RuntimeException ex ) {
      t.setException( ex );
    } finally {
      t.close();
    }
    assertEquals( metric.getCount(), BigInteger.valueOf( 3 ) );
    assertEquals( exMetric.getCount(), BigInteger.ONE );
  }
View Full Code Here


  private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger( TimerTest.class );

  @Test
  public void testTimer() throws Exception {
    TimingMetric metric = new BasicTimingMetric( "test" );
    Timer timer = new Timer( metric );
    String result = timer.time( new Callable<String>() {

      @Override
      public String call() throws Exception {
        return "Done";
      }
    } );
    assertEquals( result, "Done" );
    assertEquals( metric.getCount(), BigInteger.ONE );
    final Exception theException = new Exception();
    timer = new Timer();
    timer.setMetric( metric );
    try {
      timer.time( new Callable<String>() {

        @Override
        public String call() throws Exception {
          throw theException;
        }
      } );
      assertEquals( result, "Done" );
    } catch ( Exception ex ) {
      assertSame( ex, theException );
    }
    assertEquals( metric.getCount(), BigInteger.valueOf( 2 ) );
  }
View Full Code Here

TOP

Related Classes of com.bluesoft.util.metrics.core.impl.BasicTimingMetric

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.