diff options
author | Pascal Rapicault | 2013-01-21 16:34:38 +0000 |
---|---|---|
committer | Pascal Rapicault | 2013-01-21 16:34:38 +0000 |
commit | dfec14b67a69b6fa14efb860ef8a986053a58917 (patch) | |
tree | 7f77c6feb9c5549ffa55adce8eee34ee62cf0d81 /bundles/org.eclipse.equinox.p2.tests/src | |
parent | 6067d05e402fe796debd9d25604cae7026df5b48 (diff) | |
parent | ba5f048a3ac5563430104adeb173dc4f7dda6eca (diff) | |
download | rt.equinox.p2-dfec14b.tar.gz rt.equinox.p2-dfec14b.tar.xz rt.equinox.p2-dfec14b.zip |
Merge branch 'master' into prapicau/sharedInstall-part1
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src')
4 files changed, 189 insertions, 2 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java index 4812afd09..b7d7aa35b 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java @@ -136,8 +136,8 @@ public class ProcessingStepHandlerTest extends AbstractProvisioningTest { assertTrue("Step is not ready.", status.isOK()); InputStream inputStream = TestActivator.getContext().getBundle().getEntry("testData/jarprocessor.jar.pack.gz").openStream(); FileUtils.copyStream(inputStream, true, testStream, true); - //the value 34759 obtained by manually unpacking the test artifact using unpack200.exe from sun 7u2 JRE - assertEquals(34759, result.size()); + //the value 35062 obtained by manually unpacking the test artifact using unpack200.exe from sun 7u9 JRE + assertEquals(35062, result.size()); } public void testCreateByteShifterPS() { diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/AllTests.java index 69100ff0b..1248def6c 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/AllTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/AllTests.java @@ -37,6 +37,9 @@ public class AllTests extends TestCase { suite.addTestSuite(TouchpointManagerTest.class); suite.addTestSuite(TouchpointTest.class); suite.addTestSuite(ProvisioningEventTest.class); + suite.addTestSuite(VariableTest.class); + suite.addTestSuite(VariableTest2.class); + suite.addTestSuite(VariableTest3.class); return suite; } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseTest.java index 9b20dc28d..0ccdbe100 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseTest.java @@ -15,9 +15,15 @@ import java.io.IOException; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.p2.engine.*; +import org.eclipse.equinox.internal.p2.engine.phases.Collect; +import org.eclipse.equinox.internal.provisional.p2.core.eventbus.ProvisioningListener; import org.eclipse.equinox.p2.engine.*; import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; import org.eclipse.equinox.p2.metadata.*; +import org.eclipse.equinox.p2.query.QueryUtil; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; /** @@ -303,4 +309,67 @@ public class PhaseTest extends AbstractProvisioningTest { assertEquals(TestAction.class, ((ParameterizedProvisioningAction) actionsList2.get(0)).getAction().getClass()); } + public void testCancelHappenBeforeCompleteCollectPhase() { + final String testDataLocation = "testData/mirror/mirrorSourceRepo3"; + Set<IInstallableUnit> ius = null; + try { + IArtifactRepositoryManager mgr = getArtifactRepositoryManager(); + mgr.loadRepository((getTestData("test artifact repo", testDataLocation).toURI()), null); + IMetadataRepositoryManager metaManager = getMetadataRepositoryManager(); + IMetadataRepository metaRepo = metaManager.loadRepository((getTestData("test metadata repo", testDataLocation).toURI()), null); + ius = metaRepo.query(QueryUtil.ALL_UNITS, null).toUnmodifiableSet(); + } catch (Exception e) { + fail("1.0", e); + } + class MyCollect extends Collect { + boolean isCancelled = false; + int progress = 0; + final static int THREHOLD = 2; + + public MyCollect(int weight) { + super(weight); + } + + @Override + protected List<ProvisioningAction> getActions(InstallableUnitOperand operand) { + List<ProvisioningAction> actions = super.getActions(operand); + if (actions != null) + progress++; + if (progress > THREHOLD) + isCancelled = true; + return actions; + } + } + final MyCollect collect = new MyCollect(100); + PhaseSet phaseSet = new TestPhaseSet(new Phase[] {collect}); + IProfile profile = createProfile("PhaseTest"); + IProvisioningPlan plan = engine.createPlan(profile, null); + for (IInstallableUnit iu : ius) + plan.addInstallableUnit(iu); + class TestListener implements ProvisioningListener { + boolean collectEvent = false; + + public void notify(EventObject o) { + if (o instanceof CollectEvent) + collectEvent = true; + } + + } + TestListener listener = new TestListener(); + getEventBus().addListener(listener); + try { + IStatus status = engine.perform(plan, phaseSet, new NullProgressMonitor() { + @Override + public boolean isCanceled() { + return collect.isCancelled; + } + }); + if (!status.matches(IStatus.CANCEL)) { + fail(status.toString()); + } + assertFalse("Collect actually happened!", listener.collectEvent); + } finally { + getEventBus().removeListener(listener); + } + } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/VariableTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/VariableTest.java new file mode 100644 index 000000000..9df16a597 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/VariableTest.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2012 Landmark Graphics Corporation + * 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: + * Landmark Graphics Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.tests.engine; + +import java.util.*; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; +import org.eclipse.equinox.p2.engine.spi.Value; +import org.eclipse.equinox.p2.metadata.*; +import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription; +import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; + +public class VariableTest extends AbstractProvisioningTest { + + private IInstallableUnit createIUWithVariable() { + InstallableUnitDescription description = new MetadataFactory.InstallableUnitDescription(); + description.setId("artifactWithZip"); + description.setVersion(Version.create("1.0.0")); + Map touchpointData = new HashMap(); + touchpointData.put("install", "test.actionForVariableTesting( arg1: expectedValue ); test.actionForVariableTesting ( arg1: ${lastResult} ); test.actionForVariableTesting ( arg1: ${lastResult} )"); + + description.addTouchpointData(MetadataFactory.createTouchpointData(touchpointData)); + + return MetadataFactory.createInstallableUnit(description); + } + + public void testVariable() { + Action.reinitForNextTest(); + Map properties = new HashMap(); + properties.put(IProfile.PROP_INSTALL_FOLDER, getTempFolder().getAbsolutePath()); + IProfile profile = createProfile("testVariable1", properties); + + Iterator ius = getInstallableUnits(profile); + assertFalse(ius.hasNext()); + + IProvisioningPlan plan = getEngine().createPlan(profile, null); + plan.addInstallableUnit(createIUWithVariable()); + IStatus result = getEngine().perform(plan, PhaseSetFactory.createPhaseSetIncluding(new String[] {PhaseSetFactory.PHASE_INSTALL}), new NullProgressMonitor()); + assertOK(result); + assertEquals("expectedValueaaa", Action.result); + } + + public void testUndo() { + Action.reinitForNextTest(); + Action.failMode = true; + Map properties = new HashMap(); + properties.put(IProfile.PROP_INSTALL_FOLDER, getTempFolder().getAbsolutePath()); + IProfile profile = createProfile("testVariable2", properties); + + Iterator ius = getInstallableUnits(profile); + assertFalse(ius.hasNext()); + + IProvisioningPlan plan = getEngine().createPlan(profile, null); + plan.addInstallableUnit(createIUWithVariable()); + IStatus result = getEngine().perform(plan, PhaseSetFactory.createPhaseSetIncluding(new String[] {PhaseSetFactory.PHASE_INSTALL}), new NullProgressMonitor()); + assertNotOK(result); + assertEquals(3, Action.inputValues.size()); + assertEquals(3, Action.undoValues.size()); + + //The undo values should be the same than the input values + assertEquals(Action.inputValues.get(0), Action.undoValues.get(2)); + assertEquals(Action.inputValues.get(1), Action.undoValues.get(1)); + assertEquals(Action.inputValues.get(2), Action.undoValues.get(0)); + } + + public static class Action extends ProvisioningAction { + public static String result; + public static boolean failMode; + private static int count = 0; + private static final int failAt = 3; + + public static ArrayList<String> inputValues = new ArrayList<String>(); + public static ArrayList<String> undoValues = new ArrayList<String>(); + + public static void reinitForNextTest() { + inputValues = new ArrayList<String>(); + undoValues = new ArrayList<String>(); + failMode = false; + count = 0; + } + + @Override + public IStatus execute(Map<String, Object> parameters) { + inputValues.add((String) parameters.get("arg1")); + System.out.println(this.hashCode()); + System.out.println((String) parameters.get("arg1")); + count++; + if (failMode && count == failAt) + throw new RuntimeException("GENERATED Exception"); + result = ((String) parameters.get("arg1")) + "a"; + + return Status.OK_STATUS; + } + + @Override + public IStatus undo(Map<String, Object> parameters) { + undoValues.add((String) parameters.get("arg1")); + System.out.println("undo arg --> " + (String) parameters.get("arg1")); + return Status.OK_STATUS; + } + + public Value<String> getResult() { + return new Value<String>(result); + } + } +} |