PollingAgent"

From Documentation
(1st draft)
 
m (correct highlight (via JWB))
 
Line 3: Line 3:
 
  Since 1.2.1
 
  Since 1.2.1
  
ZATS Mimic introduces the <tt>PollingAgent</tt> to simulate client polling operation to support testing applications that uses <tt>Server Push</tt> mechanism.
+
ZATS Mimic introduces the <code>PollingAgent</code> to simulate client polling operation to support testing applications that uses <code>Server Push</code> mechanism.
  
 
The following are the usage steps:
 
The following are the usage steps:
# Obtain a <tt>PollingAgent</tt> object from desktop.
+
# Obtain a <code>PollingAgent</code> object from desktop.
#:Note that you should use the same <tt>PollingAgent</tt> object on calling all methods.
+
#:Note that you should use the same <code>PollingAgent</code> object on calling all methods.
# Start a polling by invoking <tt>start(int timeout)</tt> method.
+
# Start a polling by invoking <code>start(int timeout)</code> method.
#:The <tt>timeout</tt> indicates for how many milliseconds we should timeout the polling; a 0(zero) <tt>timeout</tt> means never timeout.
+
#:The <code>timeout</code> indicates for how many milliseconds we should timeout the polling; a 0(zero) <code>timeout</code> means never timeout.
# Invoke <tt>polling(int delay)</tt> method which will send a dummy client polling request to server and wait the specified delay time(in milliseconds) before returning. The <tt>polling</tt> method returns a boolean to indicate if the polling is stopped(false) or not(true) so you can control when to leave a polling loop.
+
# Invoke <code>polling(int delay)</code> method which will send a dummy client polling request to server and wait the specified delay time(in milliseconds) before returning. The <code>polling</code> method returns a boolean to indicate if the polling is stopped(false) or not(true) so you can control when to leave a polling loop.
#:A polling is stopped if the <tt>stop()</tt> method is called explicitly or if the polling has timed out since <tt>start</tt> the polling.
+
#:A polling is stopped if the <code>stop()</code> method is called explicitly or if the polling has timed out since <code>start</code> the polling.
# You can invoke <tt>stop()</tt> method to stop a polling explicitly.
+
# You can invoke <code>stop()</code> method to stop a polling explicitly.
  
 
= Send dummy client polling request to server and wait =
 
= Send dummy client polling request to server and wait =
Assume that we have a ZK application that use <tt>Server Push</tt> mechanism to update the component attributes after an user triggering a long server operation. We will need <tt>PollingAgent</tt> to simulate sending the dummy client polling request and wait server to complete its long operation.
+
Assume that we have a ZK application that use <code>Server Push</code> mechanism to update the component attributes after an user triggering a long server operation. We will need <code>PollingAgent</code> to simulate sending the dummy client polling request and wait server to complete its long operation.
  
<source lang="java" start="24" high="31, 32, 33, 38, 42">
+
<source lang="java" start="24" highlight="31, 32, 33, 38, 42">
 
@Test
 
@Test
 
public void test() throws Exception {
 
public void test() throws Exception {
Line 39: Line 39:
 
}
 
}
 
</source>
 
</source>
* '''Line 31''': Cast desktop to <tt>PollingAgent</tt> and keep its reference.
+
* '''Line 31''': Cast desktop to <code>PollingAgent</code> and keep its reference.
* '''Line 32''': Invoke <tt>start(5000)</tt> method to start a polling which will timeout in 5 seconds(5000 milliseconds).
+
* '''Line 32''': Invoke <code>start(5000)</code> method to start a polling which will timeout in 5 seconds(5000 milliseconds).
* '''Line 33''': Invoke <tt>polling(500)</tt> method to send the dummy client polling request to server and wait 500 milliseconds before returning; check the return value to decide if stop the polling loop.
+
* '''Line 33''': Invoke <code>polling(500)</code> method to send the dummy client polling request to server and wait 500 milliseconds before returning; check the return value to decide if stop the polling loop.
* '''Line 38''': Invoke <tt>stop()</tt> method to stop the polling since we have get the value pushed from server.
+
* '''Line 38''': Invoke <code>stop()</code> method to stop the polling since we have get the value pushed from server.
 
* '''Line 42''': Use a timeout boolean variable to distinguish whether the polling loop is timeout or explicitly stopped.
 
* '''Line 42''': Use a timeout boolean variable to distinguish whether the polling loop is timeout or explicitly stopped.
  

Latest revision as of 02:55, 18 January 2022


Since 1.2.1

ZATS Mimic introduces the PollingAgent to simulate client polling operation to support testing applications that uses Server Push mechanism.

The following are the usage steps:

  1. Obtain a PollingAgent object from desktop.
    Note that you should use the same PollingAgent object on calling all methods.
  2. Start a polling by invoking start(int timeout) method.
    The timeout indicates for how many milliseconds we should timeout the polling; a 0(zero) timeout means never timeout.
  3. Invoke polling(int delay) method which will send a dummy client polling request to server and wait the specified delay time(in milliseconds) before returning. The polling method returns a boolean to indicate if the polling is stopped(false) or not(true) so you can control when to leave a polling loop.
    A polling is stopped if the stop() method is called explicitly or if the polling has timed out since start the polling.
  4. You can invoke stop() method to stop a polling explicitly.

Send dummy client polling request to server and wait

Assume that we have a ZK application that use Server Push mechanism to update the component attributes after an user triggering a long server operation. We will need PollingAgent to simulate sending the dummy client polling request and wait server to complete its long operation.

@Test
public void test() throws Exception {
        DesktopAgent desktop = Zats.newClient().connect("/long.zul");
        ComponentAgent button = desktop.query("button");
        button.click(); //trigger long operation (will cost 3000 milliseconds)
        
        boolean timeout = true;
        PollingAgent agent = desktop.as(PollingAgent.class); 
        agent.start(5000); // start the client polling and timeout in 5000 milliseconds(5 seconds) 
        while (agent.polling(500)) { //check every 500 milliseconds before polling is stopped
        	ComponentAgent label =  desktop.query("label");
        	//assert expected status then break
        	if ( label != null){
        		Assert.assertEquals("success", label.as(Label.class).getValue());
        		agent.stop(); // stop the polling as we have done the test
        		timeout = false;
        	}
        }
        Assert.assertFalse("Timeout!", timeout); // client polling timeout
}
  • Line 31: Cast desktop to PollingAgent and keep its reference.
  • Line 32: Invoke start(5000) method to start a polling which will timeout in 5 seconds(5000 milliseconds).
  • Line 33: Invoke polling(500) method to send the dummy client polling request to server and wait 500 milliseconds before returning; check the return value to decide if stop the polling loop.
  • Line 38: Invoke stop() method to stop the polling since we have get the value pushed from server.
  • Line 42: Use a timeout boolean variable to distinguish whether the polling loop is timeout or explicitly stopped.

Supported Components

Components
Version
Note
DesktopAgent 5, 6




Last Update : 2022/01/18

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.