Module: Udat::Demo
- Defined in:
- lib/udat.rb
Overview
Module containing some demonstration functions.
Constant Summary collapse
- ExampleDocument =
A string containing an UDAT example document.
<<-'END_OF_EXAMPLE' [sample config v1.0| <network> [ <max connections> [256] <reverse lookups> [yes] ] <locale> [ <language> [de] german language <timezone> [CET] and CET timezone Comments can appear almost anywhere. ] <access control> [ <allowed> [ [user|martin] [user|max] [group|admins] [ip4network| <address> [192.168.0.0] <netmask> [255.255.255.0] ] ] <blocked> [~] The tilde symbol denotes an empty collection. ] <misc> [ <symbol for homedir> [\~] Not an empty collection but the scalar value "~". ] <address mappings> [ <email| <user> [jan.behrens] <domain> [flexiguided.de] > [mbox|jan] <email| <user> [glob|*] <domain> [flexiguided.de] > [mbox|catchall] ] <logging> [ <verbosity> [high] \## <verbosity> [debug] ## Uncomment this for debug output. <destination> [file|/var/log/sample.log] ] ] END_OF_EXAMPLE
Class Method Summary collapse
-
.rpc_selftest(port = 10330) ⇒ Object
Method to test the RPC mechanism, not for production use.
-
.run_rpc_demo_server(port, timeout = 180) ⇒ Object
Runs a demo server, not for production use.
Class Method Details
.rpc_selftest(port = 10330) ⇒ Object
Method to test the RPC mechanism, not for production use.
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 |
# File 'lib/udat.rb', line 1232 def rpc_selftest(port = 10330) a = rand(100) + 1 b = rand(100) + 1 demo_server_thread = nil begin demo_server_thread = Thread.new do Udat::Demo::run_rpc_demo_server(port) end sleep 0.5 udat_result = nil Timeout.timeout(15) do udat_result = {'operands' => [a, b], 'operator' => '+'}. to_udat("calculation request"). rpc('localhost', port) end if udat_result.tag == "error" raise "RPC call returned with an error: " << udat_result.fetch_scalar("message").to_s end result = udat_result.require_scalar("calculation result").to_f ensure demo_server_thread.kill end unless result == a + b raise "Calculation error during UDAT RPC selftest." end return "Test done: #{a} + #{b} == #{result}" end |
.run_rpc_demo_server(port, timeout = 180) ⇒ Object
Runs a demo server, not for production use.
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 |
# File 'lib/udat.rb', line 1190 def run_rpc_demo_server(port, timeout = 180) Udat::run_rpc_server(port, timeout) do |query| begin case query.tag when "echo request" query.tag = "echo reply" next query when "calculation request" begin query.require_collection operands = query.fetch_collection("operands") operand1 = operands.fetch_scalar(0).to_f operand2 = operands.fetch_scalar(1).to_f end operand1 = operands[0].to_f operand2 = operands[1].to_f operator = query.fetch_scalar("operator") case operator when "+".to_udat next (operand1 + operand2).to_udat("calculation result") when "-".to_udat next (operand1 - operand2).to_udat("calculation result") when "*".to_udat next (operand1 * operand2).to_udat("calculation result") when "/".to_udat next (operand1.quo operand2).to_udat("calculation result") else next([["message", "Unknown operator."]].to_udat("error") ) end when "time request" next Time.now.strftime("%Y-%m-%d %H:%M:%S %Z").to_udat('time') else raise Udat::UdatTagMismatch, "Unknown UDAT tag." end rescue Udat::UdatPropertyMismatch, UdatIndexError next [["message", $!.]].to_udat("error") end end end |