PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/site/chorus-website/site/pages/BuiltInHandlers/Remoting/RemotingHandlerDetails.md

http://github.com/Chorus-bdd/Chorus
Markdown | 241 lines | 182 code | 59 blank | 0 comment | 0 complexity | 0cac5b3d56cc8c123b0f295d43fbcf08 MD5 | raw file
Possible License(s): MIT
  1. ---
  2. layout: page
  3. title: Remoting Handler Details
  4. section: Remoting
  5. sectionIndex: 30
  6. ---
  7. ### Overview
  8. The `Remoting` Handler defines steps that allow the interpreter to connect to remote Java/JVM components and discover test step definitions they publish.
  9. See [Distributed Tests](/pages/DistributedTesting/DistributedTests) for an overview of distributed test steps.
  10. * [Handler Steps](#steps)
  11. * [Handler Properties](#properties)
  12. ### Using the Processes Handler
  13. The processes Chorus connects to can be services deployed within a testing environment or may be running locally.
  14. The interpreter can [start up local processes](/pages/BuiltInHandlers/Processes/ProcessesHandlerQuickStart) and then connect to them.
  15. Starting processes and connecting to them often occurs at the start of a feature, within Chorus' custom [Feature-Start:](/pages/GherkinExtensions/FeatureStartAndEnd) section.
  16. #### Example
  17. Let's pretend we have an integration test environment all ready to run some tests. We wish to write a feature which tests
  18. components are interacting in the way we expect.
  19. One component is a user interface which traders user to Buy stocks. This component is called *traderUI*. We want Chorus
  20. to remotely click the 'Buy' button as a step in our test feature
  21. The first thing we need to do is export a handler class with a step definition 'click the buy button' from the user
  22. interface component.
  23. ##### 1. Create and export a Handler class to define steps which run within the UI component
  24. First create a handler class with a 'click the buy button' step.
  25. This handler will be added to the source code for the UI component.
  26. The BuyButtonHandler class may look like this:
  27. @Handler("Buy Button")
  28. public class BuyButtonHandler {
  29. @Step("I click the buy button")
  30. public void clickBuyButton() {
  31. ..here write some code to simulate a user clicking the buy button
  32. }
  33. }
  34. Once created, add some code to export the handler class when the UI component starts up:
  35. BuyButtonHandler buyHandler = new BuyButtonHandler();
  36. new ChorusHandlerJmxExporter(buyHandler).export();
  37. ##### 2. Run the component, starting the JMX management service
  38. We need to make sure our user interface component has the jmx management service enabled when it is started up in UAT -
  39. this provides the network connectivity.
  40. Chorus' exporter will be discoverable as a JMX bean within the jmx container.
  41. This can be done by setting the following system properties when you start the java process:
  42. java -Dcom.sun.management.jmxremote
  43. -Dcom.sun.management.jmxremote.ssl=false
  44. -Dcom.sun.management.jmxremote.authenticate=false
  45. -Dcom.sun.management.jmxremote.port=${choose_a_port_number}
  46. You also need to set the following system property on your remote component to turn on chorus handler export.
  47. This would generally be turned *on* in your testing environment, but *off* in production.
  48. -Dorg.chorusbdd.chorus.jmxexporter.enabled=true
  49. n.b. You could use the [Processes Handler](/pages/BuiltInHandlers/Processes/ProcessesHandlerQuickStart) to start up the
  50. process at the start of the feature, before you connect to it
  51. ##### 3. Calling Remote Steps from Chorus
  52. We are now going to run the Chorus interpreter, adding add a feature which calls the 'I click the buy button' step on
  53. the user interface component which is running remotely.
  54. At the top of our feature file we need to add `Uses: Remoting`, to tell Chorus that we will use the built in
  55. Remoting Handler. The feature may start like this:
  56. Uses: Remoting
  57. Feature: Buy Button
  58. #! Remoting connect traderUI
  59. Scenario: Buy stocks in traderUI
  60. When I click the buy button
  61. ...
  62. ##### 4. Adding a 'Connect Directive' or a Connect step
  63. Note that the scenario above is prefixed with the following directive:
  64. #! Remoting connect traderUI
  65. This tells Chorus' Remoting handler to connect to the traderUI so that we can match and run the steps which it exports.
  66. Alternatively if you prefer you could also use a built in step `Given I connect to the traderUI process` to accomplish this
  67. Initially this scenario will fail, since we haven't yet told the Remoting handler where the traderUI process is running.
  68. ##### 5. Telling chorus where to connect to the remote process**
  69. At present Chorus does not know how to connect to the traderUI process, so the connect directive will fail.
  70. We need to add a property which will tell Chorus' Remoting Handler where the `traderUI` component is running and how to connect to it.
  71. Do this by adding a properties file in the same directory as the feature.
  72. e.g. For a feature file named `clickbuy.feature`, we would add a `clickbuy.properties`
  73. This needs to contain a connection property for each networked component.
  74. If the traderUI was running on server myserver.mydomain on port 18806 then we'd need to add the following property:
  75. remoting.traderUI.connection=jmx:myserver.mydomain:18806
  76. Note the `remoting` prefix to the property name - this tells Chorus that this is Remoting handler property.
  77. ##### 6. More about Remoting properties
  78. For all the supported RemotingHandler properties see [Remoting Handler Properties](/pages/BuiltInHandlers/Remoting/RemotingHandlerProperties)
  79. If you want to share remoting properties between all your features you can add their connectivity details to a chorus.properties
  80. at the top level on your classpath. Here you could list all your UAT components, for example, so you don't need to keep repeating yourself.
  81. <br/>
  82. <a name="steps"/>
  83. ## Steps available in the Remoting Handler:
  84. <br/>
  85. <table>
  86. <tr>
  87. <th>Step</th><th>Example</th><th>Deprecated</th><th>Description</th><th>Retry Duration (wait for step to pass)</th>
  88. </tr>
  89. <tr>
  90. <td>Remoting connect ([a-zA-Z0-9-_, ]+)</td>
  91. <td>#! Remoting connect myServiceA) myServiceB</td>
  92. <td>No</td>
  93. <td>Connect to one or more remote processes (as a Directive) at the hostnames and ports specified in the handler properties. The remote processes must be exporting steps using Chorus JMX remoting utilities, ChorusHandlerJmxExporter. The number of connection attempts and wait time between each attempt are configured in the handler properties</td>
  94. <td></td>
  95. </tr>
  96. <tr>
  97. <td>.*connect to the process(?:es)? (?:named )?([a-zA-Z0-9-_, ]+)</td>
  98. <td>Given I connect to the processes named myProcessA) myProcessB</td>
  99. <td>No</td>
  100. <td>Connect to one or more remote processes at the hostnames and ports specified in the handler properties. The remote processes must be exporting steps using Chorus JMX remoting utilities, ChorusHandlerJmxExporter. The number of connection attempts and wait time between each attempt are configured in the handler properties</td>
  101. <td></td>
  102. </tr>
  103. <tr>
  104. <td>.*connect to the ([a-zA-Z0-9-_]+) process</td>
  105. <td>Given I connect to the myProcessA</td>
  106. <td>No</td>
  107. <td>Connect to a remote process at the hostname and port specified in the handler properties. The number of connection attempts and wait time between each attempt are configured in the handler properties</td>
  108. <td></td>
  109. </tr>
  110. </table>
  111. <br/>
  112. <a name="properties"/>
  113. ## Configuration properties for the Remoting Handler:
  114. <br/>
  115. <table>
  116. <tr>
  117. <th>Property</th><th>Is Mandatory</th><th>Description</th><th>Default</th><th>Validation</th>
  118. </tr>
  119. <tr>
  120. <td>connection</td>
  121. <td>no</td>
  122. <td>A shorthand way of setting protocol host and port properties delimited by colon, e.g. jmx:myHost:myPort</td>
  123. <td></td>
  124. <td>jmx:\S+:\d+</td>
  125. </tr>
  126. <tr>
  127. <td>protocol</td>
  128. <td>yes</td>
  129. <td>Protocol to make connection (only JMX supported at present)</td>
  130. <td>jmx</td>
  131. <td>jmx</td>
  132. </tr>
  133. <tr>
  134. <td>host</td>
  135. <td>no</td>
  136. <td>host where remote component is running</td>
  137. <td></td>
  138. <td></td>
  139. </tr>
  140. <tr>
  141. <td>port</td>
  142. <td>no</td>
  143. <td>port on which remote component's jmx service is listening for connections</td>
  144. <td></td>
  145. <td>\d+</td>
  146. </tr>
  147. <tr>
  148. <td>connectionAttempts</td>
  149. <td>yes</td>
  150. <td>Number of times to attempt connection</td>
  151. <td>40</td>
  152. <td>\d+</td>
  153. </tr>
  154. <tr>
  155. <td>connectionAttemptMillis</td>
  156. <td>yes</td>
  157. <td>Wait time between each connection attempt</td>
  158. <td>250</td>
  159. <td>\d+</td>
  160. </tr>
  161. <tr>
  162. <td>scope</td>
  163. <td>yes</td>
  164. <td>Whether the remoting connection is closed at the end of the scenario or at the end of the feature. This will be set automatically to FEATURE for connections established during 'Feature-Start:' if not provided, otherwise Scenario</td>
  165. <td>SCENARIO</td>
  166. <td>One of: SCENARIO, FEATURE</td>
  167. </tr>
  168. <tr>
  169. <td>userName</td>
  170. <td>no</td>
  171. <td>User Name to provide if remote component's JMX server requires authentication</td>
  172. <td></td>
  173. <td></td>
  174. </tr>
  175. <tr>
  176. <td>password</td>
  177. <td>no</td>
  178. <td>Password to provide if remote component's JMX server requires authentication</td>
  179. <td></td>
  180. <td></td>
  181. </tr>
  182. </table>