Skip to content

Commit

Permalink
[BEAM-3640] Part1: Update Checkstyle to enforce blank lines for impor…
Browse files Browse the repository at this point in the history
…ts and classdefs
  • Loading branch information
dkulp committed Feb 16, 2018
1 parent bb8c12c commit 1cbc58b
Show file tree
Hide file tree
Showing 19 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ FieldFn<InputT> getFieldFn() {
return this.fieldFn;
}
}

/** Convert each key/score pair into a BigQuery TableRow as specified by fieldFn. */
protected class BuildRowFn extends DoFn<InputT, TableRow> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ public FunctionSpec translate(
return new RawWriteFiles(protoTransform, rehydratedComponents);
}
}

/** Registers {@link WriteFilesTranslator}. */
@AutoService(TransformPayloadTranslatorRegistrar.class)
public static class Registrar implements TransformPayloadTranslatorRegistrar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,5 @@ public boolean equals(Object other) {
public int hashCode() {
return TestCombineFnWithContext.class.hashCode();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public PCollection<Integer> expand(PCollection<KV<String, Integer>> input) {
input.getPipeline(), input.getWindowingStrategy(), input.isBounded(), VarIntCoder.of());
}
}

PTransformMatcher matcher = PTransformMatchers.classEqualTo(MyPTransform.class);
MyPTransform subclass = new MyPTransform() {};

Expand Down Expand Up @@ -160,7 +161,9 @@ public void simpleProcess(ProcessContext ctxt) {
ctxt.output(ctxt.element().getValue() + 1);
}
};

private abstract static class SomeTracker extends RestrictionTracker<Void, Void> {}

private DoFn<KV<String, Integer>, Integer> splittableDoFn =
new DoFn<KV<String, Integer>, Integer>() {
@ProcessElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,5 @@ public void processElement(
Integer currentValue = MoreObjects.firstNonNull(state.read(), 0);
state.write(currentValue + 1);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public void keyedBundleDecodeFailsAddFails() {
}

static class Record {}

static class RecordNoEncodeCoder extends AtomicCoder<Record> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public Map<PValue, ReplacementOutput> mapOutputs(
return ReplacementOutputs.singleton(outputs, newOutput);
}
}

private static class MultiOutputOverrideFactory<K, InputT, OutputT>
implements PTransformOverrideFactory<
PCollection<KV<K, InputT>>, PCollectionTuple, ParDo.MultiOutput<KV<K, InputT>, OutputT>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ public void visitValue(PValue value, Node producer) {
}
}
}

BoundednessVisitor visitor = new BoundednessVisitor();
p.traverseTopologically(visitor);
return visitor.boundedness == IsBounded.UNBOUNDED;
Expand Down Expand Up @@ -1540,6 +1541,7 @@ public void process(ProcessContext c) throws Exception {
.setCoder(source.getOutputCoder());
}
}

/**
* A marker {@link DoFn} for writing the contents of a {@link PCollection} to a streaming
* {@link PCollectionView} backend implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public void testOnErrorCancelsOutstanding() throws Exception {
client.handle(BeamFnApi.InstructionRequest.newBuilder().setInstructionId(id).build());

class FrazzleException extends Exception {}

client.asResponseObserver().onError(new FrazzleException());

thrown.expect(ExecutionException.class);
Expand Down
8 changes: 8 additions & 0 deletions sdks/java/build-tools/src/main/resources/beam/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,14 @@ page at http:https://checkstyle.sourceforge.net/config.html -->
WHITESPACE CHECKS
-->
<module name="EmptyLineSeparator">
<property name="allowNoEmptyLineBetweenFields" value="false"/>
<property name="allowMultipleEmptyLines" value="true"/>
<property name="allowMultipleEmptyLinesInsideClassMembers" value="true"/>
<property name="tokens" value="IMPORT,CLASS_DEF" />
<!-- eventually start adding: ,INTERFACE_DEF,ENUM_DEF,
STATIC_INIT,INSTANCE_INIT,METHOD_DEF,CTOR_DEF, VARIABLE_DEF -->
</module>

<module name="WhitespaceAround">
<!-- Checks that various tokens are surrounded by whitespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ public abstract static class ProcessContextParameter extends Parameter {
public abstract static class OnTimerContextParameter extends Parameter {
OnTimerContextParameter() {}
}

/**
* Descriptor for a {@link Parameter} of type {@link BoundedWindow}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,14 @@ public PCollection<Integer> expand(PCollection<Integer> input) {
return input.apply("custom_name", Sum.integersGlobally());
}
}

class ReplacementTransform extends PTransform<PCollection<Integer>, PCollection<Integer>> {
@Override
public PCollection<Integer> expand(PCollection<Integer> input) {
return input.apply("custom_name", Max.integersGlobally());
}
}

class ReplacementOverrideFactory
implements PTransformOverrideFactory<
PCollection<Integer>, PCollection<Integer>, OriginalTransform> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ private static class NonDeterministicArray {
@SuppressWarnings("unused")
private UnorderedMapClass[] arrayField;
}

@Test
public void testDeterministicNonDeterministicArray() {
assertNonDeterministic(AvroCoder.of(NonDeterministicArray.class),
Expand Down Expand Up @@ -714,7 +715,9 @@ private abstract static class DeterministicUnionBase {}

@Union({ UnionCase1.class, UnionCase2.class, UnionCase3.class })
private abstract static class NonDeterministicUnionBase {}

private static class UnionCase1 extends DeterministicUnionBase {}

private static class UnionCase2 extends DeterministicUnionBase {
@SuppressWarnings("unused")
String field;
Expand Down Expand Up @@ -903,6 +906,7 @@ private static class SomeGeneric<T> {
@SuppressWarnings("unused")
private T foo;
}

private static class Foo {
@SuppressWarnings("unused")
String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void processElement(ProcessContext c, BoundedWindow window) {
+ ":" + window.maxTimestamp().getMillis());
}
}

static class TestNoOutputDoFn extends DoFn<Integer, String> {
@ProcessElement
public void processElement(DoFn<Integer, String>.ProcessContext c) throws Exception {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class MockFn extends DoFn<String, String> {
@ProcessElement
public void processElement(ProcessContext c) throws Exception {}
}

MockFn mockFn = mock(MockFn.class);
assertEquals(stop(), invokeProcessElement(mockFn));
verify(mockFn).processElement(mockProcessContext);
Expand Down Expand Up @@ -180,6 +181,7 @@ class MockFn extends DoFn<String, String> {
@DoFn.ProcessElement
public void processElement(ProcessContext c, IntervalWindow w) throws Exception {}
}

MockFn fn = mock(MockFn.class);
assertEquals(stop(), invokeProcessElement(fn));
verify(fn).processElement(mockProcessContext, mockWindow);
Expand All @@ -204,6 +206,7 @@ class MockFn extends DoFn<String, String> {
public void processElement(ProcessContext c, @StateId(stateId) ValueState<Integer> valueState)
throws Exception {}
}

MockFn fn = mock(MockFn.class);
assertEquals(stop(), invokeProcessElement(fn));
verify(fn).processElement(mockProcessContext, mockState);
Expand All @@ -230,6 +233,7 @@ public void processElement(ProcessContext c, @TimerId(timerId) Timer timer)
@OnTimer(timerId)
public void onTimer() {}
}

MockFn fn = mock(MockFn.class);
assertEquals(stop(), invokeProcessElement(fn));
verify(fn).processElement(mockProcessContext, mockTimer);
Expand All @@ -254,6 +258,7 @@ public SomeRestrictionTracker newTracker(SomeRestriction restriction) {
return null;
}
}

MockFn fn = mock(MockFn.class);
when(fn.processElement(mockProcessContext, null)).thenReturn(resume());
assertEquals(resume(), invokeProcessElement(fn));
Expand All @@ -277,6 +282,7 @@ public void before() {}
@Teardown
public void after() {}
}

MockFn fn = mock(MockFn.class);
DoFnInvoker<String, String> invoker = DoFnInvokers.invokerFor(fn);
invoker.invokeSetup();
Expand Down Expand Up @@ -446,6 +452,7 @@ public RestrictionWithDefaultTracker getInitialRestriction(String element) {
return null;
}
}

MockFn fn = mock(MockFn.class);
DoFnInvoker<String, String> invoker = DoFnInvokers.invokerFor(fn);

Expand Down Expand Up @@ -760,7 +767,7 @@ public void onMyTimer(IntervalWindow w) {
static class StableNameTestDoFn extends DoFn<Void, Void> {
@ProcessElement
public void process() {}
};
}

/**
* This is a change-detector test that the generated name is stable across runs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class UnsplittableFn extends DoFn<Integer, String> {
@ProcessElement
public void process(ProcessContext context) {}
}

assertEquals(
PCollection.IsBounded.BOUNDED,
DoFnSignatures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void process() {}

@OnTimer(TIMER_ID)
public void onMyTimer() {}
};
}

/**
* This is a change-detector test that the generated name is stable across runs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void processElement(ProcessContext c, BoundedWindow window) {
+ ":" + window);
}
}

private WindowFn<? super String, ?> windowFn;
public WindowedCount(WindowFn<? super String, ?> windowFn) {
this.windowFn = windowFn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ public void closeClient() throws Exception {
}
}
}

static int getBackendVersion(ConnectionConfiguration connectionConfiguration) {
try (RestClient restClient = connectionConfiguration.createClient()) {
Response response = restClient.performRequest("GET", "");
Expand Down

0 comments on commit 1cbc58b

Please sign in to comment.