Skip to content

Commit

Permalink
[FLINK-2521] [tests] Adds TestLogger class which automatically logs t…
Browse files Browse the repository at this point in the history
…he currently executed test names and the reasons for a failure.

Makes test bases extend TestLogger to add automatic test name logging

Frames test logging statements to make them more prominent

This closes apache#1015.
  • Loading branch information
tillrohrmann committed Aug 18, 2015
1 parent 3fcc04a commit 2f0412f
Show file tree
Hide file tree
Showing 28 changed files with 124 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.flink.core.fs.Path;
import org.apache.flink.core.memory.DataOutputView;
import org.apache.flink.core.memory.OutputViewDataOutputStreamWrapper;
import org.apache.flink.util.TestLogger;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -42,7 +43,7 @@
/**
* Test base for {@link org.apache.flink.api.common.io.BinaryInputFormat} and {@link org.apache.flink.api.common.io.BinaryOutputFormat}.
*/
public abstract class SequentialFormatTestBase<T> {
public abstract class SequentialFormatTestBase<T> extends TestLogger {

public class InputSplitSorter implements Comparator<FileInputSplit> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.flink.core.memory.DataInputView;
import org.apache.flink.core.memory.DataOutputView;
import org.apache.flink.core.memory.MemorySegment;
import org.apache.flink.util.TestLogger;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -37,7 +38,7 @@
*
* @param <T>
*/
public abstract class ComparatorTestBase<T> {
public abstract class ComparatorTestBase<T> extends TestLogger {

// Same as in the NormalizedKeySorter
private static final int DEFAULT_MAX_NORMALIZED_KEY_LEN = 8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.IOException;
import java.util.Arrays;

import org.apache.flink.util.TestLogger;
import org.junit.Assert;

import org.apache.commons.lang3.SerializationException;
Expand All @@ -47,7 +48,7 @@
* (JodaTime DataTime) with the default KryoSerializer used to pass this test but the
* internal state would be corrupt, which becomes evident when toString is called.
*/
public abstract class SerializerTestBase<T> {
public abstract class SerializerTestBase<T> extends TestLogger {

protected abstract TypeSerializer<T> createSerializer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@

import org.apache.flink.core.testutils.CommonTestUtils;

import org.apache.flink.util.TestLogger;
import org.junit.Test;

/**
* This class contains test for the configuration package. In particular, the serialization of {@link Configuration}
* objects is tested.
*/
public class ConfigurationTest {
public class ConfigurationTest extends TestLogger {

private static final byte[] EMPTY_BYTES = new byte[0];
private static final long TOO_LONG = Integer.MAX_VALUE + 10L;
private static final double TOO_LONG_DOUBLE = Double.MAX_VALUE;


/**
* This test checks the serialization/deserialization of configuration objects.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
import java.lang.reflect.Field;

import org.apache.flink.core.testutils.CommonTestUtils;
import org.apache.flink.util.TestLogger;
import org.junit.Before;
import org.junit.Test;

/**
* This class contains tests for the global configuration (parsing configuration directory information).
*/
public class GlobalConfigurationTest {
public class GlobalConfigurationTest extends TestLogger {

@Before
public void resetSingleton() throws SecurityException, NoSuchFieldException, IllegalArgumentException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.apache.flink.util.TestLogger;
import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
Expand All @@ -34,7 +35,7 @@
* This class verifies that the Unmodifiable Configuration class overrides all setter methods in
* Configuration.
*/
public class UnmodifiableConfigurationTest {
public class UnmodifiableConfigurationTest extends TestLogger {

@Test
public void testOverrideAddMethods() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.apache.flink.util.TestLogger;
import org.junit.Test;


/**
*
*/
public abstract class ParserTestBase<T> {
public abstract class ParserTestBase<T> extends TestLogger {

public abstract String[] getValidTestValues();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* This class contains tests for the {@link org.apache.flink.util.AbstractID} class.
*/
public class AbstractIDTest {
public class AbstractIDTest extends TestLogger {
/**
* Tests the serialization/deserialization of an abstract ID.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public class InstantiationUtilTest {
public class InstantiationUtilTest extends TestLogger {

@Test
public void testInstantiationOfStringValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.junit.Test;


public class NumberSequenceIteratorTest {
public class NumberSequenceIteratorTest extends TestLogger {

@Test
public void testSplitRegular() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.junit.Test;


public class SimpleStringUtilsTest {
public class SimpleStringUtilsTest extends TestLogger {

@Test
public void testToLowerCaseConverting() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.flink.util.StringUtils;
import org.junit.Test;

public class StringUtilsTest {
public class StringUtilsTest extends TestLogger {

@Test
public void testControlCharacters() {
Expand Down
59 changes: 59 additions & 0 deletions flink-core/src/test/java/org/apache/flink/util/TestLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.flink.util;

import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Adds automatic test name logging. Every test which wants to log which test is currently
* executed and why it failed, simply has to extend this class.
*/
public class TestLogger {
protected final Logger log = LoggerFactory.getLogger(getClass());

@Rule
public TestRule watchman = new TestWatcher() {

@Override
public void starting(Description description) {
log.info("================================================================================");
log.info("Test {} is running.", description);
log.info("--------------------------------------------------------------------------------");
}

@Override
public void succeeded(Description description) {
log.info("--------------------------------------------------------------------------------");
log.info("Test {} successfully run.", description);
log.info("================================================================================");
}

@Override
public void failed(Throwable e, Description description) {
log.error("--------------------------------------------------------------------------------");
log.error("Test {} failed with:\n{}", description, StringUtils.stringifyException(e));
log.error("================================================================================");
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.flink.api.common.typeutils.TypePairComparator;
import org.apache.flink.api.java.tuple.Tuple;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.util.TestLogger;
import org.junit.Test;

/**
Expand All @@ -32,7 +33,7 @@
* @param <T>
* @param <R>
*/
public abstract class TuplePairComparatorTestBase<T extends Tuple, R extends Tuple> {
public abstract class TuplePairComparatorTestBase<T extends Tuple, R extends Tuple> extends TestLogger {

protected abstract TypePairComparator<T, R> createComparator(boolean ascending);

Expand Down
8 changes: 8 additions & 0 deletions flink-optimizer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ under the License.
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.flink.optimizer.plan.PlanNode;
import org.apache.flink.optimizer.plan.SingleInputPlanNode;
import org.apache.flink.util.OperatingSystem;
import org.apache.flink.util.TestLogger;
import org.apache.flink.util.Visitor;
import org.junit.Before;

Expand All @@ -46,7 +47,7 @@
* of a program and to fetch the nodes in an optimizer plan that correspond
* the the node in the program plan.
*/
public abstract class CompilerTestBase implements java.io.Serializable {
public abstract class CompilerTestBase extends TestLogger implements java.io.Serializable {

private static final long serialVersionUID = 1L;

Expand Down
8 changes: 8 additions & 0 deletions flink-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ under the License.
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.flink.runtime.io.network.partition;

import org.apache.flink.runtime.io.network.buffer.Buffer;
import org.apache.flink.util.TestLogger;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
Expand All @@ -27,7 +28,7 @@
/**
* Basic subpartition behaviour tests.
*/
public abstract class SubpartitionTestBase {
public abstract class SubpartitionTestBase extends TestLogger {

/**
* Return the subpartition to be tested.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.runtime.taskmanager.TaskManagerRuntimeInfo;
import org.apache.flink.util.TestLogger;
import org.junit.Assert;
import org.apache.flink.api.common.functions.Function;
import org.apache.flink.api.common.functions.util.FunctionUtils;
Expand All @@ -53,7 +54,7 @@
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class DriverTestBase<S extends Function> implements PactTaskContext<S, Record> {
public class DriverTestBase<S extends Function> extends TestLogger implements PactTaskContext<S, Record> {

protected static final long DEFAULT_PER_SORT_MEM = 16 * 1024 * 1024;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@
import org.apache.flink.types.Record;
import org.apache.flink.util.InstantiationUtil;
import org.apache.flink.util.MutableObjectIterator;
import org.apache.flink.util.TestLogger;
import org.junit.After;
import org.junit.Assert;

import java.util.List;

public abstract class TaskTestBase {
public abstract class TaskTestBase extends TestLogger {

protected long memorySize = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.flink.util.Collector;
import org.apache.flink.util.MutableObjectIterator;

import org.apache.flink.util.TestLogger;
import org.junit.After;
import org.junit.Assert;
import org.junit.runner.RunWith;
Expand All @@ -51,7 +52,7 @@
import java.util.List;

@RunWith(Parameterized.class)
public class UnaryOperatorTestBase<S extends Function, IN, OUT> implements PactTaskContext<S, OUT> {
public class UnaryOperatorTestBase<S extends Function, IN, OUT> extends TestLogger implements PactTaskContext<S, OUT> {

protected static final long DEFAULT_PER_SORT_MEM = 16 * 1024 * 1024;

Expand Down
6 changes: 6 additions & 0 deletions flink-test-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ under the License.
<artifactId>flink-runtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.flink.runtime.StreamingMode;
import org.apache.flink.runtime.testingUtils.TestingTaskManagerMessages;
import org.apache.flink.runtime.testingUtils.TestingUtils;
import org.apache.flink.util.TestLogger;
import org.apache.hadoop.fs.FileSystem;
import org.junit.Assert;
import org.slf4j.Logger;
Expand Down Expand Up @@ -66,7 +67,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestBaseUtils {
public class TestBaseUtils extends TestLogger {

private static final Logger LOG = LoggerFactory.getLogger(TestBaseUtils.class);

Expand Down
Loading

0 comments on commit 2f0412f

Please sign in to comment.