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

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

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

Timestamp.create介绍

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

代码示例

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

  1. private static Timestamp ofEpochSecond(long epochSecond, long nanoAdjustment) {
  2. long secs = TimeUtils.checkedAdd(epochSecond, floorDiv(nanoAdjustment, NANOS_PER_SECOND));
  3. int nos = (int) floorMod(nanoAdjustment, NANOS_PER_SECOND);
  4. return create(secs, nos);
  5. }

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

  1. @Test
  2. public void setAndGetTime() {
  3. TestClock clock = TestClock.create(Timestamp.create(1, 2));
  4. assertThat(clock.now()).isEqualTo(Timestamp.create(1, 2));
  5. clock.setTime(Timestamp.create(3, 4));
  6. assertThat(clock.now()).isEqualTo(Timestamp.create(3, 4));
  7. }

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

  1. @Test
  2. public void timestampAddNanos_Negative() {
  3. Timestamp timestamp = Timestamp.create(1234, 223);
  4. assertThat(timestamp.addNanos(-223)).isEqualTo(Timestamp.create(1234, 0));
  5. assertThat(timestamp.addNanos(-1000000223)).isEqualTo(Timestamp.create(1233, 0));
  6. assertThat(timestamp.addNanos(-1300200500)).isEqualTo(Timestamp.create(1232, 699799723));
  7. assertThat(timestamp.addNanos(-4123456213L)).isEqualTo(Timestamp.create(1229, 876544010));
  8. assertThat(timestamp.addNanos(Long.MIN_VALUE))
  9. .isEqualTo(Timestamp.create(1234L - 9223372036L - 1, 223 + 145224192));
  10. }

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

  1. @Test
  2. public void testConstants() {
  3. assertThat(MutableViewData.ZERO_TIMESTAMP).isEqualTo(Timestamp.create(0, 0));
  4. }
  5. }

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

  1. @Test
  2. public void timestampFromMillis() {
  3. assertThat(Timestamp.fromMillis(0)).isEqualTo(Timestamp.create(0, 0));
  4. assertThat(Timestamp.fromMillis(987)).isEqualTo(Timestamp.create(0, 987000000));
  5. assertThat(Timestamp.fromMillis(3456)).isEqualTo(Timestamp.create(3, 456000000));
  6. }

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

  1. @Test(expected = ArithmeticException.class)
  2. public void catchNegativeOverflow() {
  3. TestClock.create(Timestamp.create(Long.MIN_VALUE / NUM_NANOS_PER_SECOND - 1, 0));
  4. }
  5. }

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

  1. @Test
  2. public void timestampSubtractTimestamp_NegativeResult() {
  3. Timestamp timestamp = Timestamp.create(1234, 223);
  4. assertThat(timestamp.subtractTimestamp(Timestamp.create(1235, 223)))
  5. .isEqualTo(Duration.create(-1, 0));
  6. assertThat(timestamp.subtractTimestamp(Timestamp.create(1234, 224)))
  7. .isEqualTo(Duration.create(0, -1));
  8. assertThat(timestamp.subtractTimestamp(Timestamp.create(1235, 224)))
  9. .isEqualTo(Duration.create(-1, -1));
  10. assertThat(timestamp.subtractTimestamp(Timestamp.create(1236, 123)))
  11. .isEqualTo(Duration.create(-1, -999999900));
  12. }

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

  1. @Test
  2. public void timestampAddDuration() {
  3. Timestamp timestamp = Timestamp.create(1234, 223);
  4. assertThat(timestamp.addDuration(Duration.create(1, 0))).isEqualTo(Timestamp.create(1235, 223));
  5. assertThat(timestamp.addDuration(Duration.create(0, 1))).isEqualTo(Timestamp.create(1234, 224));
  6. assertThat(timestamp.addDuration(Duration.create(1, 1))).isEqualTo(Timestamp.create(1235, 224));
  7. assertThat(timestamp.addDuration(Duration.create(1, 999999900)))
  8. .isEqualTo(Timestamp.create(1236, 123));
  9. }

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

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

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

  1. @Test
  2. public void create_NanosTooHigh_NegativeTime() {
  3. thrown.expect(IllegalArgumentException.class);
  4. thrown.expectMessage("'nanos' is greater than maximum (999999999): 1000000000");
  5. Timestamp.create(-1, 1000000000);
  6. }

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

  1. @Test
  2. public void create_SecondsTooLow() {
  3. thrown.expect(IllegalArgumentException.class);
  4. thrown.expectMessage("'seconds' is less than minimum (-315576000000): -315576000001");
  5. Timestamp.create(-315576000001L, 0);
  6. }

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

  1. @Test
  2. public void create_NanosTooLow_PositiveTime() {
  3. thrown.expect(IllegalArgumentException.class);
  4. thrown.expectMessage("'nanos' is less than zero: -1");
  5. Timestamp.create(1, -1);
  6. }

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

  1. @Test
  2. public void create_NanosTooLow_NegativeTime() {
  3. thrown.expect(IllegalArgumentException.class);
  4. thrown.expectMessage("'nanos' is less than zero: -1");
  5. Timestamp.create(-1, -1);
  6. }

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

  1. @Test
  2. public void testGetFraction() {
  3. Timestamp thirtySecondsAfterStart = Timestamp.create(90, 0);
  4. assertThat(
  5. new IntervalBucket(START, MINUTE, MEAN, MEASURE_DOUBLE)
  6. .getFraction(thirtySecondsAfterStart))
  7. .isWithin(TOLERANCE)
  8. .of(0.5);
  9. }

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

  1. private static SpanData.TimedEvent<Annotation> sampleAnnotation() {
  2. return SpanData.TimedEvent.create(
  3. Timestamp.create(1519629872L, 987654321),
  4. Annotation.fromDescriptionAndAttributes(
  5. "annotation #1",
  6. ImmutableMap.of(
  7. "bool", AttributeValue.booleanAttributeValue(true),
  8. "long", AttributeValue.longAttributeValue(1337L),
  9. "string",
  10. AttributeValue.stringAttributeValue(
  11. "Kind words do not cost much. Yet they accomplish much. -- Pascal"))));
  12. }

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

  1. @Test
  2. public void preventCallingGetFractionOnPastBuckets() {
  3. IntervalBucket bucket = new IntervalBucket(START, MINUTE, MEAN, MEASURE_DOUBLE);
  4. Timestamp twoMinutesAfterStart = Timestamp.create(180, 0);
  5. thrown.expect(IllegalArgumentException.class);
  6. bucket.getFraction(twoMinutesAfterStart);
  7. }

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

  1. @Test
  2. public void preventCallingGetFractionOnFutureBuckets() {
  3. IntervalBucket bucket = new IntervalBucket(START, MINUTE, MEAN, MEASURE_DOUBLE);
  4. Timestamp thirtySecondsBeforeStart = Timestamp.create(30, 0);
  5. thrown.expect(IllegalArgumentException.class);
  6. bucket.getFraction(thirtySecondsBeforeStart);
  7. }
  8. }

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

  1. @Test
  2. public void convertTimestamp() {
  3. Timestamp censusTimestamp1 = Timestamp.create(100, 3000);
  4. assertThat(StackdriverExportUtils.convertTimestamp(censusTimestamp1))
  5. .isEqualTo(
  6. com.google.protobuf.Timestamp.newBuilder().setSeconds(100).setNanos(3000).build());
  7. // Stackdriver doesn't allow negative values, instead it will replace the negative values
  8. // by returning a default instance.
  9. Timestamp censusTimestamp2 = Timestamp.create(-100, 3000);
  10. assertThat(StackdriverExportUtils.convertTimestamp(censusTimestamp2))
  11. .isEqualTo(com.google.protobuf.Timestamp.newBuilder().build());
  12. }

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

  1. @Test
  2. public void noopViewManager_GetView_Interval() {
  3. View view =
  4. View.create(
  5. VIEW_NAME, VIEW_DESCRIPTION, MEASURE, AGGREGATION, Arrays.asList(KEY), INTERVAL);
  6. ViewManager viewManager = NoopStats.newNoopViewManager();
  7. viewManager.registerView(view);
  8. ViewData viewData = viewManager.getView(VIEW_NAME);
  9. assertThat(viewData.getView()).isEqualTo(view);
  10. assertThat(viewData.getAggregationMap()).isEmpty();
  11. assertThat(viewData.getWindowData()).isEqualTo(IntervalData.create(Timestamp.create(0, 0)));
  12. }

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

  1. @Test
  2. public void getProcessIdentifier() {
  3. String jvmName = "54321@my.org";
  4. Timestamp timestamp = Timestamp.create(10, 20);
  5. ProcessIdentifier processIdentifier = OcAgentNodeUtils.getProcessIdentifier(jvmName, timestamp);
  6. assertThat(processIdentifier.getHostName()).isEqualTo("my.org");
  7. assertThat(processIdentifier.getPid()).isEqualTo(54321);
  8. assertThat(processIdentifier.getStartTimestamp())
  9. .isEqualTo(com.google.protobuf.Timestamp.newBuilder().setSeconds(10).setNanos(20).build());
  10. }

相关文章