summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMengxin Zhu2012-04-28 03:06:15 (EDT)
committerMengxin Zhu2012-04-28 03:18:50 (EDT)
commite0c4ca82499a5513fc8ed1a1cbe7d8172e61df68 (patch)
treeb80349df01cf84ca040c1c469d12509ebe19ffdd
parent26efa8031a837dfcee7c3a327055cb23623c26e5 (diff)
downloadrt.equinox.p2-e0c4ca82499a5513fc8ed1a1cbe7d8172e61df68.zip
rt.equinox.p2-e0c4ca82499a5513fc8ed1a1cbe7d8172e61df68.tar.gz
rt.equinox.p2-e0c4ca82499a5513fc8ed1a1cbe7d8172e61df68.tar.bz2
Improve test cases of pausing provisioning.
Signed-off-by: Mengxin Zhu <kane.zhu@windriver.com>
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java72
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest2.java16
2 files changed, 62 insertions, 26 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java
index 7255475..88c2b18 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java
@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
import org.eclipse.equinox.internal.p2.engine.*;
+import org.eclipse.equinox.internal.p2.repository.DownloadProgressEvent;
import org.eclipse.equinox.internal.p2.touchpoint.natives.Util;
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.ProvisioningListener;
import org.eclipse.equinox.internal.provisional.p2.repository.RepositoryEvent;
@@ -260,32 +261,55 @@ public class PhaseSetTest extends AbstractProvisioningTest {
public void testCancelPausedProvisioing() throws ProvisionException, InterruptedException {
URI repoLoc = getTestData("Load test data.", "/testData/pausefeature").toURI();
final PhaseSet phaseSet = (PhaseSet) PhaseSetFactory.createDefaultPhaseSet();
- pause = new PauseJob("pause") {
- protected IStatus run(IProgressMonitor monitor) {
- if (!phaseSet.pause())
- return new Status(IStatus.ERROR, TestActivator.PI_PROV_TESTS, "pause() failed.");
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- System.out.println(new Date() + " -- paused provisioning.");
- // wait seconds
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- //
- }
- setPause(true);
- return Status.OK_STATUS;
+ class ProvListener implements ProvisioningListener {
+ boolean hasDownloadEvent = false;
+
+ public void notify(EventObject o) {
+ if (o instanceof DownloadProgressEvent)
+ hasDownloadEvent = true;
}
+
};
+ final ProvListener listener = new ProvListener();
+ getEventBus().addListener(listener);
+ try {
- basicTest(repoLoc, phaseSet, pause, QueryUtil.createLatestQuery(QueryUtil.createIUQuery("org.eclipse.equinox.executable.feature.group")), 3000, IStatus.CANCEL, new NullProgressMonitor() {
- @Override
- public boolean isCanceled() {
- return pause.isPaused();
- }
- });
+ pause = new PauseJob("pause") {
+ protected IStatus run(IProgressMonitor monitor) {
+ while (!listener.hasDownloadEvent) {
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e1) {
+ e1.printStackTrace();
+ }
+ }
+ if (!phaseSet.pause())
+ return new Status(IStatus.ERROR, TestActivator.PI_PROV_TESTS, "pause() failed.");
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ System.out.println(new Date() + " -- paused provisioning.");
+ // wait seconds
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ //
+ }
+ setPause(true);
+ return Status.OK_STATUS;
+ }
+ };
+
+ basicTest(repoLoc, phaseSet, pause, QueryUtil.createLatestQuery(QueryUtil.createIUQuery("org.eclipse.equinox.executable.feature.group")), 0, IStatus.CANCEL, new NullProgressMonitor() {
+ @Override
+ public boolean isCanceled() {
+ return pause.isPaused();
+ }
+ });
+ } finally {
+ getEventBus().removeListener(listener);
+ }
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest2.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest2.java
index 214523f..d926dab 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest2.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest2.java
@@ -186,13 +186,25 @@ public class FileReaderTest2 extends AbstractProvisioningTest {
}
}
- private void doFileReaderTest(PauseJob pauseJob, IProgressMonitor monitor) throws IOException, CoreException {
+ private void doFileReaderTest(final PauseJob pauseJob, IProgressMonitor monitor) throws IOException, CoreException {
final String testRemoteFileURL = "http://ftp.osuosl.org/pub/eclipse/rt/ecf/3.5.4/site.p2/plugins/org.eclipse.ecf.doc_1.3.0.v20111230-0120.jar";
OutputStream out = null;
OutputStream out1 = null;
File tmpFolder = getTempFolder();
File tmpFile = new File(tmpFolder, "testDownloadPauseResume.zip");
File tmpFile1 = new File(tmpFolder, "testDownloadWithoutPause.zip");
+ ProvisioningListener listener = new ProvisioningListener() {
+ boolean startedPauseJob = false;
+
+ public void notify(EventObject o) {
+ if (!startedPauseJob && o instanceof DownloadProgressEvent) {
+ pauseJob.schedule();
+ startedPauseJob = true;
+ }
+
+ }
+ };
+ getEventBus().addListener(listener);
try {
tmpFile1.createNewFile();
out1 = new FileOutputStream(tmpFile1);
@@ -203,12 +215,12 @@ public class FileReaderTest2 extends AbstractProvisioningTest {
tmpFile.createNewFile();
out = new FileOutputStream(tmpFile);
FileReader reader = pauseJob.getReader();
- pauseJob.schedule(5000);
reader.readInto(URI.create(testRemoteFileURL), out, monitor);
assertNotNull(reader.getResult());
assertTrue(reader.getResult().isOK());
assertEquals("File with pausing/resuming is not identical with file without pausing.", tmpFile1.length(), tmpFile.length());
} finally {
+ getEventBus().removeListener(listener);
if (out1 != null)
out1.close();
tmpFile1.delete();