org.openqa.grid.selenium.proxy
Class DefaultRemoteProxy

java.lang.Object
  extended by org.openqa.grid.internal.BaseRemoteProxy
      extended by org.openqa.grid.selenium.proxy.DefaultRemoteProxy
All Implemented Interfaces:
java.lang.Comparable<RemoteProxy>, CommandListener, SelfHealingProxy, TestSessionListener, TimeoutListener, RemoteProxy
Direct Known Subclasses:
SeleniumRemoteProxy, WebDriverRemoteProxy

public class DefaultRemoteProxy
extends BaseRemoteProxy
implements TimeoutListener, SelfHealingProxy, CommandListener, TestSessionListener

Default remote proxy for selenium, handling both selenium1 and webdriver requests.


Field Summary
 
Fields inherited from class org.openqa.grid.internal.BaseRemoteProxy
remoteHost
 
Constructor Summary
DefaultRemoteProxy(RegistrationRequest request, Registry registry)
           
 
Method Summary
 void addNewEvent(RemoteException event)
          Allow to record when something important about the remote state is detected.
 void afterCommand(TestSession session, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Executed just before the forwards returns.
 void afterSession(TestSession session)
          Will be run after the last command is forwarded, but before the proxy slot is released.
 void beforeCommand(TestSession session, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Executed before the hub forwards the request.
 void beforeRelease(TestSession session)
          Gives a chance to clean the resources on the remote when the session has timed out.
 void beforeSession(TestSession session)
          The client shouldn't have to care where firefox is installed as long as the correct version is launched, however with webdriver the binary location is specified in the desiredCapability, making it the responsibility of the person running the test.
 HtmlRenderer getHtmlRender()
          Returns the object responsible for rendering any information about the proxy in a Web application.
 TestSession getNewSession(java.util.Map<java.lang.String,java.lang.Object> requestedCapability)
          overwrites the session allocation to discard the proxy that are down.
 boolean isAlive()
           
 boolean isDown()
           
 void onEvent(java.util.List<RemoteException> events, RemoteException lastInserted)
          Allow to process the list of all the events that were detected on this Remote so far.
 void startPolling()
          start/restart the polling for the remote proxy.
 void stopPolling()
          put the polling on hold.
 void teardown()
          If the RemoteProxy implementation also implements TimeoutListener, then this method will stop the thread used to monitor timeouts.
 
Methods inherited from class org.openqa.grid.internal.BaseRemoteProxy
compareTo, equals, forceSlotCleanerRun, getCapabilityHelper, getConfig, getHttpClientFactory, getId, getMaxNumberOfConcurrentTestSessions, getNewInstance, getOriginalRegistrationRequest, getRegistry, getRemoteHost, getResourceUsageInPercent, getStatus, getTestSlots, getTimeOut, getTotalUsed, hasCapability, hashCode, isBusy, setupTimeoutListener, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultRemoteProxy

public DefaultRemoteProxy(RegistrationRequest request,
                          Registry registry)
Method Detail

beforeRelease

public void beforeRelease(TestSession session)
Description copied from interface: TimeoutListener
Gives a chance to clean the resources on the remote when the session has timed out.

Is executed before the session is released to the hub. If an exception is thrown, the slot that was associated with the session is considered corrupted and won't be released for future use.

You can check session.getInternalKey before timing out. internalkey==null usually means the initial POST /session hasn't been completed yet.For instance if you use web driver, that means the browser is in the process of being started. During that state, you can't really clean the resources properly.

Specified by:
beforeRelease in interface TimeoutListener

afterCommand

public void afterCommand(TestSession session,
                         javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response)
Description copied from interface: CommandListener
Executed just before the forwards returns.

Throwing an exception will result in an error for the client.

Specified by:
afterCommand in interface CommandListener

beforeCommand

public void beforeCommand(TestSession session,
                          javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
Description copied from interface: CommandListener
Executed before the hub forwards the request. reading the content of the request stream will prevent the content from being forwarded.

Throwing an exception will prevent the forward to the remote.

Specified by:
beforeCommand in interface CommandListener

getHtmlRender

public HtmlRenderer getHtmlRender()
Description copied from interface: RemoteProxy
Returns the object responsible for rendering any information about the proxy in a Web application.

Specified by:
getHtmlRender in interface RemoteProxy
Overrides:
getHtmlRender in class BaseRemoteProxy
Returns:
the renderer.

isAlive

public boolean isAlive()

startPolling

public void startPolling()
Description copied from interface: SelfHealingProxy
start/restart the polling for the remote proxy. A typical poll will try to contact the remote proxy to see if it's still accessible, but it can have more logic in it, like checking the resource usage ( RAM etc) on the remote.

Specified by:
startPolling in interface SelfHealingProxy

stopPolling

public void stopPolling()
Description copied from interface: SelfHealingProxy
put the polling on hold.

Specified by:
stopPolling in interface SelfHealingProxy

addNewEvent

public void addNewEvent(RemoteException event)
Description copied from interface: SelfHealingProxy
Allow to record when something important about the remote state is detected.

Specified by:
addNewEvent in interface SelfHealingProxy

onEvent

public void onEvent(java.util.List<RemoteException> events,
                    RemoteException lastInserted)
Description copied from interface: SelfHealingProxy
Allow to process the list of all the events that were detected on this Remote so far. A typical implementation of this method will be to put the proxy on hold if the network connection is bad, or to restart the remote if the resources used are too important

Specified by:
onEvent in interface SelfHealingProxy

getNewSession

public TestSession getNewSession(java.util.Map<java.lang.String,java.lang.Object> requestedCapability)
overwrites the session allocation to discard the proxy that are down.

Specified by:
getNewSession in interface RemoteProxy
Overrides:
getNewSession in class BaseRemoteProxy
Parameters:
requestedCapability - the type of test the client is interested in performing.
Returns:
a new TestSession if possible, null otherwise

isDown

public boolean isDown()

beforeSession

public void beforeSession(TestSession session)
The client shouldn't have to care where firefox is installed as long as the correct version is launched, however with webdriver the binary location is specified in the desiredCapability, making it the responsibility of the person running the test. With this implementation of beforeSession, that problem disappears . If the webdriver slot is registered with a firefox using a custom binary location, the hub will handle it.

For instance if a node registers: {"browserName":"firefox","version":"7.0","firefox_binary":"/home/ff7"} and later on a client requests {"browserName":"firefox","version":"7.0"} , the hub will automatically append the correct binary path to the desiredCapability before it's forwarded to the server. That way the version / install location mapping is done only once at the node level.

Specified by:
beforeSession in interface TestSessionListener
See Also:
if the setup applies to all the tests.

afterSession

public void afterSession(TestSession session)
Description copied from interface: TestSessionListener
Will be run after the last command is forwarded, but before the proxy slot is released.

If the test crashes before a session is provided by the remote, session.externalKey will be null.

WARNING : after session should NOT throw exception. If an exception is thrown, the resources will NOT be released, as it could mean the remote is now corrupted.

Specified by:
afterSession in interface TestSessionListener

teardown

public void teardown()
Description copied from interface: RemoteProxy
If the RemoteProxy implementation also implements TimeoutListener, then this method will stop the thread used to monitor timeouts.

Specified by:
teardown in interface RemoteProxy
Overrides:
teardown in class BaseRemoteProxy


Copyright © 2012. All Rights Reserved.