def test_module_roundrobin(): actor_config = ActorConfig('roundrobin', 100, 1, {}) roundrobin = RoundRobin(actor_config) roundrobin.pool.queue.inbox.disableFallThrough() roundrobin.pool.createQueue("one") roundrobin.pool.queue.one.disableFallThrough() roundrobin.pool.createQueue("two") roundrobin.pool.queue.two.disableFallThrough() roundrobin.start() event_one = Event("test") event_one.setData("one") event_two = Event("test") event_two.setData("two") roundrobin.pool.queue.inbox.put(event_one) roundrobin.pool.queue.inbox.put(event_two) assert getter(roundrobin.pool.queue.one).raw()["test"]["data"] in ["one", "two"] assert getter(roundrobin.pool.queue.two).raw()["test"]["data"] in ["one", "two"] roundrobin.stop()
def test_module_funnel(): actor_config = ActorConfig('funnel', 100, 1, {}) funnel = Funnel(actor_config) funnel.pool.queue.outbox.disableFallThrough() funnel.pool.createQueue("one") funnel.pool.queue.one.disableFallThrough() funnel.pool.createQueue("two") funnel.pool.queue.two.disableFallThrough() funnel.start() event_one = Event("test") event_one.setData("one") event_two = Event("test") event_two.setData("two") funnel.pool.queue.one.put(event_one) funnel.pool.queue.two.put(event_two) assert getter(funnel.pool.queue.outbox).raw()["test"]["data"] in ["one", "two"] assert getter(funnel.pool.queue.outbox).raw()["test"]["data"] in ["one", "two"] funnel.stop()
def test_module_jsonvalidate(): actor_config = ActorConfig('jsonvalidate', 100, 1, {}) with open("/tmp/jsonvalidate.jsonschema", "w") as j: j.write('{"type": "object", "properties": {"one": { "type": "integer"}}}') jsonvalidate = JSONValidate(actor_config, "/tmp/jsonvalidate.jsonschema") jsonvalidate.pool.queue.inbox.disableFallThrough() jsonvalidate.pool.queue.outbox.disableFallThrough() jsonvalidate.pool.queue.failed.disableFallThrough() jsonvalidate.start() valid = Event('valid') valid.setData({"one": 1}) invalid = Event('invalid') invalid.setData({"one": "one"}) jsonvalidate.pool.queue.inbox.put(valid) valid_event = getter(jsonvalidate.pool.queue.outbox) jsonvalidate.pool.queue.inbox.put(invalid) invalid_event = getter(jsonvalidate.pool.queue.failed) os.remove("/tmp/jsonvalidate.jsonschema") assert valid_event.data == {"one": 1} assert invalid_event.data == {"one": "one"}
def test_module_loglevelfilter(): actor_config = ActorConfig('loglevelfilter', 100, 1, {}) loglevelfilter = LogLevelFilter(actor_config) loglevelfilter.pool.queue.inbox.disableFallThrough() loglevelfilter.pool.queue.outbox.disableFallThrough() loglevelfilter.start() e_one = Event('test') e_one.setData((7, 1367682301.430527, 3342, 'Router', 'Received SIGINT. Shutting down.')) e_two = Event('test') e_two.setData((1, 1367682301.430527, 3342, 'Router', 'Received SIGINT. Shutting down.')) loglevelfilter.pool.queue.inbox.put(e_one) loglevelfilter.pool.queue.inbox.put(e_two) one=getter(loglevelfilter.pool.queue.outbox) assert one.data == (1, 1367682301.430527, 3342, 'Router', 'Received SIGINT. Shutting down.') try: two=getter(loglevelfilter.pool.queue.outbox) except Exception: assert True else: assert False
def test_module_fanout(): actor_config = ActorConfig('fanout', 100, 1, {}) fanout = Fanout(actor_config, deep_copy=True) fanout.pool.queue.inbox.disableFallThrough() fanout.pool.createQueue("one") fanout.pool.queue.one.disableFallThrough() fanout.pool.createQueue("two") fanout.pool.queue.two.disableFallThrough() fanout.start() e = Event('test') e.setData("hello") fanout.pool.queue.inbox.put(e) one = getter(fanout.pool.queue.one) two = getter(fanout.pool.queue.two) fanout.stop() assert one.raw()["test"]["data"] == "hello" assert two.raw()["test"]["data"] == "hello" assert id(one) != id(two)
def test_file_load(): import os import yaml import shutil os.mkdir('/tmp/wishbone_tests') actor_config = ActorConfig('match', 100, 1, {}) match = Match(actor_config, location="/tmp/wishbone_tests") match.pool.createQueue("file") match.pool.queue.file.disableFallThrough() match.pool.queue.inbox.disableFallThrough() #Test 1 rule_1 = { "condition": [ {"file": "re:.*?one.*"} ], "queue": [ {"file": {}} ] } with open('/tmp/wishbone_tests/one.yaml', 'w') as one: one.write(yaml.dump(rule_1, default_flow_style=False)) match.start() sleep(1) e = Event("test") e.setData({"file": "zero one two"}) match.pool.queue.inbox.put(e) assert getter(match.pool.queue.file).data["file"] == "zero one two" #Test 2 rule_2 = { "condition": [ {"file": "re:.*?two.*"} ], "queue": [ {"file": {}} ] } with open('/tmp/wishbone_tests/two.yaml', 'w') as one: one.write(yaml.dump(rule_2, default_flow_style=False)) sleep(1) e = Event("test") e.setData({"file": "one two three"}) match.pool.queue.inbox.put(e) assert getter(match.pool.queue.file).data["file"] == "one two three" shutil.rmtree('/tmp/wishbone_tests')
def test_module_dictgenerator_num_elements(): actor_config = ActorConfig('template', 100, 1, {}) dictgenerator = DictGenerator(actor_config, min_elements=1, max_elements=2) dictgenerator.pool.queue.outbox.disableFallThrough() dictgenerator.start() event = getter(dictgenerator.pool.queue.outbox) assert len(event.data.keys()) >= 1 and len(event.data.keys()) <= 2
def test_smaller_than_equal_to(): rule = {"smaller_equal": { "condition": [ {"smaller_equal": "<=:100"} ], "queue": [ {"smaller_equal": {}} ] }} actor = generate_actor(rule) one = Event("test") one.setData({"smaller_equal": "100"}) two = Event("test") two.setData({"smaller_equal": "99"}) actor.pool.queue.inbox.put(one) actor.pool.queue.inbox.put(two) assert int(getter(actor.pool.queue.smaller_equal).data["smaller_equal"]) == 100 assert int(getter(actor.pool.queue.smaller_equal).data["smaller_equal"]) < 100
def test_module_dictgenerator_randomize_keys(): actor_config = ActorConfig('template', 100, 1, {}) dictgenerator = DictGenerator(actor_config, randomize_keys=False) dictgenerator.pool.queue.outbox.disableFallThrough() dictgenerator.start() event = getter(dictgenerator.pool.queue.outbox) assert '0' in event.data.keys()
def test_module_jsonencode(): actor_config = ActorConfig('jsonencode', 100, 1, {}) http = HTTPInClient(actor_config, url="http://www.google.com", interval=1) http.pool.queue.outbox.disableFallThrough() http.start() one = getter(http.pool.queue.outbox) print one.data assert "Google" in one.data
def test_module_Flatten_default(): '''Tests the default behavior.''' actor_config = ActorConfig('flatten', 100, 1, {}, "") flatten = Flatten(actor_config) flatten.pool.queue.inbox.disableFallThrough() flatten.pool.queue.outbox.disableFallThrough() flatten.start() e = Event({"server": {"host01": {"memory": {"free": 10, "consumed": 90}}}}) flatten.pool.queue.inbox.put(e) one = getter(flatten.pool.queue.outbox) two = getter(flatten.pool.queue.outbox) assert isinstance(one.get(), Metric) assert isinstance(two.get(), Metric) assert one.get().name == 'server.host01.memory.free' assert two.get().name == 'server.host01.memory.consumed'
def test_module_dictgenerator_keys(): actor_config = ActorConfig('template', 100, 1, {}) dictgenerator = DictGenerator(actor_config, keys=["one", "two"]) dictgenerator.pool.queue.outbox.disableFallThrough() dictgenerator.start() event = getter(dictgenerator.pool.queue.outbox) assert "one" in event.data.keys() assert "two" in event.data.keys()
def test_module_humanlogformat(): actor_config = ActorConfig('humanlogformat', 100, 1, {}) humanlogformat = HumanLogFormat(actor_config, colorize=False, ident='setup.py') humanlogformat.pool.queue.inbox.disableFallThrough() humanlogformat.pool.queue.outbox.disableFallThrough() humanlogformat.start() e = Event('test') e.setData(Log(1367682301.430527, 6, 3342, 'Router', 'Received SIGINT. Shutting down.')) humanlogformat.pool.queue.inbox.put(e) one = getter(humanlogformat.pool.queue.outbox) assert one.data == "2013-05-04T17:45:01 setup.py[3342]: informational Router: Received SIGINT. Shutting down."
def test_module_msgpackencode(): actor_config = ActorConfig("msgpackencode", 100, 1, {}) msgpackencode = MSGPackEncode(actor_config) msgpackencode.pool.queue.inbox.disableFallThrough() msgpackencode.pool.queue.outbox.disableFallThrough() msgpackencode.start() e = Event("test") e.setData([1, 2, 3]) msgpackencode.pool.queue.inbox.put(e) one = getter(msgpackencode.pool.queue.outbox) assert one.data == "\x93\x01\x02\x03"
def test_module_dictgenerator_num_values(): actor_config = ActorConfig('template', 100, 1, {}) dictgenerator = DictGenerator(actor_config, num_values=True, num_values_min=1, num_values_max=2) dictgenerator.pool.queue.outbox.disableFallThrough() dictgenerator.start() event = getter(dictgenerator.pool.queue.outbox) for key, value in event.data.iteritems(): assert isinstance(value, int) assert isinstance(event.data.items()[0][1], int) assert event.data.items()[0][1] >= 1 and event.data.items()[0][1] <= 2
def test_module_jsonencode(): actor_config = ActorConfig('jsonencode', 100, 1, {}) jsonencode = JSONEncode(actor_config) jsonencode.pool.queue.inbox.disableFallThrough() jsonencode.pool.queue.outbox.disableFallThrough() jsonencode.start() e = Event('test') e.setData(["one", "two", "three"]) jsonencode.pool.queue.inbox.put(e) one = getter(jsonencode.pool.queue.outbox) assert one.data == '["one", "two", "three"]'
def test_module_header(): actor_config = ActorConfig('header', 100, 1, {}) header = Header(actor_config, header={"greeting": "hello"}) header.pool.queue.inbox.disableFallThrough() header.pool.queue.outbox.disableFallThrough() header.start() e = Event('test') e.setData('hello') header.pool.queue.inbox.put(e) one = getter(header.pool.queue.outbox) assert one.getHeaderValue("header", "greeting") == "hello"
def test_module_msgpackdecode(): actor_config = ActorConfig('msgpackdecode', 100, 1, {}) msgpackdecode = MSGPackDecode(actor_config) msgpackdecode.pool.queue.inbox.disableFallThrough() msgpackdecode.pool.queue.outbox.disableFallThrough() msgpackdecode.start() e = Event('test') e.setData('\x93\x01\x02\x03') msgpackdecode.pool.queue.inbox.put(e) one = getter(msgpackdecode.pool.queue.outbox) assert one.data == [1, 2, 3]
def test_smaller_than(): rule = {"smaller": { "condition": [ {"smaller": "<:100"} ], "queue": [ {"smaller": {}} ] }} actor = generate_actor(rule) one = Event("test") one.setData({"smaller": "99"}) actor.pool.queue.inbox.put(one) assert int(getter(actor.pool.queue.smaller).data["smaller"]) < 100
def test_regex(): rule = {"regex": { "condition": [ {"regex": "re:.*?two.*"} ], "queue": [ {"regex": {}} ] }} actor = generate_actor(rule) e = Event("test") e.setData({"regex": "one two three"}) actor.pool.queue.inbox.put(e) assert getter(actor.pool.queue.regex).data["regex"] == "one two three"
def test_equal_to(): rule = {"equal": { "condition": [ {"equal": "=:100"} ], "queue": [ {"equal": {}} ] }} actor = generate_actor(rule) one = Event("test") one.setData({"equal": "100"}) actor.pool.queue.inbox.put(one) assert int(getter(actor.pool.queue.equal).data["equal"]) == 100
def test_negative_list_membership(): rule = {"list_membership": { "condition": [ {"list_membership": "!in:test"} ], "queue": [ {"list_membership": {}} ] }} actor = generate_actor(rule) one = Event("test") one.setData({"list_membership": ["one", "three", "two"]}) actor.pool.queue.inbox.put(one) assert "test" not in getter(actor.pool.queue.list_membership).data["list_membership"]
def test_bigger_than(): rule = {"bigger": { "condition": [ {"bigger": ">:10"} ], "queue": [ {"bigger": {}} ] }} actor = generate_actor(rule) e = Event("test") e.setData({"bigger": "100"}) actor.pool.queue.inbox.put(e) assert getter(actor.pool.queue.bigger).data["bigger"] == "100"
def test_module_template_header(): '''Tests template defined in header.''' actor_config = ActorConfig('template', 100, 1, {}) template = Template(actor_config, header_templates={"hello": "The numerical representation of one is {{one}}"}) template.pool.queue.inbox.disableFallThrough() template.pool.queue.outbox.disableFallThrough() template.start() e = Event('test') e.setData({"one": 1}) template.pool.queue.inbox.put(e) one = getter(template.pool.queue.outbox) assert one.getHeaderValue('template', "hello") == "The numerical representation of one is 1"
def test_module_graphite(): actor_config = ActorConfig('graphite', 100, 1, {}) graphite = Graphite(actor_config, template='{type}.{source}.{name} {value} {time}') graphite.pool.queue.inbox.disableFallThrough() graphite.pool.queue.outbox.disableFallThrough() graphite.start() e = Event('test') m = Metric(1381002603.726132, "wishbone", "hostname", "queue.outbox.in_rate", 0, "", ()) e.setData(m) graphite.pool.queue.inbox.put(e) one = getter(graphite.pool.queue.outbox) assert one.last.data == "wishbone.hostname.queue.outbox.in_rate 0 1381002603.73"
def test_module_template_file(): '''Tests template defined in file.''' with open("template.tmpl", "w") as f: f.write("The numerical representation of one is {{one}}") actor_config = ActorConfig('template', 100, 1, {}) template = Template(actor_config, template="template.tmpl") template.pool.queue.inbox.disableFallThrough() template.pool.queue.outbox.disableFallThrough() template.start() e = Event('test') e.setHeaderValue("hello", "The numerical representation of one is {{one}}", "test") e.setData({"one": 1}) template.pool.queue.inbox.put(e) one = getter(template.pool.queue.outbox) unlink('template.tmpl') assert one.data == "The numerical representation of one is 1"