Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Kaegi2009-05-07 22:28:08 +0000
committerSimon Kaegi2009-05-07 22:28:08 +0000
commit202af9c95a0db8f602819a57dd088dbab7008423 (patch)
tree86f37be4c39d7d4e8fdacb2d4392f179d214ec87 /bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine
parent1824d76bad9bc0afdfe165b2a03c1a29b86ff6a7 (diff)
downloadrt.equinox.p2-202af9c95a0db8f602819a57dd088dbab7008423.tar.gz
rt.equinox.p2-202af9c95a0db8f602819a57dd088dbab7008423.tar.xz
rt.equinox.p2-202af9c95a0db8f602819a57dd088dbab7008423.zip
Bug 270542 Ensure that we have ways out of bad uninstall / unconfigure actions
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/EngineTest.java150
1 files changed, 148 insertions, 2 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/EngineTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/EngineTest.java
index 9c4d8d5df..40fbb7407 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/EngineTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/EngineTest.java
@@ -39,8 +39,12 @@ public class EngineTest extends AbstractProvisioningTest {
int operandCount = 0;
int phaseCount = 0;
+ protected CountPhase(String name, boolean forced) {
+ super(name, 1, forced);
+ }
+
protected CountPhase(String name) {
- super(name, 1);
+ this(name, false);
}
protected IStatus completeOperand(IProfile profile, Operand operand, Map parameters, IProgressMonitor monitor) {
@@ -88,8 +92,12 @@ public class EngineTest extends AbstractProvisioningTest {
}
private static class ActionNPEPhase extends CountPhase {
+ protected ActionNPEPhase(boolean forced) {
+ super("ActionNPEPhase", forced);
+ }
+
protected ActionNPEPhase() {
- super("ActionNPEPhase");
+ this(false);
}
protected ProvisioningAction[] getActions(Operand operand) {
@@ -111,6 +119,10 @@ public class EngineTest extends AbstractProvisioningTest {
public TestPhaseSet(Phase phase) {
super(new Phase[] {new Collect(100), new Unconfigure(10), new Uninstall(50), new Property(1), new CheckTrust(10), new Install(50), new Configure(10), phase});
}
+
+ public TestPhaseSet(boolean forced) {
+ super(new Phase[] {new Collect(100), new Unconfigure(10, forced), new Uninstall(50, forced), new Property(1), new CheckTrust(10), new Install(50), new Configure(10)});
+ }
}
private ServiceReference engineRef;
@@ -436,6 +448,88 @@ public class EngineTest extends AbstractProvisioningTest {
assertTrue(phase.isConsistent());
}
+ public void testPerformForcedPhaseWithActionError() {
+ Map properties = new HashMap();
+ properties.put(IProfile.PROP_INSTALL_FOLDER, testProvisioning.getAbsolutePath());
+ IProfile profile = createProfile("testPerformForceWithActionError", null, properties);
+ ActionNPEPhase phase = new ActionNPEPhase(true);
+ PhaseSet phaseSet = new TestPhaseSet(phase);
+
+ Iterator ius = getInstallableUnits(profile);
+ assertFalse(ius.hasNext());
+
+ InstallableUnitOperand[] operands = new InstallableUnitOperand[] {new InstallableUnitOperand(null, createOSGiIU())};
+ IStatus result = engine.perform(profile, phaseSet, operands, null, new NullProgressMonitor());
+ assertTrue(result.isOK());
+ ius = getInstallableUnits(profile);
+ assertTrue(ius.hasNext());
+ assertTrue(phase.isConsistent());
+ }
+
+ public void testPerformForcedUninstallWithBadUninstallIUActionThrowsException() {
+ Map properties = new HashMap();
+ properties.put(IProfile.PROP_INSTALL_FOLDER, testProvisioning.getAbsolutePath());
+ IProfile profile = createProfile("testPerformForcedUninstallWithBadUninstallIUActionThrowsException", null, properties);
+
+ // forcedUninstall is false by default
+ PhaseSet phaseSet = new DefaultPhaseSet();
+
+ Iterator ius = getInstallableUnits(profile);
+ assertFalse(ius.hasNext());
+
+ IInstallableUnit badUninstallIU = createBadUninstallIUThrowsException();
+ InstallableUnitOperand[] operands = new InstallableUnitOperand[] {new InstallableUnitOperand(null, badUninstallIU)};
+ IStatus result = engine.perform(profile, phaseSet, operands, null, new NullProgressMonitor());
+ assertTrue(result.isOK());
+ ius = getInstallableUnits(profile);
+ assertTrue(ius.hasNext());
+
+ operands = new InstallableUnitOperand[] {new InstallableUnitOperand(badUninstallIU, null)};
+ result = engine.perform(profile, phaseSet, operands, null, new NullProgressMonitor());
+ assertFalse(result.isOK());
+ ius = getInstallableUnits(profile);
+ assertTrue(ius.hasNext());
+
+ // this simulates a DefaultPhaseSet with forcedUninstall set
+ phaseSet = new TestPhaseSet(true);
+ result = engine.perform(profile, phaseSet, operands, null, new NullProgressMonitor());
+ assertTrue(result.isOK());
+ ius = getInstallableUnits(profile);
+ assertFalse(ius.hasNext());
+ }
+
+ public void testPerformForcedUninstallWithBadUninstallIUActionReturnsError() {
+ Map properties = new HashMap();
+ properties.put(IProfile.PROP_INSTALL_FOLDER, testProvisioning.getAbsolutePath());
+ IProfile profile = createProfile("testPerformForcedUninstallWithBadUninstallIUActionReturnsError", null, properties);
+
+ // forcedUninstall is false by default
+ PhaseSet phaseSet = new DefaultPhaseSet();
+
+ Iterator ius = getInstallableUnits(profile);
+ assertFalse(ius.hasNext());
+
+ IInstallableUnit badUninstallIU = createBadUninstallIUReturnsError();
+ InstallableUnitOperand[] operands = new InstallableUnitOperand[] {new InstallableUnitOperand(null, badUninstallIU)};
+ IStatus result = engine.perform(profile, phaseSet, operands, null, new NullProgressMonitor());
+ assertTrue(result.isOK());
+ ius = getInstallableUnits(profile);
+ assertTrue(ius.hasNext());
+
+ operands = new InstallableUnitOperand[] {new InstallableUnitOperand(badUninstallIU, null)};
+ result = engine.perform(profile, phaseSet, operands, null, new NullProgressMonitor());
+ assertFalse(result.isOK());
+ ius = getInstallableUnits(profile);
+ assertTrue(ius.hasNext());
+
+ // this simulates a DefaultPhaseSet with forcedUninstall set
+ phaseSet = new TestPhaseSet(true);
+ result = engine.perform(profile, phaseSet, operands, null, new NullProgressMonitor());
+ assertTrue(result.isOK());
+ ius = getInstallableUnits(profile);
+ assertFalse(ius.hasNext());
+ }
+
public void testOrphanedIUProperty() {
IProfile profile = createProfile("testOrphanedIUProperty");
PhaseSet phaseSet = new DefaultPhaseSet();
@@ -510,6 +604,58 @@ public class EngineTest extends AbstractProvisioningTest {
return MetadataFactory.createResolvedInstallableUnit(iu, cus);
}
+ private IInstallableUnit createBadUninstallIUReturnsError() {
+ InstallableUnitDescription description = new MetadataFactory.InstallableUnitDescription();
+ description.setId("org.eclipse.osgi.bad");
+ description.setVersion(new Version("3.3.1.R33x_v20070828"));
+ description.setTouchpointType(AbstractProvisioningTest.TOUCHPOINT_OSGI);
+ Map touchpointData = new HashMap();
+ String manifest = "Manifest-Version: 1.0\r\n" + "Bundle-Activator: org.eclipse.osgi.framework.internal.core.SystemBundl\r\n" + " eActivator\r\n" + "Bundle-RequiredExecutionEnvironment: J2SE-1.4,OSGi/Minimum-1.0\r\n" + "Export-Package: org.eclipse.osgi.event;version=\"1.0\",org.eclipse.osgi.\r\n" + " framework.console;version=\"1.0\",org.eclipse.osgi.framework.eventmgr;v\r\n" + " ersion=\"1.0\",org.eclipse.osgi.framework.log;version=\"1.0\",org.eclipse\r\n" + " .osgi.service.datalocation;version=\"1.0\",org.eclipse.osgi.service.deb\r\n" + " ug;version=\"1.0\",org.eclipse.osgi.service.environment;version=\"1.0\",o\r\n" + " rg.eclipse.osgi.service.localization;version=\"1.0\",org.eclipse.osgi.s\r\n" + " ervice.pluginconversion;version=\"1.0\",org.eclipse.osgi.service.resolv\r\n"
+ + " er;version=\"1.1\",org.eclipse.osgi.service.runnable;version=\"1.0\",org.\r\n" + " eclipse.osgi.service.urlconversion;version=\"1.0\",org.eclipse.osgi.sto\r\n" + " ragemanager;version=\"1.0\",org.eclipse.osgi.util;version=\"1.0\",org.osg\r\n" + " i.framework;version=\"1.3\",org.osgi.service.condpermadmin;version=\"1.0\r\n" + " \",org.osgi.service.packageadmin;version=\"1.2\",org.osgi.service.permis\r\n" + " sionadmin;version=\"1.2\",org.osgi.service.startlevel;version=\"1.0\",org\r\n" + " .osgi.service.url;version=\"1.0\",org.osgi.util.tracker;version=\"1.3.2\"\r\n" + " ,org.eclipse.core.runtime.adaptor;x-friends:=\"org.eclipse.core.runtim\r\n" + " e\",org.eclipse.core.runtime.internal.adaptor;x-internal:=true,org.ecl\r\n"
+ + " ipse.core.runtime.internal.stats;x-friends:=\"org.eclipse.core.runtime\r\n" + " \",org.eclipse.osgi.baseadaptor;x-internal:=true,org.eclipse.osgi.base\r\n" + " adaptor.bundlefile;x-internal:=true,org.eclipse.osgi.baseadaptor.hook\r\n" + " s;x-internal:=true,org.eclipse.osgi.baseadaptor.loader;x-internal:=tr\r\n" + " ue,org.eclipse.osgi.framework.adaptor;x-internal:=true,org.eclipse.os\r\n" + " gi.framework.debug;x-internal:=true,org.eclipse.osgi.framework.intern\r\n" + " al.core;x-internal:=true,org.eclipse.osgi.framework.internal.protocol\r\n" + " ;x-internal:=true,org.eclipse.osgi.framework.internal.protocol.bundle\r\n" + " entry;x-internal:=true,org.eclipse.osgi.framework.internal.protocol.b\r\n"
+ + " undleresource;x-internal:=true,org.eclipse.osgi.framework.internal.pr\r\n" + " otocol.reference;x-internal:=true,org.eclipse.osgi.framework.internal\r\n" + " .reliablefile;x-internal:=true,org.eclipse.osgi.framework.launcher;x-\r\n" + " internal:=true,org.eclipse.osgi.framework.util;x-internal:=true,org.e\r\n" + " clipse.osgi.internal.baseadaptor;x-internal:=true,org.eclipse.osgi.in\r\n" + " ternal.module;x-internal:=true,org.eclipse.osgi.internal.profile;x-in\r\n" + " ternal:=true,org.eclipse.osgi.internal.resolver;x-internal:=true,org.\r\n" + " eclipse.osgi.internal.verifier;x-internal:=true,org.eclipse.osgi.inte\r\n" + " rnal.provisional.verifier;x-friends:=\"org.eclipse.update.core,org.ecl\r\n" + " ipse.ui.workbench\"\r\n" + "Bundle-Version: 3.3.0.v20060925\r\n"
+ + "Eclipse-SystemBundle: true\r\n" + "Bundle-Copyright: %copyright\r\n" + "Bundle-Name: %systemBundle\r\n" + "Bundle-Description: %systemBundle\r\n" + "Bundle-DocUrl: http://www.eclipse.org\r\n" + "Bundle-ManifestVersion: 2\r\n" + "Export-Service: org.osgi.service.packageadmin.PackageAdmin,org.osgi.se\r\n" + " rvice.permissionadmin.PermissionAdmin,org.osgi.service.startlevel.Sta\r\n" + " rtLevel,org.eclipse.osgi.service.debug.DebugOptions\r\n" + "Bundle-Vendor: %eclipse.org\r\n" + "Main-Class: org.eclipse.core.runtime.adaptor.EclipseStarter\r\n" + "Bundle-SymbolicName: org.eclipse.osgi; singleton:=true\r\n" + "Bundle-Localization: systembundle\r\n" + "Eclipse-ExtensibleAPI: true\r\n" + "\r\n" + "";
+ touchpointData.put("manifest", manifest);
+ touchpointData.put("uninstall", "setProgramProperty(missing_mandatory_parameters:xyz)");
+
+ IInstallableUnitFragment[] cus = new IInstallableUnitFragment[1];
+ InstallableUnitFragmentDescription desc = new InstallableUnitFragmentDescription();
+ desc.addTouchpointData(MetadataFactory.createTouchpointData(touchpointData));
+ cus[0] = MetadataFactory.createInstallableUnitFragment(desc);
+
+ //IArtifactKey key = new ArtifactKey("eclipse", "plugin", "org.eclipse.osgi", new Version("3.3.1.R33x_v20070828"));
+ //iu.setArtifacts(new IArtifactKey[] {key});
+
+ IInstallableUnit iu = MetadataFactory.createInstallableUnit(description);
+ return MetadataFactory.createResolvedInstallableUnit(iu, cus);
+ }
+
+ private IInstallableUnit createBadUninstallIUThrowsException() {
+ InstallableUnitDescription description = new MetadataFactory.InstallableUnitDescription();
+ description.setId("org.eclipse.osgi.bad");
+ description.setVersion(new Version("3.3.1.R33x_v20070828"));
+ description.setTouchpointType(AbstractProvisioningTest.TOUCHPOINT_OSGI);
+ Map touchpointData = new HashMap();
+ String manifest = "Manifest-Version: 1.0\r\n" + "Bundle-Activator: org.eclipse.osgi.framework.internal.core.SystemBundl\r\n" + " eActivator\r\n" + "Bundle-RequiredExecutionEnvironment: J2SE-1.4,OSGi/Minimum-1.0\r\n" + "Export-Package: org.eclipse.osgi.event;version=\"1.0\",org.eclipse.osgi.\r\n" + " framework.console;version=\"1.0\",org.eclipse.osgi.framework.eventmgr;v\r\n" + " ersion=\"1.0\",org.eclipse.osgi.framework.log;version=\"1.0\",org.eclipse\r\n" + " .osgi.service.datalocation;version=\"1.0\",org.eclipse.osgi.service.deb\r\n" + " ug;version=\"1.0\",org.eclipse.osgi.service.environment;version=\"1.0\",o\r\n" + " rg.eclipse.osgi.service.localization;version=\"1.0\",org.eclipse.osgi.s\r\n" + " ervice.pluginconversion;version=\"1.0\",org.eclipse.osgi.service.resolv\r\n"
+ + " er;version=\"1.1\",org.eclipse.osgi.service.runnable;version=\"1.0\",org.\r\n" + " eclipse.osgi.service.urlconversion;version=\"1.0\",org.eclipse.osgi.sto\r\n" + " ragemanager;version=\"1.0\",org.eclipse.osgi.util;version=\"1.0\",org.osg\r\n" + " i.framework;version=\"1.3\",org.osgi.service.condpermadmin;version=\"1.0\r\n" + " \",org.osgi.service.packageadmin;version=\"1.2\",org.osgi.service.permis\r\n" + " sionadmin;version=\"1.2\",org.osgi.service.startlevel;version=\"1.0\",org\r\n" + " .osgi.service.url;version=\"1.0\",org.osgi.util.tracker;version=\"1.3.2\"\r\n" + " ,org.eclipse.core.runtime.adaptor;x-friends:=\"org.eclipse.core.runtim\r\n" + " e\",org.eclipse.core.runtime.internal.adaptor;x-internal:=true,org.ecl\r\n"
+ + " ipse.core.runtime.internal.stats;x-friends:=\"org.eclipse.core.runtime\r\n" + " \",org.eclipse.osgi.baseadaptor;x-internal:=true,org.eclipse.osgi.base\r\n" + " adaptor.bundlefile;x-internal:=true,org.eclipse.osgi.baseadaptor.hook\r\n" + " s;x-internal:=true,org.eclipse.osgi.baseadaptor.loader;x-internal:=tr\r\n" + " ue,org.eclipse.osgi.framework.adaptor;x-internal:=true,org.eclipse.os\r\n" + " gi.framework.debug;x-internal:=true,org.eclipse.osgi.framework.intern\r\n" + " al.core;x-internal:=true,org.eclipse.osgi.framework.internal.protocol\r\n" + " ;x-internal:=true,org.eclipse.osgi.framework.internal.protocol.bundle\r\n" + " entry;x-internal:=true,org.eclipse.osgi.framework.internal.protocol.b\r\n"
+ + " undleresource;x-internal:=true,org.eclipse.osgi.framework.internal.pr\r\n" + " otocol.reference;x-internal:=true,org.eclipse.osgi.framework.internal\r\n" + " .reliablefile;x-internal:=true,org.eclipse.osgi.framework.launcher;x-\r\n" + " internal:=true,org.eclipse.osgi.framework.util;x-internal:=true,org.e\r\n" + " clipse.osgi.internal.baseadaptor;x-internal:=true,org.eclipse.osgi.in\r\n" + " ternal.module;x-internal:=true,org.eclipse.osgi.internal.profile;x-in\r\n" + " ternal:=true,org.eclipse.osgi.internal.resolver;x-internal:=true,org.\r\n" + " eclipse.osgi.internal.verifier;x-internal:=true,org.eclipse.osgi.inte\r\n" + " rnal.provisional.verifier;x-friends:=\"org.eclipse.update.core,org.ecl\r\n" + " ipse.ui.workbench\"\r\n" + "Bundle-Version: 3.3.0.v20060925\r\n"
+ + "Eclipse-SystemBundle: true\r\n" + "Bundle-Copyright: %copyright\r\n" + "Bundle-Name: %systemBundle\r\n" + "Bundle-Description: %systemBundle\r\n" + "Bundle-DocUrl: http://www.eclipse.org\r\n" + "Bundle-ManifestVersion: 2\r\n" + "Export-Service: org.osgi.service.packageadmin.PackageAdmin,org.osgi.se\r\n" + " rvice.permissionadmin.PermissionAdmin,org.osgi.service.startlevel.Sta\r\n" + " rtLevel,org.eclipse.osgi.service.debug.DebugOptions\r\n" + "Bundle-Vendor: %eclipse.org\r\n" + "Main-Class: org.eclipse.core.runtime.adaptor.EclipseStarter\r\n" + "Bundle-SymbolicName: org.eclipse.osgi; singleton:=true\r\n" + "Bundle-Localization: systembundle\r\n" + "Eclipse-ExtensibleAPI: true\r\n" + "\r\n" + "";
+ touchpointData.put("manifest", manifest);
+ touchpointData.put("uninstall", "thisactionismissing()");
+
+ IInstallableUnitFragment[] cus = new IInstallableUnitFragment[1];
+ InstallableUnitFragmentDescription desc = new InstallableUnitFragmentDescription();
+ desc.addTouchpointData(MetadataFactory.createTouchpointData(touchpointData));
+ cus[0] = MetadataFactory.createInstallableUnitFragment(desc);
+
+ //IArtifactKey key = new ArtifactKey("eclipse", "plugin", "org.eclipse.osgi", new Version("3.3.1.R33x_v20070828"));
+ //iu.setArtifacts(new IArtifactKey[] {key});
+
+ IInstallableUnit iu = MetadataFactory.createInstallableUnit(description);
+ return MetadataFactory.createResolvedInstallableUnit(iu, cus);
+ }
+
private IInstallableUnit createMissingActionIU() {
InstallableUnitDescription description = new MetadataFactory.InstallableUnitDescription();
description.setId("org.eclipse.osgi.bad");

Back to the top