You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by to...@apache.org on 2014/06/05 12:38:29 UTC
svn commit: r1600588 - in /sling/trunk:
contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/
contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/
contrib/extensi...
Author: tommaso
Date: Thu Jun 5 10:38:29 2014
New Revision: 1600588
URL: http://svn.apache.org/r1600588
Log:
SLING-3625 - committed Marius patch for testing replication between 2 Sling instances
Added:
sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/resourceproviders/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-replicationHttpTransportConfig.json
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ForwardReplicationTest.java (with props)
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationIntegrationTestBase.java (with props)
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationUtils.java (with props)
Removed:
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationITBase.java
Modified:
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiConfigurationResourceProvider.java
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractModifyingResourceProvider.java
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractReadableResourceProvider.java
sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentQueueEventServlet.java
sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/org.apache.sling.replication.transport.impl.HttpTransportHandlerFactory-http-publish-receive.json
sling/trunk/contrib/extensions/replication/it/pom.xml
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentCommandsIntegrationTest.java
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java
sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingClient.java
Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiConfigurationResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiConfigurationResourceProvider.java?rev=1600588&r1=1600587&r2=1600588&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiConfigurationResourceProvider.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/OsgiConfigurationResourceProvider.java Thu Jun 5 10:38:29 2014
@@ -21,6 +21,7 @@ package org.apache.sling.replication.res
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;
@@ -76,6 +77,7 @@ public class OsgiConfigurationResourcePr
if (configuration == null) {
configuration = configurationAdmin.createFactoryConfiguration(configFactory);
}
+
configuration.update(toDictionary(properties));
}
@@ -196,7 +198,5 @@ public class OsgiConfigurationResourcePr
}
return dictionary;
-
}
-
}
Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractModifyingResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractModifyingResourceProvider.java?rev=1600588&r1=1600587&r2=1600588&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractModifyingResourceProvider.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractModifyingResourceProvider.java Thu Jun 5 10:38:29 2014
@@ -56,15 +56,13 @@ public abstract class AbstractModifyingR
String resourceName = pathInfo.getMainResourceName();
- final boolean deleted = this.deletedResources.remove(resourceName);
- Map existingResource = getMainResourceProperties(resourceName);
- if (!deleted && existingResource != null) {
+ boolean added = addToChangedResources(resourceName, properties, true);
+
+
+ if (!added) {
throw new PersistenceException("Resource already exists at " + path, null, resourceName, null);
}
- properties = unbindMainResourceProperties(properties);
- this.changedResources.put(resourceName, properties);
-
return buildMainResource(resolver, pathInfo, properties);
}
@@ -93,7 +91,12 @@ public abstract class AbstractModifyingR
}
public void commit(ResourceResolver resolver) throws PersistenceException {
+ if (!hasChanges(resolver)) {
+ return;
+ }
+
save(resolver, changedResources, deletedResources);
+
revert(resolver);
}
@@ -114,10 +117,30 @@ public abstract class AbstractModifyingR
String resourceName = pathInfo.getMainResourceName();
- this.deletedResources.remove(resourceName);
+ addToChangedResources(resourceName, properties, false);
+ }
+
+ private boolean addToChangedResources(String resourceName, Map<String, Object> newProperties, boolean failIfAlreadyExists) {
+ final boolean deleted = this.deletedResources.remove(resourceName);
+ Map<String, Object> existingResource = getMainResourceProperties(resourceName);
+ if (failIfAlreadyExists && !deleted && existingResource != null) {
+ return false;
+ }
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ if (existingResource != null) {
+ properties.putAll(existingResource);
+ }
+
+ newProperties = unbindMainResourceProperties(newProperties);
+
+ if (newProperties != null) {
+ properties.putAll(newProperties);
+ }
- properties = unbindMainResourceProperties(properties);
this.changedResources.put(resourceName, properties);
+
+ return true;
}
@Override
Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractReadableResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractReadableResourceProvider.java?rev=1600588&r1=1600587&r2=1600588&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractReadableResourceProvider.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/resources/impl/common/AbstractReadableResourceProvider.java Thu Jun 5 10:38:29 2014
@@ -27,6 +27,7 @@ import org.apache.sling.api.resource.Res
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.servlet.http.HttpServletRequest;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -129,6 +130,14 @@ public abstract class AbstractReadableRe
return getResourceProperties(resourceName);
}
+ /**
+ * Binds the variables in the resource property templates to the properties.
+ * Template: resourcePropertyName = "{osgiPropertyName}"
+ * Property: osgiPropertyName = osgiPropertyValue
+ * Result: resourcePropertyName = osgiPropertyValue
+ * @param properties
+ * @return
+ */
protected Map<String, Object> bindMainResourceProperties(Map<String, Object> properties) {
Map<String, Object> result = new HashMap<String, Object>();
@@ -150,10 +159,18 @@ public abstract class AbstractReadableRe
}
- return result;
+ return fixMap(result);
}
- protected Map<String, Object> unbindMainResourceProperties(Map<String, Object> requestProperties) {
+ /**
+ * Unbinds the variables in the resource property templates to the properties.
+ * Template: resourcePropertyName = "{osgiPropertyName}"
+ * Property: resourcePropertyName = osgiPropertyValue
+ * Result: osgiPropertyName = osgiPropertyValue
+ * @param properties
+ * @return
+ */
+ protected Map<String, Object> unbindMainResourceProperties(Map<String, Object> properties) {
Map<String, Object> result = new HashMap<String, Object>();
Map<String, String > resourcePropertyTemplates = additionalResourcePropertiesMap.get(MAIN_RESOURCE_PREFIX);
@@ -164,13 +181,13 @@ public abstract class AbstractReadableRe
if (templateValue.startsWith("{") && templateValue.endsWith("}")) {
String propertyName = templateValue.substring(1, templateValue.length()-1);
- Object propertyValue = requestProperties.get(templateName);
+ Object propertyValue = properties.get(templateName);
if (propertyValue != null) {
result.put(propertyName, propertyValue);
}
}
}
- return result;
+ return fixMap(result);
}
protected Resource buildMainResource(ResourceResolver resourceResolver,
@@ -201,6 +218,45 @@ public abstract class AbstractReadableRe
}
+ static <K,V> Map<String, Object> fixMap(Map<K, V> map) {
+ Map<String, Object> result = new HashMap<String , Object>();
+ for (Map.Entry<K, V> entry : map.entrySet()) {
+ K key = entry.getKey();
+ V value = entry.getValue();
+
+ if (!(key instanceof String)) continue;
+ if (!isAcceptedType(value.getClass())) continue;
+
+ String fixedKey = (String) key;
+ Object fixedValue = value;
+ if (fixedValue.getClass().isArray()) {
+ Class componentType = fixedValue.getClass().getComponentType();
+
+ if (!isAcceptedType(componentType)) {
+ Object[] array = (Object[]) value;
+ if (array == null || array.length == 0) {
+ continue;
+ }
+ fixedValue = Arrays.asList(array).toArray(new String[array.length]);
+ }
+ }
+
+ if (fixedKey == null || fixedValue == null) {
+ continue;
+ }
+
+
+ result.put(fixedKey, fixedValue);
+ }
+
+ return result;
+ }
+
+ static <T> boolean isAcceptedType(Class<T> clazz) {
+ return clazz.isPrimitive() || clazz == String.class || clazz.isArray();
+ }
+
+
protected abstract Map<String, Object> getResourceProperties(String resourceName);
protected abstract Map<String, Object> getResourceRootProperties();
}
Modified: sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentQueueEventServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentQueueEventServlet.java?rev=1600588&r1=1600587&r2=1600588&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentQueueEventServlet.java (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/java/org/apache/sling/replication/servlet/ReplicationAgentQueueEventServlet.java Thu Jun 5 10:38:29 2014
@@ -141,27 +141,27 @@ public class ReplicationAgentQueueEventS
// flush the buffers to make sure the container sends the bytes
writer.flush();
- if (log.isInfoEnabled()) {
- log.info("SSE event {}: {}", event, message);
+ if (log.isDebugEnabled()) {
+ log.debug("SSE event {}: {}", event, message);
}
}
private class SSEListener implements EventHandler {
public void handleEvent(Event event) {
- if (log.isInfoEnabled()) {
- log.info("SSE listener running on event {}", event);
+ if (log.isDebugEnabled()) {
+ log.debug("SSE listener running on event {}", event);
}
Object pathProperty = event.getProperty("replication.package.paths");
Object agentNameProperty = event.getProperty("replication.agent.name");
- if (log.isInfoEnabled()) {
- log.info("cached events {}", cachedEvents.size());
+ if (log.isDebugEnabled()) {
+ log.debug("cached events {}", cachedEvents.size());
}
if (pathProperty != null && agentNameProperty != null) {
String agentName = String.valueOf(agentNameProperty);
String[] paths = (String[]) pathProperty;
synchronized (cachedEvents) {
- if (log.isInfoEnabled()) {
- log.info("queue event for agent {} on paths {}", agentName, Arrays.toString(paths));
+ if (log.isDebugEnabled()) {
+ log.debug("queue event for agent {} on paths {}", agentName, Arrays.toString(paths));
}
Collection<String> eventsForAgent = cachedEvents.get(agentName);
if (eventsForAgent == null) {
Modified: sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/org.apache.sling.replication.transport.impl.HttpTransportHandlerFactory-http-publish-receive.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/org.apache.sling.replication.transport.impl.HttpTransportHandlerFactory-http-publish-receive.json?rev=1600588&r1=1600587&r2=1600588&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/org.apache.sling.replication.transport.impl.HttpTransportHandlerFactory-http-publish-receive.json (original)
+++ sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/org.apache.sling.replication.transport.impl.HttpTransportHandlerFactory-http-publish-receive.json Thu Jun 5 10:38:29 2014
@@ -3,5 +3,5 @@
"name" : "http-publish-receive",
"TransportAuthenticationProviderFactory.target" : "(name=user)",
"authentication.properties" : ["user=admin","password=admin"],
- "endpoints" : [ "http://localhost:4503/system/replication/importer/default" ]
+ "endpoints" : [ "http://localhost:4503/libs/sling/replication/importer/default" ]
}
\ No newline at end of file
Added: sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/resourceproviders/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-replicationHttpTransportConfig.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/resourceproviders/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-replicationHttpTransportConfig.json?rev=1600588&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/resourceproviders/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-replicationHttpTransportConfig.json (added)
+++ sling/trunk/contrib/extensions/replication/core/src/main/resources/SLING-CONTENT/libs/sling/replication/config/resourceproviders/org.apache.sling.replication.resources.impl.OsgiPropertiesResourceProviderFactory-replicationHttpTransportConfig.json Thu Jun 5 10:38:29 2014
@@ -0,0 +1,16 @@
+{
+ "jcr:primaryType" : "sling:OsgiConfig",
+ "name" : "replicationHttpTransportConfig",
+ "provider.roots" : [ "/libs/sling/replication/config/transport/http" ],
+ "serviceType" : "org.apache.sling.replication.transport.impl.HttpTransportHandlerFactory",
+ "providerType" : "osgiConfig",
+ "resourceProperties" : [
+ "../sling:resourceType=replication/config/transport/http/list",
+
+ "sling:resourceType=replication/config/transport/http",
+ "name={name}",
+ "endpoints={endpoints}"
+ ]
+
+
+}
\ No newline at end of file
Modified: sling/trunk/contrib/extensions/replication/it/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/pom.xml?rev=1600588&r1=1600587&r2=1600588&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/pom.xml (original)
+++ sling/trunk/contrib/extensions/replication/it/pom.xml Thu Jun 5 10:38:29 2014
@@ -50,9 +50,6 @@
optionally using -Dmaven.surefire.debug to enable debugging.
-->
<properties>
- <!-- Set this to run the server on a specific port
- <http.port></http.port>
- -->
<!-- Set this to run tests against an existing server instance -->
<keepJarRunning>false</keepJarRunning>
@@ -80,7 +77,9 @@
<!-- Options for the jar to execute. $JAREXEC_SERVER_PORT$ is replaced by the
selected port number -->
- <jar.executor.jar.options>-p $JAREXEC_SERVER_PORT$ -Dsling.run.modes=author</jar.executor.jar.options>
+ <author.jar.executor.jar.options>-p $JAREXEC_SERVER_PORT$ -Dsling.run.modes=author -Dsling.home=sling/author</author.jar.executor.jar.options>
+ <publish.jar.executor.jar.options>-p $JAREXEC_SERVER_PORT$ -Dsling.run.modes=publish -Dsling.home=sling/publish</publish.jar.executor.jar.options>
+
<!-- Change this to run selected tests only -->
<tests.to.run>**/**Test.java</tests.to.run>
@@ -187,7 +186,8 @@
<phase>process-resources</phase>
<configuration>
<portNames>
- <portName>http.port</portName>
+ <portName>author.http.port</portName>
+ <portName>publish.http.port</portName>
</portNames>
</configuration>
</execution>
@@ -230,12 +230,17 @@
<test.server.hostname>${test.server.hostname}</test.server.hostname>
<test.server.username>${test.server.username}</test.server.username>
<test.server.password>${test.server.password}</test.server.password>
- <jar.executor.server.port>${http.port}</jar.executor.server.port>
+ <author.jar.executor.server.port>${author.http.port}</author.jar.executor.server.port>
+ <publish.jar.executor.server.port>${publish.http.port}</publish.jar.executor.server.port>
<jar.executor.vm.options>${jar.executor.vm.options}</jar.executor.vm.options>
<jar.executor.jar.folder>${project.basedir}/target/dependency</jar.executor.jar.folder>
<jar.executor.jar.name.regexp>org.apache.sling.launchpad.*jar$</jar.executor.jar.name.regexp>
<jar.executor.work.folder>${jar.executor.work.folder}</jar.executor.work.folder>
- <jar.executor.jar.options>${jar.executor.jar.options}</jar.executor.jar.options>
+
+ <author.jar.executor.jar.options>${author.jar.executor.jar.options}</author.jar.executor.jar.options>
+ <publish.jar.executor.jar.options>${publish.jar.executor.jar.options}</publish.jar.executor.jar.options>
+
+
<additional.bundles.path>
${project.build.directory},${project.build.directory}/sling/additional-bundles
</additional.bundles.path>
@@ -285,6 +290,12 @@
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.osgi</artifactId>
+ <version>2.2.0</version>
+ <scope>provided</scope>
+ </dependency>
<!-- FILEVAULT -->
<dependency>
<groupId>org.apache.jackrabbit.vault</groupId>
Added: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ForwardReplicationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ForwardReplicationTest.java?rev=1600588&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ForwardReplicationTest.java (added)
+++ sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ForwardReplicationTest.java Thu Jun 5 10:38:29 2014
@@ -0,0 +1,48 @@
+/*
+ * 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.replication.it;
+
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.junit.Test;
+
+import static org.apache.sling.replication.it.ReplicationUtils.*;
+
+public class ForwardReplicationTest extends ReplicationIntegrationTestBase {
+
+ @Test
+ public void testAddContent() throws Exception {
+ String nodePath = createRandomNode(authorClient, "/content");
+ assertExits(authorClient, nodePath);
+ replicate(author, "publish", ReplicationActionType.ADD, nodePath);
+ assertExits(publishClient, nodePath);
+ }
+
+
+ @Test
+ public void testDeleteContent() throws Exception {
+ String nodePath = createRandomNode(authorClient, "/content");
+ replicate(author, "publish", ReplicationActionType.ADD, nodePath);
+ assertExits(publishClient, nodePath);
+
+ replicate(author, "publish", ReplicationActionType.DELETE, nodePath);
+ assertNotExits(publishClient, nodePath);
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ForwardReplicationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentCommandsIntegrationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentCommandsIntegrationTest.java?rev=1600588&r1=1600587&r2=1600588&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentCommandsIntegrationTest.java (original)
+++ sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentCommandsIntegrationTest.java Thu Jun 5 10:38:29 2014
@@ -20,29 +20,35 @@ package org.apache.sling.replication.it;
import org.apache.sling.replication.communication.ReplicationActionType;
import org.apache.sling.replication.communication.ReplicationHeader;
+import org.junit.Ignore;
import org.junit.Test;
+import static org.apache.sling.replication.it.ReplicationUtils.*;
+
/**
* Integration test for commands on {@link org.apache.sling.replication.agent.ReplicationAgent}s
*/
-public class ReplicationAgentCommandsIntegrationTest extends ReplicationITBase {
+public class ReplicationAgentCommandsIntegrationTest extends ReplicationIntegrationTestBase {
@Test
public void testAddCommand() throws Exception {
- String agentResource = getAgentUrl("publish");
- assertPostResourceWithHeaders(202, agentResource, ReplicationHeader.ACTION.toString(), ReplicationActionType.ADD.toString(), ReplicationHeader.PATH.toString(), "/libs/sling/replication");
+ String agentUrl= agentUrl("publish");
+
+ replicate(author, agentUrl, ReplicationActionType.ADD, "dummy");
}
@Test
+ @Ignore
public void testPollCommand() throws Exception {
- String agentResource = getAgentUrl("publish");
- assertPostResourceWithHeaders(200, agentResource, ReplicationHeader.ACTION.toString(), ReplicationActionType.POLL.toString());
+ String agentUrl = agentUrl("publish");
+ replicate(author, agentUrl, ReplicationActionType.POLL);
}
@Test
public void testDeleteCommand() throws Exception {
- String agentResource = getAgentUrl("publish");
- assertPostResourceWithHeaders(202, agentResource, ReplicationHeader.ACTION.toString(), ReplicationActionType.DELETE.toString(), ReplicationHeader.PATH.toString(), "/not/existing");
+ String agentUrl= agentUrl("publish");
+
+ replicate(author, agentUrl, ReplicationActionType.DELETE, "dummy");
}
}
\ No newline at end of file
Modified: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java?rev=1600588&r1=1600587&r2=1600588&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java (original)
+++ sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java Thu Jun 5 10:38:29 2014
@@ -19,15 +19,18 @@
package org.apache.sling.replication.it;
import java.io.IOException;
+import java.util.UUID;
+
import org.junit.Test;
+import static org.apache.sling.replication.it.ReplicationUtils.*;
/**
* Integration test for {@link org.apache.sling.replication.agent.ReplicationAgent} resources
*/
-public class ReplicationAgentResourcesIntegrationTest extends ReplicationITBase {
+public class ReplicationAgentResourcesIntegrationTest extends ReplicationIntegrationTestBase {
@Test
- public void testDefaultAgentConfigurationResources() throws IOException {
+ public void testDefaultAgentConfigurationResources() throws Exception {
String[] defaultAgentNames = new String[]{
"publish",
"publish-reverse",
@@ -36,13 +39,13 @@ public class ReplicationAgentResourcesIn
"cache-flush"
};
for (String agentName : defaultAgentNames) {
- assertResourceExists(getAgentConfigUrl(agentName));
+ assertExits(authorClient, agentConfigUrl(agentName));
}
}
@Test
- public void testDefaultPublishAgentResources() throws IOException {
+ public void testDefaultPublishAgentResources() throws Exception {
// these agents do not exist as they are bundled to publish runMode
String[] defaultPublishAgentNames = new String[]{
"reverserepo",
@@ -50,24 +53,24 @@ public class ReplicationAgentResourcesIn
"cache-flush"
};
for (String agentName : defaultPublishAgentNames) {
- assertResourceDoesNotExist(getAgentUrl(agentName));
+ assertNotExits(authorClient, agentUrl(agentName));
}
}
@Test
- public void testDefaultAuthorAgentResources() throws IOException {
+ public void testDefaultAuthorAgentResources() throws Exception {
// these agents exist as they are bundled to author runMode
String[] defaultAuthorAgentNames = new String[]{
"publish",
"publish-reverse"
};
for (String agentName : defaultAuthorAgentNames) {
- assertResourceExists(getAgentUrl(agentName));
+ assertExits(authorClient, agentUrl(agentName));
}
}
@Test
- public void testDefaultPublishAgentQueueResources() throws IOException {
+ public void testDefaultPublishAgentQueueResources() throws Exception {
// these agent queues do not exist as they are bundled to publish runMode
String[] defaultPublishAgentNames = new String[]{
"reverserepo",
@@ -75,39 +78,38 @@ public class ReplicationAgentResourcesIn
"cache-flush"
};
for (String agentName : defaultPublishAgentNames) {
- assertResourceDoesNotExist(getAgentUrl(agentName)+"/queue");
+ assertNotExits(authorClient, queueUrl(agentName));
}
}
@Test
- public void testDefaultAuthorAgentQueueResources() throws IOException {
+ public void testDefaultAuthorAgentQueueResources() throws Exception {
// these agent queues exist as they are bundled to author runMode
String[] defaultAuthorAgentNames = new String[]{
"publish",
"publish-reverse"
};
for (String agentName : defaultAuthorAgentNames) {
- assertResourceExists(getAgentUrl(agentName)+"/queue");
+ assertExits(authorClient, queueUrl(agentName));
}
}
@Test
public void testDefaultAgentsRootResource() throws Exception {
- String rootResource = getAgentRootUrl();
- assertResourceExists(rootResource);
- assertJsonResponseContains(rootResource,
+ assertExits(authorClient, agentRootUrl());
+ assertResponseContains(author, agentRootUrl(),
"sling:resourceType", "replication/agents",
- "items", "[\"publish-reverse\",\"publish\"]");
+ "items", "publish-reverse","publish");
}
@Test
public void testAgentConfigurationResourceCreate() throws Exception {
- String agentName = "sample-create-config";
- String newConfigResource = getAgentConfigUrl(agentName);
+ String agentName = "sample-create-config" + UUID.randomUUID();
+ String newConfigResource = agentConfigUrl(agentName);
- assertPostResourceWithParameters(201, newConfigResource, "name", agentName, "transportHandler", "(name=author)");
- assertResourceExists(newConfigResource);
- assertJsonResponseContains(newConfigResource,
+ authorClient.createNode(newConfigResource, "name", agentName, "transportHandler", "(name=author)");
+ assertExits(authorClient, newConfigResource);
+ assertResponseContains(author, newConfigResource,
"sling:resourceType", "replication/config/agent",
"name", agentName,
"transportHandler", "(name=author)");
@@ -115,24 +117,29 @@ public class ReplicationAgentResourcesIn
@Test
public void testAgentConfigurationResourceDelete() throws Exception {
- String agentName = "sample-delete-config";
- String newConfigResource = getAgentConfigUrl(agentName);
- assertPostResourceWithParameters(201, newConfigResource, "name", agentName, "transportHandler", "(name=author)");
- assertResourceExists(newConfigResource);
- assertPostResourceWithParameters(200, newConfigResource, ":operation", "delete");
- assertResourceDoesNotExist(newConfigResource);
+ String agentName = "sample-delete-config" + UUID.randomUUID();
+ String newConfigResource = agentConfigUrl(agentName);
+ authorClient.createNode(newConfigResource, "name", agentName, "transportHandler", "(name=author)");
+ assertExits(authorClient, newConfigResource);
+
+ deleteNode(author, newConfigResource);
+ // authorClient.delete does not work for some reason
+ assertNotExits(authorClient, newConfigResource);
}
@Test
public void testAgentConfigurationResourceUpdate() throws Exception {
- String agentName = "sample-update-config";
- String newConfigResource = getAgentConfigUrl(agentName);
- assertPostResourceWithParameters(201, newConfigResource, "name", agentName, "transportHandler", "(name=author)");
- assertResourceExists(newConfigResource);
- assertJsonResponseContains(newConfigResource,
+ String agentName = "sample-create-config" + UUID.randomUUID();
+ String newConfigResource = agentConfigUrl(agentName);
+
+ authorClient.createNode(newConfigResource, "name", agentName, "transportHandler", "(name=author)");
+ assertExits(authorClient, newConfigResource);
+ authorClient.setProperties(newConfigResource, "transportHandler", "(name=updated)");
+ assertResponseContains(author, newConfigResource,
"sling:resourceType", "replication/config/agent",
"name", agentName,
- "transportHandler", "(name=author)");
+ "transportHandler", "(name=updated)");
}
+
}
\ No newline at end of file
Added: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationIntegrationTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationIntegrationTestBase.java?rev=1600588&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationIntegrationTestBase.java (added)
+++ sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationIntegrationTestBase.java Thu Jun 5 10:38:29 2014
@@ -0,0 +1,75 @@
+/*
+ * 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.replication.it;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.sling.testing.tools.http.Request;
+import org.apache.sling.testing.tools.sling.SlingClient;
+import org.apache.sling.testing.tools.sling.SlingInstance;
+import org.apache.sling.testing.tools.sling.SlingInstanceManager;
+import org.apache.sling.testing.tools.sling.SlingTestBase;
+import org.junit.BeforeClass;
+
+import static org.apache.sling.replication.it.ReplicationUtils.assertExits;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Integration test base class for replication
+ */
+public abstract class ReplicationIntegrationTestBase {
+
+ static SlingInstance author;
+ static SlingInstance publish;
+
+ static SlingClient authorClient;
+ static SlingClient publishClient;
+
+ static {
+ SlingInstanceManager slingInstances = new SlingInstanceManager("author", "publish");
+ author = slingInstances.getInstance("author");
+ publish = slingInstances.getInstance("publish");
+
+ authorClient = new SlingClient(author.getServerBaseUrl(), author.getServerUsername(), author.getServerPassword());
+ publishClient = new SlingClient(publish.getServerBaseUrl(), publish.getServerUsername(), publish.getServerPassword());
+
+
+ try {
+ // change the url for publish agent and wait for it to start
+
+ String receiverUrl = "http://localhost:4503/libs/sling/replication/importer/default"
+ .replace("http://localhost:4503", publish.getServerBaseUrl());
+ authorClient.setProperties("/libs/sling/replication/config/transport/http/http-publish-receive",
+ "endpoints", receiverUrl);
+ assertExits(authorClient, "/libs/sling/replication/agent/publish");
+ }
+ catch (Exception ex) {
+
+ }
+
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationIntegrationTestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java?rev=1600588&r1=1600587&r2=1600588&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java (original)
+++ sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java Thu Jun 5 10:38:29 2014
@@ -20,25 +20,27 @@ package org.apache.sling.replication.it;
import org.junit.Test;
+import static org.apache.sling.replication.it.ReplicationUtils.*;
+
/**
* Integration test for {@link org.apache.sling.replication.serialization.ReplicationPackageImporter} resources
*/
-public class ReplicationPackageImporterResourcesIntegrationTest extends ReplicationITBase {
+public class ReplicationPackageImporterResourcesIntegrationTest extends ReplicationIntegrationTestBase {
@Test
public void testImporterRootResource() throws Exception {
- String rootResource = getImporterRootUrl();
- assertResourceExists(rootResource);
- assertJsonResponseContains(rootResource,
+ String rootResource = importerRootUrl();
+ assertExits(authorClient, rootResource);
+ assertResponseContains(author, rootResource,
"sling:resourceType", "replication/importers",
- "items", "[\"default\"]");
+ "items", "default");
}
@Test
public void testDefaultImporterResource() throws Exception {
- String rootResource = getImporterUrl("default");
- assertResourceExists(rootResource);
- assertJsonResponseContains(rootResource,
+ String rootResource = importerUrl("default");
+ assertExits(authorClient, rootResource);
+ assertResponseContains(author, rootResource,
"sling:resourceType", "replication/importer",
"name", "default");
}
Added: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationUtils.java?rev=1600588&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationUtils.java (added)
+++ sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationUtils.java Thu Jun 5 10:38:29 2014
@@ -0,0 +1,171 @@
+/*
+ * 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.replication.it;
+
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.communication.ReplicationHeader;
+import org.apache.sling.testing.tools.http.Request;
+import org.apache.sling.testing.tools.sling.SlingClient;
+import org.apache.sling.testing.tools.sling.SlingInstance;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Utils class for Replication ITs
+ */
+public class ReplicationUtils {
+
+ private static final String JSON_SELECTOR = ".json";
+ private static final String REPLICATION_ROOT_PATH = "/libs/sling/replication";
+
+ private static void assertPostResourceWithParameters(SlingInstance slingInstance,
+ int status, String path, String... parameters) throws IOException {
+ Request request = slingInstance.getRequestBuilder().buildPostRequest(path);
+
+ if (parameters != null) {
+ assertEquals(0, parameters.length % 2);
+ List<NameValuePair> valuePairList = new ArrayList<NameValuePair>();
+
+ for (int i = 0; i < parameters.length; i += 2) {
+ valuePairList.add(new BasicNameValuePair(parameters[i], parameters[i + 1]));
+ }
+ UrlEncodedFormEntity entity = new UrlEncodedFormEntity(valuePairList);
+ request.withEntity(entity);
+ }
+ slingInstance.getRequestExecutor().execute(
+ request.withCredentials(slingInstance.getServerUsername(), slingInstance.getServerPassword())
+ ).assertStatus(status);
+ }
+
+ private static void assertPostResourceWithHeaders(SlingInstance slingInstance,
+ int status, String path, String... headers) throws IOException {
+ Request request = slingInstance.getRequestBuilder().buildPostRequest(path);
+ if (headers != null) {
+ assertEquals(0, headers.length % 2);
+ for (int i = 0; i < headers.length; i += 2) {
+ request = request.withHeader(headers[i], headers[i + 1]);
+ }
+ }
+ slingInstance.getRequestExecutor().execute(
+ request.withCredentials(slingInstance.getServerUsername(), slingInstance.getServerPassword())
+ ).assertStatus(status);
+ }
+
+ public static void assertResponseContains(SlingInstance slingInstance,
+ String resource, String... parameters) throws IOException {
+ if (!resource.endsWith(JSON_SELECTOR)) {
+ resource += JSON_SELECTOR;
+ }
+ String content = slingInstance.getRequestExecutor().execute(
+ slingInstance.getRequestBuilder().buildGetRequest(resource)
+ .withCredentials(slingInstance.getServerUsername(), slingInstance.getServerPassword())
+ ).getContent().replaceAll("\n", "").trim();
+
+
+ for (int i = 0; i < parameters.length; i++) {
+ assertTrue(parameters[i] + " is not contained in " + content,
+ content.contains(parameters[i])
+ );
+ }
+ }
+
+
+ public static void replicate(SlingInstance slingInstance, String agent, ReplicationActionType action, String... paths) throws IOException {
+ String agentResource = agentUrl("publish");
+
+
+ List<String> args = new ArrayList<String>();
+ args.add(ReplicationHeader.ACTION.toString());
+ args.add(action.toString());
+
+ if (paths != null) {
+ for (String path: paths) {
+ args.add(ReplicationHeader.PATH.toString());
+ args.add(path);
+ }
+ }
+
+ assertPostResourceWithHeaders(slingInstance, 202, agentResource, args.toArray(new String[args.size()]));
+ }
+
+ public static void deleteNode(SlingInstance slingInstance, String path) throws IOException {
+ assertPostResourceWithParameters(slingInstance, 200, path, ":operation", "delete");
+
+ }
+
+ public static void assertExits(SlingClient slingClient, String path) throws Exception {
+ int retries = 100;
+ while(!slingClient.exists(path) && retries-- > 0) {
+ Thread.sleep(1000);
+ }
+
+ assertTrue(retries > 0);
+ }
+
+ public static void assertNotExits(SlingClient slingClient, String path) throws Exception {
+ int retries = 100;
+ while(slingClient.exists(path) && retries-- > 0) {
+ Thread.sleep(1000);
+ }
+
+ assertTrue(retries > 0);
+ }
+
+ public static String createRandomNode(SlingClient slingClient, String parentPath) throws Exception {
+ String nodePath = parentPath + "/" + UUID.randomUUID();
+ slingClient.createNode(nodePath, "propName", "propValue");
+ return nodePath;
+ }
+
+
+ public static String agentRootUrl() {
+ return REPLICATION_ROOT_PATH + "/agent";
+ }
+
+ public static String agentUrl(String agentName) {
+ return REPLICATION_ROOT_PATH + "/agent/" + agentName;
+ }
+
+ public static String queueUrl(String agentName) {
+ return REPLICATION_ROOT_PATH + "/agent/" + agentName +"/queue";
+ }
+
+ public static String agentConfigUrl(String agentName) {
+ return REPLICATION_ROOT_PATH + "/config/agent/" + agentName;
+ }
+
+
+ public static String importerRootUrl() {
+ return REPLICATION_ROOT_PATH + "/importer";
+ }
+
+ public static String importerUrl(String importerName) {
+ return REPLICATION_ROOT_PATH + "/importer/" + importerName;
+ }
+}
Propchange: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingClient.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingClient.java?rev=1600588&r1=1600587&r2=1600588&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingClient.java (original)
+++ sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingClient.java Thu Jun 5 10:38:29 2014
@@ -83,16 +83,8 @@ public class SlingClient {
* and even arguments are values.
*/
public String createNode(String path, String...properties) throws IOException {
- Map<String, Object> props = null;
- if(properties != null && properties.length > 0) {
- props = new HashMap<String, Object>();
- if(properties.length % 2 != 0) {
- throw new IllegalArgumentException("Odd number of properties is invalid:" + properties.length);
- }
- for(int i=0 ; i<properties.length; i+=2) {
- props.put(properties[i], properties[i+1]);
- }
- }
+ Map<String, Object> props = extractMap(properties);
+
return createNode(path, props);
}
@@ -145,6 +137,51 @@ public class SlingClient {
return locationHeaderValue;
}
}
+
+ private Map<String, Object> extractMap(String[] properties) {
+ Map<String, Object> props = null;
+ if(properties != null && properties.length > 0) {
+ props = new HashMap<String, Object>();
+ if(properties.length % 2 != 0) {
+ throw new IllegalArgumentException("Odd number of properties is invalid:" + properties.length);
+ }
+ for(int i=0 ; i<properties.length; i+=2) {
+ props.put(properties[i], properties[i+1]);
+ }
+ }
+
+ return props;
+ }
+
+ /** Updates a node at specified path, with optional properties
+ * specified as a list of String arguments, odd values are keys
+ * and even arguments are values.
+ */
+ public void setProperties(String path, String... properties) throws IOException {
+ Map<String, Object> props = extractMap(properties);
+ setProperties(path, props);
+ }
+
+ /** Updates a node at specified path, with optional properties
+ */
+ public void setProperties(String path, Map<String, Object> properties) throws IOException {
+ final MultipartEntity entity = new MultipartEntity();
+ // Add user properties
+ if(properties != null) {
+ for(Map.Entry<String, Object> e : properties.entrySet()) {
+ entity.addPart(e.getKey(), new StringBody(e.getValue().toString()));
+ }
+ }
+
+ final HttpResponse response =
+ executor.execute(
+ builder.buildPostRequest(path)
+ .withEntity(entity)
+ .withCredentials(username, password)
+ )
+ .assertStatus(200)
+ .getResponse();
+ }
/** Delete supplied path */
public void delete(String path) throws IOException {