From 863f0011c782e5089f77f0b31dbba22cb71c0412 Mon Sep 17 00:00:00 2001 From: Vitali Skleenkov Date: Wed, 23 Jul 2014 11:30:22 +0300 Subject: [PATCH] Testcase: 'java.io.IOException: Stream Closed' if test's console output exceeds 1Mb --- .../surefire/its/Junit4DmKernelRunnerIT.java | 46 +++++++++ .../pom.xml | 93 +++++++++++++++++++ .../java/junit4/DmKernelRunnerFirstIT.java | 41 ++++++++ .../java/junit4/DmKernelRunnerSecondIT.java | 40 ++++++++ .../test/java/junit4/DmKernelTestRunner.java | 80 ++++++++++++++++ .../src/test/java/junit4/IntegrationTest.java | 25 +++++ 6 files changed, 325 insertions(+) create mode 100644 surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit4DmKernelRunnerIT.java create mode 100644 surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/pom.xml create mode 100644 surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/DmKernelRunnerFirstIT.java create mode 100644 surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/DmKernelRunnerSecondIT.java create mode 100644 surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/DmKernelTestRunner.java create mode 100644 surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/IntegrationTest.java diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit4DmKernelRunnerIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit4DmKernelRunnerIT.java new file mode 100644 index 0000000000..d04971c113 --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit4DmKernelRunnerIT.java @@ -0,0 +1,46 @@ +package org.apache.maven.surefire.its; + +/* + * 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. + */ + +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.apache.maven.surefire.its.fixture.SurefireLauncher; +import org.junit.Test; + +/** + * Test JUnit 4 tests with custom runner and two sequential tests + * + * @author Vitali Skleenkov + */ +public class Junit4DmKernelRunnerIT + extends SurefireJUnit4IntegrationTestCase +{ + + @Test + public void test() + { + unpack().setJUnitVersion("4.11") + .maven().executeVerify().assertIntegrationTestSuiteResults( 2, 0, 0, 1 ); + } + + private SurefireLauncher unpack() + { + return unpack( "/junit411-dmkernel-runner-seq-tests" ); + } +} diff --git a/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/pom.xml b/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/pom.xml new file mode 100644 index 0000000000..b8d38c2aa1 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/pom.xml @@ -0,0 +1,93 @@ + + + + + 4.0.0 + + org.apache.maven.plugins.surefire + junit411-dmkernel-runner-seq-tests + 1.0-SNAPSHOT + Test for JUnit 4.11 with custom runner and two sequential tests + + + + UTF-8 + UTF-8 + 4.11 + 2.17 + + + + + junit + junit + ${junitVersion} + test + + + commons-lang + commons-lang + 2.6 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + true + + + + org.apache.maven.plugins + maven-failsafe-plugin + ${surefire.version} + + + integration-tests + + integration-test + verify + + + junit4.IntegrationTest + + + + + + + + diff --git a/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/DmKernelRunnerFirstIT.java b/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/DmKernelRunnerFirstIT.java new file mode 100644 index 0000000000..d716b5ae0e --- /dev/null +++ b/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/DmKernelRunnerFirstIT.java @@ -0,0 +1,41 @@ +package junit4; + +/* + * 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. + */ + +import static org.junit.Assert.assertTrue; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +@Category({ IntegrationTest.class }) +@RunWith(DmKernelTestRunner.class) +public class DmKernelRunnerFirstIT { + + @Test + public void test() throws InterruptedException + { + System.out.println("Test 1: Doing some testing..."); + assertTrue("Obvious first assertion failed", true); + System.out.println("Test 1: Done."); + } + +} diff --git a/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/DmKernelRunnerSecondIT.java b/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/DmKernelRunnerSecondIT.java new file mode 100644 index 0000000000..d205595f07 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/DmKernelRunnerSecondIT.java @@ -0,0 +1,40 @@ +package junit4; + +/* + * 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. + */ + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +@Category({ IntegrationTest.class }) +@RunWith(DmKernelTestRunner.class) +public class DmKernelRunnerSecondIT { + + @Test + public void test() throws InterruptedException + { + System.out.println("Test 2: Doing some testing..."); + assertTrue("Obvious second assertion failed", true); + System.out.println("Test 2: Done."); + } + +} diff --git a/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/DmKernelTestRunner.java b/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/DmKernelTestRunner.java new file mode 100644 index 0000000000..19f44fedfa --- /dev/null +++ b/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/DmKernelTestRunner.java @@ -0,0 +1,80 @@ +package junit4; + +/* + * 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. + */ + +import org.apache.commons.lang.RandomStringUtils; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.InitializationError; + +public class DmKernelTestRunner extends BlockJUnit4ClassRunner { + + public DmKernelTestRunner(Class klass) throws InitializationError + { + super(klass); + } + + @Override + public void run(RunNotifier notifier) + { + try + { + launchOsgi(); + Object targetBundleContext = null; + Class realTestClass = createOsgiTestClass(targetBundleContext); + BlockJUnit4ClassRunner realRunner = new BlockJUnit4ClassRunner(realTestClass); + realRunner.run(notifier); + } catch (Throwable e) + { + notifier.fireTestFailure(new Failure(getDescription(), e)); + } finally + { + stopOsgi(); + } + } + + private void launchOsgi() throws InterruptedException + { + System.out.println("Launching OSGi framework for " + getTestClass().getJavaClass().getName()); + generateOsgiOutput(1100000); + System.out.println("Virgo ready for " + getTestClass().getJavaClass().getName()); + } + + private void stopOsgi() + { + System.out.println("Shutting down OSGi framework for " + getTestClass().getJavaClass().getName()); + generateOsgiOutput(1000); + } + + private Class createOsgiTestClass(Object targetBundleContext) + { + return getTestClass().getJavaClass(); + } + + private void generateOsgiOutput(int n) + { + for (int i = 0; i < n / 100; i++) + { + System.out.println(RandomStringUtils.randomAlphabetic(100)); + } + } + +} diff --git a/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/IntegrationTest.java b/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/IntegrationTest.java new file mode 100644 index 0000000000..1243f3422a --- /dev/null +++ b/surefire-integration-tests/src/test/resources/junit411-dmkernel-runner-seq-tests/src/test/java/junit4/IntegrationTest.java @@ -0,0 +1,25 @@ +package junit4; + +/* + * 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. + */ + +public interface IntegrationTest +{ + +} \ No newline at end of file