PTransformMatchers { public static PTransformMatcher writeWithRunnerDeterminedSharding() { return application -> { if (WRITE_FILES_TRANSFORM_URN.equals( PTransformTranslation.urnForTransformOrNull(application.getTransform()))) { try { return WriteFilesTranslation.isRunnerDeterminedSharding((AppliedPTransform) application); } catch (IOException exc) { throw new RuntimeException( String.format( "Transform with URN %s failed to parse: %s", WRITE_FILES_TRANSFORM_URN, application.getTransform()), exc); } } return false; }; } 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 writeWithRunnerDeterminedSharding() { ResourceId outputDirectory = LocalResources.fromString("/foo/bar", true ); FilenamePolicy policy = DefaultFilenamePolicy.fromStandardParameters( StaticValueProvider.of(outputDirectory), DefaultFilenamePolicy.DEFAULT_UNWINDOWED_SHARD_TEMPLATE, "", false); WriteFiles<Integer, Void, Integer> write = WriteFiles.to( new FileBasedSink<Integer, Void, Integer>( StaticValueProvider.of(outputDirectory), DynamicFileDestinations.constant(policy)) { @Override public WriteOperation<Void, Integer> createWriteOperation() { return null; } }); assertThat( PTransformMatchers.writeWithRunnerDeterminedSharding().matches(appliedWrite(write)), is(true)); WriteFiles<Integer, Void, Integer> withStaticSharding = write.withNumShards(3); assertThat( PTransformMatchers.writeWithRunnerDeterminedSharding() .matches(appliedWrite(withStaticSharding)), is(false)); WriteFiles<Integer, Void, Integer> withCustomSharding = write.withSharding(Sum.integersGlobally().asSingletonView()); assertThat( PTransformMatchers.writeWithRunnerDeterminedSharding() .matches(appliedWrite(withCustomSharding)), is(false)); }