List of usage examples for org.joda.time Duration millis
public static Duration millis(long millis)
From source file:org.apache.beam.runners.dataflow.worker.util.GroupAlsoByWindowProperties.java
License:Apache License
/** * Tests that the given GABW implementation correctly groups elements into merged sessions with * output timestamps at the end of the merged window. *///from www .j a v a 2s. c o m public static void groupsElementsInMergedSessionsWithLatestTimestamp( GroupAlsoByWindowDoFnFactory<String, String, Iterable<String>> gabwFactory) throws Exception { WindowingStrategy<?, IntervalWindow> windowingStrategy = WindowingStrategy .of(Sessions.withGapDuration(Duration.millis(10))).withTimestampCombiner(TimestampCombiner.LATEST); BoundedWindow unmergedWindow = window(15, 25); List<WindowedValue<KV<String, Iterable<String>>>> result = runGABW(gabwFactory, windowingStrategy, "k", WindowedValue.of("v1", new Instant(0), Arrays.asList(window(0, 10)), PaneInfo.NO_FIRING), WindowedValue.of("v2", new Instant(5), Arrays.asList(window(5, 15)), PaneInfo.NO_FIRING), WindowedValue.of("v3", new Instant(15), Arrays.asList(unmergedWindow), PaneInfo.NO_FIRING)); assertThat(result, hasSize(2)); BoundedWindow mergedWindow = window(0, 15); TimestampedValue<KV<String, Iterable<String>>> item0 = getOnlyElementInWindow(result, mergedWindow); assertThat(item0.getValue().getValue(), containsInAnyOrder("v1", "v2")); assertThat(item0.getTimestamp(), equalTo(new Instant(5))); TimestampedValue<KV<String, Iterable<String>>> item1 = getOnlyElementInWindow(result, unmergedWindow); assertThat(item1.getValue().getValue(), contains("v3")); assertThat(item1.getTimestamp(), equalTo(new Instant(15))); }
From source file:org.apache.beam.runners.dataflow.worker.util.GroupAlsoByWindowProperties.java
License:Apache License
/** * Tests that the given {@link BatchGroupAlsoByWindowFn} implementation combines elements per * session window correctly according to the provided {@link CombineFn}. *///from w w w. j a v a2 s . co m public static void combinesElementsPerSessionWithEndOfWindowTimestamp( GroupAlsoByWindowDoFnFactory<String, Long, Long> gabwFactory, CombineFn<Long, ?, Long> combineFn) throws Exception { WindowingStrategy<?, IntervalWindow> windowingStrategy = WindowingStrategy .of(Sessions.withGapDuration(Duration.millis(10))) .withTimestampCombiner(TimestampCombiner.END_OF_WINDOW); BoundedWindow secondWindow = window(15, 25); List<WindowedValue<KV<String, Long>>> result = runGABW(gabwFactory, windowingStrategy, "k", WindowedValue.of(1L, new Instant(0), Arrays.asList(window(0, 10)), PaneInfo.NO_FIRING), WindowedValue.of(2L, new Instant(5), Arrays.asList(window(5, 15)), PaneInfo.NO_FIRING), WindowedValue.of(4L, new Instant(15), Arrays.asList(secondWindow), PaneInfo.NO_FIRING)); assertThat(result, hasSize(2)); BoundedWindow firstResultWindow = window(0, 15); TimestampedValue<KV<String, Long>> item0 = getOnlyElementInWindow(result, firstResultWindow); assertThat(item0.getValue().getValue(), equalTo(combineFn.apply(ImmutableList.of(1L, 2L)))); assertThat(item0.getTimestamp(), equalTo(firstResultWindow.maxTimestamp())); TimestampedValue<KV<String, Long>> item1 = getOnlyElementInWindow(result, secondWindow); assertThat(item1.getValue().getValue(), equalTo(combineFn.apply(ImmutableList.of(4L)))); assertThat(item1.getTimestamp(), equalTo(secondWindow.maxTimestamp())); }
From source file:org.apache.beam.runners.dataflow.worker.windmill.GrpcWindmillServer.java
License:Apache License
private synchronized void initializeLocalHost(int port) throws IOException { this.logEveryNStreamFailures = 1; this.maxBackoff = Duration.millis(500); this.unaryDeadlineSeconds = 10; // For local testing use a short deadline. Channel channel = localhostChannel(port); if (streamingEngineEnabled()) { this.stubList.add(CloudWindmillServiceV1Alpha1Grpc.newStub(channel)); this.syncStubList.add(CloudWindmillServiceV1Alpha1Grpc.newBlockingStub(channel)); } else {/* w ww . j av a 2s . co m*/ this.syncApplianceStub = WindmillApplianceGrpc.newBlockingStub(channel); } }
From source file:org.apache.beam.runners.direct.ExecutorServiceParallelExecutor.java
License:Apache License
@Override public State waitUntilFinish(Duration duration) throws Exception { Instant completionTime;//from w w w. j a v a 2 s . com if (duration.equals(Duration.ZERO)) { completionTime = new Instant(Long.MAX_VALUE); } else { completionTime = Instant.now().plus(duration); } VisibleExecutorUpdate update = null; while (Instant.now().isBefore(completionTime) && (update == null || isTerminalStateUpdate(update))) { // Get an update; don't block forever if another thread has handled it. The call to poll will // wait the entire timeout; this call primarily exists to relinquish any core. update = visibleUpdates.tryNext(Duration.millis(25L)); if (update == null && pipelineState.get().isTerminal()) { // there are no updates to process and no updates will ever be published because the // executor is shutdown return pipelineState.get(); } else if (update != null && update.thrown.isPresent()) { Throwable thrown = update.thrown.get(); if (thrown instanceof Exception) { throw (Exception) thrown; } else if (thrown instanceof Error) { throw (Error) thrown; } else { throw new Exception("Unknown Type of Throwable", thrown); } } } return pipelineState.get(); }
From source file:org.apache.beam.runners.reference.JobServicePipelineResult.java
License:Apache License
@Nullable @Override/*ww w.j av a 2 s. c o m*/ public State waitUntilFinish(Duration duration) { if (duration.compareTo(Duration.millis(1)) < 1) { // Equivalent to infinite timeout. return waitUntilFinish(); } else { CompletableFuture<State> result = CompletableFuture.supplyAsync(this::waitUntilFinish); try { return result.get(duration.getMillis(), TimeUnit.MILLISECONDS); } catch (TimeoutException e) { // Null result indicates a timeout. return null; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } } }
From source file:org.apache.beam.runners.samza.SamzaPipelineResult.java
License:Apache License
@Override public State cancel() { LOG.info("Start to cancel samza pipeline..."); runner.kill();/*w ww. j av a 2s . c o m*/ LOG.info("Start awaiting finish for {} ms.", shutdownTiemoutMs); return waitUntilFinish(Duration.millis(shutdownTiemoutMs)); }
From source file:org.apache.beam.runners.spark.PipelineRule.java
License:Apache License
public Duration batchDuration() { return Duration.millis(delegate.options.getBatchIntervalMillis()); }
From source file:org.apache.beam.runners.spark.SparkPipelineResult.java
License:Apache License
@Override public PipelineResult.State waitUntilFinish() { return waitUntilFinish(Duration.millis(-1)); }
From source file:org.apache.beam.runners.spark.translation.EvaluationContext.java
License:Apache License
@Override public State waitUntilFinish() { return waitUntilFinish(Duration.millis(-1)); }
From source file:org.apache.beam.sdk.extensions.sql.impl.rule.AggregateWindowFactory.java
License:Apache License
private static Duration durationParameter(List<RexNode> parameters, int parameterIndex) { return Duration.millis(intValue(parameters.get(parameterIndex))); }