Lines 101-110
Link Here
|
101 |
return this.results.size(); |
101 |
return this.results.size(); |
102 |
} |
102 |
} |
103 |
} |
103 |
} |
104 |
class WaitingJob implements IJob { |
104 |
static class WaitingJob implements IJob { |
105 |
static final int MAX_WAIT = 30000; // wait 30s max |
105 |
private static final int MAX_WAIT = 30000; // wait 30s max |
106 |
Semaphore startingSem = new Semaphore(); |
106 |
private Semaphore startingSem = new Semaphore(); |
107 |
Semaphore runningSem = new Semaphore(); |
107 |
private Semaphore runningSem = new Semaphore(); |
108 |
public boolean belongsTo(String jobFamily) { |
108 |
public boolean belongsTo(String jobFamily) { |
109 |
return false; |
109 |
return false; |
110 |
} |
110 |
} |
Lines 124-132
Link Here
|
124 |
public String getJobFamily() { |
124 |
public String getJobFamily() { |
125 |
return "SearchTests.Waiting"; |
125 |
return "SearchTests.Waiting"; |
126 |
} |
126 |
} |
|
|
127 |
public void suspend() throws Semaphore.TimeOutException, CoreException { |
128 |
runAndSuspend(null); |
129 |
} |
130 |
public void runAndSuspend(IWorkspaceRunnable runnable) throws Semaphore.TimeOutException, CoreException { |
131 |
IndexManager indexManager = JavaModelManager.getIndexManager(); |
132 |
indexManager.disable(); |
133 |
if (runnable != null) { |
134 |
runnable.run(null); |
135 |
} |
136 |
indexManager.request(this); |
137 |
indexManager.enable(); |
138 |
this.startingSem.acquire(30000); // wait for job to start (wait 30s max) |
139 |
} |
140 |
|
141 |
public void resume() { |
142 |
this.runningSem.release(); |
143 |
JavaModelManager.getIndexManager().enable(); |
144 |
} |
127 |
} |
145 |
} |
128 |
static { |
146 |
static { |
129 |
TESTS_PREFIX = "testSearchPatternValidateMatchRule"; |
147 |
//TESTS_PREFIX = "testSearchPatternValidateMatchRule"; |
130 |
} |
148 |
} |
131 |
public static Test suite() { |
149 |
public static Test suite() { |
132 |
return buildModelTestSuite(SearchTests.class); |
150 |
return buildModelTestSuite(SearchTests.class); |
Lines 235-260
Link Here
|
235 |
* a project causes another request to reindex. |
253 |
* a project causes another request to reindex. |
236 |
*/ |
254 |
*/ |
237 |
public void testChangeClasspath() throws CoreException, TimeOutException { |
255 |
public void testChangeClasspath() throws CoreException, TimeOutException { |
238 |
IndexManager indexManager = JavaModelManager.getIndexManager(); |
|
|
239 |
WaitingJob job = new WaitingJob(); |
256 |
WaitingJob job = new WaitingJob(); |
240 |
try { |
257 |
try { |
241 |
// setup: suspend indexing and create a project (prj=src) with one cu |
258 |
// setup: suspend indexing and create a project (prj=src) with one cu |
242 |
indexManager.disable(); |
259 |
job.runAndSuspend(new IWorkspaceRunnable() { |
243 |
JavaCore.run(new IWorkspaceRunnable() { |
|
|
244 |
public void run(IProgressMonitor monitor) throws CoreException { |
260 |
public void run(IProgressMonitor monitor) throws CoreException { |
245 |
createJavaProject("P1"); |
261 |
JavaCore.run(new IWorkspaceRunnable() { |
246 |
createFile( |
262 |
public void run(IProgressMonitor monitor2) throws CoreException { |
247 |
"/P1/X.java", |
263 |
createJavaProject("P1"); |
248 |
"public class X {\n" + |
264 |
createFile( |
249 |
"}" |
265 |
"/P1/X.java", |
250 |
); |
266 |
"public class X {\n" + |
|
|
267 |
"}" |
268 |
); |
269 |
} |
270 |
}, monitor); |
251 |
} |
271 |
} |
252 |
}, null); |
272 |
}); |
253 |
|
|
|
254 |
// add waiting job and wait for it to be executed |
255 |
indexManager.request(job); |
256 |
indexManager.enable(); |
257 |
job.startingSem.acquire(30000); // wait for job to start (wait 30s max) |
258 |
|
273 |
|
259 |
// remove source folder from classpath |
274 |
// remove source folder from classpath |
260 |
IJavaProject project = getJavaProject("P1"); |
275 |
IJavaProject project = getJavaProject("P1"); |
Lines 263-269
Link Here
|
263 |
null); |
278 |
null); |
264 |
|
279 |
|
265 |
// resume waiting job |
280 |
// resume waiting job |
266 |
job.runningSem.release(); |
281 |
job.resume(); |
267 |
|
282 |
|
268 |
assertAllTypes( |
283 |
assertAllTypes( |
269 |
"Unexpected all types after removing source folder", |
284 |
"Unexpected all types after removing source folder", |
Lines 271-279
Link Here
|
271 |
"" |
286 |
"" |
272 |
); |
287 |
); |
273 |
} finally { |
288 |
} finally { |
274 |
job.runningSem.release(); |
289 |
job.resume(); |
275 |
deleteProject("P1"); |
290 |
deleteProject("P1"); |
276 |
indexManager.enable(); |
|
|
277 |
} |
291 |
} |
278 |
} |
292 |
} |
279 |
/* |
293 |
/* |
Lines 337-358
Link Here
|
337 |
* (regression test for bug 35306 Index update request can be incorrectly handled) |
351 |
* (regression test for bug 35306 Index update request can be incorrectly handled) |
338 |
*/ |
352 |
*/ |
339 |
public void testConcurrentJob() throws CoreException, InterruptedException, IOException, TimeOutException { |
353 |
public void testConcurrentJob() throws CoreException, InterruptedException, IOException, TimeOutException { |
340 |
IndexManager indexManager = JavaModelManager.getIndexManager(); |
|
|
341 |
WaitingJob job = new WaitingJob(); |
354 |
WaitingJob job = new WaitingJob(); |
342 |
try { |
355 |
try { |
343 |
// setup: suspend indexing and create a project with one empty jar on its classpath |
356 |
// setup: suspend indexing and create a project with one empty jar on its classpath |
344 |
indexManager.disable(); |
357 |
job.runAndSuspend(new IWorkspaceRunnable() { |
345 |
JavaCore.run(new IWorkspaceRunnable() { |
|
|
346 |
public void run(IProgressMonitor monitor) throws CoreException { |
358 |
public void run(IProgressMonitor monitor) throws CoreException { |
347 |
createJavaProject("P1", new String[] {}, new String[] {"/P1/jclMin.jar"}, "bin"); |
359 |
JavaCore.run(new IWorkspaceRunnable() { |
348 |
createFile("/P1/jclMin.jar", EMPTY_JAR); |
360 |
public void run(IProgressMonitor monitor2) throws CoreException { |
|
|
361 |
createJavaProject("P1", new String[] {}, new String[] {"/P1/jclMin.jar"}, "bin"); |
362 |
createFile("/P1/jclMin.jar", EMPTY_JAR); |
363 |
} |
364 |
}, monitor); |
349 |
} |
365 |
} |
350 |
}, null); |
366 |
}); |
351 |
|
|
|
352 |
// add waiting job and wait for it to be executed |
353 |
indexManager.request(job); |
354 |
indexManager.enable(); |
355 |
job.startingSem.acquire(30000); // wait for job to start (wait 30s max) |
356 |
|
367 |
|
357 |
final IJavaProject project = getJavaProject("P1"); |
368 |
final IJavaProject project = getJavaProject("P1"); |
358 |
|
369 |
|
Lines 396-402
Link Here
|
396 |
getFile("/P1/jclMin.jar").setContents(new FileInputStream(getExternalJCLPathString()), IResource.NONE, null); |
407 |
getFile("/P1/jclMin.jar").setContents(new FileInputStream(getExternalJCLPathString()), IResource.NONE, null); |
397 |
|
408 |
|
398 |
// resume waiting job |
409 |
// resume waiting job |
399 |
job.runningSem.release(); |
410 |
job.resume(); |
400 |
|
411 |
|
401 |
// wait for concurrent job to finish |
412 |
// wait for concurrent job to finish |
402 |
thread.join(10000); // 10s max |
413 |
thread.join(10000); // 10s max |
Lines 404-412
Link Here
|
404 |
assertTrue("Failed to get all types", success[0]); |
415 |
assertTrue("Failed to get all types", success[0]); |
405 |
|
416 |
|
406 |
} finally { |
417 |
} finally { |
407 |
job.runningSem.release(); |
418 |
job.resume(); |
408 |
deleteProject("P1"); |
419 |
deleteProject("P1"); |
409 |
indexManager.enable(); |
|
|
410 |
} |
420 |
} |
411 |
} |
421 |
} |
412 |
/* |
422 |
/* |
Lines 415-428
Link Here
|
415 |
* (regression test for bug 33571 SearchEngine.searchAllTypeNames: NPE when passing null as progress monitor) |
425 |
* (regression test for bug 33571 SearchEngine.searchAllTypeNames: NPE when passing null as progress monitor) |
416 |
*/ |
426 |
*/ |
417 |
public void testNullProgressMonitor() throws CoreException, TimeOutException { |
427 |
public void testNullProgressMonitor() throws CoreException, TimeOutException { |
418 |
IndexManager indexManager = JavaModelManager.getIndexManager(); |
|
|
419 |
WaitingJob job = new WaitingJob(); |
428 |
WaitingJob job = new WaitingJob(); |
420 |
try { |
429 |
try { |
421 |
// add waiting job and wait for it to be executed |
430 |
job.suspend(); |
422 |
indexManager.disable(); |
|
|
423 |
indexManager.request(job); |
424 |
indexManager.enable(); |
425 |
job.startingSem.acquire(30000); // wait for job to start (wait 30s max) |
426 |
|
431 |
|
427 |
// query all type names with a null progress monitor |
432 |
// query all type names with a null progress monitor |
428 |
boolean operationCanceled = false; |
433 |
boolean operationCanceled = false; |
Lines 437-443
Link Here
|
437 |
} |
442 |
} |
438 |
assertTrue("Should throw an OperationCanceledException", operationCanceled); |
443 |
assertTrue("Should throw an OperationCanceledException", operationCanceled); |
439 |
} finally { |
444 |
} finally { |
440 |
job.runningSem.release(); |
445 |
job.resume(); |
441 |
} |
446 |
} |
442 |
} |
447 |
} |
443 |
/* |
448 |
/* |