Skip to content

Commit

Permalink
[FLINK-6688] Activate strict checkstyle for flink-test-utils
Browse files Browse the repository at this point in the history
This closes apache#3983.
  • Loading branch information
zentol committed May 26, 2017
1 parent 2597e7e commit ae2c6be
Show file tree
Hide file tree
Showing 31 changed files with 276 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public abstract class CheckedThread extends Thread {

/** The error thrown from the main work method */
/** The error thrown from the main work method. */
private volatile Throwable error;

// ------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class CommonTestUtils {

/**
* Reads the path to the directory for temporary files from the configuration and returns it.
*
*
* @return the path to the directory for temporary files
*/
public static String getTempDir() {
Expand Down Expand Up @@ -85,9 +85,9 @@ public static <T extends java.io.Serializable> T createCopySerializable(T origin
/**
* Creates a temporary file that contains the given string.
* The file is written with the platform's default encoding.
*
*
* <p>The temp file is automatically deleted on JVM exit.
*
*
* @param contents The contents to be written to the file.
* @return The temp file URI.
*/
Expand Down Expand Up @@ -267,7 +267,7 @@ public static Class<? extends Serializable> createClassNotInClassPath(ClassLoade
29, 0, 0, 0, 1, 0, 39, 0, 40, 0, 1, 0, 25, 0, 0, 0, 70, 0, 3, 0, 1, 0, 0, 0, 28, -69, 0, 8,
89, -73, 0, 9, 18, 10, -74, 0, 11, 42, -76, 0, 5, -74, 0, 12, 16, 125, -74, 0, 13, -74, 0, 14,
-80, 0, 0, 0, 2, 0, 26, 0, 0, 0, 6, 0, 1, 0, 0, 0, 51, 0, 27, 0, 0, 0, 12, 0, 1, 0, 0, 0, 28,
0, 28, 0, 29, 0, 0, 0, 1, 0, 41, 0, 0, 0, 2, 0, 42,};
0, 28, 0, 29, 0, 0, 0, 1, 0, 41, 0, 0, 0, 2, 0, 42};

try {
// define a class into the classloader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
package org.apache.flink.core.testutils;

import javax.annotation.Nonnull;

import java.util.ArrayDeque;
import java.util.concurrent.Executor;

/**
* An executor that does not immediately execute a Runnable, but only executes it
* upon an explicit trigger.
*
*
* <p>This executor can be used in concurrent tests to control when certain asynchronous
* actions should happen.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void trigger() {
/**
* Waits until {@link OneShotLatch#trigger()} is called. Once {@code trigger()} has been called this
* call will always return immediately.
*
*
* @throws InterruptedException Thrown if the thread is interrupted while waiting.
*/
public void await() throws InterruptedException {
Expand All @@ -61,15 +61,15 @@ public void await() throws InterruptedException {
/**
* Waits until {@link OneShotLatch#trigger()} is called. Once {@code #trigger()} has been called this
* call will always return immediately.
*
*
* <p>If the latch is not triggered within the given timeout, a {@code TimeoutException}
* will be thrown after the timeout.
*
*
* <p>A timeout value of zero means infinite timeout and make this equivalent to {@link #await()}.
*
*
* @param timeout The value of the timeout, a value of zero indicating infinite timeout.
* @param timeUnit The unit of the timeout
*
*
* @throws InterruptedException Thrown if the thread is interrupted while waiting.
* @throws TimeoutException Thrown, if the latch is not triggered within the timeout time.
*/
Expand Down Expand Up @@ -101,15 +101,15 @@ public void await(long timeout, TimeUnit timeUnit) throws InterruptedException,

/**
* Checks if the latch was triggered.
*
*
* @return True, if the latch was triggered, false if not.
*/
public boolean isTriggered() {
return triggered;
}

/**
* resets the latch to triggered = false
* Resets the latch so that {@link #isTriggered()} returns false.
*/
public void reset() {
synchronized (lock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* // This will be retried 1 time (total runs 2) before failing the test.
* throw new IOException("Failing test");
* }
*
*
* {@literal @}Test
* {@literal @}RetryOnException(times=1, exception=IOException.class)
* public void yourTest() throws Exception {
Expand All @@ -55,6 +55,6 @@
public @interface RetryOnException {

int times();

Class<? extends Throwable> exception();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -48,7 +47,7 @@
*/
public class RetryRule implements TestRule {

public final static Logger LOG = LoggerFactory.getLogger(RetryRule.class);
public static final Logger LOG = LoggerFactory.getLogger(RetryRule.class);

@Override
public Statement apply(Statement statement, Description description) {
Expand All @@ -69,7 +68,7 @@ public Statement apply(Statement statement, Description description) {
throw new IllegalArgumentException(
"You cannot combine the RetryOnFailure and RetryOnException annotations.");
}

if (retryOnFailure != null) {
return new RetryOnFailureStatement(retryOnFailure.times(), statement);
}
Expand Down Expand Up @@ -133,7 +132,7 @@ private static class RetryOnExceptionStatement extends Statement {
private final Class<? extends Throwable> exceptionClass;
private final int timesOnFailure;
private final Statement statement;

private int currentRun;

private RetryOnExceptionStatement(int timesOnFailure, Class<? extends Throwable> exceptionClass, Statement statement) {
Expand All @@ -150,7 +149,7 @@ private RetryOnExceptionStatement(int timesOnFailure, Class<? extends Throwable>
}

/**
* Retry a test in case of a failure with a specific exception
* Retry a test in case of a failure with a specific exception.
*
* @throws Throwable
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -63,7 +62,7 @@ public void failed(Throwable e, Description description) {
, description, exceptionToString(e));
}
};

private static String exceptionToString(Throwable t) {
if (t == null) {
return "(null)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
* Tests for the OneShotLatch.
*/
public class OneShotLatchTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@

import static org.junit.Assert.assertEquals;

/**
* Tests for the RetryOnException annotation.
*/
public class RetryOnExceptionTest {

@Rule
public RetryRule retryRule = new RetryRule();

private static final int NUMBER_OF_RUNS = 3;

private static int runsForSuccessfulTest = 0;

private static int runsForTestWithMatchingException = 0;

private static int runsForTestWithSubclassException = 0;

private static int runsForPassAfterOneFailure = 0;


@AfterClass
public static void verify() {
assertEquals(NUMBER_OF_RUNS + 1, runsForTestWithMatchingException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

import static org.junit.Assert.assertEquals;

/**
* Tests for the RetryOnFailure annotation.
*/
public class RetryOnFailureTest {

@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* shutdown of the Flink clusters (including actor systems, etc) usually dominates
* the execution of the actual tests.
*
* To write a unit test against this test base, simply extend it and add
* <p>To write a unit test against this test base, simply extend it and add
* one or more regular test methods and retrieve the StreamExecutionEnvironment from
* the context:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,30 @@

import static org.junit.Assert.fail;

/**
* Base class for unit tests that run a single test.
*
* <p>To write a unit test against this test base, simply extend it and implement the {@link #testProgram()} method.
*/
public abstract class StreamingProgramTestBase extends AbstractTestBase {

protected static final int DEFAULT_PARALLELISM = 4;

private int parallelism;



public StreamingProgramTestBase() {
super(new Configuration());
setParallelism(DEFAULT_PARALLELISM);
}


public void setParallelism(int parallelism) {
this.parallelism = parallelism;
setTaskManagerNumSlots(parallelism);
}

public int getParallelism() {
return parallelism;
}


// --------------------------------------------------------------------------------------------
// Methods to create the test program and for pre- and post- test work
Expand All @@ -55,9 +57,9 @@ public int getParallelism() {
protected abstract void testProgram() throws Exception;

protected void preSubmit() throws Exception {}

protected void postSubmit() throws Exception {}

// --------------------------------------------------------------------------------------------
// Test entry point
// --------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
* A {@link StreamExecutionEnvironment} that executes its jobs on {@link LocalFlinkMiniCluster}.
*/
public class TestStreamEnvironment extends StreamExecutionEnvironment {
/** The mini cluster in which this environment executes its jobs */

/** The mini cluster in which this environment executes its jobs. */
private final LocalFlinkMiniCluster miniCluster;

private final Collection<Path> jarFiles;
Expand All @@ -63,7 +63,6 @@ public TestStreamEnvironment(
this(miniCluster, parallelism, Collections.<Path>emptyList(), Collections.<URL>emptyList());
}


@Override
public JobExecutionResult execute(String jobName) throws Exception {
final StreamGraph streamGraph = getStreamGraph();
Expand Down Expand Up @@ -114,7 +113,7 @@ public StreamExecutionEnvironment createExecutionEnvironment() {
/**
* Sets the streaming context environment to a TestStreamEnvironment that runs its programs on
* the given cluster with the given default parallelism.
*
*
* @param cluster The test cluster to run the test program on.
* @param parallelism The default parallelism for the test programs.
*/
Expand All @@ -131,5 +130,5 @@ public static void setAsContext(final LocalFlinkMiniCluster cluster, final int p
*/
public static void unsetAsContext() {
resetContextEnvironment();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@

package org.apache.flink.test.testdata;

import org.apache.flink.api.java.tuple.Tuple2;

import org.junit.Assert;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import java.util.regex.Pattern;

import org.apache.flink.api.java.tuple.Tuple2;
import org.junit.Assert;


/**
* Test data for ConnectedComponents programs.
*/
public class ConnectedComponentsData {

public static final String getEnumeratingVertices(int num) {
Expand Down Expand Up @@ -107,7 +110,7 @@ public static void checkOddEvenResult(BufferedReader result) throws IOException
}
}
}

public static void checkOddEvenResult(List<Tuple2<Long, Long>> lines) throws IOException {
for (Tuple2<Long, Long> line : lines) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

package org.apache.flink.test.testdata;

/**
* Test data for EnumTriangle programs.
*/
public class EnumTriangleData {

public static final String EDGES =
public static final String EDGES =
"1 2\n" +
"1 3\n" +
"1 4\n" +
Expand All @@ -33,13 +36,13 @@ public class EnumTriangleData {
"3 8\n" +
"7 8\n";

public static final String TRIANGLES_BY_ID =
public static final String TRIANGLES_BY_ID =
"1,2,3\n" +
"1,3,4\n" +
"1,2,5\n" +
"3,7,8\n";
public static final String TRIANGLES_BY_DEGREE =
"3,7,8\n";

public static final String TRIANGLES_BY_DEGREE =
"2,1,3\n" +
"4,1,3\n" +
"2,1,5\n" +
Expand Down
Loading

0 comments on commit ae2c6be

Please sign in to comment.