Skip to content

Commit

Permalink
[PAXWEB-753] - Latest version is slow with the Karaf integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ANierbeck committed Nov 24, 2014
1 parent ca61793 commit 88e6688
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 325 deletions.
6 changes: 0 additions & 6 deletions pax-web-itest/pax-web-itest-karaf/pom.xml
Expand Up @@ -351,12 +351,6 @@
<includes>
<include>**/*KarafTest.java</include>
</includes>
<!-- It's insane both tests do work if replayed directly on Karaf, but
don't work here! -->
<excludes>
<exclude>**/WebJSFKarafTest.java</exclude>
<exclude>**/SpringOsgiKarafTest.java</exclude>
</excludes>
<systemPropertyVariables>
<ProjectVersion>${project.version}</ProjectVersion>
<MyFacesVersion>${jsf-myfaces.version}</MyFacesVersion>
Expand Down
@@ -1,66 +1,34 @@
package org.ops4j.pax.web.itest.karaf;

import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import static org.ops4j.pax.exam.CoreOptions.when;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import static org.ops4j.pax.exam.MavenUtils.asInProject;
import static org.ops4j.pax.exam.OptionUtils.combine;

import org.ops4j.pax.exam.CoreOptions;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyStore;
import java.util.List;

import javax.inject.Inject;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;

import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.util.EntityUtils;
import org.apache.karaf.features.FeaturesService;
import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
import org.ops4j.pax.exam.karaf.options.configs.CustomProperties;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
import org.ops4j.pax.exam.karaf.options.configs.CustomProperties;
import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
import org.ops4j.pax.exam.options.extra.VMOption;
import org.ops4j.pax.web.itest.base.HttpTestClient;
import org.ops4j.pax.web.itest.base.ServletListenerImpl;
import org.ops4j.pax.web.itest.base.VersionUtil;
Expand Down Expand Up @@ -105,7 +73,7 @@ public Option[] baseConfig() {
systemProperty("osgi.console").value("6666"),
systemProperty("osgi.console.enable.builtin").value("true")
),
logLevel(LogLevel.WARN),
logLevel(LogLevel.INFO),
keepRuntimeFolder(),
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", RMI_REG_PORT),
editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", RMI_SERVER_PORT),
Expand Down
Expand Up @@ -3,21 +3,20 @@
*/
package org.ops4j.pax.web.itest.karaf;

import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.OptionUtils.combine;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.web.service.spi.WebEvent;
import org.ops4j.pax.web.service.spi.WebListener;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.slf4j.Logger;
Expand All @@ -28,11 +27,13 @@
*
*/
@RunWith(PaxExam.class)
@Ignore("Ignored for unknown reason")
public class SpringOsgiKarafTest extends KarafBaseTest {

Logger LOG = LoggerFactory.getLogger(SpringOsgiKarafTest.class);

private org.ops4j.pax.web.itest.karaf.SpringOsgiKarafTest.WebListenerImpl webListener;
// private org.ops4j.pax.web.itest.karaf.SpringOsgiKarafTest.WebListenerImpl
// webListener;

private Bundle warBundle;

Expand Down Expand Up @@ -83,23 +84,14 @@ public void testCallController() throws Exception {
@Before
public void setUp() throws Exception {

int count = 0;
while (!testClient.checkServer("http://127.0.0.1:8181/") && count < 200) {
synchronized (this) {
this.wait(100);
count++;
}
}
LOG.info("waiting for Server took {} ms", (count * 100));

if (featuresService == null)
throw new RuntimeException("Featuresservice is null");

boolean installed = featuresService.isInstalled(featuresService
.getFeature("spring-dm"));

int counter = 0;
while (!installed && counter < 50) {
while (!installed && counter < 100) {
Thread.sleep(500);
installed = featuresService.isInstalled(featuresService
.getFeature("spring-dm"));
Expand All @@ -109,6 +101,7 @@ public void setUp() throws Exception {
if (!installed)
throw new RuntimeException("No Spring-Dm available ...");


Bundle[] bundles = bundleContext.getBundles();
for (Bundle bundle : bundles) {
String symbolicName = bundle.getSymbolicName();
Expand All @@ -119,30 +112,13 @@ public void setUp() throws Exception {
}
}

initWebListener();
String warUrl = "mvn:org.ops4j.pax.web.samples/war-spring-osgi/"
+ getProjectVersion() + "/war";
warBundle = bundleContext.installBundle(warUrl);
warBundle.start();

webListener = new WebListenerImpl();

int failCount = 0;
while (warBundle.getState() != Bundle.ACTIVE) {
Thread.sleep(500);
if (failCount > 500)
throw new RuntimeException(
"Required war-bundles is never active");
failCount++;
}

counter = 0;
while (!((WebListenerImpl) webListener).gotEvent() && counter < 100) {
synchronized (this) {
this.wait(100);
counter++;
}
}
LOG.info("waiting for Server took {} ms", (counter * 1000));
waitForWebListener();
}

@After
Expand All @@ -152,19 +128,4 @@ public void tearDown() throws BundleException {
warBundle.uninstall();
}
}

private class WebListenerImpl implements WebListener {

private boolean event = false;

public void webEvent(WebEvent event) {
LOG.info("Got event: " + event);
if (event.getType() == 2)
this.event = true;
}

public boolean gotEvent() {
return event;
}
}
}
@@ -1,21 +1,12 @@
package org.ops4j.pax.web.itest.karaf;

import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.replaceConfigurationFile;
import static org.ops4j.pax.exam.OptionUtils.combine;

import java.io.File;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.web.service.spi.WebEvent;
import org.ops4j.pax.web.service.spi.WebListener;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.slf4j.Logger;
Expand All @@ -32,8 +23,6 @@ public class WarBasicAuthIntegrationKarafTest extends KarafBaseTest {

private Bundle warBundle;

private WebListenerImpl webListener;

@Configuration
public Option[] configuration() {
return jettyConfig();
Expand Down Expand Up @@ -89,21 +78,14 @@ public void testSlash() throws Exception {
@Before
public void setUp() throws Exception {

int count = 0;
while (!testClient.checkServer("http://127.0.0.1:8181/") && count < 200) {
synchronized (this) {
this.wait(100);
count++;
}
}
LOG.info("waiting for Server took {} ms", (count * 1000));
initWebListener();

String warUrl = "webbundle:mvn:org.ops4j.pax.web.samples/war-authentication/"
+ getProjectVersion() + "/war?Web-ContextPath=/war-authentication";
warBundle = bundleContext.installBundle(warUrl);
warBundle.start();

webListener = new WebListenerImpl();
waitForWebListener();

int failCount = 0;
while (warBundle.getState() != Bundle.ACTIVE) {
Expand All @@ -114,14 +96,6 @@ public void setUp() throws Exception {
failCount++;
}

count = 0;
while (!((WebListenerImpl) webListener).gotEvent() && count < 100) {
synchronized (this) {
this.wait(100);
count++;
}
}
LOG.info("waiting for Server took {} ms", (count * 1000));
}

@After
Expand All @@ -132,19 +106,4 @@ public void tearDown() throws BundleException {
}
}

private class WebListenerImpl implements WebListener {

private boolean event = false;

public void webEvent(WebEvent event) {
LOG.info("Got event: " + event);
if (event.getType() == 2)
this.event = true;
}

public boolean gotEvent() {
return event;
}
}

}
Expand Up @@ -9,8 +9,6 @@
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.web.service.spi.WebEvent;
import org.ops4j.pax.web.service.spi.WebListener;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.slf4j.Logger;
Expand All @@ -21,7 +19,6 @@ public class WarFragmentKarafTest extends KarafBaseTest {

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

private WebListenerImpl webListener;
private Bundle warBundle, fragmentBundle;

@Configuration
Expand Down Expand Up @@ -76,40 +73,16 @@ public void testWrongServlet() throws Exception {
@Before
public void setUp() throws Exception {

int count = 0;
while (!testClient.checkServer("http://127.0.0.1:8181/") && count < 200) {
synchronized (this) {
this.wait(100);
count++;
}
}
LOG.info("waiting for Server took {} ms", (count * 1000));

warBundle = bundleContext.installBundle("mvn:org.ops4j.pax.web.samples.web-fragment/war/" + getProjectVersion());
fragmentBundle = bundleContext.installBundle("mvn:org.ops4j.pax.web.samples.web-fragment/fragment/" + getProjectVersion());

initWebListener();

warBundle.start();
fragmentBundle.start();

webListener = new WebListenerImpl();
waitForWebListener();

int failCount = 0;
while (warBundle.getState() != Bundle.ACTIVE || fragmentBundle.getState() != Bundle.ACTIVE) {
Thread.sleep(500);
if (failCount > 500)
throw new RuntimeException(
"Required war-bundles is never active");
failCount++;
}

count = 0;
while (!((WebListenerImpl) webListener).gotEvent() && count < 100) {
synchronized (this) {
this.wait(100);
count++;
}
}
LOG.info("waiting for Server took {} ms", (count * 1000));
}

@After
Expand All @@ -124,18 +97,4 @@ public void tearDown() throws BundleException {
}
}

private class WebListenerImpl implements WebListener {

private boolean event = false;

public void webEvent(WebEvent event) {
LOG.info("Got event: " + event);
if (event.getType() == 2)
this.event = true;
}

public boolean gotEvent() {
return event;
}
}
}

0 comments on commit 88e6688

Please sign in to comment.