當前位置: 首頁>>代碼示例>>Java>>正文


Java Duration.ofHours方法代碼示例

本文整理匯總了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);
}
 
開發者ID:yandex-money,項目名稱:db-queue,代碼行數:23,代碼來源:QueueRunnerInTransactionTest.java

示例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();
}
 
開發者ID:salesforce,項目名稱:grpc-java-contrib,代碼行數:23,代碼來源:DefaultDeadlineInterceptorTest.java

示例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);
}
 
開發者ID:yandex-money,項目名稱:db-queue,代碼行數:22,代碼來源:QueueRunnerInExternalExecutorTest.java

示例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");
}
 
開發者ID:spinscale,項目名稱:maxcube-java,代碼行數:23,代碼來源:DurationParser.java

示例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);
	}
}
 
開發者ID:DevOnTheRocks,項目名稱:StickyChunk,代碼行數:9,代碼來源:BlockChunkLoaderConfig.java

示例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)},
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:TCKYear.java

示例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},
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:35,代碼來源:TCKYearMonth.java

示例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},
    };
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:35,代碼來源:TCKYearMonth.java

示例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)},
    };
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:TCKYear.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:6,代碼來源:TCKDuration.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TCKDuration.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:7,代碼來源:TCKDuration.java

示例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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:TCKDuration.java

示例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);
}
 
開發者ID:StuPro-TOSCAna,項目名稱:TOSCAna,代碼行數:8,代碼來源:TagStorage.java


注:本文中的java.time.Duration.ofHours方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。