blob: beb9058c3efe6ab8c5c17169625d0e23e88be2b3 [file] [log] [blame]
/*
* 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.brooklyn.entity.webapp.jboss;
import static org.apache.brooklyn.test.HttpTestUtils.assertHttpStatusCodeEquals;
import static org.apache.brooklyn.test.HttpTestUtils.assertHttpStatusCodeEventuallyEquals;
import static org.testng.Assert.assertEquals;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.core.entity.EntityAsserts;
import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
import org.apache.brooklyn.entity.proxy.nginx.NginxController;
import org.apache.brooklyn.entity.software.base.SoftwareProcess;
import org.apache.brooklyn.entity.webapp.ControlledDynamicWebAppCluster;
import org.apache.brooklyn.test.WebAppMonitor;
import org.apache.brooklyn.test.support.TestResourceUnavailableException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
public class ControlledDynamicWebAppClusterRebindIntegrationTest extends RebindTestFixtureWithApp {
private static final Logger LOG = LoggerFactory.getLogger(ControlledDynamicWebAppClusterRebindIntegrationTest.class);
private LocalhostMachineProvisioningLocation localhostProvisioningLocation;
private List<WebAppMonitor> webAppMonitors = new CopyOnWriteArrayList<WebAppMonitor>();
private ExecutorService executor;
@BeforeMethod(alwaysRun=true)
@Override
public void setUp() throws Exception {
super.setUp();
executor = Executors.newCachedThreadPool();
localhostProvisioningLocation = app().newLocalhostProvisioningLocation();
}
@AfterMethod(alwaysRun=true)
@Override
public void tearDown() throws Exception {
try {
for (WebAppMonitor monitor : webAppMonitors) {
monitor.terminate();
}
if (executor != null) executor.shutdownNow();
} finally {
super.tearDown();
}
}
public String getTestWar() {
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/hello-world.war");
return "classpath://hello-world.war";
}
private WebAppMonitor newWebAppMonitor(String url) {
WebAppMonitor monitor = new WebAppMonitor(url)
// .delayMillis(0)
.logFailures(LOG);
webAppMonitors.add(monitor);
executor.execute(monitor);
return monitor;
}
/*
Exception java.lang.NoClassDefFoundError
Message: org/apache/brooklyn/test/HttpTestUtils$3
Stacktrace:
at org.apache.brooklyn.test.HttpTestUtils.assertHttpStatusCodeEventuallyEquals(HttpTestUtils.java:208)
at org.apache.brooklyn.test.HttpTestUtils.assertHttpStatusCodeEventuallyEquals(HttpTestUtils.java:204)
at org.apache.brooklyn.entity.webapp.jboss.ControlledDynamicWebAppClusterRebindIntegrationTest.testRebindsToRunningCluster(ControlledDynamicWebAppClusterRebindIntegrationTest.java:127)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
at org.testng.SuiteRunner.run(SuiteRunner.java:254)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:115)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:205)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:108)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:111)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
*/
@Test(groups = {"Integration","Broken"})
public void testRebindsToRunningCluster() throws Exception {
NginxController origNginx = app().createAndManageChild(EntitySpec.create(NginxController.class).configure("domain", "localhost"));
app().createAndManageChild(EntitySpec.create(ControlledDynamicWebAppCluster.class)
.configure("memberSpec", EntitySpec.create(JBoss7Server.class).configure("war", getTestWar()))
.configure("initialSize", 1)
.configure("controller", origNginx));
app().start(ImmutableList.of(localhostProvisioningLocation));
String rootUrl = origNginx.getAttribute(JBoss7Server.ROOT_URL);
assertHttpStatusCodeEventuallyEquals(rootUrl, 200);
WebAppMonitor monitor = newWebAppMonitor(rootUrl);
// Rebind
rebind();
NginxController newNginx = (NginxController) Iterables.find(app().getChildren(), Predicates.instanceOf(NginxController.class));
ControlledDynamicWebAppCluster newCluster = (ControlledDynamicWebAppCluster) Iterables.find(app().getChildren(), Predicates.instanceOf(ControlledDynamicWebAppCluster.class));
EntityAsserts.assertAttributeEqualsEventually(newNginx, SoftwareProcess.SERVICE_UP, true);
assertHttpStatusCodeEquals(rootUrl, 200);
// Confirm the cluster is usable: we can scale-up
assertEquals(newCluster.getCurrentSize(), (Integer)1);
newCluster.resize(2);
Iterable<Entity> newJbosses = Iterables.filter(newCluster.getCluster().getChildren(), Predicates.instanceOf(JBoss7Server.class));
assertEquals(Iterables.size(newJbosses), 2);
Thread.sleep(1000);
for (int i = 0; i < 10; i++) {
assertHttpStatusCodeEquals(rootUrl, 200);
}
// Ensure while doing all of this the original jboss server remained reachable
assertEquals(monitor.getFailures(), 0);
// Ensure cluster is usable: we can scale back to stop the original jboss server
newCluster.resize(0);
assertHttpStatusCodeEventuallyEquals(rootUrl, 404);
}
}