Skip to content

Commit

Permalink
[FLINK-1827] [tests] Move test classes in test folders and fix scope …
Browse files Browse the repository at this point in the history
…of test dependencies.

This closes apache#1915
  • Loading branch information
stefanobortoli authored and fhueske committed May 4, 2016
1 parent f186446 commit 70978f5
Show file tree
Hide file tree
Showing 63 changed files with 202 additions and 81 deletions.
1 change: 1 addition & 0 deletions flink-batch-connectors/flink-avro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 1 addition & 0 deletions flink-batch-connectors/flink-hadoop-compatibility/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 1 addition & 0 deletions flink-contrib/flink-operator-stats/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

Expand Down
1 change: 1 addition & 0 deletions flink-contrib/flink-storm-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

Expand Down
1 change: 1 addition & 0 deletions flink-contrib/flink-streaming-contrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 1 addition & 0 deletions flink-contrib/flink-tweet-inputformat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

Expand Down
1 change: 1 addition & 0 deletions flink-examples/flink-examples-streaming/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

Expand Down
1 change: 1 addition & 0 deletions flink-fs-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 2 additions & 0 deletions flink-java8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
Expand Down
5 changes: 3 additions & 2 deletions flink-libraries/flink-cep/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ under the License.

<artifactId>flink-cep_2.10</artifactId>
<name>flink-cep</name>
<packaging>jar</packaging>

<dependencies>
<dependency>
Expand Down Expand Up @@ -72,9 +73,11 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand All @@ -90,6 +93,4 @@ under the License.
</plugin>
</plugins>
</build>

<packaging>jar</packaging>
</project>
1 change: 1 addition & 0 deletions flink-libraries/flink-gelly-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 1 addition & 0 deletions flink-libraries/flink-gelly-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 1 addition & 0 deletions flink-libraries/flink-gelly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
1 change: 1 addition & 0 deletions flink-libraries/flink-ml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 1 addition & 0 deletions flink-libraries/flink-python/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 1 addition & 0 deletions flink-libraries/flink-table/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
import static org.junit.Assume.assumeTrue;

import java.io.File;
import java.net.BindException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.List;

import com.google.common.io.Files;

import org.apache.flink.configuration.ConfigConstants;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.util.StartupUtils;
import org.apache.flink.util.NetUtils;

import org.apache.flink.util.OperatingSystem;
Expand All @@ -48,6 +52,7 @@ public class JobManagerStartupTest {

@Before
public void before() {

// Prepare test directory
blobStorageDirectory = Files.createTempDir();

Expand All @@ -67,9 +72,10 @@ public void after() {
/**
* Verifies that the JobManager fails fast (and with expressive error message)
* when the port to listen is already in use.
* @throws Throwable
*/
@Test
public void testStartupWithPortInUse() {
@Test( expected = BindException.class )
public void testStartupWithPortInUse() throws BindException {

ServerSocket portOccupier;
final int portNum;
Expand All @@ -89,10 +95,13 @@ public void testStartupWithPortInUse() {
}
catch (Exception e) {
// expected
if(!e.getMessage().contains("Address already in use")) {
e.printStackTrace();
fail("Received wrong exception");
List<Throwable> causes = StartupUtils.getExceptionCauses(e,new ArrayList<Throwable>());
for(Throwable cause:causes) {
if(cause instanceof BindException) {
throw (BindException) cause;
}
}
fail("this should throw a BindException");
}
finally {
try {
Expand All @@ -103,7 +112,7 @@ public void testStartupWithPortInUse() {
}
}
}

/**
* Verifies that the JobManager fails fast (and with expressive error message)
* when one of its components (here the BLOB server) fails to start properly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,34 @@
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.IllegalConfigurationException;
import org.apache.flink.runtime.clusterframework.types.ResourceID;
import org.apache.flink.runtime.util.StartupUtils;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.BindException;
import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
* Tests that check how the TaskManager behaves when encountering startup problems.
* Tests that check how the TaskManager behaves when encountering startup
* problems.
*/
public class TaskManagerStartupTest {


/**
* Tests that the TaskManager fails synchronously when the actor system port
* is in use.
*
* @throws Throwable
*/
@Test
public void testStartupWhenTaskmanagerActorPortIsUsed() {
@Test(expected = BindException.class)
public void testStartupWhenTaskmanagerActorPortIsUsed() throws BindException {
ServerSocket blocker = null;
try {
final String localHostName = "localhost";
Expand All @@ -53,22 +62,21 @@ public void testStartupWhenTaskmanagerActorPortIsUsed() {
blocker = new ServerSocket(0, 50, localAddress);
final int port = blocker.getLocalPort();

try {
TaskManager.runTaskManager(
localHostName,
ResourceID.generate(),
port,
new Configuration(),
TaskManager.runTaskManager(localHostName, ResourceID.generate(), port, new Configuration(),
TaskManager.class);
fail("This should fail with an IOException");
}
catch (IOException e) {
// expected. validate the error message
assertNotNull(e.getMessage());
assertTrue(e.getMessage().contains("Address already in use"));
}
fail("This should fail with an IOException");

}
catch (IOException e) {
// expected. validate the error messagex
List<Throwable> causes = StartupUtils.getExceptionCauses(e, new ArrayList<Throwable>());
for (Throwable cause : causes) {
if (cause instanceof BindException) {
throw (BindException) cause;
}
}
fail("This should fail with an exception caused by BindException");
}
catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
Expand All @@ -77,17 +85,18 @@ public void testStartupWhenTaskmanagerActorPortIsUsed() {
if (blocker != null) {
try {
blocker.close();
}
catch (IOException e) {
} catch (IOException e) {
// no need to log here
}
}
}
}



/**
* Tests that the TaskManager startup fails synchronously when the I/O directories are
* not writable.
* Tests that the TaskManager startup fails synchronously when the I/O
* directories are not writable.
*/
@Test
public void testIODirectoryNotWritable() {
Expand Down Expand Up @@ -119,7 +128,7 @@ public void testIODirectoryNotWritable() {
fail(e.getMessage());
}
finally {
//noinspection ResultOfMethodCallIgnored
// noinspection ResultOfMethodCallIgnored
nonWritable.setWritable(true, false);
try {
FileUtils.deleteDirectory(nonWritable);
Expand Down Expand Up @@ -154,7 +163,7 @@ public void testMemoryConfigWrong() {

// something ridiculously high
final long memSize = (((long) Integer.MAX_VALUE - 1) *
ConfigConstants.DEFAULT_TASK_MANAGER_MEMORY_SEGMENT_SIZE) >> 20;
ConfigConstants.DEFAULT_TASK_MANAGER_MEMORY_SEGMENT_SIZE) >> 20;
cfg.setLong(ConfigConstants.TASK_MANAGER_MEMORY_SIZE_KEY, memSize);
try {
TaskManager.runTaskManager("localhost", ResourceID.generate(), 0, cfg);
Expand All @@ -164,8 +173,8 @@ public void testMemoryConfigWrong() {
// splendid!
assertTrue(e.getCause() instanceof OutOfMemoryError);
}
}
catch (Exception e) {
}
catch(Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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://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.runtime.util;

import java.util.List;

public class StartupUtils {

/**
* A utility method to analyze the exceptions and collect the clauses
*
* @param e the root exception (Throwable) object
* @param causes the list of exceptions that caused the root exceptions
* @return a list of Throwable
*/
public static List<Throwable> getExceptionCauses(Throwable e, List<Throwable> causes) {
if (e.getCause() == null) {
return causes;
} else {
causes.add(e.getCause());
getExceptionCauses(e.getCause(), causes);
}
return causes;
}

}
1 change: 1 addition & 0 deletions flink-scala-shell/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

Expand Down
1 change: 1 addition & 0 deletions flink-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ under the License.
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.10</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

Expand Down
Loading

0 comments on commit 70978f5

Please sign in to comment.