You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2014/05/07 12:36:19 UTC
svn commit: r1592965 - in /sling/trunk/tooling/ide/eclipse-test: META-INF/
src/org/apache/sling/ide/test/impl/
Author: rombert
Date: Wed May 7 10:36:18 2014
New Revision: 1592965
URL: http://svn.apache.org/r1592965
Log:
SLING-3544 - Integration tests running against a live Sling Launchpad
instance
Add an ExternalSlingLaunchpad rule which is able to wait for a launchpad
process to start.
Added:
sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ExternalSlingLaunchpad.java (with props)
sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/LaunchpadUtils.java (with props)
Modified:
sling/trunk/tooling/ide/eclipse-test/META-INF/MANIFEST.MF
sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/SlingWstServer.java
Modified: sling/trunk/tooling/ide/eclipse-test/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/META-INF/MANIFEST.MF?rev=1592965&r1=1592964&r2=1592965&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/eclipse-test/META-INF/MANIFEST.MF Wed May 7 10:36:18 2014
@@ -11,4 +11,5 @@ Require-Bundle: org.junit,
org.eclipse.jdt.launching,
org.eclipse.wst.server.core,
org.apache.sling.ide.eclipse-core,
- org.eclipse.debug.core
+ org.eclipse.debug.core,
+ org.apache.commons.httpclient
Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ExternalSlingLaunchpad.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ExternalSlingLaunchpad.java?rev=1592965&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ExternalSlingLaunchpad.java (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ExternalSlingLaunchpad.java Wed May 7 10:36:18 2014
@@ -0,0 +1,72 @@
+/*
+ * 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.sling.ide.test.impl;
+
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import junit.framework.AssertionFailedError;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.junit.rules.ExternalResource;
+
+public class ExternalSlingLaunchpad extends ExternalResource {
+
+ private static final Pattern STARTLEVEL_JSON_SNIPPET = Pattern.compile("\"systemStartLevel\":(\\d+)");
+ private static final int EXPECTED_START_LEVEL = 30;
+ private static final long MAX_WAIT_TIME_MS = TimeUnit.MINUTES.toMillis(1);
+
+ @Override
+ protected void before() throws Throwable {
+
+ int launchpadPort = LaunchpadUtils.getLaunchpadPort();
+
+ Credentials creds = new UsernamePasswordCredentials("admin", "admin");
+
+ HttpClient client = new HttpClient();
+ client.getState().setCredentials(new AuthScope("localhost", launchpadPort), creds);
+ GetMethod method = new GetMethod("http://localhost:" + launchpadPort + "/system/console/vmstat");
+
+ long cutoff = System.currentTimeMillis() + MAX_WAIT_TIME_MS;
+
+ while (true) {
+ int status = client.executeMethod(method);
+ if (status == 200) {
+ String responseBody = method.getResponseBodyAsString();
+ Matcher m = STARTLEVEL_JSON_SNIPPET.matcher(responseBody);
+ if (m.find()) {
+ int startLevel = Integer.parseInt(m.group(1));
+ if (startLevel >= EXPECTED_START_LEVEL) {
+ break;
+ }
+ }
+
+ }
+
+ if (System.currentTimeMillis() > cutoff) {
+ throw new AssertionFailedError("Sling launchpad did not start within " + MAX_WAIT_TIME_MS
+ + " milliseconds");
+ }
+ }
+
+ }
+}
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ExternalSlingLaunchpad.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ExternalSlingLaunchpad.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/LaunchpadUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/LaunchpadUtils.java?rev=1592965&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/LaunchpadUtils.java (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/LaunchpadUtils.java Wed May 7 10:36:18 2014
@@ -0,0 +1,27 @@
+/*
+ * 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.sling.ide.test.impl;
+
+public class LaunchpadUtils {
+
+ /**
+ * @return the configured launchpad port
+ */
+ public static int getLaunchpadPort() {
+ return Integer.getInteger("launchpad.http.port", 8080);
+ }
+}
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/LaunchpadUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/LaunchpadUtils.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/SlingWstServer.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/SlingWstServer.java?rev=1592965&r1=1592964&r2=1592965&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/SlingWstServer.java (original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/SlingWstServer.java Wed May 7 10:36:18 2014
@@ -79,13 +79,7 @@ public class SlingWstServer extends Exte
IServerWorkingCopy wc = serverType.createServer("tmp.server.id", null, new NullProgressMonitor());
// TODO - remove hardcoding
wc.setHost("localhost");
- // TODO - actually wait for the process to start, instead of guessing we're running in a Maven build by the
- // non-default port
- Integer serverPort = Integer.getInteger("launchpad.http.port", 8080);
- if (!serverPort.equals(8080)) {
- Thread.sleep(15000);
- }
- wc.setAttribute(ISlingLaunchpadServer.PROP_PORT, serverPort);
+ wc.setAttribute(ISlingLaunchpadServer.PROP_PORT, LaunchpadUtils.getLaunchpadPort());
wc.setAttribute(ISlingLaunchpadServer.PROP_CONTEXT_PATH, "/");
wc.setAttribute(ISlingLaunchpadServer.PROP_USERNAME, "admin");
wc.setAttribute(ISlingLaunchpadServer.PROP_PASSWORD, "admin");