Java Code Examples for org.joda.time.Duration#standardSeconds()
The following examples show how to use
org.joda.time.Duration#standardSeconds() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VirtualRoutingResource.java From cloudstack with Apache License 2.0 | 6 votes |
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException { _name = name; _params = params; String value = (String)params.get("ssh.sleep"); _sleep = NumbersUtil.parseInt(value, 10) * 1000; value = (String)params.get("ssh.retry"); _retry = NumbersUtil.parseInt(value, 36); value = (String)params.get("ssh.port"); _port = NumbersUtil.parseInt(value, 3922); value = (String)params.get("router.aggregation.command.each.timeout"); _eachTimeout = Duration.standardSeconds(NumbersUtil.parseInt(value, (int)VRScripts.VR_SCRIPT_EXEC_TIMEOUT.getStandardSeconds())); if (s_logger.isDebugEnabled()){ s_logger.debug("The router.aggregation.command.each.timeout in seconds is set to " + _eachTimeout.getStandardSeconds()); } if (_vrDeployer == null) { throw new ConfigurationException("Unable to find the resource for VirtualRouterDeployer!"); } _vrAggregateCommandsSet = new HashMap<>(); return true; }
Example 2
Source File: KafkaUnboundedReader.java From beam with Apache License 2.0 | 6 votes |
@VisibleForTesting static Duration resolveDefaultApiTimeout(Read<?, ?> spec) { // KIP-266 - let's allow to configure timeout in consumer settings. This is supported in // higher versions of kafka client. We allow users to set this timeout and it will be // respected // in all places where Beam's KafkaIO handles possibility of API call being blocked. // Later, we should replace the string with ConsumerConfig constant Duration timeout = tryParseDurationFromMillis(spec.getConsumerConfig().get("default.api.timeout.ms")); if (timeout == null) { Duration value = tryParseDurationFromMillis( spec.getConsumerConfig().get(ConsumerConfig.REQUEST_TIMEOUT_MS_CONFIG)); if (value != null) { // 2x request timeout to be compatible with previous version timeout = Duration.millis(2 * value.getMillis()); } } return timeout == null ? Duration.standardSeconds(60) : timeout; }
Example 3
Source File: PubsubUnboundedSinkTest.java From beam with Apache License 2.0 | 5 votes |
@Test public void sendMoreThanOneBatchByNumMessages() throws IOException { List<OutgoingMessage> outgoing = new ArrayList<>(); List<String> data = new ArrayList<>(); int batchSize = 2; int batchBytes = 1000; for (int i = 0; i < batchSize * 10; i++) { String str = String.valueOf(i); outgoing.add( OutgoingMessage.of( com.google.pubsub.v1.PubsubMessage.newBuilder() .setData(ByteString.copyFromUtf8(str)) .build(), TIMESTAMP, getRecordId(str))); data.add(str); } try (PubsubTestClientFactory factory = PubsubTestClient.createFactoryForPublish(TOPIC, outgoing, ImmutableList.of())) { PubsubUnboundedSink sink = new PubsubUnboundedSink( factory, StaticValueProvider.of(TOPIC), TIMESTAMP_ATTRIBUTE, ID_ATTRIBUTE, NUM_SHARDS, batchSize, batchBytes, Duration.standardSeconds(2), RecordIdMethod.DETERMINISTIC); p.apply(Create.of(data)).apply(ParDo.of(new Stamp())).apply(sink); p.run(); } // The PubsubTestClientFactory will assert fail on close if the actual published // message does not match the expected publish message. }
Example 4
Source File: TransactionConfiguration.java From evt4j with MIT License | 5 votes |
public static String getExpirationTime(@NotNull String referenceTime, @Nullable String type) { int TIMESTAMP_LENGTH = 19; Duration expireDuration = Duration.standardSeconds(100); if (type != null && type.equals("everipay")) { expireDuration = Duration.standardSeconds(10); } DateTime dateTime = Utils.getCorrectedTime(referenceTime); DateTime expiration = dateTime.plus(expireDuration); return expiration.toString().substring(0, TIMESTAMP_LENGTH); }
Example 5
Source File: PubsubUnboundedSinkTest.java From beam with Apache License 2.0 | 5 votes |
@Test public void sendOneMessageWithoutAttributes() throws IOException { List<OutgoingMessage> outgoing = ImmutableList.of( OutgoingMessage.of( com.google.pubsub.v1.PubsubMessage.newBuilder() .setData(ByteString.copyFromUtf8(DATA)) .build(), TIMESTAMP, getRecordId(DATA))); try (PubsubTestClientFactory factory = PubsubTestClient.createFactoryForPublish(TOPIC, outgoing, ImmutableList.of())) { PubsubUnboundedSink sink = new PubsubUnboundedSink( factory, StaticValueProvider.of(TOPIC), TIMESTAMP_ATTRIBUTE, ID_ATTRIBUTE, NUM_SHARDS, 1 /* batchSize */, 1 /* batchBytes */, Duration.standardSeconds(2), RecordIdMethod.DETERMINISTIC); p.apply(Create.of(ImmutableList.of(DATA))) .apply(ParDo.of(new Stamp(null /* attributes */))) .apply(sink); p.run(); } // The PubsubTestClientFactory will assert fail on close if the actual published // message does not match the expected publish message. }
Example 6
Source File: FixedWindowsTest.java From beam with Apache License 2.0 | 5 votes |
@Test public void testDisplayData() { Duration offset = Duration.standardSeconds(1234); Duration size = Duration.standardSeconds(2345); FixedWindows fixedWindows = FixedWindows.of(size).withOffset(offset); DisplayData displayData = DisplayData.from(fixedWindows); assertThat(displayData, hasDisplayItem("size", size)); assertThat(displayData, hasDisplayItem("offset", offset)); }
Example 7
Source File: SnippetsTest.java From beam with Apache License 2.0 | 5 votes |
@Test @Category({NeedsRunner.class, UsesStatefulParDo.class}) public void testSlowlyUpdatingSideInputsWindowed() { Instant startAt = Instant.now().minus(Duration.standardMinutes(3)); Duration duration = Duration.standardSeconds(10); Instant stopAt = startAt.plus(duration); Duration interval1 = Duration.standardSeconds(1); Duration interval2 = Duration.standardSeconds(1); File f = null; try { f = File.createTempFile("testSlowlyUpdatingSIWindowed", "txt"); try (BufferedWriter fw = Files.newWriter(f, Charset.forName("UTF-8"))) { fw.append("testdata"); } } catch (IOException e) { Assert.fail("failed to create temp file: " + e.toString()); throw new RuntimeException("Should never reach here"); } PCollection<Long> result = Snippets.PeriodicallyUpdatingSideInputs.main( p, startAt, stopAt, interval1, interval2, f.getPath()); ArrayList<Long> expectedResults = new ArrayList<Long>(); expectedResults.add(0L); for (Long i = startAt.getMillis(); i < stopAt.getMillis(); i = i + interval2.getMillis()) { expectedResults.add(1L); } PAssert.that(result).containsInAnyOrder(expectedResults); p.run().waitUntilFinish(); f.deleteOnExit(); }
Example 8
Source File: VirtualRoutingResource.java From cloudstack with Apache License 2.0 | 5 votes |
private Answer execute(PrepareFilesCommand cmd) { String fileList = String.join(" ", cmd.getFilesToRetrieveList()); _eachTimeout = Duration.standardSeconds(cmd.getTimeout()); final ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), VRScripts.RETRIEVE_DIAGNOSTICS, fileList, _eachTimeout); if (result.isSuccess()) { return new PrepareFilesAnswer(cmd, true, result.getDetails()); } return new PrepareFilesAnswer(cmd, false, result.getDetails()); }
Example 9
Source File: SplittableParDoProcessFnTest.java From beam with Apache License 2.0 | 5 votes |
@Test public void testCheckpointsAfterDuration() throws Exception { // Don't bound number of outputs. int max = Integer.MAX_VALUE; // But bound bundle duration - the bundle should terminate. Duration maxBundleDuration = Duration.standardSeconds(1); // Create an fn that attempts to 2x output more than checkpointing allows. DoFn<Integer, String> fn = new CounterFn(Integer.MAX_VALUE); Instant base = Instant.now(); int baseIndex = 42; ProcessFnTester<Integer, String, OffsetRange, Long, Void> tester = new ProcessFnTester<>( base, fn, BigEndianIntegerCoder.of(), SerializableCoder.of(OffsetRange.class), VoidCoder.of(), max, maxBundleDuration); List<String> elements; tester.startElement(baseIndex, new OffsetRange(0, Long.MAX_VALUE)); // Bundle should terminate, and should do at least some processing. elements = tester.takeOutputElements(); assertFalse(elements.isEmpty()); // Bundle should have run for at least the requested duration. assertThat( Instant.now().getMillis() - base.getMillis(), greaterThanOrEqualTo(maxBundleDuration.getMillis())); }
Example 10
Source File: DynamoDBFibonacciRetryerTest.java From emr-dynamodb-connector with Apache License 2.0 | 5 votes |
@Test(expected = RuntimeException.class) public void testRetryableASEException() throws Exception { AmazonServiceException ase = new AmazonServiceException("Test"); ase.setErrorCode("ArbitRetryableException"); ase.setStatusCode(500); when(call.call()).thenThrow(ase); DynamoDBFibonacciRetryer retryer = new DynamoDBFibonacciRetryer(Duration.standardSeconds(10)); try { retryer.runWithRetry(call, null, null); } finally { verify(call, atLeastOnce()).call(); verify(call, atMost(15)).call(); } }
Example 11
Source File: PubsubUnboundedSinkTest.java From beam with Apache License 2.0 | 4 votes |
@Test public void sendMoreThanOneBatchByByteSize() throws IOException { List<OutgoingMessage> outgoing = new ArrayList<>(); List<String> data = new ArrayList<>(); int batchSize = 100; int batchBytes = 10; int n = 0; while (n < batchBytes * 10) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < batchBytes; i++) { sb.append(String.valueOf(n)); } String str = sb.toString(); outgoing.add( OutgoingMessage.of( com.google.pubsub.v1.PubsubMessage.newBuilder() .setData(ByteString.copyFromUtf8(str)) .build(), TIMESTAMP, getRecordId(str))); data.add(str); n += str.length(); } try (PubsubTestClientFactory factory = PubsubTestClient.createFactoryForPublish(TOPIC, outgoing, ImmutableList.of())) { PubsubUnboundedSink sink = new PubsubUnboundedSink( factory, StaticValueProvider.of(TOPIC), TIMESTAMP_ATTRIBUTE, ID_ATTRIBUTE, NUM_SHARDS, batchSize, batchBytes, Duration.standardSeconds(2), RecordIdMethod.DETERMINISTIC); p.apply(Create.of(data)).apply(ParDo.of(new Stamp())).apply(sink); p.run(); } // The PubsubTestClientFactory will assert fail on close if the actual published // message does not match the expected publish message. }
Example 12
Source File: PersistedCassandraFrameworkConfiguration.java From cassandra-mesos-deprecated with Apache License 2.0 | 4 votes |
@NotNull public Duration healthCheckInterval() { return Duration.standardSeconds(get().getHealthCheckIntervalSeconds()); }
Example 13
Source File: DnsUpdateConfigModule.java From nomulus with Apache License 2.0 | 4 votes |
/** * Timeout on the socket for DNS update requests. */ @Provides @Config("dnsUpdateTimeout") public static Duration provideDnsUpdateTimeout() { return Duration.standardSeconds(30); }
Example 14
Source File: MapFnRunnersTest.java From beam with Apache License 2.0 | 4 votes |
@Test public void testFullWindowedValueMappingWithCompressedWindow() throws Exception { List<WindowedValue<?>> outputConsumer = new ArrayList<>(); PCollectionConsumerRegistry consumers = new PCollectionConsumerRegistry( mock(MetricsContainerStepMap.class), mock(ExecutionStateTracker.class)); consumers.register("outputPC", "pTransformId", outputConsumer::add); PTransformFunctionRegistry startFunctionRegistry = new PTransformFunctionRegistry( mock(MetricsContainerStepMap.class), mock(ExecutionStateTracker.class), "start"); PTransformFunctionRegistry finishFunctionRegistry = new PTransformFunctionRegistry( mock(MetricsContainerStepMap.class), mock(ExecutionStateTracker.class), "finish"); List<ThrowingRunnable> teardownFunctions = new ArrayList<>(); MapFnRunners.forWindowedValueMapFnFactory(this::createMapFunctionForPTransform) .createRunnerForPTransform( PipelineOptionsFactory.create(), null /* beamFnDataClient */, null /* beamFnStateClient */, null /* beamFnTimerClient */, EXPECTED_ID, EXPECTED_PTRANSFORM, Suppliers.ofInstance("57L")::get, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), consumers, startFunctionRegistry, finishFunctionRegistry, teardownFunctions::add, null /* addProgressRequestCallback */, null /* splitListener */, null /* bundleFinalizer */); assertThat(startFunctionRegistry.getFunctions(), empty()); assertThat(finishFunctionRegistry.getFunctions(), empty()); assertThat(teardownFunctions, empty()); assertThat(consumers.keySet(), containsInAnyOrder("inputPC", "outputPC")); IntervalWindow firstWindow = new IntervalWindow(new Instant(0L), Duration.standardMinutes(10L)); IntervalWindow secondWindow = new IntervalWindow(new Instant(-10L), Duration.standardSeconds(22L)); consumers .getMultiplexingConsumer("inputPC") .accept( WindowedValue.of( "abc", new Instant(12), ImmutableSet.of(firstWindow, GlobalWindow.INSTANCE, secondWindow), PaneInfo.NO_FIRING)); assertThat( outputConsumer, containsInAnyOrder( WindowedValue.timestampedValueInGlobalWindow("ABC", new Instant(12)), WindowedValue.of("ABC", new Instant(12), secondWindow, PaneInfo.NO_FIRING), WindowedValue.of("ABC", new Instant(12), firstWindow, PaneInfo.NO_FIRING))); }
Example 15
Source File: RegistryConfig.java From nomulus with Apache License 2.0 | 4 votes |
/** Returns the amount of time a singleton should be cached, before expiring. */ public static Duration getSingletonCacheRefreshDuration() { return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.singletonCacheRefreshSeconds); }
Example 16
Source File: DynamoDBFibonacciRetryerTest.java From emr-dynamodb-connector with Apache License 2.0 | 4 votes |
@Test public void testSuceedCall() throws Exception { DynamoDBFibonacciRetryer retryer = new DynamoDBFibonacciRetryer(Duration.standardSeconds(10)); retryer.runWithRetry(call, null, null); verify(call).call(); }
Example 17
Source File: RegistryConfig.java From nomulus with Apache License 2.0 | 4 votes |
/** Returns the amount of time a singleton should be cached in persist mode, before expiring. */ public static Duration getSingletonCachePersistDuration() { return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.singletonCachePersistSeconds); }
Example 18
Source File: QuotaConfig.java From nomulus with Apache License 2.0 | 4 votes |
/** Returns the refill period for the given {@code userId}. */ Duration getRefillPeriod(String userId) { return Duration.standardSeconds(findQuotaGroup(userId).refillSeconds); }
Example 19
Source File: RegistryConfig.java From nomulus with Apache License 2.0 | 4 votes |
/** * Returns the amount of time an EPP resource or key should be cached in memory before expiring. */ public static Duration getEppResourceCachingDuration() { return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.eppResourceCachingSeconds); }
Example 20
Source File: RegistryConfig.java From nomulus with Apache License 2.0 | 2 votes |
/** * Returns the amount of time a domain label list should be cached in memory before expiring. * * @see google.registry.model.registry.label.ReservedList * @see google.registry.model.registry.label.PremiumList */ public static Duration getDomainLabelListCacheDuration() { return Duration.standardSeconds(CONFIG_SETTINGS.get().caching.domainLabelCachingSeconds); }