ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ange...@apache.org
Subject svn commit: r1063410 - in /incubator/ace/trunk: ace-integrationtests/ ace-integrationtests/src/test/java/org/apache/ace/it/ ace-integrationtests/src/test/java/org/apache/ace/it/deployment/ ace-integrationtests/src/test/java/org/apache/ace/it/useradminc...
Date Tue, 25 Jan 2011 19:23:39 GMT
Author: angelos
Date: Tue Jan 25 19:23:38 2011
New Revision: 1063410

URL: http://svn.apache.org/viewvc?rev=1063410&view=rev
Log:
ACE-79 ported over the Deployment integration test.

Added:
    incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/deployment/
    incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/deployment/DeploymentIntegrationTest.java
    incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/Util.java
Modified:
    incubator/ace/trunk/ace-integrationtests/pom.xml
    incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/IntegrationTestBase.java
    incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/Options.java
    incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java

Modified: incubator/ace/trunk/ace-integrationtests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-integrationtests/pom.xml?rev=1063410&r1=1063409&r2=1063410&view=diff
==============================================================================
--- incubator/ace/trunk/ace-integrationtests/pom.xml (original)
+++ incubator/ace/trunk/ace-integrationtests/pom.xml Tue Jan 25 19:23:38 2011
@@ -86,6 +86,14 @@
             <artifactId>org.apache.felix.prefs</artifactId>
             <version>1.0.4</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.eventadmin</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.deploymentadmin</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>org.knopflerfish.bundle.useradmin</groupId>
@@ -103,6 +111,16 @@
             <artifactId>ace-scheduler</artifactId>
             <version>0.8.0-SNAPSHOT</version>
         </dependency>
+      <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-discovery-property</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-identification-property</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.ace</groupId>
             <artifactId>ace-httplistener</artifactId>
@@ -153,11 +171,72 @@
             <artifactId>ace-range-api</artifactId>
             <version>0.8.0-SNAPSHOT</version>
         </dependency>
-      <dependency>
-          <groupId>org.apache.ace</groupId>
-          <artifactId>ace-deployment-provider-api</artifactId>
-          <version>0.8.0-SNAPSHOT</version>
-      </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-deployment-provider-api</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-deployment-provider-base</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-deployment-provider-filebased</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-discovery-api</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-discovery-property</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-identification-api</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-identification-property</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-deployment-provider-base</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-deployment-api</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-deployment-deploymentadmin</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-deployment-servlet</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-deployment-task</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ace</groupId>
+            <artifactId>ace-deployment-streamgenerator</artifactId>
+            <version>0.8.0-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 
     <build>

Modified: incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/IntegrationTestBase.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/IntegrationTestBase.java?rev=1063410&r1=1063409&r2=1063410&view=diff
==============================================================================
--- incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/IntegrationTestBase.java
(original)
+++ incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/IntegrationTestBase.java
Tue Jan 25 19:23:38 2011
@@ -37,6 +37,7 @@ import java.util.concurrent.CountDownLat
 import java.util.concurrent.TimeUnit;
 
 import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.ace.test.utils.Util.properties;
 import static org.junit.Assert.fail;
 
 /**
@@ -181,14 +182,6 @@ public class IntegrationTestBase {
         return admin.createFactoryConfiguration(factoryPid, null);
     }
 
-    private static Properties properties(String... values) {
-        Properties props = new Properties();
-        for (int i = 0; i < values.length; i += 2) {
-            props.put(values[i], values[i+1]);
-        }
-        return props;
-    }
-
     // Dependency Manager bridge methods
 
     protected Component createComponent() {

Modified: incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/Options.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/Options.java?rev=1063410&r1=1063409&r2=1063410&view=diff
==============================================================================
--- incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/Options.java
(original)
+++ incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/Options.java
Tue Jan 25 19:23:38 2011
@@ -19,8 +19,10 @@
 package org.apache.ace.it;
 
 import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
+import org.ops4j.pax.exam.options.WrappedUrlProvisionOption;
 
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
 
 /**
  * This class contains a set of Pax Exam options, intended for typo-free provisioning of
bundles.
@@ -49,16 +51,45 @@ public class Options {
             return maven("org.apache.felix.configadmin");
         }
 
+        public static MavenArtifactProvisionOption eventAdmin() {
+            return maven("org.apache.felix.eventadmin");
+        }
+
+        public static MavenArtifactProvisionOption deploymentAdmin() {
+            return maven("org.apache.felix.deploymentadmin");
+        }
+
         private static MavenArtifactProvisionOption maven(String artifactId) {
             return Options.maven("org.apache.felix", artifactId);
         }
     }
 
     public static class Ace {
+        public static WrappedUrlProvisionOption util() {
+            // we do this because we need access to some test classes that aren't exported
+            return wrappedBundle(mavenBundle("org.apache.ace", "ace-util")).overwriteManifest(WrappedUrlProvisionOption.OverwriteMode.FULL);
+        }
+
         public static MavenArtifactProvisionOption rangeApi() {
             return maven("ace-range-api");
         }
 
+        public static MavenArtifactProvisionOption discoveryApi() {
+            return maven("ace-discovery-api");
+        }
+
+        public static MavenArtifactProvisionOption discoveryProperty() {
+            return maven("ace-discovery-property");
+        }
+
+        public static MavenArtifactProvisionOption identificationApi() {
+            return maven("ace-identification-api");
+        }
+
+        public static MavenArtifactProvisionOption identificationProperty() {
+            return maven("ace-identification-property");
+        }
+
         public static MavenArtifactProvisionOption scheduler() {
             return maven("ace-scheduler");
         }
@@ -99,10 +130,34 @@ public class Options {
             return maven("ace-configurator-useradmin-task");
         }
 
+        public static MavenArtifactProvisionOption deploymentApi() {
+            return maven("ace-deployment-api");
+        }
+
+        public static MavenArtifactProvisionOption deploymentDeploymentAdmin() {
+            return maven("ace-deployment-deploymentadmin");
+        }
+
+        public static MavenArtifactProvisionOption deploymentServlet() {
+            return maven("ace-deployment-servlet");
+        }
+
+        public static MavenArtifactProvisionOption deploymentTask() {
+            return maven("ace-deployment-task");
+        }
+
+        public static MavenArtifactProvisionOption deploymentStreamgenerator() {
+            return maven("ace-deployment-streamgenerator");
+        }
+
         public static MavenArtifactProvisionOption deploymentProviderApi() {
             return maven("ace-deployment-provider-api");
         }
 
+        public static MavenArtifactProvisionOption deploymentProviderFilebased() {
+            return maven("ace-deployment-provider-filebased");
+        }
+
         private static MavenArtifactProvisionOption maven(String artifactId) {
             return Options.maven("org.apache.ace", artifactId);
         }

Added: incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/deployment/DeploymentIntegrationTest.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/deployment/DeploymentIntegrationTest.java?rev=1063410&view=auto
==============================================================================
--- incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/deployment/DeploymentIntegrationTest.java
(added)
+++ incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/deployment/DeploymentIntegrationTest.java
Tue Jan 25 19:23:38 2011
@@ -0,0 +1,401 @@
+/*
+ * 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.ace.it.deployment;
+
+import org.apache.ace.deployment.provider.ArtifactData;
+import org.apache.ace.deployment.provider.impl.ArtifactDataImpl;
+import org.apache.ace.discovery.property.constants.DiscoveryConstants;
+import org.apache.ace.http.listener.constants.HttpConstants;
+import org.apache.ace.identification.property.constants.IdentificationConstants;
+import org.apache.ace.it.IntegrationTestBase;
+import org.apache.ace.scheduler.constants.SchedulerConstants;
+import org.apache.ace.test.constants.TestConstants;
+import org.apache.ace.test.utils.deployment.BundleStreamGenerator;
+import org.apache.felix.dm.Component;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.container.def.options.VMOption;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.deploymentadmin.DeploymentAdmin;
+import org.osgi.service.deploymentadmin.DeploymentException;
+import org.osgi.service.deploymentadmin.DeploymentPackage;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+import org.osgi.service.http.HttpService;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.*;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.ace.it.Options.*;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+@RunWith(JUnit4TestRunner.class)
+public class DeploymentIntegrationTest extends IntegrationTestBase implements BundleListener,
EventHandler {
+
+    @org.ops4j.pax.exam.junit.Configuration
+    public Option[] configuration() {
+        return options(
+            systemProperty("org.osgi.service.http.port").value("" + TestConstants.PORT),
+            new VMOption("-ea"),
+            provision(
+                wrappedBundle(maven("org.apache.ace", "ace-deployment-provider-base")), //
necessary since we use an impl class here...
+                Ace.util(),
+                Osgi.compendium(),
+                Felix.dependencyManager(),
+                jetty(),
+                Felix.configAdmin(),
+                Felix.eventAdmin(),
+                Felix.deploymentAdmin(),
+                Ace.scheduler(),
+                Ace.deploymentProviderApi(),
+                Ace.deploymentProviderFilebased(),
+                Ace.discoveryApi(),
+                Ace.discoveryProperty(),
+                Ace.identificationApi(),
+                Ace.identificationProperty(),
+                Ace.httplistener(),
+                Ace.deploymentApi(),
+                Ace.deploymentDeploymentAdmin(),
+                Ace.deploymentServlet(),
+                Ace.deploymentTask(),
+                Ace.deploymentStreamgenerator()
+            )
+        );
+    }
+
+    protected void before() throws IOException {
+        m_tempDir = File.createTempFile("test", "");
+        m_tempDir.delete();
+        m_tempDir.mkdir();
+    }
+
+    protected Component[] getDependencies() {
+        return new Component[] {
+            createComponent()
+                .setImplementation(this)
+                .add(createServiceDependency().setService(HttpService.class).setRequired(true))
+                .add(createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true))
+                .add(createServiceDependency().setService(DeploymentAdmin.class).setRequired(true)),
+        };
+    }
+
+    public static final String HOST = "localhost";
+    public static final String GWID = "gw-id";
+    public static final long POLL_INTERVAL = 1000;
+    private volatile ConfigurationAdmin m_config;
+    private volatile DeploymentAdmin m_deployment;
+    private volatile File m_tempDir;
+    private final Semaphore m_semaphore = new Semaphore(0);
+    Map<Integer, List<Bundle>> m_events = new HashMap<Integer, List<Bundle>>();
+    private ServiceRegistration m_deploymentAdminProxyRegistration;
+
+    @After
+    public void tearDown() {
+        deleteDirOrFile(m_tempDir);
+    }
+
+    private void deleteDirOrFile(File root) {
+        if (root.isDirectory()) {
+            for (File file : root.listFiles()) {
+                deleteDirOrFile(file);
+            }
+        }
+        root.delete();
+    }
+
+    @Test
+    public void deployVersionSeries() throws Exception {
+        Bundle[] start = m_bundleContext.getBundles();
+
+        // Test deploy initial version 1.0.0 with 3 bundles in version 1.0.0
+        String[] versions = new String[] { "bundle1", "bundle2", "bundle3" };
+        generateBundles(createVersion("1.0.0"), versions, 0, versions.length, "1.0.0");
+        executeTest();
+        // start + versions bundles may be present
+        assertState(start, m_bundleContext.getBundles(), versions);
+        assert m_events.get(BundleEvent.STARTED).size() == versions.length : "Received unexpected
amount of starting events.";
+        assert m_events.get(BundleEvent.STOPPED) == null : "Received unexpected amount of
stopping events";
+        m_events.clear();
+
+        // Test correct presence of deployment packages in deployment admin
+        assert m_deployment.listDeploymentPackages().length == 1 : "Deployment admin reports
unexpected number of deployment packages";
+        assert m_deployment.getDeploymentPackage(GWID) != null : "Deployment admin did not
return the expected deployment package";
+        Bundle[] bundles = m_bundleContext.getBundles();
+        Bundle bundle = null;
+        for (int i = 0; i < bundles.length; i++) {
+            if("bundle1".equals(bundles[i].getSymbolicName())) {
+                bundle = bundles[i];
+                break;
+            }
+        }
+        assert m_deployment.getDeploymentPackage(bundle) != null : "Deployment admin did
not return the expected deployment package";
+
+        // Test deploy a version 1.1.0 on top of the previous 1.0.0 with one new bundle and
one updated to version 1.1.0 (i.e., two fix-package bundles)
+        versions = new String[] { "bundle1", "bundle2", "bundle3", "bundle4" };
+        File version = createVersion("1.1.0");
+        generateBundle(new File(version, "0.jar"), versions[0], "1.1.0");
+        generateBundles(version, versions, 1, versions.length, "1.0.0");
+        executeTest();
+        // start + versions bundles may be present
+        assertState(start, m_bundleContext.getBundles(), versions);
+        assert m_events.get(BundleEvent.UPDATED).size() == 1 : "Received unexpected amount
of updated events.";
+        assert m_events.get(BundleEvent.UPDATED).get(0).getSymbolicName().equals(versions[0])
: "Received unexpected update event.";
+        assert m_events.get(BundleEvent.STOPPED).size() == versions.length - 1 : "Received
unexpected amount of stopped events.";
+        assert m_events.get(BundleEvent.STARTED).size() == versions.length : "Received unexpected
amount of started events: expected " + versions.length + ", received " + m_events.get(BundleEvent.STARTED).size()
+ ".";
+        m_events.clear();
+
+        // Test to deploy an empty version 2.0.0, but break the stream which should cancel
the deployment
+        createVersion("2.0.0");
+        executeTestWithFailingStream();
+        m_events.clear();
+
+        // Test to deploy an empty version 2.0.0 which should remove all the previously installed
bundles
+        executeTest();
+
+        // only start bundles may be present
+        assertState(start, m_bundleContext.getBundles(), new String[0]);
+        assert m_events.get(BundleEvent.INSTALLED) == null : "Received unexpected amount
of installed events.";
+        assert m_events.get(BundleEvent.STARTED) == null : "Received unexpected amount of
starting events.";
+        assert m_events.get(BundleEvent.UNINSTALLED).size() == versions.length : "Received
unexpected amount of uninstalled events: " + m_events.get(BundleEvent.UNINSTALLED).size()
+ " instead of " + versions.length;
+        assert m_events.get(BundleEvent.STOPPED).size() == versions.length : "Received unexpected
amount of stopped events: " + m_events.get(BundleEvent.STOPPED).size() + " instead of " +
versions.length;
+        m_events.clear();
+
+    }
+
+    public void bundleChanged(BundleEvent event) {
+        synchronized (m_events) {
+            if (!m_events.containsKey(Integer.valueOf(event.getType()))) {
+                m_events.put(Integer.valueOf(event.getType()), new ArrayList<Bundle>());
+            }
+            m_events.get(Integer.valueOf(event.getType())).add(event.getBundle());
+        }
+    }
+
+    public void handleEvent(Event event) {
+        System.out.println("Event: " + event);
+        m_semaphore.release();
+    }
+
+    private void generateBundles(File dir, String[] versions, int off, int len, String version)
throws Exception {
+        for (int i = off; i < len; i++) {
+            generateBundle(new File(dir, i + ".jar"), versions[i], version);
+        }
+    }
+
+    private void assertState(Bundle[] start, Bundle[] current, String[] versions) {
+        assert (start.length + versions.length) == current.length : "System has " + (((start.length
+ versions.length) < current.length) ? "more" : "less") + " bundes then expected: expected
" + (start.length + versions.length) + ", found " + current.length;
+        for (int i = 0; i < start.length; i++) {
+            assert current[i].getSymbolicName().equals(start[i].getSymbolicName()) : "Bundle
names do not match: " + current[i].getSymbolicName() + " v.s. " + start[i];
+        }
+        List<String> index = Arrays.asList(versions);
+        for (int i = start.length; i < current.length; i++) {
+            assert index.contains(current[i].getSymbolicName()) : "Bundle names do not match:
" + current[i].getSymbolicName();
+        }
+    }
+
+    private File createVersion(String version) {
+        File versionFile = new File(new File(m_tempDir, GWID), version);
+        versionFile.mkdirs();
+        return versionFile;
+    }
+
+    @SuppressWarnings("serial")
+    private void executeTest() throws IOException, InterruptedException {
+        m_bundleContext.addBundleListener(this);
+        ServiceRegistration reg = m_bundleContext.registerService(EventHandler.class.getName(),
this, new Properties() {
+            {
+                put(EventConstants.EVENT_TOPIC, "org/osgi/service/deployment/COMPLETE");
+                put(EventConstants.EVENT_FILTER, "(successful=true)");
+            }
+        });
+        configureGateway();
+        configureServer();
+        assert m_semaphore.tryAcquire(8, TimeUnit.SECONDS) : "Timed out while waiting for
deployment to complete.";
+        unconfigureServer();
+        unconfigureGateway();
+        reg.unregister();
+        m_bundleContext.removeBundleListener(this);
+    }
+
+    private void executeTestWithFailingStream() throws IOException, InterruptedException
{
+        m_bundleContext.addBundleListener(this);
+        registerDeploymentAdminProxy(new FailingDeploymentAdmin(m_deployment, 50));
+        configureGateway();
+        configureServer();
+        assert m_semaphore.tryAcquire(8, TimeUnit.SECONDS) : "Timed out while waiting for
deployment to abort.";
+        unconfigureServer();
+        unconfigureGateway();
+        unregisterDeploymentAdminProxy();
+        m_bundleContext.removeBundleListener(this);
+    }
+
+    /**
+     * Input stream wrapper that creates an input stream that breaks after N bytes. When
it
+     * breaks, it will throw an IO exception and sends a notification to the semaphore that
+     * allows the overall test to continue.
+     */
+    private class BrokenInputStream extends InputStream {
+        private final InputStream m_normalStream;
+        private int m_bytesUntilBreakdown;
+        private boolean m_isBroken;
+
+        public BrokenInputStream(InputStream normalStream, int bytesUntilBreakdown) {
+            m_normalStream = normalStream;
+            m_bytesUntilBreakdown = bytesUntilBreakdown;
+        }
+
+        private synchronized void breakStream() throws IOException {
+            if (!m_isBroken) {
+                m_isBroken = true;
+
+                // release the semaphore to continue the test
+                m_semaphore.release();
+            }
+            throw new IOException("Stream broken.");
+        }
+
+        @Override
+        public int read() throws IOException {
+            if (m_bytesUntilBreakdown-- < 1) {
+                breakStream();
+            }
+            return m_normalStream.read();
+        }
+
+        @Override
+        public void close() throws IOException {
+            m_normalStream.close();
+            breakStream();
+        }
+
+    }
+
+    /**
+     * Wrapper around the deployment admin that will fail once, after N bytes.
+     */
+    private class FailingDeploymentAdmin implements DeploymentAdmin {
+        private final DeploymentAdmin m_deploymentAdmin;
+        private boolean m_wasBroken;
+        private final int m_failAfterBytes;
+
+        public FailingDeploymentAdmin(DeploymentAdmin deploymentAdmin, int failAfterBytes)
{
+            m_deploymentAdmin = deploymentAdmin;
+            m_failAfterBytes = failAfterBytes;
+        }
+
+        public boolean cancel() {
+            return m_deploymentAdmin.cancel();
+        }
+
+        public DeploymentPackage getDeploymentPackage(String symbName) {
+            return m_deploymentAdmin.getDeploymentPackage(symbName);
+        }
+
+        public DeploymentPackage getDeploymentPackage(Bundle bundle) {
+            return m_deploymentAdmin.getDeploymentPackage(bundle);
+        }
+
+        public DeploymentPackage installDeploymentPackage(InputStream in) throws DeploymentException
{
+            synchronized (this) {
+                if (!m_wasBroken) {
+                    m_wasBroken = true;
+                    in = new BrokenInputStream(in, m_failAfterBytes);
+                }
+            }
+            return m_deploymentAdmin.installDeploymentPackage(in);
+        }
+
+        public DeploymentPackage[] listDeploymentPackages() {
+            return m_deploymentAdmin.listDeploymentPackages();
+        }
+    }
+
+    private void configureGateway() throws IOException {
+        // configure discovery bundle
+        setProperty(DiscoveryConstants.DISCOVERY_PID, new Object[][] { { DiscoveryConstants.DISCOVERY_URL_KEY,
"http://" + HOST + ":" + TestConstants.PORT } });
+        // configure identification bundle
+        setProperty(IdentificationConstants.IDENTIFICATION_PID, new Object[][] { { IdentificationConstants.IDENTIFICATION_GATEWAYID_KEY,
GWID } });
+        // configure scheduler
+        setProperty(SchedulerConstants.SCHEDULER_PID, new Object[][] {
+            { "org.apache.ace.gateway.auditlog.task.AuditLogSyncTask", POLL_INTERVAL },
+            { "org.apache.ace.deployment.task.DeploymentUpdateTask", POLL_INTERVAL }
+            });
+    }
+
+    private void unconfigureGateway() throws IOException {
+        m_config.getConfiguration(DiscoveryConstants.DISCOVERY_PID, null).delete();
+        m_config.getConfiguration(IdentificationConstants.IDENTIFICATION_PID, null).delete();
+        m_config.getConfiguration(SchedulerConstants.SCHEDULER_PID, null).delete();
+    }
+
+    private void unconfigureServer() throws IOException {
+        m_config.getConfiguration("org.apache.ace.deployment.servlet", null).delete();
+        m_config.getConfiguration("org.apache.ace.deployment.provider.filebased", null).delete();
+    }
+
+    private void configureServer() throws IOException {
+        // configure data bundle
+        setProperty(org.apache.ace.deployment.servlet.Activator.PID, new Object[][] { { HttpConstants.ENDPOINT,
"/deployment" } });
+        // configure file based backend
+        setProperty(org.apache.ace.deployment.provider.filebased.Activator.PID, new Object[][]
{ { "BaseDirectoryName", m_tempDir.getAbsolutePath() } });
+    }
+
+    @SuppressWarnings("unchecked")
+    private void setProperty(String pid, Object[][] props) throws IOException {
+        Configuration configuration = m_config.getConfiguration(pid, null);
+        Dictionary dictionary = configuration.getProperties();
+        if (dictionary == null) {
+            dictionary = new Hashtable();
+        }
+        for (Object[] pair : props) {
+            dictionary.put(pair[0], pair[1]);
+        }
+        configuration.update(dictionary);
+    }
+
+    private ArtifactData generateBundle(File file, String symbolicName, String version) throws
Exception {
+        ArtifactData bundle = new ArtifactDataImpl(file.getName(), symbolicName, version,
file.toURI().toURL(), false);
+        BundleStreamGenerator.generateBundle(bundle);
+        return bundle;
+    }
+
+    private void registerDeploymentAdminProxy(DeploymentAdmin proxy) {
+        Properties props = new Properties();
+        props.put(org.osgi.framework.Constants.SERVICE_RANKING, 1);
+        m_deploymentAdminProxyRegistration = m_bundleContext.registerService(DeploymentAdmin.class.getName(),
proxy, props);
+    }
+
+    private void unregisterDeploymentAdminProxy() {
+        m_deploymentAdminProxyRegistration.unregister();
+    }
+}

Modified: incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java?rev=1063410&r1=1063409&r2=1063410&view=diff
==============================================================================
--- incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java
(original)
+++ incubator/ace/trunk/ace-integrationtests/src/test/java/org/apache/ace/it/useradminconfigurator/ConfiguratorTest.java
Tue Jan 25 19:23:38 2011
@@ -28,6 +28,7 @@ import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.Configuration;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.options.WrappedUrlProvisionOption;
 import org.osgi.service.useradmin.User;
 import org.osgi.service.useradmin.UserAdmin;
 
@@ -47,6 +48,7 @@ public class ConfiguratorTest extends In
         return options(
             systemProperty("org.osgi.service.http.port").value("" + TestConstants.PORT),
   
             provision(
+                wrappedBundle(maven("org.apache.ace", "ace-util")).overwriteManifest(WrappedUrlProvisionOption.OverwriteMode.FULL),
// we do this because we need access to some test classes that aren't exported
                 Osgi.compendium(),
                 jetty(),
                 Felix.preferences(),

Added: incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/Util.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/Util.java?rev=1063410&view=auto
==============================================================================
--- incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/Util.java (added)
+++ incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/Util.java Tue Jan
25 19:23:38 2011
@@ -0,0 +1,38 @@
+/*
+ * 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.ace.test.utils;
+
+import java.util.Properties;
+
+public class Util {
+
+    /**
+     * Creates a Properties object from a list of key-value pairs, e.g.
+     * <pre>
+     * properties("key", "value", "key2", "value2");
+     * </pre>
+     */
+    public static Properties properties(String... values) {
+        Properties props = new Properties();
+        for (int i = 0; i < values.length; i += 2) {
+            props.put(values[i], values[i+1]);
+        }
+        return props;
+    }
+}



Mime
View raw message