Package org.apache.hadoop.hive.common.metrics.Metrics

Examples of org.apache.hadoop.hive.common.metrics.Metrics.MetricsScope


    }
  }

  @Test
  public void testScopeSingleThread() throws Exception {
    final MetricsScope fooScope = Metrics.startScope(scopeName);
    // the time and number counters become available only after the 1st
    // scope close:
    expectIOE(new Callable<Long>() {
      @Override
      public Long call() throws Exception {
        Long num = fooScope.getNumCounter();
        return num;
      }
    });
    expectIOE(new Callable<Long>() {
      @Override
      public Long call() throws Exception {
        Long time = fooScope.getTimeCounter();
        return time;
      }
    });
    // cannot open scope that is already open:
    expectIOE(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        fooScope.open();
        return null;
      }
    });
   
    assertSame(fooScope, Metrics.getScope(scopeName));
    Thread.sleep(periodMs+1);
    // 1st close:
    // closing of open scope should be ok:
    Metrics.endScope(scopeName);
    expectIOE(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        Metrics.endScope(scopeName); // closing of closed scope not allowed
        return null;
      }
    });
   
    assertEquals(Long.valueOf(1), fooScope.getNumCounter());
    final long t1 = fooScope.getTimeCounter().longValue();
    assertTrue(t1 > periodMs);
   
    assertSame(fooScope, Metrics.getScope(scopeName));
   
   // opening allowed after closing:
    Metrics.startScope(scopeName);
    // opening of already open scope not allowed:
    expectIOE(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        Metrics.startScope(scopeName);
        return null;
      }
    });
   
    assertEquals(Long.valueOf(1), fooScope.getNumCounter());
    assertEquals(t1, fooScope.getTimeCounter().longValue());
   
    assertSame(fooScope, Metrics.getScope(scopeName));
    Thread.sleep(periodMs + 1);
    // Reopening (close + open) allowed in opened state:
    fooScope.reopen();

    assertEquals(Long.valueOf(2), fooScope.getNumCounter());
    assertTrue(fooScope.getTimeCounter().longValue() > 2 * periodMs);
   
    Thread.sleep(periodMs + 1);
    // 3rd close:
    fooScope.close();
   
    assertEquals(Long.valueOf(3), fooScope.getNumCounter());
    assertTrue(fooScope.getTimeCounter().longValue() > 3 * periodMs);
    Double avgT = (Double)Metrics.get("foo.avg_t");
    assertTrue(avgT.doubleValue() > periodMs);
  }
View Full Code Here


    assertTrue(avgT.doubleValue() > periodMs);
  }
 
  @Test
  public void testScopeConcurrency() throws Exception {
    MetricsScope fooScope = Metrics.startScope(scopeName);
    final int threads = 10;
    ExecutorService executorService = Executors.newFixedThreadPool(threads);
    for (int i=0; i<threads; i++) {
      final int n = i;
      executorService.submit(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
          testScopeImpl(n);
          return null;
        }
      });
    }
    executorService.shutdown();
    assertTrue(executorService.awaitTermination(periodMs * 3 * threads, TimeUnit.MILLISECONDS));

    fooScope = Metrics.getScope(scopeName);
    assertEquals(Long.valueOf(3 * threads), fooScope.getNumCounter());
    assertTrue(fooScope.getTimeCounter().longValue() > 3 * periodMs * threads);
    Double avgT = (Double)Metrics.get("foo.avg_t");
    assertTrue(avgT.doubleValue() > periodMs);
    Metrics.endScope(scopeName);
  }
View Full Code Here

    assertTrue(avgT.doubleValue() > periodMs);
    Metrics.endScope(scopeName);
  }
 
  void testScopeImpl(int n) throws Exception {
    final MetricsScope fooScope = Metrics.startScope(scopeName);
    // cannot open scope that is already open:
    expectIOE(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        fooScope.open();
        return null;
      }
    });
   
    assertSame(fooScope, Metrics.getScope(scopeName));
    Thread.sleep(periodMs+1);
    // 1st close:
    Metrics.endScope(scopeName); // closing of open scope should be ok.
   
    assertTrue(fooScope.getNumCounter().longValue() >= 1);
    final long t1 = fooScope.getTimeCounter().longValue();
    assertTrue(t1 > periodMs);
   
    expectIOE(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        Metrics.endScope(scopeName); // closing of closed scope not allowed
        return null;
      }
    });
   
    assertSame(fooScope, Metrics.getScope(scopeName));
   
   // opening allowed after closing:
    Metrics.startScope(scopeName);
   
    assertTrue(fooScope.getNumCounter().longValue() >= 1);
    assertTrue(fooScope.getTimeCounter().longValue() >= t1);
   
   // opening of already open scope not allowed:
    expectIOE(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        Metrics.startScope(scopeName);
        return null;
      }
    });
   
    assertSame(fooScope, Metrics.getScope(scopeName));
    Thread.sleep(periodMs + 1);
    // Reopening (close + open) allowed in opened state:
    fooScope.reopen();

    assertTrue(fooScope.getNumCounter().longValue() >= 2);
    assertTrue(fooScope.getTimeCounter().longValue() > 2 * periodMs);
   
    Thread.sleep(periodMs + 1);
    // 3rd close:
    fooScope.close();
   
    assertTrue(fooScope.getNumCounter().longValue() >= 3);
    assertTrue(fooScope.getTimeCounter().longValue() > 3 * periodMs);
    Double avgT = (Double)Metrics.get("foo.avg_t");
    assertTrue(avgT.doubleValue() > periodMs);
  }
View Full Code Here

    }
  }

  @Test
  public void testScopeSingleThread() throws Exception {
    final MetricsScope fooScope = Metrics.startScope(scopeName);
    // the time and number counters become available only after the 1st
    // scope close:
    expectIOE(new Callable<Long>() {
      @Override
      public Long call() throws Exception {
        Long num = fooScope.getNumCounter();
        return num;
      }
    });
    expectIOE(new Callable<Long>() {
      @Override
      public Long call() throws Exception {
        Long time = fooScope.getTimeCounter();
        return time;
      }
    });
    // cannot open scope that is already open:
    expectIOE(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        fooScope.open();
        return null;
      }
    });
   
    assertSame(fooScope, Metrics.getScope(scopeName));
    Thread.sleep(periodMs+1);
    // 1st close:
    // closing of open scope should be ok:
    Metrics.endScope(scopeName);
    expectIOE(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        Metrics.endScope(scopeName); // closing of closed scope not allowed
        return null;
      }
    });
   
    assertEquals(Long.valueOf(1), fooScope.getNumCounter());
    final long t1 = fooScope.getTimeCounter().longValue();
    assertTrue(t1 > periodMs);
   
    assertSame(fooScope, Metrics.getScope(scopeName));
   
   // opening allowed after closing:
    Metrics.startScope(scopeName);
    // opening of already open scope not allowed:
    expectIOE(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        Metrics.startScope(scopeName);
        return null;
      }
    });
   
    assertEquals(Long.valueOf(1), fooScope.getNumCounter());
    assertEquals(t1, fooScope.getTimeCounter().longValue());
   
    assertSame(fooScope, Metrics.getScope(scopeName));
    Thread.sleep(periodMs + 1);
    // Reopening (close + open) allowed in opened state:
    fooScope.reopen();

    assertEquals(Long.valueOf(2), fooScope.getNumCounter());
    assertTrue(fooScope.getTimeCounter().longValue() > 2 * periodMs);
   
    Thread.sleep(periodMs + 1);
    // 3rd close:
    fooScope.close();
   
    assertEquals(Long.valueOf(3), fooScope.getNumCounter());
    assertTrue(fooScope.getTimeCounter().longValue() > 3 * periodMs);
    Double avgT = (Double)Metrics.get("foo.avg_t");
    assertTrue(avgT.doubleValue() > periodMs);
  }
View Full Code Here

      });
    }
    executorService.shutdown();
    assertTrue(executorService.awaitTermination(periodMs * 3 * threads, TimeUnit.MILLISECONDS));
   
    final MetricsScope fooScope = Metrics.getScope(scopeName);
    assertEquals(Long.valueOf(3 * threads), fooScope.getNumCounter());
    assertTrue(fooScope.getTimeCounter().longValue() > 3 * periodMs * threads);
    Double avgT = (Double)Metrics.get("foo.avg_t");
    assertTrue(avgT.doubleValue() > periodMs);
  }
View Full Code Here

    Double avgT = (Double)Metrics.get("foo.avg_t");
    assertTrue(avgT.doubleValue() > periodMs);
  }
 
  void testScopeImpl(int n) throws Exception {
    final MetricsScope fooScope = Metrics.startScope(scopeName);
    // cannot open scope that is already open:
    expectIOE(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        fooScope.open();
        return null;
      }
    });
   
    assertSame(fooScope, Metrics.getScope(scopeName));
    Thread.sleep(periodMs+1);
    // 1st close:
    Metrics.endScope(scopeName); // closing of open scope should be ok.
   
    assertTrue(fooScope.getNumCounter().longValue() >= 1);
    final long t1 = fooScope.getTimeCounter().longValue();
    assertTrue(t1 > periodMs);
   
    expectIOE(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        Metrics.endScope(scopeName); // closing of closed scope not allowed
        return null;
      }
    });
   
    assertSame(fooScope, Metrics.getScope(scopeName));
   
   // opening allowed after closing:
    Metrics.startScope(scopeName);
   
    assertTrue(fooScope.getNumCounter().longValue() >= 1);
    assertTrue(fooScope.getTimeCounter().longValue() >= t1);
   
   // opening of already open scope not allowed:
    expectIOE(new Callable<Void>() {
      @Override
      public Void call() throws Exception {
        Metrics.startScope(scopeName);
        return null;
      }
    });
   
    assertSame(fooScope, Metrics.getScope(scopeName));
    Thread.sleep(periodMs + 1);
    // Reopening (close + open) allowed in opened state:
    fooScope.reopen();

    assertTrue(fooScope.getNumCounter().longValue() >= 2);
    assertTrue(fooScope.getTimeCounter().longValue() > 2 * periodMs);
   
    Thread.sleep(periodMs + 1);
    // 3rd close:
    fooScope.close();
   
    assertTrue(fooScope.getNumCounter().longValue() >= 3);
    assertTrue(fooScope.getTimeCounter().longValue() > 3 * periodMs);
    Double avgT = (Double)Metrics.get("foo.avg_t");
    assertTrue(avgT.doubleValue() > periodMs);
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.common.metrics.Metrics.MetricsScope

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.