/** * Constructs a {@link SingletonAssert} for the value of the provided {@link PCollection} with the * specified reason. The {@link PCollection} must have at most one value per key. * * <p>Note that the actual value must be coded by a {@link KvCoder}, not just any {@code Coder<K, * V>}. */ public static <K, V> SingletonAssert<Map<K, V>> thatMap( String reason, PCollection<KV<K, V>> actual) { @SuppressWarnings("unchecked") KvCoder<K, V> kvCoder = (KvCoder<K, V>) actual.getCoder(); return new PCollectionViewAssert<>( actual, View.asMap(), MapCoder.of(kvCoder.getKeyCoder(), kvCoder.getValueCoder()), PAssertionSite.capture(reason)); }
@Override public PCollectionViewAssert<ElemT, ViewT> inOnTimePane(BoundedWindow window) { return inPane(window, PaneExtractors.onTimePane()); }
/** * Applies an {@link AssertRelation} to check the provided relation against the value of this * assert and the provided expected value. * * <p>Returns this {@code SingletonAssert}. */ private PCollectionViewAssert<ElemT, ViewT> satisfies( AssertRelation<ViewT, ViewT> relation, final ViewT expectedValue) { return satisfies(new CheckRelationAgainstExpected<>(relation, expectedValue, coder)); }
/** * Constructs a {@link SingletonAssert} for the value of the provided {@link PCollection} with the * specified reason. * * <p>Note that the actual value must be coded by a {@link KvCoder}, not just any {@code Coder<K, * V>}. */ public static <K, V> SingletonAssert<Map<K, Iterable<V>>> thatMultimap( String reason, PCollection<KV<K, V>> actual) { @SuppressWarnings("unchecked") KvCoder<K, V> kvCoder = (KvCoder<K, V>) actual.getCoder(); return new PCollectionViewAssert<>( actual, View.asMultimap(), MapCoder.of(kvCoder.getKeyCoder(), IterableCoder.of(kvCoder.getValueCoder())), PAssertionSite.capture(reason)); }
@Override public PCollectionViewAssert<ElemT, ViewT> inFinalPane(BoundedWindow window) { return inPane(window, PaneExtractors.finalPane()); }
@Override public PCollectionViewAssert<ElemT, ViewT> inOnlyPane(BoundedWindow window) { return inPane(window, PaneExtractors.onlyPane(site)); }
/** * Constructs a {@link SingletonAssert} for the value of the provided {@code PCollection * PCollection<T>} with the specified reason. The provided PCollection must be a singleton. */ public static <T> SingletonAssert<T> thatSingleton(String reason, PCollection<T> actual) { return new PCollectionViewAssert<>( actual, View.asSingleton(), actual.getCoder(), PAssertionSite.capture(reason)); }
@Override public PCollectionViewAssert<ElemT, ViewT> isEqualTo(ViewT expectedValue) { return satisfies(new AssertIsEqualToRelation<>(), expectedValue); }
@Override public PCollectionViewAssert<ElemT, ViewT> inEarlyPane(BoundedWindow window) { return inPane(window, PaneExtractors.earlyPanes()); }
@Override public PCollectionViewAssert<ElemT, ViewT> notEqualTo(ViewT expectedValue) { return satisfies(new AssertNotEqualToRelation<>(), expectedValue); }
private PCollectionViewAssert<ElemT, ViewT> inPane( BoundedWindow window, SimpleFunction<Iterable<ValueInSingleWindow<ElemT>>, Iterable<ElemT>> paneExtractor) { return new PCollectionViewAssert<>( actual, view, IntoStaticWindows.of( (Coder) actual.getWindowingStrategy().getWindowFn().windowCoder(), window), paneExtractor, coder, site); }