def test_sendBatchMessages(sqs): fake_data0 = {"foo": "bar"} fake_data1 = {"john": "doe"} jsonized0 = json.dumps(fake_data0) jsonized1 = json.dumps(fake_data1) md5_0 = hashlib.md5(jsonized0.encode("utf-8")).hexdigest() md5_1 = hashlib.md5(jsonized1.encode("utf-8")).hexdigest() proj = generate_proj() from ndingest.ndqueue.uploadqueue import UploadQueue UploadQueue.createQueue(proj) upload_queue = UploadQueue(proj) try: response = upload_queue.sendBatchMessages([jsonized0, jsonized1], 0) assert "Successful" in response success_ids = [] for msg_result in response["Successful"]: id = msg_result["Id"] success_ids.append(id) if id == "0": assert md5_0 == msg_result["MD5OfMessageBody"] elif id == "1": assert md5_1 == msg_result["MD5OfMessageBody"] assert "0" in success_ids assert "1" in success_ids finally: for message_id, receipt_handle, _ in upload_queue.receiveMessage(): upload_queue.deleteMessage(message_id, receipt_handle)
def test_generate_upload_tasks(self): """""" try: ingest_mgmr = IngestManager() ingest_job = ingest_mgmr.setup_ingest(self.user.id, self.example_config_data) ingest_mgmr.generate_upload_tasks(ingest_job.id) assert (ingest_job.collection == 'my_col_1') assert (ingest_job.experiment == 'my_exp_1') assert (ingest_job.channel == 'my_ch_1') # Pull the messages off the queue proj_class = BossIngestProj.load() nd_proj = proj_class(ingest_job.collection, ingest_job.experiment, ingest_job.channel, ingest_job.resolution, ingest_job.id) queue = UploadQueue(nd_proj, endpoint_url=None) tmp = queue.receiveMessage(number_of_messages=10) # receive message from the queue for message_id, receipt_handle, message_body in tmp: assert(message_body['job_id'] == ingest_job.id) # delete message from the queue response = queue.deleteMessage(message_id, receipt_handle) assert ('Successful' in response) ingest_mgmr.remove_ingest_credentials(ingest_job.id) except: raise finally: ingest_mgmr.delete_upload_queue() ingest_mgmr.delete_ingest_queue()
def test_message(sqs): """Test put, get and delete Message""" x_tile = 0 y_tile = 0 proj = generate_proj() from ndingest.ndqueue.uploadqueue import UploadQueue UploadQueue.createQueue(proj) upload_queue = UploadQueue(proj) for z_tile in range(0, 2, 1): # encode the message message = serializer.encodeUploadMessage( proj.project_name, proj.channel_name, proj.resolution, x_tile, y_tile, z_tile, ) # send message to the queue upload_queue.sendMessage(message) # receive message from the queue for message_id, receipt_handle, message_body in upload_queue.receiveMessage( number_of_messages=3 ): # check if we get the tile_info back correctly assert message_body["z_tile"] in [0, 1, 2] # delete message from the queue response = upload_queue.deleteMessage(message_id, receipt_handle) # check if the message was sucessfully deleted assert "Successful" in response
error_code = err.response['Error'].get('Code', 'Unknown') if error_code == 'ConditionalCheckFailedException': print('Chunk key entry already created - proceeding.') else: raise chunk_ready = tile_index_db.markTileAsUploaded(metadata["chunk_key"], tile_key, int(metadata["ingest_job"])) # ingest the chunk if we have all the tiles if chunk_ready: print("CHUNK READY SENDING MESSAGE: {}".format(metadata["chunk_key"])) # insert a new job in the insert queue if we have all the tiles ingest_queue = IngestQueue(proj_info) ingest_queue.sendMessage(json.dumps(metadata)) # Invoke Ingest lambda function metadata["lambda-name"] = "ingest" lambda_client = boto3.client('lambda', region_name=SETTINGS.REGION_NAME) response = lambda_client.invoke( FunctionName=metadata["parameters"]["ingest_lambda"], InvocationType='Event', Payload=json.dumps(metadata).encode()) else: print("Chunk not ready for ingest yet: {}".format(metadata["chunk_key"])) # Delete message from upload queue upload_queue = UploadQueue(proj_info) upload_queue.deleteMessage(message_id, receipt_handle) print("DONE!")