Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2009-05-04 17:50:30 +0000
committerPascal Rapicault2009-05-04 17:50:30 +0000
commitec3620d8cd957870fd1ae084394c491e353a4b52 (patch)
tree43d09561cc553fb4c4a546ca908aa812dcb33000 /bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact
parentff33d294b7979d96f762921b0b8a5c949b687100 (diff)
downloadrt.equinox.p2-ec3620d8cd957870fd1ae084394c491e353a4b52.tar.gz
rt.equinox.p2-ec3620d8cd957870fd1ae084394c491e353a4b52.tar.xz
rt.equinox.p2-ec3620d8cd957870fd1ae084394c491e353a4b52.zip
Bug 273519 - File corruption when mirroring packed features.
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/MirrorRequestTest.java90
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/SimpleArtifactRepositoryTest.java34
2 files changed, 118 insertions, 6 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/MirrorRequestTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/MirrorRequestTest.java
index 555a9c9b3..11a636d6d 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/MirrorRequestTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/MirrorRequestTest.java
@@ -14,7 +14,7 @@ import java.io.*;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.Properties;
+import java.util.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.eclipse.core.runtime.*;
@@ -37,7 +37,7 @@ public class MirrorRequestTest extends AbstractProvisioningTest {
private static final String testDataLocation = "testData/artifactRepo/emptyJarRepo";
File targetLocation;
IArtifactRepository targetRepository, sourceRepository;
- URI destination, failedOptimized;
+ URI destination, failedOptimized, pakedRepositoryLocation;
public void setUp() throws Exception {
super.setUp();
@@ -49,6 +49,7 @@ public class MirrorRequestTest extends AbstractProvisioningTest {
IArtifactRepositoryManager mgr = getArtifactRepositoryManager();
sourceRepository = mgr.loadRepository((getTestData("EmptyJar repo", testDataLocation).toURI()), null);
failedOptimized = URIUtil.toJarURI(getTestData("Error loading test data", "testData/mirror/invalidPackedMissingCanonical.zip").toURI(), null);
+ pakedRepositoryLocation = getTestData("Error loading packed repository", "testData/mirror/mirrorPackedRepo").toURI();
destination = getTempFolder().toURI();
}
@@ -56,6 +57,7 @@ public class MirrorRequestTest extends AbstractProvisioningTest {
getArtifactRepositoryManager().removeRepository(destination);
getArtifactRepositoryManager().removeRepository(failedOptimized);
getArtifactRepositoryManager().removeRepository(targetLocation.toURI());
+ getArtifactRepositoryManager().removeRepository(pakedRepositoryLocation);
AbstractProvisioningTest.delete(targetLocation);
delete(new File(destination));
super.tearDown();
@@ -116,6 +118,58 @@ public class MirrorRequestTest extends AbstractProvisioningTest {
assertTrue("All mirrors utilized", selector.index == selector.mirrors.length);
}
+ /*
+ * Test that the expected Status level is returned when a mirror fails from packed to canonical
+ */
+ public void testStatusFromFailover() {
+ StatusSequenceRepository source = null;
+ LinkedList seq = new LinkedList();
+ try {
+ source = new StatusSequenceRepository(getArtifactRepositoryManager().loadRepository(pakedRepositoryLocation, new NullProgressMonitor()));
+
+ } catch (ProvisionException e) {
+ fail("Failed to load source repository");
+ }
+ // Set status sequence, actual Statuses added later
+ source.setSequence(seq);
+ // Grab an ArtifactKey to mirror, doesn't matter which
+ IArtifactKey[] keys = source.getArtifactKeys();
+ assertTrue("Unable to obtain artifact keys", keys != null && keys.length > 0);
+
+ MirrorRequest req = new MirrorRequest(keys[0], targetRepository, null, null);
+ req.setSourceRepository(source);
+ // Set Status sequence
+ seq.add(new Status(IStatus.ERROR, "Activator", "Message"));
+ seq.add(new Status(IStatus.WARNING, "Activator", "Message"));
+ req.perform(new NullProgressMonitor());
+
+ assertEquals("Expected WARNING status", IStatus.WARNING, req.getResult().getSeverity());
+
+ // Remove key from repo so the same one can be used
+ targetRepository.removeDescriptor(keys[0]);
+ // Set Status sequence
+ req = new MirrorRequest(keys[0], targetRepository, null, null);
+ req.setSourceRepository(source);
+ seq.add(new Status(IStatus.WARNING, "Activator", "Message"));
+ seq.add(new Status(IStatus.INFO, "Activator", "Message"));
+ req.perform(new NullProgressMonitor());
+
+ assertEquals("Expected INFO status", IStatus.INFO, req.getResult().getSeverity());
+
+ // Remove key from repo so the same one can be used
+ targetRepository.removeDescriptor(keys[0]);
+ // Set Status sequence
+ req = new MirrorRequest(keys[0], targetRepository, null, null);
+ req.setSourceRepository(source);
+ seq.add(new Status(IStatus.INFO, "Activator", "Message"));
+ req.perform(new NullProgressMonitor());
+
+ assertEquals("Expected OK status", IStatus.OK, req.getResult().getSeverity());
+ }
+
+ /*
+ *
+ */
public void testFailedOptimizedMissingCanonical() {
try {
@@ -151,6 +205,38 @@ public class MirrorRequestTest extends AbstractProvisioningTest {
fail(message);
}
+ class StatusSequenceRepository extends AbstractWrappedArtifactRepository {
+ Queue sequence;
+
+ public StatusSequenceRepository(IArtifactRepository repo) {
+ super(repo);
+ }
+
+ public URI getLocation() {
+ // Lie about the location so packed files are used
+ try {
+ return new URI("http://somewhere");
+ } catch (URISyntaxException e) {
+ return null;
+ }
+ }
+
+ public IStatus getArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) {
+ try {
+ destination.write(new byte[] {1, 1, 2});
+ } catch (Exception e) {
+ fail("Failed to write to stream", e);
+ }
+ if (sequence.isEmpty())
+ return Status.OK_STATUS;
+ return (IStatus) sequence.remove();
+ }
+
+ public void setSequence(Queue queue) {
+ sequence = queue;
+ }
+ }
+
private static boolean statusContains(IStatus status, String statusString) {
if (status.getMessage().indexOf(statusString) != -1)
return true;
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/SimpleArtifactRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/SimpleArtifactRepositoryTest.java
index d711d7eb6..f458ab76b 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/SimpleArtifactRepositoryTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/SimpleArtifactRepositoryTest.java
@@ -6,8 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * compeople AG (Stefan Liebig) - initial API and implementation
- * Code 9 - ongoing development
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ * Code 9 - ongoing development
+ * IBM - ongoing development
*******************************************************************************/
package org.eclipse.equinox.p2.tests.artifact.repository;
@@ -20,8 +21,7 @@ import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository;
import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*;
-import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
-import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepHandler;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.*;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
import org.eclipse.equinox.internal.provisional.p2.core.Version;
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
@@ -235,4 +235,30 @@ public class SimpleArtifactRepositoryTest extends AbstractProvisioningTest {
}
}
+
+ /*
+ * Test that the appropriate location for a packed feature is returned.
+ */
+ public void testProperPackedFeatureLocation() {
+ try {
+ repositoryFile = getTempFolder();
+ repositoryURI = repositoryFile.toURI();
+
+ // Create a descriptor for a packed repo
+ ArtifactDescriptor descriptor = new ArtifactDescriptor(new ArtifactKey("org.eclipse.update.feature", "test", Version.parseVersion("1.0.0")));
+ descriptor.setProperty(IArtifactDescriptor.FORMAT, "packed");
+ descriptor.setProcessingSteps(new ProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true)});
+
+ // Create repository
+ Map properties = new HashMap();
+ properties.put("publishPackFilesAsSiblings", Boolean.TRUE.toString());
+ SimpleArtifactRepository repo = (SimpleArtifactRepository) getArtifactRepositoryManager().createRepository(repositoryURI, "My Repo", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties);
+
+ URI location = repo.getLocation(descriptor);
+ assertNotNull("Null location returned", location);
+ assertTrue("Unexpected location", location.toString().endsWith(".pack.gz"));
+ } catch (Exception e) {
+ fail("Test failed", e);
+ }
+ }
}

Back to the top