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

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

本文整理了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

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

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

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

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

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

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

@Test
 public void testConstants() {
  assertThat(MutableViewData.ZERO_TIMESTAMP).isEqualTo(Timestamp.create(0, 0));
 }
}

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

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

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

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

代码示例来源: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 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 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 create_NanosTooHigh_NegativeTime() {
 thrown.expect(IllegalArgumentException.class);
 thrown.expectMessage("'nanos' is greater than maximum (999999999): 1000000000");
 Timestamp.create(-1, 1000000000);
}

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

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

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

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

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

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

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

@Test
public void testGetFraction() {
 Timestamp thirtySecondsAfterStart = Timestamp.create(90, 0);
 assertThat(
     new IntervalBucket(START, MINUTE, MEAN, MEASURE_DOUBLE)
       .getFraction(thirtySecondsAfterStart))
   .isWithin(TOLERANCE)
   .of(0.5);
}

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

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

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

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

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

@Test
 public void preventCallingGetFractionOnFutureBuckets() {
  IntervalBucket bucket = new IntervalBucket(START, MINUTE, MEAN, MEASURE_DOUBLE);
  Timestamp thirtySecondsBeforeStart = Timestamp.create(30, 0);
  thrown.expect(IllegalArgumentException.class);
  bucket.getFraction(thirtySecondsBeforeStart);
 }
}

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

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

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

@Test
public void noopViewManager_GetView_Interval() {
 View view =
   View.create(
     VIEW_NAME, VIEW_DESCRIPTION, MEASURE, AGGREGATION, Arrays.asList(KEY), INTERVAL);
 ViewManager viewManager = NoopStats.newNoopViewManager();
 viewManager.registerView(view);
 ViewData viewData = viewManager.getView(VIEW_NAME);
 assertThat(viewData.getView()).isEqualTo(view);
 assertThat(viewData.getAggregationMap()).isEmpty();
 assertThat(viewData.getWindowData()).isEqualTo(IntervalData.create(Timestamp.create(0, 0)));
}

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

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

相关文章