PTransformMatchers { public static PTransformMatcher createViewWithViewFn(final Class<? extends ViewFn> viewFnType) { return application -> { if (!(application.getTransform() instanceof CreatePCollectionView)) { return false; } CreatePCollectionView<?, ?> createView = (CreatePCollectionView<?, ?>) application.getTransform(); ViewFn<?, ?> viewFn = createView.getView().getViewFn(); return viewFn.getClass().equals(viewFnType); }; } private  PTransformMatchers(); static PTransformMatcher urnEqualTo(String urn); static PTransformMatcher classEqualTo(Class<? extends PTransform> clazz); static PTransformMatcher requiresStableInputParDoSingle(); static PTransformMatcher requiresStableInputParDoMulti(); static PTransformMatcher splittableParDoSingle(); static PTransformMatcher stateOrTimerParDoSingle(); static PTransformMatcher splittableParDoMulti(); static PTransformMatcher splittableParDo(); static PTransformMatcher splittableProcessKeyedBounded(); static PTransformMatcher splittableProcessKeyedUnbounded(); static PTransformMatcher stateOrTimerParDo(); static PTransformMatcher stateOrTimerParDoMulti(); static PTransformMatcher parDoWithFnType(final Class<? extends DoFn> fnType); static PTransformMatcher createViewWithViewFn(final Class<? extends ViewFn> viewFnType); static PTransformMatcher emptyFlatten(); static PTransformMatcher flattenWithDuplicateInputs(); static PTransformMatcher groupWithShardableStates(); static PTransformMatcher writeWithRunnerDeterminedSharding();  }
@Test public void createViewWithViewFn() { PCollection<Integer> input = p.apply(Create.of(1)); PCollectionView<Iterable<Integer>> view = input.apply(View.asIterable()); ViewFn<?, ?> viewFn = view.getViewFn(); CreatePCollectionView<?, ?> createView = CreatePCollectionView.of(view); PTransformMatcher matcher = PTransformMatchers.createViewWithViewFn(viewFn.getClass()); assertThat(matcher.matches(getAppliedTransform(createView)), is(true)); }
@Test public void createViewWithViewFnDifferentViewFn() { PCollection<Integer> input = p.apply(Create.of(1)); PCollectionView<Iterable<Integer>> view = input.apply(View.asIterable()); IterableViewFn<Integer> viewFn = new PCollectionViews.IterableViewFn<Integer>(() -> TypeDescriptors.integers()) {}; CreatePCollectionView<?, ?> createView = CreatePCollectionView.of(view); PTransformMatcher matcher = PTransformMatchers.createViewWithViewFn(viewFn.getClass()); assertThat(matcher.matches(getAppliedTransform(createView)), is(false)); }
@Test public void createViewWithViewFnNotCreatePCollectionView() { PCollection<Integer> input = p.apply(Create.of(1)); PCollectionView<Iterable<Integer>> view = input.apply(View.asIterable()); PTransformMatcher matcher = PTransformMatchers.createViewWithViewFn(view.getViewFn().getClass()); assertThat(matcher.matches(getAppliedTransform(View.asIterable())), is(false)); }