io.opencensus.common.Duration.create()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(128)

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

Duration.create介绍

[英]Creates a new time duration from given seconds and nanoseconds.
[中]从给定的秒和纳秒创建新的持续时间。

代码示例

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void testDurationEqual() {
 // Positive tests.
 assertThat(Duration.create(0, 0)).isEqualTo(Duration.create(0, 0));
 assertThat(Duration.create(24, 42)).isEqualTo(Duration.create(24, 42));
 assertThat(Duration.create(-24, -42)).isEqualTo(Duration.create(-24, -42));
 // Negative tests.
 assertThat(Duration.create(25, 42)).isNotEqualTo(Duration.create(24, 42));
 assertThat(Duration.create(24, 43)).isNotEqualTo(Duration.create(24, 42));
 assertThat(Duration.create(-25, -42)).isNotEqualTo(Duration.create(-24, -42));
 assertThat(Duration.create(-24, -43)).isNotEqualTo(Duration.create(-24, -42));
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
 public void toMillis() {
  assertThat(Duration.create(10, 0).toMillis()).isEqualTo(10000L);
  assertThat(Duration.create(10, 1000).toMillis()).isEqualTo(10000L);
  assertThat(Duration.create(0, (int) 1e6).toMillis()).isEqualTo(1L);
  assertThat(Duration.create(0, 0).toMillis()).isEqualTo(0L);
  assertThat(Duration.create(-10, 0).toMillis()).isEqualTo(-10000L);
  assertThat(Duration.create(-10, -1000).toMillis()).isEqualTo(-10000L);
  assertThat(Duration.create(0, -(int) 1e6).toMillis()).isEqualTo(-1L);
 }
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void testDurationCreate() {
 assertThat(Duration.create(24, 42).getSeconds()).isEqualTo(24);
 assertThat(Duration.create(24, 42).getNanos()).isEqualTo(42);
 assertThat(Duration.create(-24, -42).getSeconds()).isEqualTo(-24);
 assertThat(Duration.create(-24, -42).getNanos()).isEqualTo(-42);
 assertThat(Duration.create(315576000000L, 999999999).getSeconds()).isEqualTo(315576000000L);
 assertThat(Duration.create(315576000000L, 999999999).getNanos()).isEqualTo(999999999);
 assertThat(Duration.create(-315576000000L, -999999999).getSeconds()).isEqualTo(-315576000000L);
 assertThat(Duration.create(-315576000000L, -999999999).getNanos()).isEqualTo(-999999999);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void testDurationFromMillisNegative() {
 assertThat(Duration.fromMillis(-1)).isEqualTo(Duration.create(0, -1000000));
 assertThat(Duration.fromMillis(-999)).isEqualTo(Duration.create(0, -999000000));
 assertThat(Duration.fromMillis(-1000)).isEqualTo(Duration.create(-1, 0));
 assertThat(Duration.fromMillis(-3456)).isEqualTo(Duration.create(-3, -456000000));
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void testDurationFromMillis() {
 assertThat(Duration.fromMillis(0)).isEqualTo(Duration.create(0, 0));
 assertThat(Duration.fromMillis(987)).isEqualTo(Duration.create(0, 987000000));
 assertThat(Duration.fromMillis(3456)).isEqualTo(Duration.create(3, 456000000));
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Override
 public ViewData apply(ViewData.AggregationWindowData.IntervalData arg) {
  Duration duration = ((View.AggregationWindow.Interval) view.getWindow()).getDuration();
  return createInternal(
    view,
    Collections.unmodifiableMap(deepCopy),
    arg,
    arg.getEnd()
      .addDuration(Duration.create(-duration.getSeconds(), -duration.getNanos())),
    arg.getEnd());
 }
},

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void interruptWorkerThreadStops() throws InterruptedException {
 SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(1, 0));
 spanExporter.registerHandler("test.service", serviceHandler);
 Thread serviceExporterThread = spanExporter.getServiceExporterThread();
 serviceExporterThread.interrupt();
 // Test that the worker thread will stop.
 serviceExporterThread.join();
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void timestampAddDuration() {
 Timestamp timestamp = Timestamp.create(1234, 223);
 assertThat(timestamp.addDuration(Duration.create(1, 0))).isEqualTo(Timestamp.create(1235, 223));
 assertThat(timestamp.addDuration(Duration.create(0, 1))).isEqualTo(Timestamp.create(1234, 224));
 assertThat(timestamp.addDuration(Duration.create(1, 1))).isEqualTo(Timestamp.create(1235, 224));
 assertThat(timestamp.addDuration(Duration.create(1, 999999900)))
   .isEqualTo(Timestamp.create(1236, 123));
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void timestampSubtractTimestamp_NegativeResult() {
 Timestamp timestamp = Timestamp.create(1234, 223);
 assertThat(timestamp.subtractTimestamp(Timestamp.create(1235, 223)))
   .isEqualTo(Duration.create(-1, 0));
 assertThat(timestamp.subtractTimestamp(Timestamp.create(1234, 224)))
   .isEqualTo(Duration.create(0, -1));
 assertThat(timestamp.subtractTimestamp(Timestamp.create(1235, 224)))
   .isEqualTo(Duration.create(-1, -1));
 assertThat(timestamp.subtractTimestamp(Timestamp.create(1236, 123)))
   .isEqualTo(Duration.create(-1, -999999900));
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void create_PositiveSecondsNegativeNanos() {
 thrown.expect(IllegalArgumentException.class);
 thrown.expectMessage("'seconds' and 'nanos' have inconsistent sign: seconds=1, nanos=-1");
 Duration.create(1, -1);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void settingStateToDisabledWillClearStats_Interval() {
 View intervalView =
   View.create(
     VIEW_NAME_2,
     VIEW_DESCRIPTION,
     MEASURE_DOUBLE,
     MEAN,
     Arrays.asList(KEY),
     Interval.create(Duration.create(60, 0)));
 settingStateToDisabledWillClearStats(intervalView);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void create_SecondsTooHigh() {
 thrown.expect(IllegalArgumentException.class);
 thrown.expectMessage("'seconds' is greater than maximum (315576000000): 315576000001");
 Duration.create(315576000001L, 0);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void create_NanosTooLow() {
 thrown.expect(IllegalArgumentException.class);
 thrown.expectMessage("'nanos' is less than minimum (-999999999): -1000000000");
 Duration.create(0, -1000000000);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void create_NanosTooHigh() {
 thrown.expect(IllegalArgumentException.class);
 thrown.expectMessage("'nanos' is greater than maximum (999999999): 1000000000");
 Duration.create(0, 1000000000);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void create_NegativeSecondsPositiveNanos() {
 thrown.expect(IllegalArgumentException.class);
 thrown.expectMessage("'seconds' and 'nanos' have inconsistent sign: seconds=-1, nanos=1");
 Duration.create(-1, 1);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void create_SecondsTooLow() {
 thrown.expect(IllegalArgumentException.class);
 thrown.expectMessage("'seconds' is less than minimum (-315576000000): -315576000001");
 Duration.create(-315576000001L, 0);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void advanceTime() {
 TestClock clock = TestClock.create(Timestamp.create(1, 500 * 1000 * 1000));
 clock.advanceTime(Duration.create(2, 600 * 1000 * 1000));
 assertThat(clock.now()).isEqualTo(Timestamp.create(4, 100 * 1000 * 1000));
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
 public void buildWithNegativeDuration() {
  thrown.expect(IllegalArgumentException.class);
  thrown.expectMessage("Interval duration must be positive");
  SignalFxStatsConfiguration.builder()
    .setToken(TEST_TOKEN)
    .setExportInterval(Duration.create(-1, 0))
    .build();
 }
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void exportDifferentSampledSpans() {
 SpanExporterImpl spanExporter = SpanExporterImpl.create(4, Duration.create(1, 0));
 StartEndHandler startEndHandler =
   new StartEndHandlerImpl(spanExporter, runningSpanStore, null, new SimpleEventQueue());
 spanExporter.registerHandler("test.service", serviceHandler);
 RecordEventsSpanImpl span1 = createSampledEndedSpan(startEndHandler, SPAN_NAME_1);
 RecordEventsSpanImpl span2 = createSampledEndedSpan(startEndHandler, SPAN_NAME_2);
 List<SpanData> exported = serviceHandler.waitForExport(2);
 assertThat(exported).containsExactly(span1.toSpanData(), span2.toSpanData());
}

代码示例来源:origin: census-instrumentation/opencensus-java

private void addSpanNameToAllErrorBuckets(String spanName) {
 for (CanonicalCode code : CanonicalCode.values()) {
  if (code != CanonicalCode.OK) {
   Span sampledSpan = createSampledSpan(spanName);
   Span notSampledSpan = createNotSampledSpan(spanName);
   testClock.advanceTime(Duration.create(0, 1000));
   sampledSpan.end(EndSpanOptions.builder().setStatus(code.toStatus()).build());
   notSampledSpan.end(EndSpanOptions.builder().setStatus(code.toStatus()).build());
  }
 }
}

相关文章