コード例 #1
0
  @Override
  public void processElement(ProcessContext c) throws Exception {
    KeyedWorkItem<K, InputT> element = c.element();

    K key = c.element().key();
    TimerInternals timerInternals = c.windowingInternals().timerInternals();
    StateInternals<K> stateInternals = stateInternalsFactory.stateInternalsForKey(key);

    ReduceFnRunner<K, InputT, OutputT, W> reduceFnRunner =
        new ReduceFnRunner<>(
            key,
            windowingStrategy,
            ExecutableTriggerStateMachine.create(
                TriggerStateMachines.stateMachineForTrigger(windowingStrategy.getTrigger())),
            stateInternals,
            timerInternals,
            WindowingInternalsAdapters.outputWindowedValue(c.windowingInternals()),
            WindowingInternalsAdapters.sideInputReader(c.windowingInternals()),
            droppedDueToClosedWindow,
            reduceFn,
            c.getPipelineOptions());

    reduceFnRunner.processElements(element.elementsIterable());
    for (TimerData timer : element.timersIterable()) {
      reduceFnRunner.onTimer(timer);
    }
    reduceFnRunner.persist();
  }
コード例 #2
0
  /**
   * Verifies that the the set of windows that have any state stored is exactly {@code
   * expectedWindows} and that each of these windows has only tags from {@code allowedTags}.
   */
  private void assertHasOnlyGlobalAndAllowedTags(
      Set<W> expectedWindows, Set<StateTag<?>> allowedTags) {
    runner.persist();

    Set<StateNamespace> expectedWindowsSet = new HashSet<>();
    for (W expectedWindow : expectedWindows) {
      expectedWindowsSet.add(windowNamespace(expectedWindow));
    }
    Set<StateNamespace> actualWindows = new HashSet<>();

    for (StateNamespace namespace : stubContexts.state.getNamespacesInUse()) {
      if (namespace instanceof StateNamespaces.GlobalNamespace) {
        continue;
      } else if (namespace instanceof StateNamespaces.WindowNamespace) {
        Set<StateTag<?>> tagsInUse = stubContexts.state.getTagsInUse(namespace);
        if (tagsInUse.isEmpty()) {
          continue;
        }
        actualWindows.add(namespace);
        Set<StateTag<?>> unexpected = Sets.difference(tagsInUse, allowedTags);
        if (unexpected.isEmpty()) {
          continue;
        } else {
          fail(namespace + " has unexpected states: " + tagsInUse);
        }
      } else if (namespace instanceof StateNamespaces.WindowAndTriggerNamespace) {
        Set<StateTag<?>> tagsInUse = stubContexts.state.getTagsInUse(namespace);
        assertTrue(namespace + " contains " + tagsInUse, tagsInUse.isEmpty());
      } else {
        fail("Unrecognized namespace " + namespace);
      }
    }

    assertEquals(expectedWindowsSet, actualWindows);
  }
コード例 #3
0
 public void injectElement(InputT value, Instant timestamp) throws Exception {
   Collection<W> windows =
       windowFn.assignWindows(
           new TriggerTester.StubAssignContext<W>(
               windowFn, value, timestamp, Arrays.asList(GlobalWindow.INSTANCE)));
   logInteraction(
       "Element %s at time %d put in windows %s", value, timestamp.getMillis(), windows);
   runner.processElement(WindowedValue.of(value, timestamp, windows, PaneInfo.NO_FIRING));
 }
コード例 #4
0
 public void fireTimer(W window, Instant timestamp, TimeDomain domain) {
   runner.onTimer(
       TimerData.of(StateNamespaces.window(windowFn.windowCoder(), window), timestamp, domain));
 }
コード例 #5
0
 public void doMerge() throws Exception {
   runner.merge();
 }
コード例 #6
0
 public Instant getWatermarkHold() {
   runner.persist();
   return stubContexts.state.minimumWatermarkHold();
 }
コード例 #7
0
 public boolean isMarkedFinished(W window) {
   return runner.isFinished(window);
 }