List of usage examples for org.joda.time Duration millis
public static Duration millis(long millis)
From source file:com.google.cloud.dataflow.sdk.runners.worker.DataflowWorkProgressUpdater.java
License:Apache License
@Override protected void reportProgressHelper() throws Exception { WorkItemStatus status = buildStatus(workItem, false/*completed*/, worker.getOutputCounters(), worker.getOutputMetrics(), options, worker.getWorkerProgress(), dynamicSplitResultToReport, null/*sourceOperationResponse*/, null/*errors*/, getNextReportIndex()); status.setRequestedLeaseDuration(toCloudDuration(Duration.millis(requestedLeaseDurationMs))); WorkItemServiceState result = workUnitClient.reportWorkItemStatus(status); if (result != null) { // Resets state after a successful progress report. dynamicSplitResultToReport = null; nextReportIndex++;/*from ww w . j a v a2 s. com*/ progressReportIntervalMs = nextProgressReportInterval( fromCloudDuration(result.getReportStatusInterval()).getMillis(), leaseRemainingTime(getLeaseExpirationTimestamp(result))); ApproximateProgress suggestedStopPoint = result.getSuggestedStopPoint(); if (suggestedStopPoint != null) { LOG.info("Proposing dynamic split of work unit {} at {}", workString(), suggestedStopPoint); dynamicSplitResultToReport = worker.requestDynamicSplit(toDynamicSplitRequest(suggestedStopPoint)); } } }
From source file:com.google.cloud.dataflow.sdk.transforms.windowing.SlidingWindows.java
License:Apache License
static Duration getDefaultPeriod(Duration size) { if (size.isLongerThan(Duration.standardHours(1))) { return Duration.standardHours(1); }/*from w w w . j a va2 s . c o m*/ if (size.isLongerThan(Duration.standardMinutes(1))) { return Duration.standardMinutes(1); } if (size.isLongerThan(Duration.standardSeconds(1))) { return Duration.standardSeconds(1); } return Duration.millis(1); }
From source file:com.google.cloud.dataflow.sdk.util.GroupAlsoByWindowsProperties.java
License:Apache License
/** * Tests that for empty input and the given {@link WindowingStrategy}, the provided GABW * implementation produces no output.// w w w .j a va 2s. co m * * <p>The input type is deliberately left as a wildcard, since it is not relevant. */ public static <K, InputT, OutputT> void emptyInputEmptyOutput( GroupAlsoByWindowsDoFnFactory<K, InputT, OutputT> gabwFactory) throws Exception { WindowingStrategy<?, IntervalWindow> windowingStrategy = WindowingStrategy .of(FixedWindows.of(Duration.millis(10))); List<?> result = runGABW(gabwFactory, windowingStrategy, (K) null, // key should never be used Collections.<WindowedValue<InputT>>emptyList()); assertThat(result.size(), equalTo(0)); }
From source file:com.google.cloud.dataflow.sdk.util.GroupAlsoByWindowsProperties.java
License:Apache License
/** * Tests that for a simple sequence of elements on the same key, the given GABW implementation * correctly groups them according to fixed windows. *//*from www .ja v a 2s.co m*/ public static void groupsElementsIntoFixedWindows( GroupAlsoByWindowsDoFnFactory<String, String, Iterable<String>> gabwFactory) throws Exception { WindowingStrategy<?, IntervalWindow> windowingStrategy = WindowingStrategy .of(FixedWindows.of(Duration.millis(10))); List<WindowedValue<KV<String, Iterable<String>>>> result = runGABW(gabwFactory, windowingStrategy, "key", WindowedValue.of("v1", new Instant(1), Arrays.asList(window(0, 10)), PaneInfo.NO_FIRING), WindowedValue.of("v2", new Instant(2), Arrays.asList(window(0, 10)), PaneInfo.NO_FIRING), WindowedValue.of("v3", new Instant(13), Arrays.asList(window(10, 20)), PaneInfo.NO_FIRING)); assertThat(result.size(), equalTo(2)); assertThat(result, containsInAnyOrder(gabwResult(window(0, 10), new Instant(1), "v1", "v2"), gabwResult(window(10, 20), new Instant(13), "v3"))); }
From source file:com.google.cloud.dataflow.sdk.util.GroupAlsoByWindowsProperties.java
License:Apache License
/** * Tests that for a simple sequence of elements on the same key, the given GABW implementation * correctly groups them into sliding windows. * * <p>In the input here, each element occurs in multiple windows. */// ww w . j a v a 2 s . co m public static void groupsElementsIntoSlidingWindows( GroupAlsoByWindowsDoFnFactory<String, String, Iterable<String>> gabwFactory) throws Exception { WindowingStrategy<?, IntervalWindow> windowingStrategy = WindowingStrategy .of(SlidingWindows.of(Duration.millis(20)).every(Duration.millis(10))); List<WindowedValue<KV<String, Iterable<String>>>> result = runGABW(gabwFactory, windowingStrategy, "key", WindowedValue.of("v1", new Instant(5), Arrays.asList(window(-10, 10), window(0, 20)), PaneInfo.NO_FIRING), WindowedValue.of("v2", new Instant(15), Arrays.asList(window(0, 20), window(10, 30)), PaneInfo.NO_FIRING)); assertThat(result.size(), equalTo(3)); assertThat(result, containsInAnyOrder(gabwResult(window(-10, 10), new Instant(5), "v1"), gabwResult(window(0, 20), new Instant(10), "v1", "v2"), gabwResult(window(10, 30), new Instant(20), "v2"))); }
From source file:com.google.cloud.dataflow.sdk.util.GroupAlsoByWindowsProperties.java
License:Apache License
/** * Tests that for a simple sequence of elements on the same key, the given GABW implementation * correctly groups and combines them according to sliding windows. * * <p>In the input here, each element occurs in multiple windows. *//* ww w . j av a 2s .c om*/ public static void combinesElementsInSlidingWindows( GroupAlsoByWindowsDoFnFactory<String, Long, Long> gabwFactory, CombineFn<Long, ?, Long> combineFn) throws Exception { WindowingStrategy<?, IntervalWindow> windowingStrategy = WindowingStrategy .of(SlidingWindows.of(Duration.millis(20)).every(Duration.millis(10))); List<WindowedValue<KV<String, Long>>> result = runGABW(gabwFactory, windowingStrategy, "k", WindowedValue.of(1L, new Instant(5), Arrays.asList(window(-10, 10), window(0, 20)), PaneInfo.NO_FIRING), WindowedValue.of(2L, new Instant(15), Arrays.asList(window(0, 20), window(10, 30)), PaneInfo.NO_FIRING), WindowedValue.of(4L, new Instant(18), Arrays.asList(window(0, 20), window(10, 30)), PaneInfo.NO_FIRING)); assertThat(result.size(), equalTo(3)); assertThat(result, contains( WindowMatchers.isSingleWindowedValue( KvMatcher.isKv(equalTo("k"), equalTo(combineFn.apply(ImmutableList.of(1L)))), 5, // aggregate timestamp -10, // window start 10), // window end WindowMatchers.isSingleWindowedValue( KvMatcher.isKv(equalTo("k"), equalTo(combineFn.apply(ImmutableList.of(1L, 2L, 4L)))), 10, // aggregate timestamp 0, // window start 20), // window end WindowMatchers.isSingleWindowedValue( KvMatcher.isKv(equalTo("k"), equalTo(combineFn.apply(ImmutableList.of(2L, 4L)))), 20, // aggregate timestamp 10, // window start 30))); // window end }
From source file:com.google.cloud.dataflow.sdk.util.GroupAlsoByWindowsProperties.java
License:Apache License
/** * Tests that the given GABW implementation correctly groups elements that fall into overlapping * windows that are not merged.// w w w . j a va2 s . c o m */ public static void groupsIntoOverlappingNonmergingWindows( GroupAlsoByWindowsDoFnFactory<String, String, Iterable<String>> gabwFactory) throws Exception { WindowingStrategy<?, IntervalWindow> windowingStrategy = WindowingStrategy .of(FixedWindows.of(Duration.millis(10))); List<WindowedValue<KV<String, Iterable<String>>>> result = runGABW(gabwFactory, windowingStrategy, "key", WindowedValue.of("v1", new Instant(1), Arrays.asList(window(0, 5)), PaneInfo.NO_FIRING), WindowedValue.of("v2", new Instant(4), Arrays.asList(window(1, 5)), PaneInfo.NO_FIRING), WindowedValue.of("v3", new Instant(4), Arrays.asList(window(0, 5)), PaneInfo.NO_FIRING)); assertThat(result.size(), equalTo(2)); assertThat(result, containsInAnyOrder(gabwResult(window(0, 5), new Instant(1), "v1", "v3"), gabwResult(window(1, 5), new Instant(4), "v2"))); }
From source file:com.google.cloud.dataflow.sdk.util.GroupAlsoByWindowsProperties.java
License:Apache License
/** * Tests that the given GABW implementation correctly groups elements into merged sessions. *//*from www. ja v a2 s .c o m*/ public static void groupsElementsInMergedSessions( GroupAlsoByWindowsDoFnFactory<String, String, Iterable<String>> gabwFactory) throws Exception { WindowingStrategy<?, IntervalWindow> windowingStrategy = WindowingStrategy .of(Sessions.withGapDuration(Duration.millis(10))); List<WindowedValue<KV<String, Iterable<String>>>> result = runGABW(gabwFactory, windowingStrategy, "key", 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(window(15, 25)), PaneInfo.NO_FIRING)); assertThat(result.size(), equalTo(2)); assertThat(result, containsInAnyOrder(gabwResult(window(0, 15), new Instant(0), "v1", "v2"), gabwResult(window(15, 25), new Instant(15), "v3"))); }
From source file:com.google.cloud.dataflow.sdk.util.GroupAlsoByWindowsProperties.java
License:Apache License
/** * Tests that the given {@link GroupAlsoByWindowsDoFn} implementation combines elements per * session window correctly according to the provided {@link CombineFn}. *//*from ww w.j av a 2s. com*/ public static void combinesElementsPerSession(GroupAlsoByWindowsDoFnFactory<String, Long, Long> gabwFactory, CombineFn<Long, ?, Long> combineFn) throws Exception { WindowingStrategy<?, IntervalWindow> windowingStrategy = WindowingStrategy .of(Sessions.withGapDuration(Duration.millis(10))); 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(window(15, 25)), PaneInfo.NO_FIRING)); assertThat(result, contains( WindowMatchers.isSingleWindowedValue( KvMatcher.isKv(equalTo("k"), equalTo(combineFn.apply(ImmutableList.of(1L, 2L)))), 0, // aggregate timestamp 0, // window start 15), // window end WindowMatchers.isSingleWindowedValue( KvMatcher.isKv(equalTo("k"), equalTo(combineFn.apply(ImmutableList.of(4L)))), 15, // aggregate timestamp 15, // window start 25))); // window end }
From source file:com.google.cloud.dataflow.sdk.util.GroupAlsoByWindowsProperties.java
License:Apache License
/** * Tests that for a simple sequence of elements on the same key, the given GABW implementation * correctly groups them according to fixed windows and also sets the output timestamp * according to the policy {@link OutputTimeFns#outputAtEndOfWindow()}. *//*from ww w .j a v a 2s . c om*/ public static void groupsElementsIntoFixedWindowsWithEndOfWindowTimestamp( GroupAlsoByWindowsDoFnFactory<String, String, Iterable<String>> gabwFactory) throws Exception { WindowingStrategy<?, IntervalWindow> windowingStrategy = WindowingStrategy .of(FixedWindows.of(Duration.millis(10))).withOutputTimeFn(OutputTimeFns.outputAtEndOfWindow()); List<WindowedValue<KV<String, Iterable<String>>>> result = runGABW(gabwFactory, windowingStrategy, "key", WindowedValue.of("v1", new Instant(1), Arrays.asList(window(0, 10)), PaneInfo.NO_FIRING), WindowedValue.of("v2", new Instant(2), Arrays.asList(window(0, 10)), PaneInfo.NO_FIRING), WindowedValue.of("v3", new Instant(13), Arrays.asList(window(10, 20)), PaneInfo.NO_FIRING)); assertThat(result.size(), equalTo(2)); assertThat(result, containsInAnyOrder(gabwResult(window(0, 10), window(0, 10).maxTimestamp(), "v1", "v2"), gabwResult(window(10, 20), window(10, 20).maxTimestamp(), "v3"))); }