Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBorislav Kapukaranov2011-02-16 08:10:02 -0500
committerBorislav Kapukaranov2011-02-16 08:10:02 -0500
commited5b4b70f8a7e28eb644f03ae18da163359538be (patch)
tree23f277b9e658218d2932427a0e65da10e8eff74d /org.eclipse.virgo.kernel.deployer.test
parent517a5b8b81f20b0ddd74674301eb51f1fe69c69a (diff)
downloadorg.eclipse.virgo.kernel-ed5b4b70f8a7e28eb644f03ae18da163359538be.tar.gz
org.eclipse.virgo.kernel-ed5b4b70f8a7e28eb644f03ae18da163359538be.tar.xz
org.eclipse.virgo.kernel-ed5b4b70f8a7e28eb644f03ae18da163359538be.zip
bug336200 Deploying atomic plan with lazy bundles in it produces two starting event logs for the atomic plan. This commit fixes that and provides a test
Diffstat (limited to 'org.eclipse.virgo.kernel.deployer.test')
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ParRefreshTests.java197
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanDeploymentTests.java173
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/util/ArtifactLifecycleEvent.java60
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/util/ArtifactListener.java157
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/util/TestLifecycleEvent.java16
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/resources/bug336200.plan11
-rw-r--r--org.eclipse.virgo.kernel.deployer.test/src/test/resources/plan-deployment/lazyBundle.jarbin0 -> 1429 bytes
7 files changed, 391 insertions, 223 deletions
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ParRefreshTests.java b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ParRefreshTests.java
index 3b392247..72f1fe56 100644
--- a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ParRefreshTests.java
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/ParRefreshTests.java
@@ -15,24 +15,21 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
-import java.util.ArrayList;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
+import org.eclipse.virgo.kernel.deployer.test.util.ArtifactLifecycleEvent;
+import org.eclipse.virgo.kernel.deployer.test.util.ArtifactListener;
+import org.eclipse.virgo.kernel.deployer.test.util.TestLifecycleEvent;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifactLifecycleListener;
+import org.eclipse.virgo.util.math.Sets;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
-import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
-import org.eclipse.virgo.kernel.install.artifact.InstallArtifactLifecycleListener;
-import org.eclipse.virgo.kernel.install.artifact.InstallArtifactLifecycleListenerSupport;
-
-import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
-import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
-import org.eclipse.virgo.util.math.Sets;
-
/**
* Test refresh of artifacts in a Par
*
@@ -180,184 +177,4 @@ public class ParRefreshTests extends AbstractDeployerIntegrationTest {
}
}
- private static enum TestLifecycleEvent {
- INSTALLED, INSTALLING, RESOLVED, RESOLVING, STARTED, STARTING, STOPPED, STOPPING, UNINSTALLED, UNINSTALLING, UNRESOLVED
- }
-
- private static class ArtifactLifecycleEvent {
- public ArtifactLifecycleEvent(TestLifecycleEvent lifecycleEvent, String type, String name, Version version) {
- this.lifeCycleEvent = lifecycleEvent;
- this.type = type;
- this.name = name;
- this.version = version;
- }
- public boolean equals(Object obj) {
- if (obj instanceof ArtifactLifecycleEvent) {
- ArtifactLifecycleEvent other = (ArtifactLifecycleEvent) obj;
- return (this.lifeCycleEvent.equals(other.lifeCycleEvent)
- && this.type.equals(other.type)
- && this.name.equals(other.name)
- && this.version.equals(other.version));
- }
- return false;
- }
- public int hashCode() {
- final int prime = 17;
- int result = this.lifeCycleEvent.hashCode() + prime
- * (this.name.hashCode() + prime * (this.type.hashCode() + prime * (this.version.hashCode())));
- return result;
- }
- public String toString() {
- StringBuilder sb = new StringBuilder("[");
- sb.append(this.lifeCycleEvent).append(", ");
- sb.append(this.type).append(", ");
- sb.append(this.name).append(", ");
- sb.append(this.version).append("]");
- return sb.toString();
- }
-
- private final TestLifecycleEvent lifeCycleEvent;
- private final String type;
- private final String name;
- private final Version version;
- }
-
- private static class ArtifactListener extends InstallArtifactLifecycleListenerSupport {
-
- private final Object monitor = new Object();
-
- List<ArtifactLifecycleEvent> eventList = new ArrayList<ArtifactLifecycleEvent>();
-
- public void clear() {
- synchronized (this.monitor) {
- this.eventList.clear();
- }
- }
-
- public boolean waitForEvents(final Set<ArtifactLifecycleEvent> expectedEventSet, long timeout) {
- boolean allReceived = eventsReceived(expectedEventSet);
- while (!allReceived && timeout>0) {
- timeout -= 50L;
- try {
- Thread.sleep(50L);
- } catch (InterruptedException _) {
- // do nothing
- }
- allReceived = eventsReceived(expectedEventSet);
- }
- return allReceived;
- }
-
- private boolean eventsReceived(Set<ArtifactLifecycleEvent> eventSet) {
- synchronized (this.monitor) {
- for (ArtifactLifecycleEvent event : eventSet) {
- if (!this.eventList.contains(event)) {
- return false;
- }
- }
- return true;
- }
- }
-
- public List<ArtifactLifecycleEvent> extract() {
- synchronized (this.monitor) {
- return new ArrayList<ArtifactLifecycleEvent>(this.eventList);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onInstalled(InstallArtifact installArtifact) {
- addEvent(TestLifecycleEvent.INSTALLED, installArtifact);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onInstalling(InstallArtifact installArtifact) {
- addEvent(TestLifecycleEvent.INSTALLING, installArtifact);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onResolved(InstallArtifact installArtifact) {
- addEvent(TestLifecycleEvent.RESOLVED, installArtifact);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onResolving(InstallArtifact installArtifact) {
- addEvent(TestLifecycleEvent.RESOLVING, installArtifact);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onStarted(InstallArtifact installArtifact) {
- addEvent(TestLifecycleEvent.STARTED, installArtifact);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onStarting(InstallArtifact installArtifact) {
- addEvent(TestLifecycleEvent.STARTING, installArtifact);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onStopped(InstallArtifact installArtifact) {
- addEvent(TestLifecycleEvent.STOPPED, installArtifact);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onStopping(InstallArtifact installArtifact) {
- addEvent(TestLifecycleEvent.STOPPING, installArtifact);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onUninstalled(InstallArtifact installArtifact) {
- addEvent(TestLifecycleEvent.UNINSTALLED, installArtifact);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onUninstalling(InstallArtifact installArtifact) {
- addEvent(TestLifecycleEvent.UNINSTALLING, installArtifact);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onUnresolved(InstallArtifact installArtifact) {
- addEvent(TestLifecycleEvent.UNRESOLVED, installArtifact);
- }
-
- private void addEvent(TestLifecycleEvent event, InstallArtifact installArtifact) {
- synchronized (this.monitor) {
- this.eventList.add(new ArtifactLifecycleEvent(event, installArtifact.getType(), installArtifact.getName(),
- installArtifact.getVersion()));
- }
- }
- }
}
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanDeploymentTests.java b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanDeploymentTests.java
index 031e2036..29fb7476 100644
--- a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanDeploymentTests.java
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/PlanDeploymentTests.java
@@ -20,34 +20,50 @@ import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Dictionary;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
-import java.util.Map.Entry;
import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
+import org.eclipse.virgo.kernel.deployer.test.util.ArtifactLifecycleEvent;
+import org.eclipse.virgo.kernel.deployer.test.util.ArtifactListener;
+import org.eclipse.virgo.kernel.deployer.test.util.TestLifecycleEvent;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifactLifecycleListener;
+import org.eclipse.virgo.util.math.Sets;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
-
public class PlanDeploymentTests extends AbstractDeployerIntegrationTest {
- private ServiceReference<ConfigurationAdmin> configAdminServiceReference;
+ private ServiceReference<ConfigurationAdmin> configAdminServiceReference;
+
+ private ConfigurationAdmin configAdmin;
+
+ private static final String PLAN_SYMBOLIC_NAME_BUG336200 = "bug336200.plan";
+
+ private static final String BUG336200_LAZY_BSN = "lazyBundle";
+
+ private static final Version VERSION_BUG336200 = new Version(1, 0, 0);
+
+ private final ArtifactListener artifactListener = new ArtifactListener();
+
+ @Test
+ public void planReferencingAPar() throws Exception {
+ testPlanDeployment(new File("src/test/resources/test-with-par.plan"), null, "par-deployed-by-plan-1-one");
+ }
- private ConfigurationAdmin configAdmin;
-
- @Test
- public void planReferencingAPar() throws Exception {
- testPlanDeployment(new File("src/test/resources/test-with-par.plan"), null, "par-deployed-by-plan-1-one");
- }
-
- @Test(expected=DeploymentException.class)
+ @Test(expected = DeploymentException.class)
public void scopedPlanReferencingAPar() throws Exception {
testPlanDeployment(new File("src/test/resources/scoped-test-with-par.plan"), null);
}
@@ -57,9 +73,10 @@ public class PlanDeploymentTests extends AbstractDeployerIntegrationTest {
String oneBsn = "simple.bundle.one";
String twoBsn = "simple.bundle.two";
- testPlanDeployment(new File("src/test/resources/test.plan"), new File("src/test/resources/plan-deployment/com.foo.bar.properties"), oneBsn, twoBsn);
+ testPlanDeployment(new File("src/test/resources/test.plan"), new File("src/test/resources/plan-deployment/com.foo.bar.properties"), oneBsn,
+ twoBsn);
}
-
+
@Test
public void testSimpleBundleWithFragment() throws Exception {
String oneBsn = "simple.bundle.one";
@@ -67,13 +84,14 @@ public class PlanDeploymentTests extends AbstractDeployerIntegrationTest {
testPlanDeployment(new File("src/test/resources/fragment.plan"), null, oneBsn, twoBsn);
}
-
+
@Test
public void testUnscopedNonAtomicPlan() throws Exception {
String oneBsn = "simple.bundle.one";
String twoBsn = "simple.bundle.two";
- testPlanDeployment(new File("src/test/resources/testunscopednonatomic.plan"), new File("src/test/resources/plan-deployment/com.foo.bar.properties"), oneBsn, twoBsn);
+ testPlanDeployment(new File("src/test/resources/testunscopednonatomic.plan"), new File(
+ "src/test/resources/plan-deployment/com.foo.bar.properties"), oneBsn, twoBsn);
}
@Test
@@ -82,18 +100,24 @@ public class PlanDeploymentTests extends AbstractDeployerIntegrationTest {
Bundle[] bundles = this.context.getBundles();
boolean found = false;
for (Bundle bundle : bundles) {
- if("bundle.properties".equals(bundle.getSymbolicName())) {
+ if ("bundle.properties".equals(bundle.getSymbolicName())) {
found = true;
assertEquals("foo", bundle.getHeaders().get("Test-Header"));
}
}
assertTrue(found);
}
-
+
+ @Test
+ public void testUnscopedAtomicPlanStartingEventsDuringDeployment() throws Exception {
+ testPlanDeploymentStartingEvents(new File("src/test/resources/bug336200.plan"), BUG336200_LAZY_BSN);
+ }
+
@Before
- public void setUp() throws Exception {
+ public void setUp() throws Exception {
this.configAdminServiceReference = this.context.getServiceReference(ConfigurationAdmin.class);
this.configAdmin = this.context.getService(this.configAdminServiceReference);
+ this.context.registerService(InstallArtifactLifecycleListener.class.getName(), artifactListener, null);
}
private void testPlanDeployment(File plan, File propertiesFile, String... candidateBsns) throws Exception {
@@ -103,23 +127,107 @@ public class PlanDeploymentTests extends AbstractDeployerIntegrationTest {
DeploymentIdentity deploymentIdentity = this.deployer.deploy(plan.toURI());
Bundle[] afterDeployBundles = this.context.getBundles();
assertBundlesInstalled(afterDeployBundles, candidateBsns);
-
+
String pid = null;
-
+
if (propertiesFile != null) {
- pid = propertiesFile.getName().substring(0, propertiesFile.getName().length() - ".properties".length());
- checkConfigAvailable(pid, propertiesFile);
+ pid = propertiesFile.getName().substring(0, propertiesFile.getName().length() - ".properties".length());
+ checkConfigAvailable(pid, propertiesFile);
}
this.deployer.undeploy(deploymentIdentity);
Bundle[] afterUndeployBundles = this.context.getBundles();
assertBundlesNotInstalled(afterUndeployBundles, candidateBsns);
-
+
if (propertiesFile != null) {
- checkConfigUnavailable(pid);
+ checkConfigUnavailable(pid);
}
}
+ private void testPlanDeploymentStartingEvents(File plan, String... candidateBsns) throws Exception {
+
+ this.artifactListener.clear();
+
+ Set<ArtifactLifecycleEvent> expectedEventSet = new HashSet<ArtifactLifecycleEvent>();
+ // events expected due to explicit refresh;
+ expectedEventSet.add(new ArtifactLifecycleEvent(TestLifecycleEvent.RESOLVING, "plan", PLAN_SYMBOLIC_NAME_BUG336200, VERSION_BUG336200));
+ expectedEventSet.add(new ArtifactLifecycleEvent(TestLifecycleEvent.RESOLVED, "plan", PLAN_SYMBOLIC_NAME_BUG336200, VERSION_BUG336200));
+ expectedEventSet.add(new ArtifactLifecycleEvent(TestLifecycleEvent.INSTALLING, "plan", PLAN_SYMBOLIC_NAME_BUG336200, VERSION_BUG336200));
+ expectedEventSet.add(new ArtifactLifecycleEvent(TestLifecycleEvent.INSTALLED, "plan", PLAN_SYMBOLIC_NAME_BUG336200, VERSION_BUG336200));
+ expectedEventSet.add(new ArtifactLifecycleEvent(TestLifecycleEvent.STARTING, "plan", PLAN_SYMBOLIC_NAME_BUG336200, VERSION_BUG336200));
+ expectedEventSet.add(new ArtifactLifecycleEvent(TestLifecycleEvent.STARTED, "plan", PLAN_SYMBOLIC_NAME_BUG336200, VERSION_BUG336200));
+
+ expectedEventSet.add(new ArtifactLifecycleEvent(TestLifecycleEvent.RESOLVING, "bundle", BUG336200_LAZY_BSN, VERSION_BUG336200));
+ expectedEventSet.add(new ArtifactLifecycleEvent(TestLifecycleEvent.RESOLVED, "bundle", BUG336200_LAZY_BSN, VERSION_BUG336200));
+ expectedEventSet.add(new ArtifactLifecycleEvent(TestLifecycleEvent.INSTALLING, "bundle", BUG336200_LAZY_BSN, VERSION_BUG336200));
+ expectedEventSet.add(new ArtifactLifecycleEvent(TestLifecycleEvent.INSTALLED, "bundle", BUG336200_LAZY_BSN, VERSION_BUG336200));
+ expectedEventSet.add(new ArtifactLifecycleEvent(TestLifecycleEvent.STARTING, "bundle", BUG336200_LAZY_BSN, VERSION_BUG336200));
+ expectedEventSet.add(new ArtifactLifecycleEvent(TestLifecycleEvent.STARTED, "bundle", BUG336200_LAZY_BSN, VERSION_BUG336200));
+
+ Bundle[] beforeDeployBundles = this.context.getBundles();
+ assertBundlesNotInstalled(beforeDeployBundles, candidateBsns);
+ Thread startBundleThread = new Thread(new StartBundleRunnable(this.context));
+ startBundleThread.start();
+
+ DeploymentIdentity deploymentIdentity = this.deployer.deploy(plan.toURI());
+ waitForAndCheckEventsReceived(expectedEventSet, 10000L);
+
+ Bundle[] afterDeployBundles = this.context.getBundles();
+ assertBundlesInstalled(afterDeployBundles, candidateBsns);
+
+ this.deployer.undeploy(deploymentIdentity);
+ Bundle[] afterUndeployBundles = this.context.getBundles();
+ assertBundlesNotInstalled(afterUndeployBundles, candidateBsns);
+ }
+
+ private class StartBundleRunnable implements Runnable {
+
+ BundleContext context = null;
+
+ public StartBundleRunnable(BundleContext bundleContext) {
+ this.context = bundleContext;
+ }
+
+ @Override
+ public void run() {
+ try {
+ waitAndStartLazyBundle();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } catch (BundleException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ private void waitAndStartLazyBundle() throws InterruptedException, BundleException {
+ Thread.sleep(2500);
+
+ for (Bundle bundle : this.context.getBundles()) {
+ if (bundle.getSymbolicName().equals(BUG336200_LAZY_BSN)) {
+ bundle.start();
+ }
+ }
+ }
+
+ }
+
+ private void waitForAndCheckEventsReceived(Set<ArtifactLifecycleEvent> expectedEventSet, long timeout) {
+ this.artifactListener.waitForEvents(expectedEventSet, timeout);
+
+ Set<ArtifactLifecycleEvent> actualEventSet = new HashSet<ArtifactLifecycleEvent>(this.artifactListener.extract());
+
+ Set<ArtifactLifecycleEvent> extraEvents = Sets.difference(actualEventSet, expectedEventSet);
+ Set<ArtifactLifecycleEvent> missingEvents = Sets.difference(expectedEventSet, actualEventSet);
+
+ assertTrue("More events were received than expected: " + extraEvents, extraEvents.isEmpty());
+ assertTrue("There were missing events: " + missingEvents, missingEvents.isEmpty());
+
+ List<ArtifactLifecycleEvent> actualEventSetList = this.artifactListener.extract();
+ ArtifactLifecycleEvent planStartingEvent = new ArtifactLifecycleEvent(TestLifecycleEvent.STARTING, "bundle", BUG336200_LAZY_BSN, VERSION_BUG336200);
+ assertTrue("More than one STARTING event received for the atomic plan.", actualEventSetList.indexOf(planStartingEvent) == actualEventSetList.lastIndexOf(planStartingEvent));
+ }
+
private void assertBundlesNotInstalled(Bundle[] bundles, String... candidateBsns) {
List<String> installedBsns = getInstalledBsns(bundles);
for (String candidateBsn : candidateBsns) {
@@ -130,21 +238,21 @@ public class PlanDeploymentTests extends AbstractDeployerIntegrationTest {
}
}
}
-
+
@SuppressWarnings("unchecked")
private void checkConfigAvailable(String pid, File propertiesFile) throws IOException {
Configuration configuration = this.configAdmin.getConfiguration(pid, null);
Dictionary<Object, Object> dictionary = configuration.getProperties();
-
+
Properties properties = new Properties();
properties.load(new FileReader(propertiesFile));
-
+
Set<Entry<Object, Object>> entrySet = properties.entrySet();
-
+
for (Entry<Object, Object> entry : entrySet) {
- Assert.assertEquals(entry.getValue(), dictionary.get(entry.getKey()));
- }
-
+ Assert.assertEquals(entry.getValue(), dictionary.get(entry.getKey()));
+ }
+
Assert.assertEquals(pid, dictionary.get("service.pid"));
}
@@ -174,6 +282,5 @@ public class PlanDeploymentTests extends AbstractDeployerIntegrationTest {
return installedBsns;
}
-
-
+
}
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/util/ArtifactLifecycleEvent.java b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/util/ArtifactLifecycleEvent.java
new file mode 100644
index 00000000..18f20303
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/util/ArtifactLifecycleEvent.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2011 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.test.util;
+
+import org.osgi.framework.Version;
+
+public class ArtifactLifecycleEvent {
+
+ public ArtifactLifecycleEvent(TestLifecycleEvent lifecycleEvent, String type, String name, Version version) {
+ this.lifeCycleEvent = lifecycleEvent;
+ this.type = type;
+ this.name = name;
+ this.version = version;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof ArtifactLifecycleEvent) {
+ ArtifactLifecycleEvent other = (ArtifactLifecycleEvent) obj;
+ return this.lifeCycleEvent.equals(other.lifeCycleEvent) && this.type.equals(other.type) && this.name.equals(other.name)
+ && this.version.equals(other.version);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 17;
+ int result = this.lifeCycleEvent.hashCode() + prime
+ * (this.name.hashCode() + prime * (this.type.hashCode() + prime * this.version.hashCode()));
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("[");
+ sb.append(this.lifeCycleEvent).append(", ");
+ sb.append(this.type).append(", ");
+ sb.append(this.name).append(", ");
+ sb.append(this.version).append("]");
+ return sb.toString();
+ }
+
+ private final TestLifecycleEvent lifeCycleEvent;
+
+ private final String type;
+
+ private final String name;
+
+ private final Version version;
+} \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/util/ArtifactListener.java b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/util/ArtifactListener.java
new file mode 100644
index 00000000..ad3b4dc3
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/util/ArtifactListener.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2011 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.test.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifactLifecycleListenerSupport;
+
+public class ArtifactListener extends InstallArtifactLifecycleListenerSupport {
+
+ private final Object monitor = new Object();
+
+ List<ArtifactLifecycleEvent> eventList = new ArrayList<ArtifactLifecycleEvent>();
+
+ public void clear() {
+ synchronized (this.monitor) {
+ this.eventList.clear();
+ }
+ }
+
+ public boolean waitForEvents(final Set<ArtifactLifecycleEvent> expectedEventSet, long timeout) {
+ boolean allReceived = eventsReceived(expectedEventSet);
+ while (!allReceived && timeout > 0) {
+ timeout -= 50L;
+ try {
+ Thread.sleep(50L);
+ } catch (InterruptedException _) {
+ // do nothing
+ }
+ allReceived = eventsReceived(expectedEventSet);
+ }
+ return allReceived;
+ }
+
+ private boolean eventsReceived(Set<ArtifactLifecycleEvent> eventSet) {
+ synchronized (this.monitor) {
+ for (ArtifactLifecycleEvent event : eventSet) {
+ if (!this.eventList.contains(event)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ public List<ArtifactLifecycleEvent> extract() {
+ synchronized (this.monitor) {
+ return new ArrayList<ArtifactLifecycleEvent>(this.eventList);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onInstalled(InstallArtifact installArtifact) {
+ addEvent(TestLifecycleEvent.INSTALLED, installArtifact);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onInstalling(InstallArtifact installArtifact) {
+ addEvent(TestLifecycleEvent.INSTALLING, installArtifact);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onResolved(InstallArtifact installArtifact) {
+ addEvent(TestLifecycleEvent.RESOLVED, installArtifact);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onResolving(InstallArtifact installArtifact) {
+ addEvent(TestLifecycleEvent.RESOLVING, installArtifact);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onStarted(InstallArtifact installArtifact) {
+ addEvent(TestLifecycleEvent.STARTED, installArtifact);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onStarting(InstallArtifact installArtifact) {
+ addEvent(TestLifecycleEvent.STARTING, installArtifact);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onStopped(InstallArtifact installArtifact) {
+ addEvent(TestLifecycleEvent.STOPPED, installArtifact);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onStopping(InstallArtifact installArtifact) {
+ addEvent(TestLifecycleEvent.STOPPING, installArtifact);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onUninstalled(InstallArtifact installArtifact) {
+ addEvent(TestLifecycleEvent.UNINSTALLED, installArtifact);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onUninstalling(InstallArtifact installArtifact) {
+ addEvent(TestLifecycleEvent.UNINSTALLING, installArtifact);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onUnresolved(InstallArtifact installArtifact) {
+ addEvent(TestLifecycleEvent.UNRESOLVED, installArtifact);
+ }
+
+ private void addEvent(TestLifecycleEvent event, InstallArtifact installArtifact) {
+ synchronized (this.monitor) {
+ this.eventList.add(new ArtifactLifecycleEvent(event, installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion()));
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/util/TestLifecycleEvent.java b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/util/TestLifecycleEvent.java
new file mode 100644
index 00000000..fa86ee80
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/java/org/eclipse/virgo/kernel/deployer/test/util/TestLifecycleEvent.java
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2011 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.test.util;
+
+public enum TestLifecycleEvent {
+ INSTALLED, INSTALLING, RESOLVED, RESOLVING, STARTED, STARTING, STOPPED, STOPPING, UNINSTALLED, UNINSTALLING, UNRESOLVED
+}
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/resources/bug336200.plan b/org.eclipse.virgo.kernel.deployer.test/src/test/resources/bug336200.plan
new file mode 100644
index 00000000..f64ea0a1
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/resources/bug336200.plan
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plan name="bug336200.plan" version="1.0.0" scoped="false" atomic="true"
+ xmlns="http://www.eclipse.org/virgo/schema/plan"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.eclipse.org/virgo/schema/plan
+ http://www.eclipse.org/virgo/schema/plan/eclipse-virgo-plan.xsd">
+
+ <artifact type="bundle" name="lazyBundle" version="0.0.0"/>
+
+</plan> \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer.test/src/test/resources/plan-deployment/lazyBundle.jar b/org.eclipse.virgo.kernel.deployer.test/src/test/resources/plan-deployment/lazyBundle.jar
new file mode 100644
index 00000000..5ec5d329
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer.test/src/test/resources/plan-deployment/lazyBundle.jar
Binary files differ

Back to the top