def test03_get_from_empty_queue(self): """ Empty queue returns a deferred with None """ collector = Collector(self.sessions) reason = collector.get() self.assertTrue(reason is None)
def test04_get_only_valid_requests(self): """ - create a lot of requests marked as 'expired' - wait some time - create another lot of requests marked as 'valid' -> check if only 'valid' requests present """ clock = Clock() sessions = Sessions(False, 10, clock) collector = Collector(sessions) dl = [] for i in xrange(10): d = collector.queue_and_process("192.168.45.12", "expired") dl.append(d) clock.advance(15) for i in xrange(10): d = collector.queue_and_process("192.168.45.12", "valid") dl.append(d) dfl = DeferredList(dl) @dfl.addCallback def get_result(ignored): for i in xrange(10): uid, ip, request = collector.get() self.assertEqual(request, "valid")
def test03_make_echo_with_collector(self): """ Test with correct handler used in the package. - Get the request from server - Sending the same response """ clock = Clock() sessions = Sessions(False, 10, clock) trigger = DummyTrigger() factory = GatheringFactory() collector = Collector(sessions) factory.protocol.set_handler(collector) factory.protocol.set_trigger(trigger) protocol = factory.buildProtocol(("127.0.0.1", 0)) transport = StringTransport() protocol.makeConnection(transport) protocol.dataReceived("hello") uid, ip, data = collector.get() collector.release(uid, data) self.assertEqual(transport.value(), "hello")
def test01_first_add_and_get(self): """ First element added to queue will be returned as first. """ collector = Collector(self.sessions) first_data = "my first data" collector.queue_and_process("192.168.45.12", first_data) # We are sure that only one element queued uid, ip, request = collector.get() self.assertEqual(request, first_data)
def __init__(self, config): """ @param config: Configuration container @type config: Config """ self.config = config self.logger = logging.getLogger() self.server = Server( config.server.port, config.server.ssl_key_file, config.server.ssl_crt_file, config.server.ssl_method, ) self.collector = Collector() self.endpoints_root = EndpointsRoot(self.collector) self.endpoints_lookup = config.server.endpoints
def test02_add_and_release(self): """ - Add an element and get its deferred (as my_deferred) - Add another elements - Because this is a first element, first get() returns its uid -> Release an element with our uid, we get the same deferred """ collector = Collector(self.sessions) any_data = "any data" my_deferred = collector.queue_and_process("192.168.45.12", any_data) for i in xrange(10): collector.queue_and_process("192.168.127.22", "%s_%d" % (any_data, i)) uid, ip, request = collector.get() d = collector.release(uid, "any result") self.assertTrue(my_deferred is d)