You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2008/12/03 16:17:50 UTC

svn commit: r722928 - in /incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest: JcrinstallTestBase.java StopAndChangeBundlesTest.java StopAndRestartTest.java

Author: bdelacretaz
Date: Wed Dec  3 07:17:50 2008
New Revision: 722928

URL: http://svn.apache.org/viewvc?rev=722928&view=rev
Log:
SLING-734 - StopAndChangeBundlesTest and StopAndRestartTest added, jcrinstall stress tests

Added:
    incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndChangeBundlesTest.java   (with props)
    incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndRestartTest.java   (with props)
Modified:
    incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/JcrinstallTestBase.java

Modified: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/JcrinstallTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/JcrinstallTestBase.java?rev=722928&r1=722927&r2=722928&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/JcrinstallTestBase.java (original)
+++ incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/JcrinstallTestBase.java Wed Dec  3 07:17:50 2008
@@ -24,6 +24,7 @@
 import java.util.Properties;
 import java.util.Set;
 
+import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.sling.commons.testing.integration.HttpTestBase;
 import org.apache.sling.jcr.jcrinstall.integrationtest.util.BundleCloner;
 import org.osgi.framework.Bundle;
@@ -61,9 +62,19 @@
 		super.setUp();
 		scaleFactor = requireIntProperty(SCALE_FACTOR_PROP);
 		defaultBundlesTimeout = requireIntProperty(DEFAULT_TIMEOUT_PROP);
+		enableJcrinstallService(true);
     }
     
-    protected int requireIntProperty(String systemPropertyKey) throws Exception {
+    @Override
+	protected void tearDown() throws Exception {
+		// TODO Auto-generated method stub
+		super.tearDown();
+		enableJcrinstallService(true);
+	}
+
+
+
+	protected int requireIntProperty(String systemPropertyKey) throws Exception {
     	final String s = System.getProperty(systemPropertyKey);
     	if(s == null) {
     		throw new Exception("Missing system property '" + systemPropertyKey + "'");
@@ -77,17 +88,31 @@
     	final long start = System.currentTimeMillis();
     	final long timeout = start + timeoutSeconds * 1000L;
     	int count = 0;
+    	int lastCount = -1;
     	while(System.currentTimeMillis() < timeout) {
     		count = getActiveBundlesCount();
-    		if(count == expectedCount) {
+    		if(count != lastCount) {
+    			// continue until the count is stable for at least one second
+    			lastCount = count;
+        		sleep(1000);
+    			continue;
+    		} else if(count == expectedCount) {
     			return;
     		}
+    		sleep(500);
     	}
     	final long delta = System.currentTimeMillis() - start;
     	fail(message + ": expected " + expectedCount + " active bundles, found " + count
     			+ " after waiting " + delta / 1000.0 + " seconds");
     }
     
+    protected void sleep(long millis) {
+    	try {
+    		Thread.sleep(millis);
+    	} catch(InterruptedException ignore) {
+    	}
+    }
+    
     protected int getActiveBundlesCount() throws IOException {
     	final String key = "bundles.in.state." + Bundle.ACTIVE;
     	final Properties props = getJcrInstallProperties();
@@ -98,6 +123,22 @@
     	return result;
     }
     
+    protected boolean getJcrinstallServiceEnabled() throws IOException {
+    	final Properties props = getJcrInstallProperties();
+    	return "true".equals(props.get("jcrinstall.enabled"));
+    }
+    
+    protected void enableJcrinstallService(boolean enable) throws IOException {
+    	if(enable != getJcrinstallServiceEnabled()) {
+            final PostMethod post = new PostMethod(HTTP_BASE_URL + JCRINSTALL_STATUS_PATH);
+            post.setFollowRedirects(false);
+            post.addParameter("enabled", String.valueOf(enable));
+            final int status = httpClient.executeMethod(post);
+            assertEquals("Expected status 200 in enableJcrinstallService", 200, status);
+            assertEquals("Expected jcrinstall.enabled to be " + enable, enable, getJcrinstallServiceEnabled());
+    	}
+    }
+    
     /** Return the Properties found at /system/sling/jcrinstall */ 
     protected Properties getJcrInstallProperties() throws IOException {
     	final String content = getContent(HTTP_BASE_URL + JCRINSTALL_STATUS_PATH, CONTENT_TYPE_PLAIN);

Added: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndChangeBundlesTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndChangeBundlesTest.java?rev=722928&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndChangeBundlesTest.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndChangeBundlesTest.java Wed Dec  3 07:17:50 2008
@@ -0,0 +1,76 @@
+/*
+ * 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.jcr.jcrinstall.integrationtest;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/** Test replacing bundles while jcrinstall is disabled
+ */
+public class StopAndChangeBundlesTest extends JcrinstallTestBase {
+	
+	public void testStopAndRestart() throws Exception {
+		final int activeBeforeTest = getActiveBundlesCount();
+		final List<String> installed = new LinkedList<String>();
+		
+		final int nBundlesA = 7 * scaleFactor;
+		final int nBundlesB = 13 * scaleFactor;
+		
+		assertActiveBundleCount("before adding bundles", 
+				activeBeforeTest, defaultBundlesTimeout);
+		
+		// Add a first set of bundles A
+		for(int i=0 ; i < nBundlesA; i++) {
+			installed.add(installClonedBundle(null, null));
+		}
+		
+		// And check that they all start
+		assertActiveBundleCount("after adding bundles", 
+				activeBeforeTest + nBundlesA, defaultBundlesTimeout);
+		
+		// Disable jcrinstall (to simulate repository going away),
+		// delete set A and add another set of bundles B
+		enableJcrinstallService(false);
+		
+		for(String path : installed) {
+			removeClonedBundle(path);
+		}
+		installed.clear();
+		
+		for(int i=0 ; i < nBundlesB; i++) {
+			installed.add(installClonedBundle(null, null));
+		}
+		
+		// Before reactivating, bundles count must be the initial count,
+		// as jcrinstall brings the start level down
+		assertActiveBundleCount("after replacing bundles", 
+				activeBeforeTest, defaultBundlesTimeout);
+		
+		// Re-enable and verify that only original bundles + set B are active
+		enableJcrinstallService(true);
+		assertActiveBundleCount("after re-enabling jcrinstall", 
+				activeBeforeTest + nBundlesB, defaultBundlesTimeout);
+		
+		// Remove everything and check
+		for(String path : installed) {
+			removeClonedBundle(path);
+		}
+		
+		assertActiveBundleCount("after removing all added bundles", 
+				activeBeforeTest, defaultBundlesTimeout);
+	}
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndChangeBundlesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndChangeBundlesTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndRestartTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndRestartTest.java?rev=722928&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndRestartTest.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndRestartTest.java Wed Dec  3 07:17:50 2008
@@ -0,0 +1,56 @@
+/*
+ * 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.jcr.jcrinstall.integrationtest;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/** Verify that stopping and restarting jcrinstall (simulating a disappearing
+ * 	repository) works as expected.
+ */
+public class StopAndRestartTest extends JcrinstallTestBase {
+	
+	public void testStopAndRestart() throws Exception {
+		final int activeBeforeTest = getActiveBundlesCount();
+		final List<String> installed = new LinkedList<String>();
+		
+		final int nBundles = 10 * scaleFactor;
+		for(int i=0 ; i < nBundles; i++) {
+			installed.add(installClonedBundle(null, null));
+		}
+		
+		assertActiveBundleCount("after adding bundles", 
+				activeBeforeTest + nBundles, defaultBundlesTimeout);
+		
+		enableJcrinstallService(false);
+		
+		assertActiveBundleCount("after disabling jcrinstall", 
+				activeBeforeTest, defaultBundlesTimeout);
+		
+		enableJcrinstallService(true);
+		
+		assertActiveBundleCount("after re-enabling jcrinstall", 
+				activeBeforeTest + nBundles, defaultBundlesTimeout);
+		
+		for(String path : installed) {
+			removeClonedBundle(path);
+		}
+		
+		assertActiveBundleCount("after removing added bundles", 
+				activeBeforeTest, defaultBundlesTimeout);
+	}
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndRestartTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/StopAndRestartTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL