def prepare(): set_active_scenario('PREPARE') kw.wait_suppliers_connected(scenarios.CUSTOMERS_IDS_1, expected_min_suppliers=2, expected_max_suppliers=2) kw.wait_service_state(scenarios.SUPPLIERS_IDS_12 + [ 'supplier-rotated', ], 'service_supplier', 'ON') kw.wait_service_state(scenarios.CUSTOMERS_IDS_1, 'service_customer', 'ON') kw.wait_service_state(scenarios.CUSTOMERS_IDS_1, 'service_shared_data', 'ON') kw.wait_service_state(scenarios.CUSTOMERS_IDS_1, 'service_personal_messages', 'ON') kw.wait_service_state(scenarios.CUSTOMERS_IDS_1, 'service_private_groups', 'ON') kw.wait_service_state(scenarios.CUSTOMERS_IDS_1, 'service_message_history', 'ON') kw.wait_service_state(scenarios.BROKERS_IDS + [ 'broker-rotated', ], 'service_message_broker', 'ON') kw.config_set_v1('customer-1', 'services/employer/candidates', '') kw.wait_packets_finished(scenarios.PROXY_IDS + scenarios.CUSTOMERS_IDS_1 + scenarios.BROKERS_IDS + [ 'broker-rotated', ] + scenarios.SUPPLIERS_IDS_12 + [ 'supplier-rotated', ])
def prepare(): set_active_scenario('PREPARE') kw.wait_suppliers_connected(scenarios.CUSTOMERS_IDS_12, expected_min_suppliers=2, expected_max_suppliers=2) kw.wait_service_state(scenarios.SUPPLIERS_IDS_12, 'service_supplier', 'ON') kw.wait_service_state(scenarios.CUSTOMERS_IDS_12, 'service_customer', 'ON') kw.wait_service_state(scenarios.CUSTOMERS_IDS_12, 'service_shared_data', 'ON') # kw.wait_service_state(scenarios.CUSTOMERS_IDS_12, 'service_personal_messages', 'ON') kw.wait_service_state(scenarios.CUSTOMERS_IDS_12, 'service_private_groups', 'ON') kw.wait_service_state(scenarios.CUSTOMERS_IDS_12, 'service_message_history', 'ON') kw.wait_packets_finished(scenarios.PROXY_IDS + scenarios.CUSTOMERS_IDS_12 + scenarios.SUPPLIERS_IDS_12)
def test_customers_1_2_3_communicate_via_message_brokers(): if os.environ.get('RUN_TESTS', '1') == '0': return pytest.skip() # @UndefinedVariable # prepare customers 1, 2 and 3 kw.supplier_list_v1('customer-1', expected_min_suppliers=2, expected_max_suppliers=2) kw.service_info_v1('customer-1', 'service_shared_data', 'ON') kw.service_info_v1('customer-1', 'service_private_groups', 'ON') kw.supplier_list_v1('customer-2', expected_min_suppliers=2, expected_max_suppliers=2) kw.service_info_v1('customer-2', 'service_shared_data', 'ON') kw.service_info_v1('customer-2', 'service_private_groups', 'ON') kw.supplier_list_v1('customer-3', expected_min_suppliers=2, expected_max_suppliers=2) kw.service_info_v1('customer-3', 'service_shared_data', 'ON') kw.service_info_v1('customer-3', 'service_private_groups', 'ON') kw.wait_packets_finished(CUSTOMERS_IDS + BROKERS_IDS) assert kw.queue_list_v1('broker-1', extract_ids=True) == [] assert kw.queue_list_v1('broker-2', extract_ids=True) == [] assert kw.queue_list_v1('broker-3', extract_ids=True) == [] assert kw.queue_list_v1('broker-4', extract_ids=True) == [] assert kw.queue_list_v1('broker-5', extract_ids=True) == [] assert kw.queue_consumer_list_v1('broker-1', extract_ids=True) == [] assert kw.queue_consumer_list_v1('broker-2', extract_ids=True) == [] assert kw.queue_consumer_list_v1('broker-3', extract_ids=True) == [] assert kw.queue_consumer_list_v1('broker-4', extract_ids=True) == [] assert kw.queue_consumer_list_v1('broker-5', extract_ids=True) == [] assert kw.queue_producer_list_v1('broker-1', extract_ids=True) == [] assert kw.queue_producer_list_v1('broker-2', extract_ids=True) == [] assert kw.queue_producer_list_v1('broker-3', extract_ids=True) == [] assert kw.queue_producer_list_v1('broker-4', extract_ids=True) == [] assert kw.queue_producer_list_v1('broker-5', extract_ids=True) == [] # remember suppliers of customer-1 customer_1_suppliers = kw.supplier_list_v1('customer-1', expected_min_suppliers=2, expected_max_suppliers=2, extract_suppliers=True) first_supplier_customer_1 = customer_1_suppliers[0].replace( 'http://*****:*****@')[0] assert active_queue_id in kw.queue_list_v1(active_broker_name, extract_ids=True) broker_consumers = kw.queue_consumer_list_v1(active_broker_name, extract_ids=True) broker_producers = kw.queue_producer_list_v1(active_broker_name, extract_ids=True) assert len(broker_consumers) == 1 assert len(broker_producers) == 1 assert 'customer-1@id-a_8084' in broker_consumers assert 'customer-1@id-a_8084' in broker_producers # share group key from customer-1 to customer-2 kw.group_share_v1('customer-1', group_key_id, 'customer-2@id-b_8084') # second member join the group kw.group_join_v1('customer-2', group_key_id) kw.wait_packets_finished(CUSTOMERS_IDS + BROKERS_IDS) assert kw.group_info_v1('customer-2', group_key_id)['result']['last_sequence_id'] == -1 broker_consumers = kw.queue_consumer_list_v1(active_broker_name, extract_ids=True) broker_producers = kw.queue_producer_list_v1(active_broker_name, extract_ids=True) assert len(broker_consumers) == 2 assert len(broker_producers) == 2 assert 'customer-1@id-a_8084' in broker_consumers assert 'customer-1@id-a_8084' in broker_producers assert 'customer-2@id-b_8084' in broker_consumers assert 'customer-2@id-b_8084' in broker_producers # MESSAGE A: from customer 1 to the group, customers 1 and 2 must receive the message execute_message_send_receive( group_key_id, producer_id='customer-1', consumers_ids=[ 'customer-1', 'customer-2', ], message_label='A', expected_results={ 'customer-1': True, 'customer-2': True, }, expected_last_sequence_id={ 'customer-1': 0, 'customer-2': 0, }, ) # customer-2 share group key to customer-3 kw.group_share_v1('customer-2', group_key_id, 'customer-3@id-a_8084') # third member join the group kw.group_join_v1('customer-3', group_key_id) kw.wait_packets_finished(CUSTOMERS_IDS + BROKERS_IDS) broker_consumers = kw.queue_consumer_list_v1(active_broker_name, extract_ids=True) broker_producers = kw.queue_producer_list_v1(active_broker_name, extract_ids=True) assert len(broker_consumers) == 3 assert len(broker_producers) == 3 assert 'customer-1@id-a_8084' in broker_consumers assert 'customer-1@id-a_8084' in broker_producers assert 'customer-2@id-b_8084' in broker_consumers assert 'customer-2@id-b_8084' in broker_producers assert 'customer-3@id-a_8084' in broker_consumers assert 'customer-3@id-a_8084' in broker_producers assert kw.group_info_v1('customer-3', group_key_id)['result']['last_sequence_id'] == 0 # MESSAGE B: from customer 3 to the group, customers 1, 2 and 3 must receive the message execute_message_send_receive( group_key_id, producer_id='customer-3', consumers_ids=[ 'customer-1', 'customer-2', 'customer-3', ], message_label='B', expected_results={ 'customer-1': True, 'customer-2': True, 'customer-3': True, }, expected_last_sequence_id={ 'customer-1': 1, 'customer-2': 1, 'customer-3': 1, }, ) # customer-2 leave the group kw.group_leave_v1('customer-2', group_key_id) kw.wait_packets_finished(CUSTOMERS_IDS + BROKERS_IDS) group_info_offline = kw.group_info_v1('customer-2', group_key_id)['result'] assert group_info_offline['state'] == 'OFFLINE' assert group_info_offline['label'] == 'TestGroup123' assert group_info_offline['last_sequence_id'] == 1 assert 'customer-1@id-a_8084' in kw.queue_consumer_list_v1( active_broker_name, extract_ids=True) assert 'customer-1@id-a_8084' in kw.queue_producer_list_v1( active_broker_name, extract_ids=True) assert 'customer-2@id-b_8084' not in kw.queue_consumer_list_v1( active_broker_name, extract_ids=True) assert 'customer-2@id-b_8084' not in kw.queue_producer_list_v1( active_broker_name, extract_ids=True) assert 'customer-3@id-a_8084' in kw.queue_consumer_list_v1( active_broker_name, extract_ids=True) assert 'customer-3@id-a_8084' in kw.queue_producer_list_v1( active_broker_name, extract_ids=True) # MESSAGE C: from customer 1 to the group, customers 1 and 3 must receive the message, customer 2 must not receive it execute_message_send_receive( group_key_id, producer_id='customer-1', consumers_ids=[ 'customer-1', 'customer-2', 'customer-3', ], message_label='C', expected_results={ 'customer-1': True, 'customer-2': False, 'customer-3': True, }, expected_last_sequence_id={ 'customer-1': 2, 'customer-2': 1, 'customer-3': 2, }, ) # at that point 3 messages already passed thru the group and archive snapshot suppose to be triggered # kw.wait_packets_finished(CUSTOMERS_IDS + BROKERS_IDS + SUPPLIERS_IDS) # sending 3 other messages to the group from customer 1 for i in range(3): execute_message_send_receive( group_key_id, producer_id='customer-1', consumers_ids=[ 'customer-1', 'customer-2', 'customer-3', ], message_label='D%d' % (i + 1), expected_results={ 'customer-1': True, 'customer-2': False, 'customer-3': True, }, expected_last_sequence_id={}, ) assert kw.group_info_v1('customer-1', group_key_id)['result']['last_sequence_id'] == 5 assert kw.group_info_v1('customer-2', group_key_id)['result']['last_sequence_id'] == 1 assert kw.group_info_v1('customer-3', group_key_id)['result']['last_sequence_id'] == 5 # second member now join the group again... he missed some conversations : expect 4 messages to be missed kw.group_join_v1('customer-2', group_key_id) kw.wait_packets_finished(CUSTOMERS_IDS + BROKERS_IDS) assert len(kw.queue_consumer_list_v1(active_broker_name, extract_ids=True)) == 3 assert len(kw.queue_producer_list_v1(active_broker_name, extract_ids=True)) == 3 # all messages suppose to be restored from archive history # assert kw.group_info_v1('customer-2', group_key_id)['result']['last_sequence_id'] == 5 # all customers leave the group, except customer-3 kw.group_leave_v1('customer-1', group_key_id) kw.group_leave_v1('customer-2', group_key_id) kw.wait_packets_finished(CUSTOMERS_IDS + BROKERS_IDS) assert len(kw.queue_consumer_list_v1(active_broker_name, extract_ids=True)) == 1 assert len(kw.queue_producer_list_v1(active_broker_name, extract_ids=True)) == 1 group_info_offline = kw.group_info_v1('customer-1', group_key_id)['result'] assert group_info_offline['state'] == 'OFFLINE' assert group_info_offline['label'] == 'TestGroup123' assert group_info_offline['last_sequence_id'] == 5 group_info_offline = kw.group_info_v1('customer-2', group_key_id)['result'] assert group_info_offline['state'] == 'OFFLINE' assert group_info_offline['label'] == 'TestGroup123' # assert group_info_offline['last_sequence_id'] == 5 group_info_offline = kw.group_info_v1('customer-3', group_key_id)['result'] assert group_info_offline['state'] == 'IN_SYNC!' assert group_info_offline['label'] == 'TestGroup123' assert group_info_offline['last_sequence_id'] == 5 kw.supplier_list_v1('customer-1', expected_min_suppliers=2, expected_max_suppliers=2) kw.file_list_all_v1('customer-2')