Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 381832 | Differences between
and this patch

Collapse All | Expand All

(-)a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/session/TestConcurrentWorkspaceSave.java (+98 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.tests.resources.session;
12
13
import org.eclipse.core.resources.*;
14
import org.eclipse.core.runtime.*;
15
import org.eclipse.core.runtime.jobs.ISchedulingRule;
16
import org.eclipse.core.runtime.jobs.Job;
17
import org.eclipse.core.tests.resources.ResourceTest;
18
19
/**
20
 * Test for concurrent workspace save
21
 */
22
public class TestConcurrentWorkspaceSave extends ResourceTest {
23
	private static class BadSaveParticipant implements ISaveParticipant {
24
		public BadSaveParticipant() {
25
		}
26
27
		private void runWorkspaceOperation() {
28
			try {
29
				getWorkspace().run(new IWorkspaceRunnable() {
30
					public void run(IProgressMonitor monitor) {
31
						// noop
32
					}
33
				}, null, 0, null);
34
			} catch (CoreException e) {
35
				fail("1.0", e);
36
			}
37
		}
38
39
		public void prepareToSave(ISaveContext context) {
40
			runWorkspaceOperation();
41
		}
42
43
		public void saving(ISaveContext context) {
44
			runWorkspaceOperation();
45
		}
46
47
		public void doneSaving(ISaveContext context) {
48
			runWorkspaceOperation();
49
		}
50
51
		public void rollback(ISaveContext context) {
52
			runWorkspaceOperation();
53
		}
54
	}
55
56
	private static class InvalidRule implements ISchedulingRule {
57
		public InvalidRule() {
58
		}
59
60
		public boolean isConflicting(ISchedulingRule rule) {
61
			return this == rule;
62
		}
63
64
		public boolean contains(ISchedulingRule rule) {
65
			return this == rule || getWorkspace().getRoot().contains(rule);
66
		}
67
	}
68
69
	public void testBug() throws CoreException, InterruptedException {
70
		final IWorkspace workspace = getWorkspace();
71
		String pluginId = "org.eclipse.core.tests.resources.session.TestBug149121";
72
		try {
73
			workspace.addSaveParticipant(pluginId, new BadSaveParticipant());
74
75
			// ask for snapshot
76
			workspace.save(false, getMonitor());
77
78
			// run full save with invalid rule (bug 381724)
79
			Job job = new Job("full save") {
80
				protected IStatus run(IProgressMonitor monitor) {
81
					ISchedulingRule rule = new InvalidRule();
82
					Job.getJobManager().beginRule(rule, getMonitor());
83
					try {
84
						workspace.save(true, getMonitor());
85
					} catch (CoreException e) {
86
						fail("1.0", e);
87
					}
88
					Job.getJobManager().endRule(rule);
89
					return Status.OK_STATUS;
90
				}
91
			};
92
			job.schedule();
93
			job.join();
94
		} finally {
95
			workspace.removeSaveParticipant(pluginId);
96
		}
97
	}
98
}

Return to bug 381832