Lines 62-69
Link Here
|
62 |
import java.util.Set; |
62 |
import java.util.Set; |
63 |
import java.util.TreeSet; |
63 |
import java.util.TreeSet; |
64 |
import java.util.WeakHashMap; |
64 |
import java.util.WeakHashMap; |
65 |
import java.util.concurrent.Executors; |
|
|
66 |
import java.util.concurrent.TimeUnit; |
67 |
import java.util.jar.JarEntry; |
65 |
import java.util.jar.JarEntry; |
68 |
import java.util.jar.JarOutputStream; |
66 |
import java.util.jar.JarOutputStream; |
69 |
import java.util.logging.Level; |
67 |
import java.util.logging.Level; |
Lines 74-81
Link Here
|
74 |
import org.netbeans.junit.MockServices; |
72 |
import org.netbeans.junit.MockServices; |
75 |
import org.netbeans.junit.NbTestCase; |
73 |
import org.netbeans.junit.NbTestCase; |
76 |
import org.openide.util.Lookup; |
74 |
import org.openide.util.Lookup; |
77 |
import org.openide.util.LookupEvent; |
|
|
78 |
import org.openide.util.LookupListener; |
79 |
import org.openide.util.test.MockLookup; |
75 |
import org.openide.util.test.MockLookup; |
80 |
|
76 |
|
81 |
/** Test finding services from manifest. |
77 |
/** Test finding services from manifest. |
Lines 389-427
Link Here
|
389 |
assertGC("Class can be garbage collected", ref); |
385 |
assertGC("Class can be garbage collected", ref); |
390 |
} |
386 |
} |
391 |
|
387 |
|
392 |
public void testListenersAreNotifiedWithoutHoldingALockIssue36035() throws Exception { |
388 |
public void testSuperTypes() throws Exception { |
393 |
final Lookup l = getTestedLookup(c2); |
389 |
final Lookup l = getTestedLookup(c2); |
394 |
final Class xface = c1.loadClass("org.foo.Interface"); |
390 |
final Class<?> xface = c1.loadClass("org.foo.Interface"); |
395 |
final Lookup.Result res = l.lookup(new Lookup.Template(Object.class)); |
391 |
final Lookup.Result<Object> res = l.lookupResult(Object.class); |
396 |
|
|
|
397 |
class L implements LookupListener, Runnable { |
398 |
private Thread toInterrupt; |
399 |
|
400 |
public void run() { |
401 |
assertNotNull("Possible to query lookup", l.lookup(xface)); |
402 |
assertEquals("and there are two items", 2, res.allInstances().size()); |
403 |
toInterrupt.interrupt(); |
404 |
} |
405 |
|
406 |
public synchronized void resultChanged(LookupEvent ev) { |
407 |
toInterrupt = Thread.currentThread(); |
408 |
Executors.newSingleThreadScheduledExecutor().schedule(this, 0, TimeUnit.MICROSECONDS); |
409 |
try { |
410 |
wait(3000); |
411 |
fail("Should be interrupted - means it was not possible to finish query in run() method"); |
412 |
} catch (InterruptedException ex) { |
413 |
// this is what we want |
414 |
} |
415 |
} |
416 |
} |
417 |
L listener = new L(); |
418 |
|
419 |
res.addLookupListener(listener); |
420 |
assertEquals("Nothing yet", 0, res.allInstances().size()); |
392 |
assertEquals("Nothing yet", 0, res.allInstances().size()); |
421 |
|
|
|
422 |
assertNotNull("Interface found", l.lookup(xface)); |
393 |
assertNotNull("Interface found", l.lookup(xface)); |
423 |
assertNotNull("Listener notified", listener.toInterrupt); |
|
|
424 |
|
425 |
assertEquals("Now two", 2, res.allInstances().size()); |
394 |
assertEquals("Now two", 2, res.allInstances().size()); |
426 |
} |
395 |
} |
427 |
|
396 |
|