Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2010-08-18 16:09:04 +0000
committerPascal Rapicault2010-08-18 16:09:04 +0000
commitfef51192626d2570af041e80e0b93078d390b8d1 (patch)
tree6ba1a4b59ce45da4941b11da39f7bcff0d3ace14 /bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact
parent25d4506a68edf084ad53e317101671103a570749 (diff)
downloadrt.equinox.p2-fef51192626d2570af041e80e0b93078d390b8d1.tar.gz
rt.equinox.p2-fef51192626d2570af041e80e0b93078d390b8d1.tar.xz
rt.equinox.p2-fef51192626d2570af041e80e0b93078d390b8d1.zip
Bug 313744 - SimpleArtifactRepository does not allow the user to limit the number of threads used for downloads
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/SimpleArtifactRepositoryTest.java47
1 files changed, 47 insertions, 0 deletions
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 5ab2f2a24..0d26dd9b0 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
@@ -14,6 +14,7 @@
package org.eclipse.equinox.p2.tests.artifact.repository;
import java.io.*;
+import java.lang.reflect.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
@@ -386,4 +387,50 @@ public class SimpleArtifactRepositoryTest extends AbstractProvisioningTest {
IArtifactDescriptor resultDescriptor = result.iterator().next();
assertEquals(d3.getArtifactKey(), resultDescriptor.getArtifactKey());
}
+
+ /*
+ * Tests the number of threads allowed
+ */
+ public void testMaximumThreads() throws Exception {
+ File folder = getTestFolder("ArtifactRepository_testQuery");
+ repositoryURI = folder.toURI();
+ IArtifactRepository repo = getArtifactRepositoryManager().createRepository(repositoryURI, "test", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, new HashMap());
+
+ Method getMaximumThreads = SimpleArtifactRepository.class.getDeclaredMethod("getMaximumThreads");
+ getMaximumThreads.setAccessible(true);
+
+ Field defaultMaxThreadsField = SimpleArtifactRepository.class.getDeclaredField("DEFAULT_MAX_THREADS");
+ defaultMaxThreadsField.setAccessible(true);
+
+ int defaultMaxThreads = defaultMaxThreadsField.getInt(repo);
+
+ assertEquals("Default setting", defaultMaxThreads, getIntVal(getMaximumThreads, repo));
+
+ // Legitimate user value
+ System.setProperty(SimpleArtifactRepository.PROP_MAX_THREADS, "2");
+ assertEquals("Valid User setting", 2, getIntVal(getMaximumThreads, repo));
+
+ // User value is too high
+ System.setProperty(SimpleArtifactRepository.PROP_MAX_THREADS, "22");
+ assertEquals("Invalid User setting", defaultMaxThreads, getIntVal(getMaximumThreads, repo));
+ System.clearProperty(SimpleArtifactRepository.PROP_MAX_THREADS);
+
+ // Legitimate repo value
+ repo.setProperty(SimpleArtifactRepository.PROP_MAX_THREADS, "4");
+ assertEquals("Valid repository specified setting", 4, getIntVal(getMaximumThreads, repo));
+
+ // User value is lower should take precedence
+ repo.setProperty(SimpleArtifactRepository.PROP_MAX_THREADS, "3");
+ System.setProperty(SimpleArtifactRepository.PROP_MAX_THREADS, "2");
+ assertEquals("User setting should take precedence", 2, getIntVal(getMaximumThreads, repo));
+
+ // User value is lower should take precedence
+ repo.setProperty(SimpleArtifactRepository.PROP_MAX_THREADS, "2");
+ System.setProperty(SimpleArtifactRepository.PROP_MAX_THREADS, "3");
+ assertEquals("User setting should take precedence", 2, getIntVal(getMaximumThreads, repo));
+ }
+
+ private int getIntVal(Method m, Object repo) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
+ return ((Integer) m.invoke(repo, new Object[] {})).intValue();
+ }
}

Back to the top