Ejemplo n.º 1
0
    def test_dispatcher_that_start_formula_crashing_at_initialization_musnt_forward_report_to_this_formula(self, system, dispatch_rules, actor, logger, dummy_pipe_out):

        route_table = RouteTable()
        for report_type, gbr in dispatch_rules:
            route_table.dispatch_rule(report_type, gbr)
        values = FormulaValues({'fake_pusher': LOGGER_NAME})
        start_message =  DispatcherStartMessage('system', 'dispatcher', CrashInitFormulaActor, values, route_table, 'test_device')
        system.ask(actor, start_message)
        system.tell(actor, REPORT_1)
        assert recv_from_pipe(dummy_pipe_out, 0.5)  == (None,None)
Ejemplo n.º 2
0
 def test_starting_actor_in_stream_mode_dont_terminate_itself_after_empty_db(
         self, system, actor, fake_db, fake_filter):
     assert is_actor_alive(system, actor)
     puller_start_message = PullerStartMessage('system', 'puller_test',
                                               fake_db, fake_filter, True)
     answer = system.ask(actor, puller_start_message)
     time.sleep(1)
     assert is_actor_alive(system, actor)
Ejemplo n.º 3
0
 def test_create_puller_with_router_without_rules_must_raise_RouterWithoutRuleException(
         self, system, empty_filter, fake_db):
     puller = system.createActor(PullerActor)
     puller_start_message = PullerStartMessage('system', 'puller_test',
                                               fake_db, empty_filter, False)
     answer = system.ask(puller, puller_start_message)
     assert isinstance(answer, ErrorMessage)
     assert answer.error_message == 'filter without rules'
Ejemplo n.º 4
0
def test_generate_pusher_with_socket_tags_and_send_it_a_powerReport_must_store_PowerReport_with_right_tag(
        system, influx_database, power_report):
    """
    Create a PusherGenerator that generate pusher with a PowerReportModel that keep formula_name metadata in PowerReport
    Generate a pusher connected to an influxDB
    send a powerReport with formula_name metadata to the pusher
    test if stored data have tag with formula_name
    """

    config = {
        'verbose': True,
        'stream': False,
        'output': {
            'test_pusher': {
                'type': 'influxdb',
                'tags': 'socket',
                'model': 'PowerReport',
                'name': 'test_pusher',
                'uri': INFLUX_URI,
                'port': INFLUX_PORT,
                'db': INFLUX_DBNAME
            }
        }
    }

    generator = PusherGenerator()
    generator.remove_model_factory('PowerReport')
    generator.add_model_factory('PowerReport', PowerReport)

    actors = generator.generate(config)
    pusher_cls, pusher_start_message = actors['test_pusher']

    pusher = system.createActor(pusher_cls)
    system.ask(pusher, pusher_start_message)
    system.tell(pusher, power_report)
    time.sleep(0.3)
    system.tell(pusher, ActorExitRequest())
    influx_database.switch_database(INFLUX_DBNAME)
    reports = list(
        influx_database.query('SELECT * FROM "power_consumption"').get_points(
            tags={'socket': '1'}))
    assert len(reports) == 1
Ejemplo n.º 5
0
 def test_starting_actor_with_a_non_PullerStartMessage_must_answer_error_message(
         self, system, actor):
     puller_start_message = StartMessage('system', 'puller_test')
     answer = system.ask(actor, puller_start_message)
     assert isinstance(answer, ErrorMessage)
     assert answer.error_message == 'use PullerStartMessage instead of StartMessage'
Ejemplo n.º 6
0
 def test_starting_dummy_formula_without_DummyFormulaStartMessage_answer_ErrorMessage(self, system, actor):
     answer = system.ask(actor, StartMessage('system', 'test'))
     assert isinstance(answer, ErrorMessage)
     assert answer.error_message == 'use FormulaStartMessage instead of StartMessage'
Ejemplo n.º 7
0
def test_create_pusher_and_connect_it_to_mongodb_with_bad_config_must_answer_error_message(
        system, pusher, database, report_type):
    answer = system.ask(pusher,
                        PusherStartMessage('system', PUSHER_NAME, database))
    assert isinstance(answer, ErrorMessage)
Ejemplo n.º 8
0
 def test_starting_actor_with_db_that_crash_when_connected_must_answer_error_message(
         self, system, actor, crash_db):
     start_msg = PusherStartMessage('system', 'pusher_test', crash_db)
     msg = system.ask(actor, start_msg)
     assert isinstance(msg, ErrorMessage)
     assert msg.error_message == 'crash'
Ejemplo n.º 9
0
 def test_starting_actor_without_DispatcherStartMessage_must_answer_error_message(self, system, actor, logger):
     answer = system.ask(actor, StartMessage('system', 'test'))
     assert isinstance(answer, ErrorMessage)
     assert answer.error_message == 'use DispatcherStartMessage instead of StartMessage'