List of usage examples for org.joda.time Duration millis
public static Duration millis(long millis)
From source file:org.apache.beam.sdk.extensions.sql.impl.rule.BeamAggregationRule.java
License:Apache License
private static Duration durationParameter(List<RexNode> parameters, int parameterIndex) { return Duration.millis(longValue(parameters.get(parameterIndex))); }
From source file:org.apache.beam.sdk.io.elasticsearch.ElasticsearchIOTestCommon.java
License:Apache License
/** * Test that retries are invoked when Elasticsearch returns a specific error code. We invoke this * by issuing corrupt data and retrying on the `400` error code. Normal behaviour is to retry on * `429` only but that is difficult to simulate reliably. The logger is used to verify expected * behavior./*from www . ja va 2s . co m*/ */ void testWriteRetry() throws Throwable { expectedException.expectCause(isA(IOException.class)); // max attempt is 3, but retry is 2 which excludes 1st attempt when error was identified and // retry started. expectedException .expectMessage(String.format(ElasticsearchIO.Write.WriteFn.RETRY_FAILED_LOG, EXPECTED_RETRIES)); ElasticsearchIO.Write write = ElasticsearchIO.write().withConnectionConfiguration(connectionConfiguration) .withRetryConfiguration(ElasticsearchIO.RetryConfiguration .create(MAX_ATTEMPTS, Duration.millis(35000)).withRetryPredicate(CUSTOM_RETRY_PREDICATE)); pipeline.apply(Create.of(Arrays.asList(BAD_FORMATTED_DOC))).apply(write); pipeline.run(); }
From source file:org.apache.beam.sdk.io.elasticsearch.ElasticsearchIOTestCommon.java
License:Apache License
void testWriteRetryValidRequest() throws Exception { Write write = ElasticsearchIO.write().withConnectionConfiguration(connectionConfiguration) .withRetryConfiguration(ElasticsearchIO.RetryConfiguration .create(MAX_ATTEMPTS, Duration.millis(35000)).withRetryPredicate(CUSTOM_RETRY_PREDICATE)); executeWriteTest(write);/*from ww w . ja v a2 s.c om*/ }
From source file:org.apache.beam.sdk.io.gcp.bigquery.FakeJobService.java
License:Apache License
@Override public Job pollJob(JobReference jobRef, int maxAttempts) throws InterruptedException { BackOff backoff = BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.withMaxRetries(maxAttempts) .withInitialBackoff(Duration.millis(10)).withMaxBackoff(Duration.standardSeconds(1)).backoff()); Sleeper sleeper = Sleeper.DEFAULT;/*w w w .jav a2s.c o m*/ try { do { Job job = getJob(jobRef); if (job != null) { JobStatus status = job.getStatus(); if (status != null && ("DONE".equals(status.getState()) || "FAILED".equals(status.getState()))) { return job; } } } while (BackOffUtils.next(sleeper, backoff)); } catch (IOException e) { return null; } return null; }
From source file:org.apache.beam.sdk.io.synthetic.SyntheticSourceOptions.java
License:Apache License
/** * Generates a random delay value for the synthetic source initialization using the distribution * defined by {@link #initializeDelayDistribution}. *//*from w w w. j a v a 2 s .c o m*/ public Duration nextInitializeDelay(long seed) { return Duration.millis((long) initializeDelayDistribution.sample(seed)); }
From source file:org.apache.beam.sdk.io.synthetic.SyntheticSourceOptions.java
License:Apache License
/** * Generates a random delay value between event and processing time using the distribution defined * by {@link #processingTimeDelayDistribution}. *//* w ww .j a va2 s. co m*/ public Duration nextProcessingTimeDelay(long seed) { return Duration.millis((long) processingTimeDelayDistribution.sample(seed)); }
From source file:org.apache.beam.sdk.io.synthetic.SyntheticStep.java
License:Apache License
private KV<byte[], byte[]> outputElement(byte[] inputKey, byte[] inputValue, long inputValueHashcode, int index, Random random) {// www.j a va 2 s. c om long seed = options.hashFunction().hashLong(inputValueHashcode + index).asLong(); Duration delay = Duration.millis(options.nextDelay(seed)); long millisecondsSpentSleeping = 0; while (delay.getMillis() > 0) { millisecondsSpentSleeping += delay(delay, options.cpuUtilizationInMixedDelay, options.delayType, random); if (isWithinThroughputLimit()) { break; } else { // try an extra delay of 1 millisecond delay = Duration.millis(1); } } reportThrottlingTimeMetrics(millisecondsSpentSleeping); if (options.preservesInputKeyDistribution) { // Generate the new byte array value whose hashcode will be // used as seed to initialize a Random object in next stages. byte[] newValue = new byte[inputValue.length]; random.nextBytes(newValue); return KV.of(inputKey, newValue); } else { return options.genKvPair(seed); } }
From source file:org.apache.beam.sdk.io.synthetic.SyntheticStep.java
License:Apache License
@StartBundle public void startBundle() throws Exception { if (options.perBundleDelay > 0) { SyntheticDelay.delay(Duration.millis(options.perBundleDelay), options.cpuUtilizationInMixedDelay, options.perBundleDelayType, new Random()); }// w w w . ja v a 2 s . c o m }
From source file:org.apache.beam.sdk.io.synthetic.SyntheticWatermark.java
License:Apache License
/** Calculates new watermark value and returns it if it's greater than the previous one. */ Instant calculateNew(long currentOffset, Instant processingTime) { // the source has seen all elements so the watermark is "+infinity" if (currentOffset >= endOffset) { watermark = BoundedWindow.TIMESTAMP_MAX_VALUE; return watermark; }/*from ww w .j av a 2 s . c o m*/ Instant newWatermark = findLowestEventTimeInAdvance(currentOffset, processingTime) .minus(Duration.millis(options.watermarkDriftMillis)); if (newWatermark.getMillis() > watermark.getMillis()) { watermark = newWatermark; } return watermark; }
From source file:org.apache.beam.sdk.testing.StaticWindows.java
License:Apache License
@Override public WindowMappingFn<BoundedWindow> getDefaultWindowMappingFn() { return new WindowMappingFn<BoundedWindow>(Duration.millis(Long.MAX_VALUE)) { @Override//www .j a v a 2s .com public BoundedWindow getSideInputWindow(BoundedWindow mainWindow) { checkArgument(windows.get().contains(mainWindow), "%s only supports side input windows for main input windows that it contains", StaticWindows.class.getSimpleName()); return mainWindow; } }; }