Example #1
0
def test_retry_logic():
    VISIBILITY_TIMEOUT = 2
    MAX_RECEIVE_COUNT = 2
    queue_name = id_generator.generate_job_item_id()
    dead_letter_queue_name = queue_name + "_dead"

    dead_queue = sqs.create_queue(dead_letter_queue_name, 43200)

    dead_arn = dead_queue.attributes['QueueArn']
    redrive_policy = {
        "maxReceiveCount": MAX_RECEIVE_COUNT,
        "deadLetterTargetArn": dead_arn
    }
    queue = sqs.create_queue(queue_name, VISIBILITY_TIMEOUT, redrive_policy)

    # Create Message
    expected_message_id = sqs.send_message(
        queue, 'boto3',
        {'Author': {
            'StringValue': 'Daniel',
            'DataType': 'String'
        }})

    # 1st message request succeeds
    message = sqs.get_next_message(queue)
    assert message['MessageId'] == expected_message_id

    # Visibilty Timeout not exceeded
    message = sqs.get_next_message(queue)
    assert message is None

    # Visibilty Timeout exceeded
    time.sleep(VISIBILITY_TIMEOUT)

    # 2nd message request succeeds
    message = sqs.get_next_message(queue)
    assert message['MessageId'] == expected_message_id

    # Visibilty Timeout exceeded
    time.sleep(VISIBILITY_TIMEOUT)

    # 3rd message request fails - MAX_RECEIVE_COUNT exceeded
    message = sqs.get_next_message(queue)
    assert message is None

    # 3rd message in Dead Letter Queue
    message = sqs.get_next_message(dead_queue)
    assert message['MessageId'] == expected_message_id

    # Cleanup
    time.sleep(VISIBILITY_TIMEOUT)
    sqs.delete_queue(dead_queue)
    sqs.delete_queue(queue)
Example #2
0
def test_create_queue():
    queue_name = id_generator.generate_job_item_id()
    dead_letter_queue_name = queue_name + "_dead"

    dead_queue = sqs.create_queue(dead_letter_queue_name, 43200)

    dead_arn = dead_queue.attributes['QueueArn']
    redrive_policy = {"maxReceiveCount": 5, "deadLetterTargetArn": dead_arn}
    new_queue = sqs.create_queue(queue_name, 30, redrive_policy)

    sqs.delete_queue(dead_queue)
    sqs.delete_queue(new_queue)
Example #3
0
def test_create_queue():
	queue_name = id_generator.generate_job_item_id()
	dead_letter_queue_name = queue_name + "_dead"

	dead_queue = sqs.create_queue(dead_letter_queue_name, 43200)
	
	dead_arn = dead_queue.attributes['QueueArn']
	redrive_policy = {"maxReceiveCount":5, "deadLetterTargetArn":dead_arn}
	new_queue = sqs.create_queue(queue_name, 30, redrive_policy)

	sqs.delete_queue(dead_queue)
	sqs.delete_queue(new_queue)
Example #4
0
def test_retry_logic():
	VISIBILITY_TIMEOUT = 2
	MAX_RECEIVE_COUNT = 2
	queue_name = id_generator.generate_job_item_id()
	dead_letter_queue_name = queue_name + "_dead"

	dead_queue = sqs.create_queue(dead_letter_queue_name, 43200)
	
	dead_arn = dead_queue.attributes['QueueArn']
	redrive_policy = {"maxReceiveCount":MAX_RECEIVE_COUNT, "deadLetterTargetArn":dead_arn}
	queue = sqs.create_queue(queue_name, VISIBILITY_TIMEOUT, redrive_policy)

	# Create Message
	expected_message_id = sqs.send_message(queue, 'boto3', {
    	'Author': {
        	'StringValue': 'Daniel',
        	'DataType': 'String'
    	}
	})

	# 1st message request succeeds
	message = sqs.get_next_message(queue)
	assert message['MessageId'] == expected_message_id

	# Visibilty Timeout not exceeded
	message = sqs.get_next_message(queue)
	assert message is None

	# Visibilty Timeout exceeded
	time.sleep(VISIBILITY_TIMEOUT)

	# 2nd message request succeeds
	message = sqs.get_next_message(queue)
	assert message['MessageId'] == expected_message_id

	# Visibilty Timeout exceeded
	time.sleep(VISIBILITY_TIMEOUT)

	# 3rd message request fails - MAX_RECEIVE_COUNT exceeded
	message = sqs.get_next_message(queue)
	assert message is None

	# 3rd message in Dead Letter Queue
	message = sqs.get_next_message(dead_queue)
	assert message['MessageId'] == expected_message_id

	# Cleanup
	time.sleep(VISIBILITY_TIMEOUT)
	sqs.delete_queue(dead_queue)
	sqs.delete_queue(queue)
Example #5
0
def test_get_queue():
    fake_queue = sqs.get_queue("fake-queue")
    assert fake_queue is None

    queue_name = id_generator.generate_job_item_id()
    queue = sqs.create_queue(queue_name)
    assert queue is not None
Example #6
0
def test_get_queue():
	fake_queue = sqs.get_queue("fake-queue")
	assert fake_queue is None

	queue_name = id_generator.generate_job_item_id()
	queue = sqs.create_queue(queue_name)
	assert queue is not None
Example #7
0
def get_test_queue(queue_name):
    queue = sqs.create_queue(queue_name)
    return queue
Example #8
0
def get_test_queue(queue_name):
	queue = sqs.create_queue(queue_name)
	return queue