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 294894 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 30-35 Link Here
30
 org.eclipse.test.performance;resolution:=optional,
30
 org.eclipse.test.performance;resolution:=optional,
31
 org.eclipse.core.filesystem,
31
 org.eclipse.core.filesystem,
32
 org.eclipse.core.runtime,
32
 org.eclipse.core.runtime,
33
 org.eclipse.core.expressions
33
 org.eclipse.core.expressions,
34
 org.eclipse.ui
34
Eclipse-AutoStart: true
35
Eclipse-AutoStart: true
35
Bundle-Activator: org.eclipse.core.tests.internal.resources.TestActivator
36
Bundle-Activator: org.eclipse.core.tests.internal.resources.TestActivator
(-)src/org/eclipse/core/tests/resources/regression/Bug_294894.java (+135 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Broadcom Coporation 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
 *    James Blackburn (Broadcom Corp.) - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.core.tests.resources.regression;
13
14
import java.io.*;
15
import org.eclipse.core.resources.*;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.jobs.Job;
18
import org.eclipse.core.tests.resources.ResourceTest;
19
import org.eclipse.swt.widgets.Display;
20
21
/**
22
 * Testsuite for resources plugin lock-up
23
 */
24
public class Bug_294894 extends ResourceTest {
25
26
	protected void setUp() throws Exception {
27
		super.setUp();
28
	}
29
30
	protected void tearDown() throws Exception {
31
		super.tearDown();
32
	}
33
34
	public void testDeadLockFail() throws Exception {
35
		final String proj = "testProject";
36
37
		final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(proj);
38
		create(project, true);
39
40
		final IFile file = project.getFile("foo");
41
		project.getFile("foo").create(new ByteArrayInputStream(new byte[] {'a'}), true, null);
42
43
		for (int i = 0; i < 1000; i++) {
44
			System.out.println(i);
45
			// Run this in a job holding the appropriate scheduling rule
46
			Job j = new Job("jobwithfilelock") {
47
48
				protected IStatus run(IProgressMonitor monitor) {
49
50
					// Job to deadlock with this: Display -> Resource Lock
51
					Job j = new Job("Workspace refresh") {
52
						protected IStatus run(IProgressMonitor monitor) {
53
							Display.getDefault().syncExec(new Runnable() {
54
								public void run() {
55
									try {
56
										appendContentsWithException(project);
57
										ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
58
									} catch (Exception e) {
59
										fail();
60
									}
61
								}
62
							});
63
							return Status.OK_STATUS;
64
						}
65
					};
66
67
					j.schedule();
68
					try {
69
						Thread.sleep(1);
70
					} catch (Exception e) {
71
						fail();
72
					}
73
74
					// Grab Display and refresh the file... [Resource -> Display ]
75
					Display.getDefault().syncExec(new Runnable() {
76
						public void run() {
77
							try {
78
								file.refreshLocal(IResource.DEPTH_ONE, null);
79
							} catch (Exception e) {
80
								fail();
81
							}
82
						}
83
					});
84
					return Status.OK_STATUS;
85
				}
86
			};
87
			j.setRule(file);
88
			j.schedule();
89
			j.join();
90
91
			// Now try to append to the file
92
			file.appendContents(new ByteArrayInputStream(new byte[] {'a'}), IResource.FORCE, null);
93
		}
94
	}
95
96
	public InputStream getContents(String text) {
97
		return new ByteArrayInputStream(text.getBytes());
98
	}
99
100
	public void appendContentsWithException(IProject project) {
101
		int count = 5;
102
		final IFile targets[] = new IFile[count];
103
		for (int i = 0; i < count; i++)
104
			targets[i] = project.getFile("file" + i);
105
		try {
106
			for (int i = 0; i < count; i++)
107
				if (!targets[i].exists())
108
					targets[i].create(getContents("abc"), false, null);
109
		} catch (CoreException e) {
110
			fail("1.0");
111
		}
112
113
		// Run [count] failing append content jobs
114
		Job[] js = new Job[count];
115
		for (int i = 0; i < count; i++) {
116
			final int j = i;
117
			js[i] = new Job("bad append") {
118
				protected IStatus run(IProgressMonitor monitor) {
119
					try {
120
						targets[j].appendContents(new InputStream() {
121
							public int read() throws IOException {
122
								throw new IOException("Stream closed");
123
							}
124
						}, false, false, null);
125
					} catch (CoreException e) {
126
						fail("2.0");
127
					}
128
					return Status.OK_STATUS;
129
				}
130
			};
131
			js[i].schedule();
132
		}
133
	}
134
135
}

Return to bug 294894