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 (+93 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.Job;
16
import org.eclipse.core.tests.resources.ResourceTest;
17
18
/**
19
 * Test for concurrent workspace save
20
 */
21
public class TestConcurrentWorkspaceSave extends ResourceTest {
22
	private static class BadSaveParticipant implements ISaveParticipant {
23
		public BadSaveParticipant() {
24
		}
25
26
		private void runWorkspaceOperation() {
27
			try {
28
				getWorkspace().run(new IWorkspaceRunnable() {
29
					public void run(IProgressMonitor monitor) {
30
						// noop
31
					}
32
				}, null, 0, null);
33
			} catch (CoreException e) {
34
				fail("1.0", e);
35
			}
36
		}
37
38
		public void prepareToSave(ISaveContext context) {
39
			runWorkspaceOperation();
40
		}
41
42
		public void saving(ISaveContext context) {
43
			runWorkspaceOperation();
44
		}
45
46
		public void doneSaving(ISaveContext context) {
47
			runWorkspaceOperation();
48
		}
49
50
		public void rollback(ISaveContext context) {
51
			runWorkspaceOperation();
52
		}
53
	}
54
55
	public void testBug() throws CoreException, InterruptedException {
56
		final IWorkspace workspace = getWorkspace();
57
		String pluginId = "org.eclipse.core.tests.resources.session.TestConcurrentWorkspaceSave";
58
		try {
59
			workspace.addSaveParticipant(pluginId, new BadSaveParticipant());
60
61
			final IProject project1 = workspace.getRoot().getProject("project1");
62
			final IProject project2 = workspace.getRoot().getProject("project2");
63
			ensureExistsInWorkspace(new IResource[] {project1, project2}, true);
64
65
			Job job1 = new Job("project1 close") {
66
				protected IStatus run(IProgressMonitor monitor) {
67
					try {
68
						project1.close(null);
69
					} catch (CoreException e) {
70
						return e.getStatus();
71
					}
72
					return Status.OK_STATUS;
73
				}
74
			};
75
			Job job2 = new Job("project2 close") {
76
				protected IStatus run(IProgressMonitor monitor) {
77
					try {
78
						project2.close(null);
79
					} catch (CoreException e) {
80
						return e.getStatus();
81
					}
82
					return Status.OK_STATUS;
83
				}
84
			};
85
			job1.schedule();
86
			job2.schedule();
87
			job1.join();
88
			job2.join();
89
		} finally {
90
			workspace.removeSaveParticipant(pluginId);
91
		}
92
	}
93
}

Return to bug 381832