本文整理汇总了Java中java.time.Duration.ofHours方法的典型用法代码示例。如果您正苦于以下问题:Java Duration.ofHours方法的具体用法?Java Duration.ofHours怎么用?Java Duration.ofHours使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Duration
的用法示例。
在下文中一共展示了Duration.ofHours方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: should_wait_notasktimeout_when_no_task_found
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void should_wait_notasktimeout_when_no_task_found() throws Exception {
Duration betweenTaskTimeout = Duration.ofHours(1L);
Duration noTaskTimeout = Duration.ofMillis(5L);
QueueConsumer queueConsumer = mock(QueueConsumer.class);
TaskPicker taskPicker = mock(TaskPicker.class);
when(taskPicker.pickTask(queueConsumer)).thenReturn(null);
TaskProcessor taskProcessor = mock(TaskProcessor.class);
QueueDao queueDao = mock(QueueDao.class);
when(queueDao.getTransactionTemplate()).thenReturn(new FakeTransactionTemplate());
when(queueConsumer.getQueueConfig()).thenReturn(new QueueConfig(testLocation1,
QueueSettings.builder().withBetweenTaskTimeout(betweenTaskTimeout).withNoTaskTimeout(noTaskTimeout).build()));
QueueProcessingStatus status = new QueueRunnerInTransaction(taskPicker, taskProcessor, queueDao).runQueue(queueConsumer);
assertThat(status, equalTo(QueueProcessingStatus.SKIPPED));
verify(queueDao).getTransactionTemplate();
verify(taskPicker).pickTask(queueConsumer);
verifyZeroInteractions(taskProcessor);
}
示例2: interceptorShouldAddDeadlineWhenAbsent
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void interceptorShouldAddDeadlineWhenAbsent() {
AtomicBoolean called = new AtomicBoolean(false);
DefaultDeadlineInterceptor interceptor = new DefaultDeadlineInterceptor(Duration.ofHours(1));
interceptor.interceptCall(null, CallOptions.DEFAULT, new Channel() {
@Override
public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(MethodDescriptor<RequestT, ResponseT> methodDescriptor, CallOptions callOptions) {
called.set(true);
assertThat(callOptions.getDeadline().timeRemaining(TimeUnit.MINUTES)).isEqualTo(59);
return null;
}
@Override
public String authority() {
return null;
}
});
assertThat(called.get()).isTrue();
}
示例3: should_wait_notasktimeout_when_no_task_found
import java.time.Duration; //导入方法依赖的package包/类
@Test
public void should_wait_notasktimeout_when_no_task_found() throws Exception {
Duration betweenTaskTimeout = Duration.ofHours(1L);
Duration noTaskTimeout = Duration.ofMillis(5L);
FakeExecutor executor = spy(new FakeExecutor());
QueueConsumer queueConsumer = mock(QueueConsumer.class);
TaskPicker taskPicker = mock(TaskPicker.class);
when(taskPicker.pickTask(queueConsumer)).thenReturn(null);
TaskProcessor taskProcessor = mock(TaskProcessor.class);
when(queueConsumer.getQueueConfig()).thenReturn(new QueueConfig(testLocation1,
QueueSettings.builder().withBetweenTaskTimeout(betweenTaskTimeout).withNoTaskTimeout(noTaskTimeout).build()));
QueueProcessingStatus status = new QueueRunnerInExternalExecutor(taskPicker, taskProcessor, executor).runQueue(queueConsumer);
assertThat(status, equalTo(QueueProcessingStatus.SKIPPED));
verifyZeroInteractions(executor);
verify(taskPicker).pickTask(queueConsumer);
verifyZeroInteractions(taskProcessor);
}
示例4: parse
import java.time.Duration; //导入方法依赖的package包/类
public static Duration parse(String input) {
if (input == null || input.trim().length() < 1) {
throw new IllegalArgumentException("Duration must be a number and a unit");
}
input = input.trim();
String number = input.substring(0, input.length() - 1);
Long value = Long.valueOf(number);
if (input.endsWith("s")) {
return Duration.ofSeconds(value);
} else if (input.endsWith("m")) {
return Duration.ofMinutes(value);
} else if (input.endsWith("h")) {
return Duration.ofHours(value);
} else if (input.endsWith("d")) {
return Duration.ofDays(value);
}
throw new IllegalArgumentException("Unknown unit, must be one of s/m/h/d");
}
示例5: getFuelDuration
import java.time.Duration; //导入方法依赖的package包/类
public Duration getFuelDuration() {
try {
return Duration.parse(fuelDuration);
} catch (DateTimeParseException e) {
StickyChunk.getInstance().getLogger().warn(String.format("Fuel-Duration (%s) of %s is malformed. Using 8h instead", fuelDuration, getName()));
return Duration.ofHours(8);
}
}
示例6: data_minusInvalidUnit
import java.time.Duration; //导入方法依赖的package包/类
@DataProvider(name="minusInvalidUnit")
Object[][] data_minusInvalidUnit() {
return new Object[][] {
{Period.of(0, 1, 0)},
{Period.of(0, 0, 1)},
{Period.of(0, 1, 1)},
{Period.of(1, 1, 1)},
{Duration.ofDays(1)},
{Duration.ofHours(1)},
{Duration.ofMinutes(1)},
{Duration.ofSeconds(1)},
};
}
示例7: data_plus_TemporalAmount
import java.time.Duration; //导入方法依赖的package包/类
@DataProvider(name="plus_TemporalAmount")
Object[][] data_plus_TemporalAmount() {
return new Object[][] {
{YearMonth.of(1, 1), Period.ofYears(1), YearMonth.of(2, 1), null},
{YearMonth.of(1, 1), Period.ofYears(-12), YearMonth.of(-11, 1), null},
{YearMonth.of(1, 1), Period.ofYears(0), YearMonth.of(1, 1), null},
{YearMonth.of(999999999, 12), Period.ofYears(0), YearMonth.of(999999999, 12), null},
{YearMonth.of(-999999999, 1), Period.ofYears(0), YearMonth.of(-999999999, 1), null},
{YearMonth.of(0, 1), Period.ofYears(-999999999), YearMonth.of(-999999999, 1), null},
{YearMonth.of(0, 12), Period.ofYears(999999999), YearMonth.of(999999999, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(1), YearMonth.of(1, 2), null},
{YearMonth.of(1, 1), Period.ofMonths(-12), YearMonth.of(0, 1), null},
{YearMonth.of(1, 1), Period.ofMonths(121), YearMonth.of(11, 2), null},
{YearMonth.of(1, 1), Period.ofMonths(0), YearMonth.of(1, 1), null},
{YearMonth.of(999999999, 12), Period.ofMonths(0), YearMonth.of(999999999, 12), null},
{YearMonth.of(-999999999, 1), Period.ofMonths(0), YearMonth.of(-999999999, 1), null},
{YearMonth.of(-999999999, 2), Period.ofMonths(-1), YearMonth.of(-999999999, 1), null},
{YearMonth.of(999999999, 11), Period.ofMonths(1), YearMonth.of(999999999, 12), null},
{YearMonth.of(1, 1), Period.ofYears(1).withMonths(2), YearMonth.of(2, 3), null},
{YearMonth.of(1, 1), Period.ofYears(-12).withMonths(-1), YearMonth.of(-12, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(2).withYears(1), YearMonth.of(2, 3), null},
{YearMonth.of(1, 1), Period.ofMonths(-1).withYears(-12), YearMonth.of(-12, 12), null},
{YearMonth.of(1, 1), Period.ofDays(365), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofDays(365), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofHours(365*24), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofMinutes(365*24*60), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofSeconds(365*24*3600), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofNanos(365*24*3600*1000000000), null, DateTimeException.class},
};
}
示例8: data_minus_TemporalAmount
import java.time.Duration; //导入方法依赖的package包/类
@DataProvider(name="minus_TemporalAmount")
Object[][] data_minus_TemporalAmount() {
return new Object[][] {
{YearMonth.of(1, 1), Period.ofYears(1), YearMonth.of(0, 1), null},
{YearMonth.of(1, 1), Period.ofYears(-12), YearMonth.of(13, 1), null},
{YearMonth.of(1, 1), Period.ofYears(0), YearMonth.of(1, 1), null},
{YearMonth.of(999999999, 12), Period.ofYears(0), YearMonth.of(999999999, 12), null},
{YearMonth.of(-999999999, 1), Period.ofYears(0), YearMonth.of(-999999999, 1), null},
{YearMonth.of(0, 1), Period.ofYears(999999999), YearMonth.of(-999999999, 1), null},
{YearMonth.of(0, 12), Period.ofYears(-999999999), YearMonth.of(999999999, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(1), YearMonth.of(0, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(-12), YearMonth.of(2, 1), null},
{YearMonth.of(1, 1), Period.ofMonths(121), YearMonth.of(-10, 12), null},
{YearMonth.of(1, 1), Period.ofMonths(0), YearMonth.of(1, 1), null},
{YearMonth.of(999999999, 12), Period.ofMonths(0), YearMonth.of(999999999, 12), null},
{YearMonth.of(-999999999, 1), Period.ofMonths(0), YearMonth.of(-999999999, 1), null},
{YearMonth.of(-999999999, 2), Period.ofMonths(1), YearMonth.of(-999999999, 1), null},
{YearMonth.of(999999999, 11), Period.ofMonths(-1), YearMonth.of(999999999, 12), null},
{YearMonth.of(1, 1), Period.ofYears(1).withMonths(2), YearMonth.of(-1, 11), null},
{YearMonth.of(1, 1), Period.ofYears(-12).withMonths(-1), YearMonth.of(13, 2), null},
{YearMonth.of(1, 1), Period.ofMonths(2).withYears(1), YearMonth.of(-1, 11), null},
{YearMonth.of(1, 1), Period.ofMonths(-1).withYears(-12), YearMonth.of(13, 2), null},
{YearMonth.of(1, 1), Period.ofDays(365), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofDays(365), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofHours(365*24), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofMinutes(365*24*60), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofSeconds(365*24*3600), null, DateTimeException.class},
{YearMonth.of(1, 1), Duration.ofNanos(365*24*3600*1000000000), null, DateTimeException.class},
};
}
示例9: shouldKeepTypesWhenDeserializingSerializedTinkerGraph
import java.time.Duration; //导入方法依赖的package包/类
/**
* Those kinds of types are declared differently in the GraphSON type deserializer, check that all are handled
* properly.
*/
@Test
public void shouldKeepTypesWhenDeserializingSerializedTinkerGraph() throws IOException {
final TinkerGraph tg = TinkerGraph.open();
final Vertex v = tg.addVertex("vertexTest");
final UUID uuidProp = UUID.randomUUID();
final Duration durationProp = Duration.ofHours(3);
final Long longProp = 2L;
final ByteBuffer byteBufferProp = ByteBuffer.wrap("testbb".getBytes());
final InetAddress inetAddressProp = InetAddress.getByName("10.10.10.10");
// One Java util type natively supported by Jackson
v.property("uuid", uuidProp);
// One custom time type added by the GraphSON module
v.property("duration", durationProp);
// One Java native type not handled by JSON natively
v.property("long", longProp);
// One Java util type added by GraphSON
v.property("bytebuffer", byteBufferProp);
v.property("inetaddress", inetAddressProp);
final GraphWriter writer = getWriter(defaultMapperV2d0);
final GraphReader reader = getReader(defaultMapperV2d0);
try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
writer.writeGraph(out, tg);
final String json = out.toString();
final TinkerGraph read = TinkerGraph.open();
reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
final Vertex vRead = read.traversal().V().hasLabel("vertexTest").next();
assertEquals(vRead.property("uuid").value(), uuidProp);
assertEquals(vRead.property("duration").value(), durationProp);
assertEquals(vRead.property("long").value(), longProp);
assertEquals(vRead.property("bytebuffer").value(), byteBufferProp);
assertEquals(vRead.property("inetaddress").value(), inetAddressProp);
}
}
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:42,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java
示例10: data_plusInvalidUnit
import java.time.Duration; //导入方法依赖的package包/类
@DataProvider(name="plusInvalidUnit")
Object[][] data_plusInvalidUnit() {
return new Object[][] {
{Period.of(0, 1, 0)},
{Period.of(0, 0, 1)},
{Period.of(0, 1, 1)},
{Period.of(1, 1, 1)},
{Duration.ofDays(1)},
{Duration.ofHours(1)},
{Duration.ofMinutes(1)},
{Duration.ofSeconds(1)},
};
}
示例11: minusHours_long_overflowTooSmall
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions = {ArithmeticException.class})
public void minusHours_long_overflowTooSmall() {
Duration t = Duration.ofHours(Long.MIN_VALUE/3600);
t.minusHours(1);
}
示例12: factory_hours_tooBig
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions=ArithmeticException.class)
public void factory_hours_tooBig() {
Duration.ofHours(Long.MAX_VALUE / 3600 + 1);
}
示例13: minusHours_long
import java.time.Duration; //导入方法依赖的package包/类
@Test(dataProvider="MinusHours")
public void minusHours_long(long hours, long amount, long expectedHours) {
Duration t = Duration.ofHours(hours);
t = t.minusHours(amount);
assertEquals(t.toHours(), expectedHours);
}
示例14: minusHours_long_overflowTooBig
import java.time.Duration; //导入方法依赖的package包/类
@Test(expectedExceptions = {ArithmeticException.class})
public void minusHours_long_overflowTooBig() {
Duration t = Duration.ofHours(Long.MAX_VALUE/3600);
t.minusHours(-1);
}
示例15: getNextUpdate
import java.time.Duration; //导入方法依赖的package包/类
/**
Returns a point in time when the next persist is due.
*/
Instant getNextUpdate() {
Duration updateIntervalDuration = Duration.ofHours(updateInterval);
return Instant.ofEpochMilli(data.lastUpdateTime).plus(updateIntervalDuration);
}