List of usage examples for java.time Duration ofHours
public static Duration ofHours(long hours)
From source file:org.apache.james.modules.mailbox.TikaConfigurationReaderTest.java
@Test public void readTikaConfigurationShouldDefaultToSecondWhenMissingUnitForCacheEvitionPeriod() throws Exception { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.load(new StringReader("tika.enabled=true\n" + "tika.host=172.0.0.5\n" + "tika.port=889\n" + "tika.timeoutInMillis=500\n" + "tika.cache.eviction.period=3600")); assertThat(TikaConfigurationReader.readTikaConfiguration(configuration)) .isEqualTo(TikaConfiguration.builder().enabled().host("172.0.0.5").port(889).timeoutInMillis(500) .cacheEvictionPeriod(Duration.ofHours(1)).build()); }
From source file:org.apache.james.queue.rabbitmq.view.cassandra.configuration.CassandraMailQueueViewConfigurationTest.java
@Test void validateConfigurationChangeShouldAcceptIdentity() { CassandraMailQueueViewConfiguration configuration = CassandraMailQueueViewConfiguration.builder() .bucketCount(2).updateBrowseStartPace(1000).sliceWindow(Duration.ofHours(1)).build(); assertThatCode(() -> configuration.validateConfigurationChange(configuration)).doesNotThrowAnyException(); }
From source file:org.apache.james.queue.rabbitmq.view.cassandra.configuration.CassandraMailQueueViewConfigurationTest.java
@Test void validateConfigurationChangeShouldAcceptBucketCountIncrease() { CassandraMailQueueViewConfiguration configuration = CassandraMailQueueViewConfiguration.builder() .bucketCount(2).updateBrowseStartPace(1000).sliceWindow(Duration.ofHours(1)).build(); assertThatCode(() -> configuration.validateConfigurationChange(CassandraMailQueueViewConfiguration.builder() .bucketCount(3).updateBrowseStartPace(1000).sliceWindow(Duration.ofHours(1)).build())) .doesNotThrowAnyException(); }
From source file:org.apache.james.queue.rabbitmq.view.cassandra.configuration.CassandraMailQueueViewConfigurationTest.java
@Test void validateConfigurationChangeShouldAcceptDividingSliceWindow() { CassandraMailQueueViewConfiguration configuration = CassandraMailQueueViewConfiguration.builder() .bucketCount(2).updateBrowseStartPace(1000).sliceWindow(Duration.ofHours(1)).build(); assertThatCode(() -> configuration.validateConfigurationChange(CassandraMailQueueViewConfiguration.builder() .bucketCount(2).updateBrowseStartPace(1000).sliceWindow(Duration.ofMinutes(20)).build())) .doesNotThrowAnyException(); }
From source file:org.apache.james.queue.rabbitmq.view.cassandra.configuration.CassandraMailQueueViewConfigurationTest.java
@Test void validateConfigurationChangeShouldRejectArbitraryDecreaseSliceWindow() { CassandraMailQueueViewConfiguration configuration = CassandraMailQueueViewConfiguration.builder() .bucketCount(2).updateBrowseStartPace(1000).sliceWindow(Duration.ofHours(1)).build(); assertThatThrownBy(() -> configuration.validateConfigurationChange(CassandraMailQueueViewConfiguration .builder().bucketCount(2).updateBrowseStartPace(1000).sliceWindow(Duration.ofMinutes(25)).build())) .isInstanceOf(IllegalArgumentException.class); }
From source file:org.apache.james.queue.rabbitmq.view.cassandra.configuration.CassandraMailQueueViewConfigurationTest.java
@Test void validateConfigurationChangeShouldRejectDecreaseBucketCount() { CassandraMailQueueViewConfiguration configuration = CassandraMailQueueViewConfiguration.builder() .bucketCount(2).updateBrowseStartPace(1000).sliceWindow(Duration.ofHours(1)).build(); assertThatThrownBy(() -> configuration.validateConfigurationChange(CassandraMailQueueViewConfiguration .builder().bucketCount(1).updateBrowseStartPace(1000).sliceWindow(Duration.ofHours(1)).build())) .isInstanceOf(IllegalArgumentException.class); }
From source file:org.apache.samza.operators.impl.TestOperatorImplGraph.java
@Test public void testJoinChain() { ApplicationRunner mockRunner = mock(ApplicationRunner.class); when(mockRunner.getStreamSpec(eq("input1"))) .thenReturn(new StreamSpec("input1", "input-stream1", "input-system")); when(mockRunner.getStreamSpec(eq("input2"))) .thenReturn(new StreamSpec("input2", "input-stream2", "input-system")); StreamGraphImpl streamGraph = new StreamGraphImpl(mockRunner, mock(Config.class)); JoinFunction mockJoinFunction = mock(JoinFunction.class); MessageStream<Object> inputStream1 = streamGraph.getInputStream("input1", (k, v) -> v); MessageStream<Object> inputStream2 = streamGraph.getInputStream("input2", (k, v) -> v); inputStream1.join(inputStream2, mockJoinFunction, Duration.ofHours(1)); TaskContext mockTaskContext = mock(TaskContext.class); when(mockTaskContext.getMetricsRegistry()).thenReturn(new MetricsRegistryMap()); OperatorImplGraph opImplGraph = new OperatorImplGraph(streamGraph, mock(Config.class), mockTaskContext, mock(Clock.class)); // verify that join function is initialized once. verify(mockJoinFunction, times(1)).init(any(Config.class), any(TaskContext.class)); InputOperatorImpl inputOpImpl1 = opImplGraph .getInputOperator(new SystemStream("input-system", "input-stream1")); InputOperatorImpl inputOpImpl2 = opImplGraph .getInputOperator(new SystemStream("input-system", "input-stream2")); PartialJoinOperatorImpl leftPartialJoinOpImpl = (PartialJoinOperatorImpl) inputOpImpl1.registeredOperators .iterator().next();//from w w w.ja va 2 s . c o m PartialJoinOperatorImpl rightPartialJoinOpImpl = (PartialJoinOperatorImpl) inputOpImpl2.registeredOperators .iterator().next(); assertEquals(leftPartialJoinOpImpl.getOperatorSpec(), rightPartialJoinOpImpl.getOperatorSpec()); assertNotSame(leftPartialJoinOpImpl, rightPartialJoinOpImpl); Object joinKey = new Object(); // verify that left partial join operator calls getFirstKey Object mockLeftMessage = mock(Object.class); when(mockJoinFunction.getFirstKey(eq(mockLeftMessage))).thenReturn(joinKey); inputOpImpl1.onMessage(Pair.of("", mockLeftMessage), mock(MessageCollector.class), mock(TaskCoordinator.class)); verify(mockJoinFunction, times(1)).getFirstKey(mockLeftMessage); // verify that right partial join operator calls getSecondKey Object mockRightMessage = mock(Object.class); when(mockJoinFunction.getSecondKey(eq(mockRightMessage))).thenReturn(joinKey); inputOpImpl2.onMessage(Pair.of("", mockRightMessage), mock(MessageCollector.class), mock(TaskCoordinator.class)); verify(mockJoinFunction, times(1)).getSecondKey(mockRightMessage); // verify that the join function apply is called with the correct messages on match verify(mockJoinFunction, times(1)).apply(mockLeftMessage, mockRightMessage); }
From source file:org.hawkular.client.test.metrics.openshift.CollectionRateDetailTest.java
@Test public void findZeroValuesTest() throws Exception { String project = "zproject9"; String container = "stress"; String testID = "namespace: " + project + ", container: " + container; // for easy identification in the log String metricID = super.getMetricID(project, container, METRIC_SUFFIX.CPU_USAGE); // Get a lot of data in the last few days long now = Instant.now().toEpochMilli(); long start = now - Duration.ofHours(36).toMillis(); long end = start + Duration.ofHours(36).toMillis(); Duration timeBucket = Duration.ofHours(1); getData(metricID, testID, start, end, timeBucket); // get data in the last hour start = now - Duration.ofHours(1).toMillis(); end = now;/* w w w . j a v a2 s. c o m*/ timeBucket = Duration.ofMinutes(1); getData(metricID, testID, start, end, timeBucket); }
From source file:org.hawkular.client.test.metrics.openshift.OpenshiftCollectionHistTest.java
public Map<Long, Integer> getHistogram(String podNamespace, String containerName, String metricName) { String podId = getPodUID(podNamespace, containerName); String metricID = containerName + "/" + podId + "/" + metricName; long now = Instant.now().toEpochMilli(); long start = now - Duration.ofHours(36).toMillis(); long dur = start + Duration.ofHours(36).toMillis(); List<DataPoint<Double>> rawData = client().metrics().gauge() .findGaugeDataWithId(metricID, String.valueOf(start), String.valueOf(dur), null, null, null) .getEntity();/* ww w . j ava 2 s . co m*/ Assert.assertNotNull(rawData, "namespace: " + podNamespace + ", container: " + containerName); Duration timeBucket = Duration.ofHours(1); return OpenshiftBaseTest.makeHistogram(rawData, timeBucket); }
From source file:org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfigurationUnitTests.java
@Test // DATAREDIS-667 public void shouldConfigureAllProperties() { ClientOptions clientOptions = ClientOptions.create(); ClientResources sharedClientResources = LettuceTestClientResources.getSharedClientResources(); GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); LettucePoolingClientConfiguration configuration = LettucePoolingClientConfiguration.builder() // .useSsl() // .disablePeerVerification() // .startTls().and() // .poolConfig(poolConfig) // .clientOptions(clientOptions) // .clientResources(sharedClientResources) // .commandTimeout(Duration.ofMinutes(5)) // .shutdownTimeout(Duration.ofHours(2)) // .shutdownQuietPeriod(Duration.ofMinutes(5)) // .build();//from w ww . j av a 2 s . c o m assertThat(configuration.getPoolConfig()).isEqualTo(poolConfig); assertThat(configuration.isUseSsl()).isTrue(); assertThat(configuration.isVerifyPeer()).isFalse(); assertThat(configuration.isStartTls()).isTrue(); assertThat(configuration.getClientOptions()).contains(clientOptions); assertThat(configuration.getClientResources()).contains(sharedClientResources); assertThat(configuration.getCommandTimeout()).isEqualTo(Duration.ofMinutes(5)); assertThat(configuration.getShutdownTimeout()).isEqualTo(Duration.ofHours(2)); assertThat(configuration.getShutdownQuietPeriod()).isEqualTo(Duration.ofMinutes(5)); }