def test_publisher_publish_async_invalid_callback(self): self.mock_call.result.return_value = self.publisher_options client = Client(self.mock_tchannel, self.logger) publisher = client.create_publisher(self.test_path) publisher.open() # nothing happens if no callback provided (no exception) publisher.publish_async(self.test_msg_id, self.test_msg, None) publisher.close()
def test_publisher_publish_exception(self): self.mock_call.result.return_value = self.publisher_options client = Client(self.mock_tchannel, self.logger) publisher = client.create_publisher(self.test_path) publisher.open() self.mock_call.result.side_effect = Exception(self.test_err_msg) ack = publisher.publish(self.test_msg_id, self.test_msg) publisher.close() self.assertEquals(self.test_msg_id, ack.id) self.assertEquals(cherami.Status.FAILED, ack.status) self.assertTrue(self.test_err_msg in ack.message)
def test_publisher_publish_failed(self): self.mock_call.result.return_value = self.publisher_options client = Client(self.mock_tchannel, self.logger) publisher = client.create_publisher(self.test_path) publisher.open() self.mock_call.result.return_value = self.send_ack_failed ack = publisher.publish(self.test_msg_id, self.test_msg) publisher.close() self.assertEquals(self.test_msg_id, ack.id) self.assertEquals(cherami.Status.FAILED, ack.status) self.assertEquals(self.test_err_msg, ack.message)
def test_publisher_create(self): self.mock_call.result.return_value = self.publisher_options client = Client(self.mock_tchannel, self.logger) publisher = client.create_publisher(self.test_path) self.assertEquals(0, len(publisher.workers)) self.assertIsNone(publisher.reconfigure_thread) publisher.open() publisher.close() args, kwargs = self.mock_tchannel.thrift.call_args self.assertEquals('BFrontend::readPublisherOptions', args[0].endpoint) self.assertEquals(self.test_path, args[0].call_args.getPublisherOptionsRequest.path) self.assertEquals(10, len(publisher.workers)) self.assertTrue(publisher.reconfigure_thread.is_alive())
def test_publisher_publish_timeout(self): self.mock_call.result.return_value = self.publisher_options client = Client(self.mock_tchannel, self.logger, timeout_seconds=1) publisher = client.create_publisher(self.test_path) publisher.open() def side_effect(): time.sleep(3) return self.send_ack_success self.mock_call.result.side_effect = side_effect ack = publisher.publish(self.test_msg_id, self.test_msg) publisher.close() self.assertEquals(self.test_msg_id, ack.id) self.assertEquals(cherami.Status.TIMEDOUT, ack.status)
def test_publisher_publish(self): self.mock_call.result.return_value = self.publisher_options client = Client(self.mock_tchannel, self.logger) publisher = client.create_publisher(self.test_path) publisher.open() self.mock_call.result.return_value = self.send_ack_success ack = publisher.publish(self.test_msg_id, self.test_msg) publisher.close() args, kwargs = self.mock_tchannel.thrift.call_args self.assertEquals('BIn::putMessageBatch', args[0].endpoint) self.assertEquals(self.test_path, args[0].call_args.request.destinationPath) self.assertEquals(1, len(args[0].call_args.request.messages)) self.assertEquals(self.test_msg_id, args[0].call_args.request.messages[0].id) self.assertEquals(self.test_msg, args[0].call_args.request.messages[0].data) self.assertEquals(self.test_msg_id, ack.id) self.assertEquals(cherami.Status.OK, ack.status) self.assertEquals(self.test_receipt, ack.receipt)
def test_publisher_publish_async(self): self.mock_call.result.return_value = self.publisher_options done_signal = threading.Event() acks = [] client = Client(self.mock_tchannel, self.logger) publisher = client.create_publisher(self.test_path) publisher.open() def callback(ack): acks.append(ack) done_signal.set() self.mock_call.result.return_value = self.send_ack_success publisher.publish_async(self.test_msg_id, self.test_msg, callback) done_signal.wait(5) publisher.close() self.assertEquals(1, len(acks)) self.assertEquals(self.test_msg_id, acks[0].id) self.assertEquals(cherami.Status.OK, acks[0].status) self.assertEquals(self.test_receipt, acks[0].receipt)
def test_publisher_open_exception(self): self.mock_call.result.side_effect = Exception(self.test_err_msg) client = Client(self.mock_tchannel, self.logger) publisher = client.create_publisher(self.test_path) self.assertRaises(Exception, publisher.open) self.assertTrue(publisher.reconfigure_thread is None)