def test_support_multiple_carbon_cache_options(self): """ Multiple carbon-cache sections get handled as multiple carbon-cache backend options had been specified in the command line. """ o = service.StatsDOptions() config_file = ConfigParser.RawConfigParser() config_file.readfp(StringIO("\n".join([ "[statsd]", "[carbon-cache-a]", "carbon-cache-host = 127.0.0.1", "carbon-cache-port = 2004", "carbon-cache-name = a", "[carbon-cache-b]", "carbon-cache-host = 127.0.0.2", "carbon-cache-port = 2005", "carbon-cache-name = b", "[carbon-cache-c]", "carbon-cache-host = 127.0.0.3", "carbon-cache-port = 2006", "carbon-cache-name = c", ]))) o.configure(config_file) self.assertEquals(o["carbon-cache-host"], ["127.0.0.1", "127.0.0.2", "127.0.0.3"]) self.assertEquals(o["carbon-cache-port"], [2004, 2005, 2006]) self.assertEquals(o["carbon-cache-name"], ["a", "b", "c"])
def test_default_clients(self): """ Test that default clients are created when none is specified. """ o = service.StatsDOptions() s = service.createService(o) manager = s.services[1] self.assertEqual(sorted(manager.client_factories.keys()), [("127.0.0.1", 2004, None)])
def test_carbon_client_options(self): """ Options for carbon-client get set into carbon's settings object. """ from carbon.conf import settings o = service.StatsDOptions() o["max-queue-size"] = 10001 o["max-datapoints-per-message"] = 10002 service.createService(o) self.assertEqual(settings.MAX_QUEUE_SIZE, 10001) self.assertEqual(settings.MAX_DATAPOINTS_PER_MESSAGE, 10002)
def test_service(self): """ The StatsD service can be created. """ o = service.StatsDOptions() s = service.createService(o) self.assertTrue(isinstance(s, service.MultiService)) reporting, manager, statsd, udp, httpinfo = s.services self.assertTrue(isinstance(reporting, ReportingService)) self.assertTrue(isinstance(manager, CarbonClientManager)) self.assertTrue(isinstance(statsd, service.StatsDService)) self.assertTrue(isinstance(udp, UDPServer))
def test_multiple_clients(self): """ Test that multiple clients are created when the config specifies so. """ o = service.StatsDOptions() o["carbon-cache-host"] = ["127.0.0.1", "127.0.0.2"] o["carbon-cache-port"] = [2004, 2005] o["carbon-cache-name"] = ["a", "b"] s = service.createService(o) manager = s.services[1] self.assertEqual(sorted(manager.client_factories.keys()), [("127.0.0.1", 2004, "a"), ("127.0.0.2", 2005, "b")])
def get_results(self, path, **kwargs): webport = 12323 o = service.StatsDOptions() o["http-port"] = webport d = Dummy() d.__dict__.update(kwargs) self.service = s = httpinfo.makeService(o, d, d) s.startService() agent = Agent(reactor) result = yield agent.request('GET', 'http://localhost:%s/%s' % (webport, path)) if result.code != 200: raise HttpException(result) data = yield collect_response(result) defer.returnValue(data)
def test_monitor_response(self): """ The StatsD service messages the expected response to the monitoring agent. """ from twisted.internet import reactor options = service.StatsDOptions() processor = MessageProcessor() statsd_server_protocol = StatsDServerProtocol( processor, monitor_message=options["monitor-message"], monitor_response=options["monitor-response"]) reactor.listenUDP(options["listen-port"], statsd_server_protocol) agent = Agent() reactor.listenUDP(0, agent) @inlineCallbacks def exercise(): def monitor_send(): agent.transport.write( options["monitor-message"], ("127.0.0.1", options["listen-port"])) def statsd_response(result): self.assertEqual(options["monitor-response"], agent.monitor_response) yield monitor_send() d = Deferred() d.addCallback(statsd_response) reactor.callLater(.1, d.callback, None) try: yield d except: raise finally: reactor.stop() reactor.callWhenRunning(exercise) reactor.run()