summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Bull2012-02-14 23:43:10 (EST)
committerIan Bull2012-02-14 23:43:10 (EST)
commit46eb5d94fff77e8d2814d9c2be3c6de5f57b232d (patch)
treed0184f50a68a7cd008fbfbe119a0b0de03dd8ff4
parentba9d65a0a0c32649760d06e5d53fe1d124e360e5 (diff)
downloadrt.equinox.p2-46eb5d94fff77e8d2814d9c2be3c6de5f57b232d.zip
rt.equinox.p2-46eb5d94fff77e8d2814d9c2be3c6de5f57b232d.tar.gz
rt.equinox.p2-46eb5d94fff77e8d2814d9c2be3c6de5f57b232d.tar.bz2
Bug 371566 - test failure in I20120214-0800
We hijack the mirror selector and never removed it. Whne the tests run in a non-deterministic order, the temp selector causes problems with other test cases. This fixes it by clearing the custom selector after the test finishes.
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/repository/MirrorRequestTest.java41
1 files changed, 31 insertions, 10 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 702a52f..cc43a3a 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
@@ -102,16 +102,19 @@ public class MirrorRequestTest extends AbstractProvisioningTest {
// Test that SimpleArtifactRepository & MirrorRequest use mirrors in the event of a failure.
public void testMirrorFailOver() {
OrderedMirrorSelector selector = new OrderedMirrorSelector(sourceRepository);
-
- // call test
- IArtifactKey key = new ArtifactKey("test.txt", "HelloWorldText", Version.parseVersion("1.0.0"));
- MirrorRequest request = new MirrorRequest(key, targetRepository, null, null, getTransport());
- request.perform(sourceRepository, new NullProgressMonitor());
-
- // The download succeeded
- assertTrue(request.getResult().toString(), request.getResult().isOK());
- // All available mirrors used
- assertEquals("All mirrors utilized", selector.mirrors.length, selector.index);
+ try {
+ // call test
+ IArtifactKey key = new ArtifactKey("test.txt", "HelloWorldText", Version.parseVersion("1.0.0"));
+ MirrorRequest request = new MirrorRequest(key, targetRepository, null, null, getTransport());
+ request.perform(sourceRepository, new NullProgressMonitor());
+
+ // The download succeeded
+ assertTrue(request.getResult().toString(), request.getResult().isOK());
+ // All available mirrors used
+ assertEquals("All mirrors utilized", selector.mirrors.length, selector.index);
+ } finally {
+ selector.clearSelector();
+ }
}
/*
@@ -313,6 +316,7 @@ public class MirrorRequestTest extends AbstractProvisioningTest {
int index = 0;
MirrorInfo[] mirrors;
IArtifactRepository repo;
+ MirrorSelector oldSelector = null;
OrderedMirrorSelector(IArtifactRepository repo) {
super(repo, getTransport());
@@ -331,12 +335,29 @@ public class MirrorRequestTest extends AbstractProvisioningTest {
try {
mirrorField = SimpleArtifactRepository.class.getDeclaredField("mirrors");
mirrorField.setAccessible(true);
+ oldSelector = (MirrorSelector) mirrorField.get(repo); // Store the old value so we can restore it
mirrorField.set(repo, this);
} catch (Exception e) {
fail("0.2", e);
}
}
+ // Clear the mirror selector we place on the repository
+ public void clearSelector() {
+ if (repo == null || oldSelector == null) {
+ return;
+ }
+ repo.setProperty(SimpleArtifactRepository.PROP_FORCE_THREADING, String.valueOf(false));
+ Field mirrorField = null;
+ try {
+ mirrorField = SimpleArtifactRepository.class.getDeclaredField("mirrors");
+ mirrorField.setAccessible(true);
+ mirrorField.set(repo, oldSelector);
+ } catch (Exception e) {
+ fail("0.2", e);
+ }
+ }
+
// Overridden to prevent mirror sorting
@Override
public synchronized void reportResult(String toDownload, IStatus result) {