/** * Causes this thread to call the named method, and asserts that this thread becomes blocked on * the lock-like object. The lock-like object must have a method equivalent to {@link * java.util.concurrent.locks.ReentrantLock#hasQueuedThread(Thread)}. */ public void callAndAssertBlocks(String methodName, Object... arguments) throws Exception { checkNotNull(methodName); checkNotNull(arguments); assertEquals(false, invokeMethod("hasQueuedThread", this)); sendRequest(methodName, arguments); Thread.sleep(DUE_DILIGENCE_MILLIS); assertEquals(true, invokeMethod("hasQueuedThread", this)); assertNull(responseQueue.poll()); }
/** * Causes this thread to call the named method, and asserts that this thread thereby waits on the * given condition-like object. The lock-like object must have a method equivalent to {@link * java.util.concurrent.locks.ReentrantLock#hasWaiters(java.util.concurrent.locks.Condition)}, * except that the method parameter must accept whatever condition-like object is passed into this * method. */ public void callAndAssertWaits(String methodName, Object conditionLikeObject) throws Exception { checkNotNull(methodName); checkNotNull(conditionLikeObject); // TODO: Restore the following line when Monitor.hasWaiters() no longer acquires the lock. // assertEquals(false, invokeMethod("hasWaiters", conditionLikeObject)); sendRequest(methodName, conditionLikeObject); Thread.sleep(DUE_DILIGENCE_MILLIS); assertEquals(true, invokeMethod("hasWaiters", conditionLikeObject)); assertNull(responseQueue.poll()); }
@Override public void run() { assertSame(this, Thread.currentThread()); try { while (true) { Request request = requestQueue.take(); Object result; try { result = invokeMethod(request.methodName, request.arguments); } catch (ThreadDeath death) { return; } catch (InvocationTargetException exception) { responseQueue.put(new Response(request.methodName, null, exception.getTargetException())); continue; } catch (Throwable throwable) { responseQueue.put(new Response(request.methodName, null, throwable)); continue; } responseQueue.put(new Response(request.methodName, result, null)); } } catch (ThreadDeath death) { return; } catch (InterruptedException ignored) { // SynchronousQueue sometimes throws InterruptedException while the threads are stopping. } catch (Throwable uncaught) { this.uncaughtThrowable = uncaught; } }
/** * Causes this thread to call the named method, and asserts that this thread becomes blocked on * the lock-like object. The lock-like object must have a method equivalent to {@link * java.util.concurrent.locks.ReentrantLock#hasQueuedThread(Thread)}. */ public void callAndAssertBlocks(String methodName, Object... arguments) throws Exception { checkNotNull(methodName); checkNotNull(arguments); assertEquals(false, invokeMethod("hasQueuedThread", this)); sendRequest(methodName, arguments); Thread.sleep(DUE_DILIGENCE_MILLIS); assertEquals(true, invokeMethod("hasQueuedThread", this)); assertNull(responseQueue.poll()); }
/** * Causes this thread to call the named method, and asserts that this thread thereby waits on * the given condition-like object. The lock-like object must have a method equivalent to {@link * java.util.concurrent.locks.ReentrantLock#hasWaiters(java.util.concurrent.locks.Condition)}, * except that the method parameter must accept whatever condition-like object is passed into * this method. */ public void callAndAssertWaits(String methodName, Object conditionLikeObject) throws Exception { checkNotNull(methodName); checkNotNull(conditionLikeObject); // TODO: Restore the following line when Monitor.hasWaiters() no longer acquires the lock. // assertEquals(false, invokeMethod("hasWaiters", conditionLikeObject)); sendRequest(methodName, conditionLikeObject); Thread.sleep(DUE_DILIGENCE_MILLIS); assertEquals(true, invokeMethod("hasWaiters", conditionLikeObject)); assertNull(responseQueue.poll()); }
@Override public void run() { assertSame(this, Thread.currentThread()); try { while (true) { Request request = requestQueue.take(); Object result; try { result = invokeMethod(request.methodName, request.arguments); } catch (ThreadDeath death) { return; } catch (InvocationTargetException exception) { responseQueue.put( new Response(request.methodName, null, exception.getTargetException())); continue; } catch (Throwable throwable) { responseQueue.put(new Response(request.methodName, null, throwable)); continue; } responseQueue.put(new Response(request.methodName, result, null)); } } catch (ThreadDeath death) { return; } catch (InterruptedException ignored) { // SynchronousQueue sometimes throws InterruptedException while the threads are stopping. } catch (Throwable uncaught) { this.uncaughtThrowable = uncaught; } }