def testSampler(self, count=1, frequency=10): self.server.max_connections = 1 oself = self class Gen(Timeout): def __init__(self): self.sent = 0 def on_sample(self, event): event.link.send(Message("test-%s" % self.sent)) self.sent += 1 if self.sent >= count: event.link.close() self.cancel() def on_timer_task(self, event): snd.stop(event.reactor) gen = Gen(); snd = Sender("//localhost:%s" % PORT, Sampler(gen, frequency)) self.reactor.handler.add(snd) gen.set_timeout(self.reactor, 2) snd.start(self.reactor) self.reactor.run() assert gen.cancelled, "Sampling timed out" assert len(self.sink.messages) == count, len(self.sink.messages) for i in range(count): assert self.sink.messages[i] == "test-%s" % i
def testSampler(self, count=1, frequency=10): self.server.max_connections = 1 oself = self class Gen(Timeout): def __init__(self): self.sent = 0 def on_sample(self, event): event.link.send(Message("test-%s" % self.sent)) self.sent += 1 if self.sent >= count: event.link.close() self.cancel() def on_timer_task(self, event): snd.stop(event.reactor) gen = Gen() snd = Sender("//localhost:%s" % PORT, Sampler(gen, frequency)) self.reactor.handler.add(snd) gen.set_timeout(self.reactor, 2) snd.start(self.reactor) self.reactor.run() assert gen.cancelled, "Sampling timed out" assert len(self.sink.messages) == count, len(self.sink.messages) for i in range(count): assert self.sink.messages[i] == "test-%s" % i
def testSender(self, count=1): self.server.max_connections = 1 snd = Sender("//localhost:%s" % PORT) self.reactor.handler.add(snd) snd.start(self.reactor) for i in range(count): snd.send("test-%s" % i) snd.close() self.reactor.run() assert len(self.sink.messages) == count for i in range(count): assert self.sink.messages[i] == "test-%s" % i, self.sink.messages[i]
class PutBark(object): def __init__(self, user, content, hostname): self.bark = common.Bark(user, content) self.sender = Sender("//%s/outbox/%s" % (hostname, user)) def on_reactor_init(self, event): self.sender.start(event.reactor) self.sender.send(tuple(self.bark)) self.sender.close()
def __init__(self, user, content, hostname): self.bark = common.Bark(user, content) self.sender = Sender("//%s/outbox/%s" % (hostname, user))