com.netflix.spectator.api.Utils.first()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中com.netflix.spectator.api.Utils.first()方法的一些代码示例,展示了Utils.first()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.first()方法的具体详情如下:
包路径:com.netflix.spectator.api.Utils
类名称:Utils
方法名:first

Utils.first介绍

[英]Returns the first measurement with a given tag value.
[中]返回具有给定标记值的第一个测量值。

代码示例

代码示例来源:origin: Netflix/spectator

/**
 * Returns the first measurement with a given tag value.
 *
 * @param ms
 *     A set of measurements.
 * @param k
 *     Key to search for.
 * @param v
 *     Value that should be associated with k on the ids.
 * @return
 *     Measurement or null if no matches are found.
 */
public static Measurement first(final Iterable<Measurement> ms, final String k, final String v) {
 return first(ms, value -> v.equals(getTagValue(value.id(), k)));
}

代码示例来源:origin: com.netflix.spectator/spectator-api

/**
 * Returns the first measurement with a given tag value.
 *
 * @param ms
 *     A set of measurements.
 * @param k
 *     Key to search for.
 * @param v
 *     Value that should be associated with k on the ids.
 * @return
 *     Measurement or null if no matches are found.
 */
public static Measurement first(final Iterable<Measurement> ms, final String k, final String v) {
 return first(ms, value -> v.equals(getTagValue(value.id(), k)));
}

代码示例来源:origin: Netflix/spectator

/**
 * Returns the first measurement with a given tag value.
 *
 * @param ms
 *     A set of measurements.
 * @param t
 *     The key and value to search for.
 * @return
 *     Measurement or null if no matches are found.
 */
public static Measurement first(Iterable<Measurement> ms, Tag t) {
 return first(ms, t.key(), t.value());
}

代码示例来源:origin: com.netflix.spectator/spectator-api

/**
 * Returns the first measurement with a given tag value.
 *
 * @param ms
 *     A set of measurements.
 * @param t
 *     The key and value to search for.
 * @return
 *     Measurement or null if no matches are found.
 */
public static Measurement first(Iterable<Measurement> ms, Tag t) {
 return first(ms, t.key(), t.value());
}

代码示例来源:origin: Netflix/spectator

@Test
public void totalOfSquaresOverflow() {
 final long seconds = 10;
 final long nanos = TimeUnit.SECONDS.toNanos(seconds);
 final BigInteger s = new BigInteger("" + nanos);
 final BigInteger s2 = s.multiply(s);
 Timer t = newTimer("foo");
 t.record(seconds, TimeUnit.SECONDS);
 clock.setWallTime(61000L);
 final double v = Utils.first(t.measure(), Statistic.totalOfSquares).value();
 final double factor = 1e9 * 1e9;
 final BigInteger perSec = s2.divide(BigInteger.valueOf(60));
 Assertions.assertEquals(perSec.doubleValue() / factor, v, 1e-12);
}

代码示例来源:origin: Netflix/spectator

@Test
public void firstPredicateEmpty() {
 List<Measurement> ms = newList(10);
 Measurement m = Utils.first(ms, v -> false);
 Assertions.assertEquals(null, m);
}

代码示例来源:origin: Netflix/spectator

@Test
public void totalOfSquaresManySmallValues() {
 Timer t = newTimer("foo");
 BigInteger sumOfSq = new BigInteger("0");
 for (int i = 0; i < 100000; ++i) {
  final long nanos = i;
  final BigInteger s = new BigInteger("" + nanos);
  final BigInteger s2 = s.multiply(s);
  sumOfSq = sumOfSq.add(s2);
  t.record(i, TimeUnit.NANOSECONDS);
 }
 clock.setWallTime(61000L);
 final double v = Utils.first(t.measure(), Statistic.totalOfSquares).value();
 final double factor = 1e9 * 1e9;
 sumOfSq = sumOfSq.divide(BigInteger.valueOf(60));
 Assertions.assertEquals(sumOfSq.doubleValue() / factor, v, 1e-12);
}

代码示例来源:origin: Netflix/spectator

@Test
public void totalOfSquaresManyBigValues() {
 Timer t = newTimer("foo");
 BigInteger sumOfSq = new BigInteger("0");
 for (int i = 0; i < 100000; ++i) {
  final long nanos = TimeUnit.SECONDS.toNanos(i);
  final BigInteger s = new BigInteger("" + nanos);
  final BigInteger s2 = s.multiply(s);
  sumOfSq = sumOfSq.add(s2);
  t.record(i, TimeUnit.SECONDS);
 }
 clock.setWallTime(61000L);
 final double v = Utils.first(t.measure(), Statistic.totalOfSquares).value();
 // Expected :3.3332833335E14
 // Actual   :3.3332833334999825E14
 final double factor = 1e9 * 1e9;
 sumOfSq = sumOfSq.divide(BigInteger.valueOf(60));
 Assertions.assertEquals(sumOfSq.doubleValue() / factor, v, 2.0);
}

代码示例来源:origin: Netflix/spectator

@Test
public void testMeasure() {
 Timer t = newTimer("foo");
 t.record(42, TimeUnit.MILLISECONDS);
 clock.setWallTime(61000L);
 for (Measurement m : t.measure()) {
  Assertions.assertEquals(m.timestamp(), 61000L);
  final double count = Utils.first(t.measure(), Statistic.count).value();
  final double totalTime = Utils.first(t.measure(), Statistic.totalTime).value();
  Assertions.assertEquals(count, 1.0 / 60.0, 0.1e-12);
  Assertions.assertEquals(totalTime, 42e-3 / 60.0, 0.1e-12);
 }
}

代码示例来源:origin: Netflix/spectator

@Test
public void readLatency() throws Exception {
 Registry r = new DefaultRegistry(new ManualClock());
 List<JmxConfig> configs = configs();
 JmxData data = timer("keyspace=test,name=ReadLatency,scope=foo,type=ColumnFamily", 0);
 List<Measurement> ms = measure(r, configs, data);
 Assertions.assertEquals(7, ms.size());
 Assertions.assertEquals(
   50.0e-4,
   Utils.first(ms, "statistic", "percentile_50").value(),
   1e-12);
 data = timer("keyspace=test,name=ReadLatency,scope=foo,type=ColumnFamily", 1);
 ms = measure(r, configs, data);
 Assertions.assertEquals(7, ms.size());
 Assertions.assertEquals(
   50.01e-4,
   Utils.first(ms, "statistic", "percentile_50").value(),
   1e-12);
}

代码示例来源:origin: Netflix/spectator

@Test
public void testMeasure() {
 Registry r = new DefaultRegistry(clock);
 clock.setWallTime(61000L);
 Id id = r.createId("test");
 Counter c = IntervalCounter.get(r, id);
 // all meters should have the correct timestamp
 r.stream().forEach(meter -> {
  for (Measurement m : meter.measure()) {
   Assertions.assertEquals(m.timestamp(), 61000L);
  }
 });
 final List<Measurement> measurements = getAllMeasurements(r);
 final double initAge = Utils.first(measurements, Statistic.duration).value();
 final double initCount = Utils.first(measurements, Statistic.count).value();
 Assertions.assertEquals(61.0, initAge, EPSILON);
 Assertions.assertEquals(0.0, initCount, EPSILON);
 clock.setWallTime(120000L);
 c.increment();
 final List<Measurement> afterMeasurements = getAllMeasurements(r);
 final double afterAge = Utils.first(afterMeasurements, Statistic.duration).value();
 final double afterCount = Utils.first(afterMeasurements, Statistic.count).value();
 Assertions.assertEquals(0.0, afterAge, EPSILON);
 Assertions.assertEquals(1.0, afterCount, EPSILON);
}

代码示例来源:origin: Netflix/spectator

@Test
public void firstTag() {
 List<Measurement> ms = newList(10);
 Tag t = new BasicTag("i", "7");
 Measurement m = Utils.first(ms, t);
 Assertions.assertEquals(m.id().tags(), ArrayTagSet.create(t));
}

代码示例来源:origin: Netflix/spectator

@Test
public void readLatencyNoActivity() throws Exception {
 Registry r = new DefaultRegistry(new ManualClock());
 List<JmxConfig> configs = configs();
 JmxData data = timer("keyspace=test,name=ReadLatency,scope=foo,type=ColumnFamily", 0);
 List<Measurement> ms = measure(r, configs, data);
 Assertions.assertEquals(7, ms.size());
 Assertions.assertEquals(
   50.0e-4,
   Utils.first(ms, "statistic", "percentile_50").value(),
   1e-12);
 data = timer("keyspace=test,name=ReadLatency,scope=foo,type=ColumnFamily", 0);
 ms = measure(r, configs, data);
 Assertions.assertEquals(7, ms.size());
 Assertions.assertEquals(
   0.0,
   Utils.first(ms, "statistic", "percentile_50").value(),
   1e-12);
 data = timer("keyspace=test,name=ReadLatency,scope=foo,type=ColumnFamily", 1);
 ms = measure(r, configs, data);
 Assertions.assertEquals(7, ms.size());
 Assertions.assertEquals(
   50.01e-4,
   Utils.first(ms, "statistic", "percentile_50").value(),
   1e-12);
}

代码示例来源:origin: Netflix/spectator

@Test
public void firstKV() {
 List<Measurement> ms = newList(10);
 Tag t = new BasicTag("i", "7");
 Measurement m = Utils.first(ms, "i", "7");
 Assertions.assertEquals(m.id().tags(), ArrayTagSet.create(t));
}

代码示例来源:origin: Netflix/spectator

@Test
public void firstPredicate() {
 List<Measurement> ms = newList(10);
 Tag t = new BasicTag("i", "7");
 Measurement m = Utils.first(ms, v -> v.value() == 7.0);
 Assertions.assertEquals(m.id().tags(), ArrayTagSet.create(t));
}

相关文章