Skip to content

Commit

Permalink
Merge pull request Alluxio#2696 from siyangy/addWebTest
Browse files Browse the repository at this point in the history
[TACHYON-700] add web server smoke test
  • Loading branch information
yupeng9 committed Feb 26, 2016
2 parents 31c72f4 + fe43698 commit 985eccb
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<slf4j.version>1.7.2</slf4j.version>
<test.output.redirect>true</test.output.redirect>
<hadoop-openstack.version>2.6.0</hadoop-openstack.version>
<surefire.useSystemClassLoader>true</surefire.useSystemClassLoader>
</properties>

<modules>
Expand Down Expand Up @@ -345,6 +346,7 @@
<configuration>
<argLine>-Djava.net.preferIPv4Stack=true -Djava.security.krb5.realm= -Djava.security.krb5.kdc=</argLine>
<redirectTestOutputToFile>${test.output.redirect}</redirectTestOutputToFile>
<useSystemClassLoader>${surefire.useSystemClassLoader}</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
Expand Down
24 changes: 24 additions & 0 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<license.header.path>${project.parent.basedir}/build/license/</license.header.path>
<checkstyle.path>${project.parent.basedir}/build/checkstyle/</checkstyle.path>
<findbugs.path>${project.parent.basedir}/build/findbugs/</findbugs.path>
<surefire.useSystemClassLoader>false</surefire.useSystemClassLoader>
</properties>

<dependencies>
Expand All @@ -53,7 +54,9 @@
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-minicluster</artifactId>
<scope>test</scope>

<!-- Exclude the Jersey artifacts to prevent clashes with alluxio-core-server -->
<!-- Exclude the jsp/servlet related dependencies to avoid troubles in web test -->
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
Expand All @@ -67,7 +70,28 @@
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
</exclusion>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1</artifactId>
</exclusion>
<exclusion>
<groupId>tomcat</groupId>
<artifactId>jasper-runtime</artifactId>
</exclusion>
<exclusion>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
</exclusion>
</exclusions>

</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
107 changes: 107 additions & 0 deletions tests/src/test/java/alluxio/web/WebServerIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the “License”). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package alluxio.web;

import alluxio.Configuration;
import alluxio.LocalAlluxioClusterResource;
import alluxio.master.LocalAlluxioCluster;
import alluxio.util.network.NetworkAddressUtils;
import alluxio.util.network.NetworkAddressUtils.ServiceType;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.Multimap;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.URL;
import java.util.Map.Entry;
import java.util.Scanner;

/**
* Tests the web server is up when Alluxio starts.
*/
public class WebServerIntegrationTest {
private Configuration mMasterConf;
private Configuration mWorkerConf;

// Web pages that will be verified.
private static final Multimap<ServiceType, String> PAGES =
new ImmutableListMultimap.Builder<ServiceType, String>()
.putAll(ServiceType.MASTER_WEB, "/home", "/browse", "/configuration", "/workers",
"/memory", "/browseLogs", "/metricsui")
.putAll(ServiceType.WORKER_WEB, "/home", "/blockInfo", "/browseLogs", "/metricsui")
.build();

@Rule
public LocalAlluxioClusterResource mLocalAlluxioClusterResource =
new LocalAlluxioClusterResource();

@Before
public final void before() throws Exception {
LocalAlluxioCluster localAlluxioCluster = mLocalAlluxioClusterResource.get();
mMasterConf = localAlluxioCluster.getMasterConf();
mWorkerConf = localAlluxioCluster.getWorkerConf();
}

private void verifyWebService(ServiceType serviceType, String path)
throws IOException {
Configuration conf =
serviceType == ServiceType.MASTER_WEB ? mMasterConf : mWorkerConf;

InetSocketAddress webAddr =
NetworkAddressUtils.getConnectAddress(serviceType, conf);
HttpURLConnection webService = (HttpURLConnection) new URL(
"http://" + webAddr.getAddress().getHostAddress() + ":"
+ webAddr.getPort() + path).openConnection();
webService.connect();
Assert.assertEquals(200, webService.getResponseCode());

Scanner pageScanner = null;
boolean verified = false;

try {
pageScanner = new Scanner(webService.getInputStream());

while (pageScanner.hasNextLine()) {
String line = pageScanner.nextLine();
if (line.equals("<title>Alluxio</title>") || line.equals("<title>Workers</title>")) {
verified = true;
break;
}
}
} finally {
if (pageScanner != null) {
pageScanner.close();
}
webService.disconnect();
}

Assert.assertTrue(String.format("%s was started but not successfully verified.",
serviceType.getServiceName()), verified);
}

/**
* Tests whether the master and worker web homepage is up.
*/
@Test
public void serverUpTest() throws Exception {
for (Entry<ServiceType, String> entry : PAGES.entries()) {
verifyWebService(entry.getKey(), entry.getValue());
}
}
}
25 changes: 25 additions & 0 deletions underfs/glusterfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@
<groupId>org.gluster</groupId>
<artifactId>glusterfs-hadoop</artifactId>
<version>${glusterfs-hadoop.version}</version>

<!-- Exclude the jsp/servlet related dependencies to avoid troubles in web test -->
<exclusions>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1</artifactId>
</exclusion>
<exclusion>
<groupId>tomcat</groupId>
<artifactId>jasper-runtime</artifactId>
</exclusion>
<exclusion>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
</exclusion>
</exclusions>

</dependency>
<dependency>
<groupId>org.alluxio</groupId>
Expand Down
25 changes: 25 additions & 0 deletions underfs/swift/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-openstack</artifactId>
<version>${hadoop-openstack.version}</version>

<!-- Exclude the jsp/servlet related dependencies to avoid troubles in web test -->
<exclusions>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1</artifactId>
</exclusion>
<exclusion>
<groupId>tomcat</groupId>
<artifactId>jasper-runtime</artifactId>
</exclusion>
<exclusion>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
</exclusion>
</exclusions>

</dependency>
<dependency>
<groupId>org.alluxio</groupId>
Expand Down

0 comments on commit 985eccb

Please sign in to comment.