diff options
author | Pascal Rapicault | 2013-02-05 01:29:29 +0000 |
---|---|---|
committer | Pascal Rapicault | 2013-02-05 01:34:38 +0000 |
commit | c0d06cc4735ba69c02d5783b602942725339f39f (patch) | |
tree | 5adaa245e536d170602585771c83d2caa42ab9d4 /bundles | |
parent | 5abf4e9621f428eb2e5cac19c40a715833a24cdd (diff) | |
download | rt.equinox.p2-c0d06cc4735ba69c02d5783b602942725339f39f.tar.gz rt.equinox.p2-c0d06cc4735ba69c02d5783b602942725339f39f.tar.xz rt.equinox.p2-c0d06cc4735ba69c02d5783b602942725339f39f.zip |
Add end to end tests for shared installv20130205-013438
Diffstat (limited to 'bundles')
12 files changed, 364 insertions, 3 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests.verifier/src/org/eclipse/equinox/internal/p2/tests/verifier/VerifierApplication.java b/bundles/org.eclipse.equinox.p2.tests.verifier/src/org/eclipse/equinox/internal/p2/tests/verifier/VerifierApplication.java index fd9029c8d..0c53a5489 100644 --- a/bundles/org.eclipse.equinox.p2.tests.verifier/src/org/eclipse/equinox/internal/p2/tests/verifier/VerifierApplication.java +++ b/bundles/org.eclipse.equinox.p2.tests.verifier/src/org/eclipse/equinox/internal/p2/tests/verifier/VerifierApplication.java @@ -279,9 +279,11 @@ public class VerifierApplication implements IApplication { IProfile profile = registry.getProfile(IProfileRegistry.SELF); if (profile == null) return createError("SELF profile not available in profile registry."); //$NON-NLS-1$ - IQueryResult results = profile.query(QueryUtil.createIUQuery(Activator.PLUGIN_ID), null); - if (results.isEmpty()) - return createError(NLS.bind("IU for {0} not found in SELF profile.", Activator.PLUGIN_ID)); //$NON-NLS-1$ + if (!Boolean.FALSE.toString().equals(properties.get("checkPresenceOfVerifier"))) { + IQueryResult results = profile.query(QueryUtil.createIUQuery(Activator.PLUGIN_ID), null); + if (results.isEmpty()) + return createError(NLS.bind("IU for {0} not found in SELF profile.", Activator.PLUGIN_ID)); //$NON-NLS-1$ + } return Status.OK_STATUS; } @@ -302,7 +304,69 @@ public class VerifierApplication implements IApplication { if (!temp.isOK()) result.merge(temp); + temp = hasProfileFlag(); + if (!temp.isOK()) + result.merge(temp); + + temp = checkAbsenceOfBundles(); + if (!temp.isOK()) + result.merge(temp); + + temp = checkPresenceOfBundles(); + if (!temp.isOK()) + result.merge(temp); + return result; } + private IStatus checkAbsenceOfBundles() { + MultiStatus result = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "Some bundles should not be there", null); + String unexpectedBundlesString = properties.getProperty("unexpectedBundleList"); + if (unexpectedBundlesString == null) + return Status.OK_STATUS; + String[] unexpectedBundles = unexpectedBundlesString.split(","); + for (String bsn : unexpectedBundles) { + if (containsBundle(bsn)) { + result.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, bsn + " should not have been found in the install")); + } + } + if (result.getChildren().length == 0) + return Status.OK_STATUS; + return result; + } + + private IStatus checkPresenceOfBundles() { + MultiStatus result = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "Some bundles should not be there", null); + String expectedBundlesString = properties.getProperty("expectedBundleList"); + if (expectedBundlesString == null) + return Status.OK_STATUS; + String[] expectedBundles = expectedBundlesString.split(","); + for (String bsn : expectedBundles) { + if (!containsBundle(bsn)) { + result.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, bsn + " is missing from the install")); + } + } + if (result.getChildren().length == 0) + return Status.OK_STATUS; + return result; + } + + private boolean containsBundle(String bsn) { + PlatformAdmin platformAdmin = (PlatformAdmin) ServiceHelper.getService(Activator.getBundleContext(), PlatformAdmin.class.getName()); + State state = platformAdmin.getState(false); + return state.getBundle(bsn, null) != null; + } + + private IStatus hasProfileFlag() { + if (properties.getProperty("checkProfileResetFlag") == null) + return Status.OK_STATUS; + //Make sure that the profile is already loaded + IProfileRegistry reg = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME); + reg.getProfile(IProfileRegistry.SELF); + + if (Boolean.valueOf(properties.getProperty("checkProfileResetFlag")).booleanValue() == (agent.getService(IProfileRegistry.SERVICE_SHARED_INSTALL_NEW_TIMESTAMP) != null)) + return Status.OK_STATUS; + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "The flag indicating that a profile has been reset is incorrectly setup"); + } + } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractSharedInstallTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractSharedInstallTest.java new file mode 100644 index 000000000..3ad64a762 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/AbstractSharedInstallTest.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson AB and others. 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: + * Ericsson AB - ongoing development + ******************************************************************************/ +package org.eclipse.equinox.p2.tests.reconciler.dropins; + +import java.io.*; +import java.util.Properties; + +public abstract class AbstractSharedInstallTest extends AbstractReconcilerTest { + static final boolean WINDOWS = java.io.File.separatorChar == '\\'; + protected static File readOnlyBase; + protected static File userBase; + protected static String profileId; + + public File getUserBundleInfo() { + return new File(userBase, "configuration/org.eclipse.equinox.simpleconfigurator/bundles.info"); + } + + public static Properties loadProperties(File inputFile) throws FileNotFoundException, IOException { + Properties props = new Properties(); + InputStream is = null; + try { + is = new FileInputStream(inputFile); + props.load(is); + } finally { + if (is != null) + is.close(); + is = null; + } + return props; + } + + public static void setupReadOnlyInstall() { + readOnlyBase = new File(output, "eclipse"); + assertTrue(readOnlyBase.canWrite()); + setReadOnly(readOnlyBase, true); + userBase = new File(output, "user"); + userBase.mkdir(); + String[] files = new File(readOnlyBase, "p2/org.eclipse.equinox.p2.engine/profileRegistry/").list(); + if (files.length > 1 || files.length == 0) + fail("The profile for the read only install located at: " + output + "could not be determined"); + else + profileId = files[0].substring(0, files[0].indexOf('.')); + } + + public static void setReadOnly(File target, boolean readOnly) { + if (WINDOWS) { + String targetPath = target.getAbsolutePath(); + String[] command = new String[] {"attrib", readOnly ? "+r" : "-r", targetPath, "/s", "/d"}; + run("setReadOnly " + readOnly + " failed on" + target.getAbsolutePath(), command); + if (target.isDirectory()) { + targetPath += "\\*.*"; + command = new String[] {"attrib", readOnly ? "+r" : "-r", targetPath, "/s", "/d"}; + run("setReadOnly " + readOnly + " failed on" + target.getAbsolutePath(), command); + } + } else { + String[] command = new String[] {"chmod", "-R", readOnly ? "a-w" : "a+w", target.getAbsolutePath()}; + run("setReadOnly " + readOnly + " failed on" + target.getAbsolutePath(), command); + } + } + + public AbstractSharedInstallTest(String name) { + super(name); + } + +} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/SharedInstallEnd2End.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/SharedInstallEnd2End.java new file mode 100644 index 000000000..5909b2742 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/reconciler/dropins/SharedInstallEnd2End.java @@ -0,0 +1,222 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson AB and others. 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: + * Ericsson AB - ongoing development + ******************************************************************************/ +package org.eclipse.equinox.p2.tests.reconciler.dropins; + +import java.io.File; +import java.io.IOException; +import java.util.*; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry; +import org.eclipse.equinox.p2.engine.IProfile; + +public class SharedInstallEnd2End extends AbstractSharedInstallTest { + public static Test suite() { + TestSuite suite = new ReconcilerTestSuite(); + suite.setName(SharedInstallEnd2End.class.getName()); + suite.addTest(new SharedInstallEnd2End("testInitialRun")); + suite.addTest(new SharedInstallEnd2End("testInstallInUserSpace")); + suite.addTest(new SharedInstallEnd2End("testBaseChange")); + return suite; + } + + public SharedInstallEnd2End(String name) { + super(name); + } + + private String getTestRepo() { + return getTestData("repo for shared install tests", "testData/sharedInstall/repo").toURI().toString(); + } + + private File getUserBundleInfoTimestamp() { + return new File(userBase, "configuration/org.eclipse.equinox.simpleconfigurator/.baseBundlesInfoTimestamp"); + } + + protected File getUserProfileRegistryFolder() { + return new File(userBase, "p2/org.eclipse.equinox.p2.engine/profileRegistry/"); + } + + private File getUserProfileFolder() { + return new File(getUserProfileRegistryFolder(), profileId + ".profile"); + } + + private File getBaseProfileRegistryFolder() { + return new File(output, "eclipse/p2/org.eclipse.equinox.p2.engine/profileRegistry/"); + } + + private long[] getProfileTimestampsFromUser() { + return new SimpleProfileRegistry(getAgent(), getUserProfileRegistryFolder()).listProfileTimestamps(profileId); + } + + private long getMostRecentProfileTimestamp(File profileFolder) { + long[] ts = new SimpleProfileRegistry(getAgent(), profileFolder).listProfileTimestamps(profileId); + return ts[ts.length - 1]; + } + + private long getMostRecentProfileTimestampFromBase() { + return getMostRecentProfileTimestamp(getBaseProfileRegistryFolder()); + } + + private void assertProfileStatePropertiesHasValue(File profileFolder, String value) { + try { + Properties p = loadProperties(new File(profileFolder, "state.properties")); + Collection<Object> values = p.values(); + for (Object v : values) { + if (((String) v).contains(value)) { + return; + } + } + fail("Value: " + value + " not found."); + } catch (IOException e) { + fail("exception while loading profile state properties in " + profileFolder.getAbsolutePath()); + } + + } + + private File getConfigIniTimestamp() { + return new File(userBase, "configuration/.baseConfigIniTimestamp"); + } + + private void assertProfileStatePropertiesHasKey(File profileFolder, String key) { + try { + Properties p = loadProperties(new File(profileFolder, "state.properties")); + Set<Object> keys = p.keySet(); + for (Object k : keys) { + if (((String) k).contains(key)) { + return; + } + } + fail("Key: " + key + " not found."); + } catch (IOException e) { + fail("exception while loading profile state properties in " + profileFolder.getAbsolutePath()); + } + + } + + private void installInUser() { + //TODO Install something into eclipse - make sure that this can be done in an automated setup + runEclipse("Installing in user", output, new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.director", "-installIU", "p2TestFeature1.feature.group,Verifier.feature.group", "-repository", getTestRepo()}); + } + + private void installInUser2() { + runEclipse("user2", output, new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.director", "-installIU", "p2TestFeature2.feature.group", "-repository", getTestRepo()}); + } + + private void installVerifierInBase() { + setReadOnly(readOnlyBase, false); + runEclipse("Running eclipse", output, new String[] {"-application", "org.eclipse.equinox.p2.director", "-installIU", "Verifier.feature.group", "-repository", getTestRepo()}); + setReadOnly(readOnlyBase, true); + } + + private boolean isInUserBundlesInfo(String bundleId) { + try { + return isInBundlesInfo(getUserBundlesInfo(), bundleId, null, null); + } catch (IOException e) { + fail("Problem reading bundles.info"); + } + //should never be reached + return false; + } + + private File getUserBundlesInfo() { + return new File(userBase, "configuration/org.eclipse.equinox.simpleconfigurator/bundles.info"); + } + + private void startEclipseAsUser() { + runEclipse("Running eclipse", output, new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.garbagecollector.application", "-profile", "_SELF_"}); + } + + public void testInitialRun() { + assertInitialized(); + setupReadOnlyInstall(); + //Here we are invoking the GC to force the profile to be loaded. + startEclipseAsUser(); + assertFalse(getUserBundleInfo().exists()); + assertFalse(getUserBundleInfoTimestamp().exists()); + assertProfileStatePropertiesHasKey(getUserProfileFolder(), IProfile.STATE_PROP_SHARED_INSTALL); + assertProfileStatePropertiesHasValue(getUserProfileFolder(), IProfile.STATE_SHARED_INSTALL_VALUE_INITIAL); + assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); + } + + public void testInstallInUserSpace() { + assertInitialized(); + setupReadOnlyInstall(); + + installInUser(); + assertTrue(isInUserBundlesInfo("p2TestBundle1")); + assertTrue(isInUserBundlesInfo("org.eclipse.swt")); //this verifies that we have the bundles from the base installed in the user bundles.info + + assertTrue(getUserBundleInfoTimestamp().exists()); + assertTrue(getConfigIniTimestamp().exists()); + assertProfileStatePropertiesHasKey(getUserProfileFolder(), IProfile.STATE_PROP_SHARED_INSTALL); + assertProfileStatePropertiesHasValue(getUserProfileFolder(), IProfile.STATE_SHARED_INSTALL_VALUE_INITIAL); + assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); + assertEquals(3, getProfileTimestampsFromUser().length); + } + + public void testBaseChange() { + assertInitialized(); + setupReadOnlyInstall(); + System.out.println(readOnlyBase); + System.out.println(userBase); + + { //install verifier and something else in user and checks there are there + installInUser(); + Properties verificationProperties = new Properties(); + verificationProperties.setProperty("expectedBundleList", "p2TestBundle1,org.eclipse.equinox.p2.tests.verifier"); + verificationProperties.setProperty("checkProfileResetFlag", "false"); + executeVerifier(verificationProperties); + + assertTrue(isInUserBundlesInfo("p2TestBundle1")); + assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); + } + + { //Now change the base. Install the verifier and something else in the base, and run the verifier as a user + installVerifierInBase(); + + Properties verificationProperties = new Properties(); + verificationProperties.setProperty("unexpectedBundleList", "p2TestBundle1"); + verificationProperties.setProperty("checkPresenceOfVerifier", "false"); + verificationProperties.setProperty("expectedBundleList", "org.eclipse.equinox.p2.tests.verifier"); + verificationProperties.setProperty("checkProfileResetFlag", "true"); + executeVerifier(verificationProperties); + assertTrue(isInUserBundlesInfo("p2TestBundle1")); //Despite the reset, the bundles.info is still on-disk unmodified since no provisioning has been done + assertProfileStatePropertiesHasKey(getUserProfileFolder(), "_simpleProfileRegistry_internal_" + getMostRecentProfileTimestampFromBase()); + + verificationProperties = new Properties(); + //Execute the verifier another time, to check that the profile reset flag is not set + verificationProperties.setProperty("checkProfileResetFlag", "false"); + verificationProperties.setProperty("checkPresenceOfVerifier", "false"); + verificationProperties.setProperty("expectedBundleList", "org.eclipse.equinox.p2.tests.verifier"); + executeVerifier(verificationProperties); + } + + { //Now add something into the user install again + installInUser2(); + Properties verificationProperties = new Properties(); + verificationProperties.setProperty("expectedBundleList", "org.eclipse.equinox.p2.tests.verifier"); + executeVerifier(verificationProperties); + assertTrue(isInUserBundlesInfo("p2TestBundle2")); + assertTrue(isInUserBundlesInfo("org.eclipse.equinox.p2.tests.verifier")); //It is now coming from the base + assertFalse(isInUserBundlesInfo("p2TestBundle1")); + + } + } + + private void executeVerifier(Properties verificationProperties) { + File verifierConfig = new File(getTempFolder(), "verification.properties"); + try { + writeProperties(verifierConfig, verificationProperties); + } catch (IOException e) { + fail("Failing to write out properties to configure verifier", e); + } + assertEquals(0, runEclipse("Running verifier", output, new String[] {"-configuration", userBase.getAbsolutePath() + java.io.File.separatorChar + "configuration", "-application", "org.eclipse.equinox.p2.tests.verifier.application", "-verifier.properties", verifierConfig.getAbsolutePath(), "-consoleLog"})); + } +} diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/artifacts.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/artifacts.jar Binary files differnew file mode 100644 index 000000000..c19f0b317 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/artifacts.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/content.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/content.jar Binary files differnew file mode 100644 index 000000000..217ce912c --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/content.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/Verifier_1.0.0.201302041958.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/Verifier_1.0.0.201302041958.jar Binary files differnew file mode 100644 index 000000000..b60bf6b9a --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/Verifier_1.0.0.201302041958.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature1_1.0.0.201302041958.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature1_1.0.0.201302041958.jar Binary files differnew file mode 100644 index 000000000..427842b21 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature1_1.0.0.201302041958.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature2_1.0.0.201302041958.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature2_1.0.0.201302041958.jar Binary files differnew file mode 100644 index 000000000..cf3aa866a --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/features/p2TestFeature2_1.0.0.201302041958.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/org.eclipse.equinox.p2.tests.verifier_1.0.100.201302041958.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/org.eclipse.equinox.p2.tests.verifier_1.0.100.201302041958.jar Binary files differnew file mode 100644 index 000000000..ed56eac95 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/org.eclipse.equinox.p2.tests.verifier_1.0.100.201302041958.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle1_1.0.0.201302041958.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle1_1.0.0.201302041958.jar Binary files differnew file mode 100644 index 000000000..51e68eddf --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle1_1.0.0.201302041958.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle2_1.0.0.201302041958.jar b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle2_1.0.0.201302041958.jar Binary files differnew file mode 100644 index 000000000..3842472b3 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/plugins/p2TestBundle2_1.0.0.201302041958.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/readme.txt b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/readme.txt new file mode 100644 index 000000000..d23b9bd22 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/sharedInstall/repo/readme.txt @@ -0,0 +1,3 @@ +This repository is used by the SharedInstallEnd2End test. +It contains two dummy bundles installable by two dummy features. Those are just used to install content into the base or the user install. +It also contains the code of the p2 verifier bundle wrapped by a feature to make it easily installable.
\ No newline at end of file |