def test_config_file(self): options = VumiOptions() self.mk_config_file('vumi', ["username: foo", "password: bar"]) options.parseOptions(['--vumi-config', self.config_file['vumi']]) self.assertEqual({}, options.opts) self.assertEqual(dict(VumiOptions.default_vumi_options, username='******', password='******'), options.vumi_options)
def test_override(self): options = VumiOptions() options.parseOptions(['--hostname', 'blah', '--username', 'haxor']) self.assertEqual({}, options.opts) self.assertEqual(dict(VumiOptions.default_vumi_options, username='******', hostname='blah'), options.vumi_options)
def test_override(self): options = VumiOptions() options.parseOptions(['--hostname', 'blah', '--username', 'haxor']) self.assertEqual({}, options.opts) self.assertEqual( dict(VumiOptions.default_vumi_options, username='******', hostname='blah'), options.vumi_options)
def postOptions(self): VumiOptions.postOptions(self) if not self['vumigo-config']: raise usage.UsageError( "Please provide the vumigo-config parameter.") if not self['user-account-key']: raise usage.UsageError( "Please provide the user-account-key parameter.")
def test_config_file_override(self): self.mk_config_file('vumi', ["username: foo", "password: bar"]) options = VumiOptions() options.parseOptions(['--vumi-config', self.config_file['vumi'], '--hostname', 'blah', '--username', 'haxor']) self.assertEqual({}, options.opts) self.assertEqual(dict(VumiOptions.default_vumi_options, username='******', password='******', hostname='blah'), options.vumi_options)
def postOptions(self): VumiOptions.postOptions(self) if not self['vumigo-config']: raise usage.UsageError( "Please provide the vumigo-config parameter.") if not self['user-account-key']: raise usage.UsageError( "Please provide the user-account-key parameter.") if not self['conversation-key']: raise usage.UsageError( "Please provide the conversation-key parameter.") try: hz = float(self['hz']) except (TypeError, ValueError): hz_okay = False else: hz_okay = bool(hz > 0) if not hz_okay: raise usage.UsageError("Please provide a positive float for hz") self['hz'] = hz
def postOptions(self): VumiOptions.postOptions(self) if not self['vumigo-config']: raise usage.UsageError( "Please provide the vumigo-config parameter.") if not self['user-account-key']: raise usage.UsageError( "Please provide the user-account-key parameter.") if not self['conversation-key']: raise usage.UsageError( "Please provide the conversation-key parameter.") try: hz = float(self['hz']) except (TypeError, ValueError): hz_okay = False else: hz_okay = bool(hz > 0) if not hz_okay: raise usage.UsageError( "Please provide a positive float for hz") self['hz'] = hz
def postOptions(self): VumiOptions.postOptions(self) if not self['transport-name']: raise usage.UsageError("Please provide the " "transport-name parameter.")
def test_defaults(self): options = VumiOptions() options.parseOptions([]) self.assertEqual({}, options.opts) self.assertEqual(VumiOptions.default_vumi_options, options.vumi_options)
def run_bench(loops): opts = VumiOptions() opts.postOptions() worker_creator = WorkerCreator(opts.vumi_options) app = worker_creator.create_worker_by_class( BenchApp, { "transport_name": "dummy", "javascript": """ api.on_inbound_message = function(command) { this.request('outbound.reply_to', { content: 'reply', in_reply_to: command.msg.message_id, }, function (reply) { this.done(); }); }; """, "sandbox": { 'log': { 'cls': 'vumi.application.sandbox.LoggingResource', }, 'outbound': { 'cls': 'vumi.application.sandbox.OutboundResource', }, }, }) transport = worker_creator.create_worker_by_class( BenchTransport, { "transport_name": "dummy", }) yield transport.startService() log.msg("Waiting for transport ...") yield BenchTransport.WORKER_QUEUE.get() yield app.startService() log.msg("Waiting for worker ...") yield BenchApp.WORKER_QUEUE.get() print "Starting %d loops ..." % (loops, ) timer = Timer() for i in range(loops): with timer: transport.publish_message( content="Hi!", to_addr="+1234", from_addr="+5678", transport_type="ussd", ) reply = yield transport.message_queue.get() log.msg("Reply ID: %s" % reply['message_id']) print "Total time: %.2f" % timer.total() print "Time per message: %g" % timer.mean() print " max: %g, min: %g" % (timer.max(), timer.min()) print " loops: %d" % timer.loops() yield transport.stopService() yield app.stopService() reactor.stop()
def run_bench(loops): opts = VumiOptions() opts.postOptions() worker_creator = WorkerCreator(opts.vumi_options) app = worker_creator.create_worker_by_class(BenchApp, { "transport_name": "dummy", "javascript": """ api.on_inbound_message = function(command) { this.request('outbound.reply_to', { content: 'reply', in_reply_to: command.msg.message_id, }, function (reply) { this.done(); }); }; """, "sandbox": { 'log': { 'cls': 'vumi.application.sandbox.LoggingResource', }, 'outbound': { 'cls': 'vumi.application.sandbox.OutboundResource', }, }, }) transport = worker_creator.create_worker_by_class(BenchTransport, { "transport_name": "dummy", }) yield transport.startService() log.msg("Waiting for transport ...") yield BenchTransport.WORKER_QUEUE.get() yield app.startService() log.msg("Waiting for worker ...") yield BenchApp.WORKER_QUEUE.get() print "Starting %d loops ..." % (loops,) timer = Timer() for i in range(loops): with timer: transport.publish_message( content="Hi!", to_addr="+1234", from_addr="+5678", transport_type="ussd", ) reply = yield transport.message_queue.get() log.msg("Reply ID: %s" % reply['message_id']) print "Total time: %.2f" % timer.total() print "Time per message: %g" % timer.mean() print " max: %g, min: %g" % (timer.max(), timer.min()) print " loops: %d" % timer.loops() yield transport.stopService() yield app.stopService() reactor.stop()