com.google.testing.threadtester.utils
Class BlockingProxy<T>

java.lang.Object
  extended by com.google.testing.threadtester.AbstractBreakpoint
      extended by com.google.testing.threadtester.utils.BlockingProxy<T>
Type Parameters:
T - the fake object being proxied
All Implemented Interfaces:
Breakpoint, ReusableBreakpoint, InvocationHandler

public class BlockingProxy<T>
extends AbstractBreakpoint
implements ReusableBreakpoint, InvocationHandler

Provides a proxy that can be used to control thread execution by blocking at a given point. It can be used to proxy method calls to a fake test object, and provide a BreakPoint at the point where a particular method is called.

Author:
alasdair.mackintosh@gmail.com (Alasdair Mackintosh)

Field Summary
 
Fields inherited from class com.google.testing.threadtester.AbstractBreakpoint
blocked, enabled, limit, numHits, thread
 
Method Summary
static
<T> BlockingProxy<T>
create(Class<T> clss, T original, Method method, boolean before)
          Creates a new BlockingProxy for the given object.
static
<T> BlockingProxy<T>
create(Class<T> clss, T original, String methodName, boolean before)
          Creates a new BlockingProxy for the given object.
 T getProxy()
          Gets the dynamic proxy object.
 Thread getThread()
          Gets the thread associated with this Breakpoint, if any.
 Object invoke(Object proxy, Method invoked, Object[] args)
           
 void setThread(Thread thread)
          Sets the thread associated with this breakpoint.
 
Methods inherited from class com.google.testing.threadtester.AbstractBreakpoint
await, disable, enable, finishWaiting, getHits, getId, getLimit, hitBreakpoint, isBlocked, isEnabled, reset, resume, resume, setHandler, setLimit, setThreadImpl, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.testing.threadtester.Breakpoint
await, disable, enable, getLimit, isBlocked, isEnabled, resume, resume, setHandler, setLimit
 

Method Detail

getProxy

public T getProxy()
Gets the dynamic proxy object. All methods invked on this will be proxied to the underlying original object


invoke

public Object invoke(Object proxy,
                     Method invoked,
                     Object[] args)
              throws Throwable
Specified by:
invoke in interface InvocationHandler
Throws:
Throwable

getThread

public Thread getThread()
Description copied from interface: Breakpoint
Gets the thread associated with this Breakpoint, if any. Some Breakpoints may only be valid for a given thread, and will not block when reached by another thread. Consult the documentation for the specific Breakpoint type for details. If this Breakpoint is not associated with a thread, returns null.

Specified by:
getThread in interface Breakpoint
Overrides:
getThread in class AbstractBreakpoint

setThread

public void setThread(Thread thread)
Description copied from interface: ReusableBreakpoint
Sets the thread associated with this breakpoint. Invoking this method will also reset other internal state. This method may be invoked before a breakpoint is used, or after a thread has called Breakpoint.await() followed by Breakpoint.resume().

Specified by:
setThread in interface ReusableBreakpoint

create

public static <T> BlockingProxy<T> create(Class<T> clss,
                                          T original,
                                          String methodName,
                                          boolean before)
Creates a new BlockingProxy for the given object. The proxy will block at the given named method.

Parameters:
clss - the class being proxied. Must be an interface.
original - the object being proxied. Must implement the given interface.
methodName - the name of the method where this proxy will block.
before - if true, block before calling the given method. If false, block afterwards.

create

public static <T> BlockingProxy<T> create(Class<T> clss,
                                          T original,
                                          Method method,
                                          boolean before)
Creates a new BlockingProxy for the given object. The proxy will block at the given method.

Parameters:
clss - the class being proxied. Must be an interface.
original - the object being proxied. Must implement the given interface.
method - the method where this proxy will block.
before - if true, block before calling the given method. If false, block afterwards.


Copyright © 2011. All Rights Reserved.