Created
November 3, 2011 23:30
-
-
Save mattfitzgerald/1338260 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def SqsTest.send_batch_of_long_messages | |
IntegrationTest.print_test_name "SqsTest.send_batch_of_long_messages" | |
SqsTest.before_each | |
sqs_client = Client.find_by_name "sqs_client" | |
sqs = RightAws::SqsGen2.new(sqs_client.access_key_id, sqs_client.secret_access_key) | |
sqs_queue = RightAws::Sqs::Queue.create(sqs, sqs_client.sqs_input_queue) | |
#### send a batch of messages to sqs queue #### | |
message = {} | |
long_message_body = "EUROPE'S leaders, making plain that they've reached the end of their patience with Greece, demanded yesterday that the beleaguered nation declare whether it wants to remain in the euro currency union - or risk going it alone in a dramatic secession." | |
message["id"] = ["1","2","3"] | |
message["source_addr"] = "spec" | |
message["destination_addr"] = ["61414111111","61414222222","61414333333"] | |
message["short_message"] = long_message_body | |
message["high_quality"] = false | |
puts "sending message to sqs" | |
sqs_queue.send_message(message.to_json) | |
#### wait for message to appear as sent in database ### | |
print "waiting for message to appear as sent in database" | |
result = IntegrationTest.wait_for_condition 30 do | |
SmsMessage.find(:all, :conditions => "submit_sm_sent_at IS NOT NULL").count == 6 | |
end | |
if !result | |
puts "ERROR: message parts never appeared as sent in database" | |
IntegrationTest.stop_processes | |
exit | |
end | |
# all message parts in db | |
sent_message_count = SmsMessage.find(:all, :conditions => "submit_sm_sent_at IS NOT NULL").count | |
IntegrationTest.compare "Six message parts in database", 6, sent_message_count | |
# message parts have the correct ids | |
sent_message_count = SmsMessage.find(:all, :conditions => "remote_id = 1").count | |
IntegrationTest.compare "Two for messages 1", 2, sent_message_count | |
sent_message_count = SmsMessage.find(:all, :conditions => "remote_id = 2").count | |
IntegrationTest.compare "Two for messages 2", 2, sent_message_count | |
sent_message_count = SmsMessage.find(:all, :conditions => "remote_id = 3").count | |
IntegrationTest.compare "Two for messages 3", 2, sent_message_count | |
# some message content is present in each part | |
sent_message_count = SmsMessage.find(:all, :conditions => "short_message is not null and length(short_message) > 0").count | |
IntegrationTest.compare "Message bodies are not empty", 6, sent_message_count | |
# here I'm assuming all the message parts are in order (may get false failures if this is not the case) | |
message_parts = SmsMessage.all | |
body = [] | |
body[0] = long_message_body[0..152] | |
body[1] = long_message_body[153..-1] | |
# message parts are what they should be in the database | |
# message 1 part 1 | |
part = "1 of 1" | |
part_id = 0 | |
IntegrationTest.compare "#{part} remote_id", message_parts[part_id][:remote_id], "1" | |
IntegrationTest.compare "#{part} source_addr", message_parts[part_id][:source_addr], "spec" | |
IntegrationTest.compare "#{part} destination_addr", message_parts[part_id][:destination_addr], "61414111111" | |
IntegrationTest.compare "#{part} short_message", message_parts[part_id][:short_message], body[0] | |
IntegrationTest.is_not_nil "#{part} routed_at", message_parts[part_id][:routed_at] | |
IntegrationTest.is_not_nil "#{part} submit_sm_sent_at", message_parts[part_id][:submit_sm_sent_at] | |
IntegrationTest.compare "#{part} client_id", message_parts[part_id][:client_id], 1 | |
IntegrationTest.compare "#{part} forced_route", message_parts[part_id][:forced_route], false | |
IntegrationTest.compare "#{part} part_of_a_long_message", message_parts[part_id][:part_of_a_long_message], true | |
IntegrationTest.compare "#{part} udh", message_parts[part_id][:udh], "05:00:03:01:02:01:" | |
IntegrationTest.compare "#{part} sms_interface_id", message_parts[part_id][:sms_interface_id], 1 | |
IntegrationTest.compare "#{part} high_quality", message_parts[part_id][:high_quality], false | |
# message 1 part 2 | |
part = "2 of 1" | |
part_id = 1 | |
IntegrationTest.compare "#{part} remote_id", message_parts[part_id][:remote_id], "1" | |
IntegrationTest.compare "#{part} source_addr", message_parts[part_id][:source_addr], "spec" | |
IntegrationTest.compare "#{part} destination_addr", message_parts[part_id][:destination_addr], "61414111111" | |
IntegrationTest.compare "#{part} short_message", message_parts[part_id][:short_message], body[1] | |
IntegrationTest.is_not_nil "#{part} routed_at", message_parts[part_id][:routed_at] | |
IntegrationTest.is_not_nil "#{part} submit_sm_sent_at", message_parts[part_id][:submit_sm_sent_at] | |
IntegrationTest.compare "#{part} client_id", message_parts[part_id][:client_id], 1 | |
IntegrationTest.compare "#{part} forced_route", message_parts[part_id][:forced_route], false | |
IntegrationTest.compare "#{part} part_of_a_long_message", message_parts[part_id][:part_of_a_long_message], true | |
IntegrationTest.compare "#{part} udh", message_parts[part_id][:udh], "05:00:03:01:02:02:" | |
IntegrationTest.compare "#{part} sms_interface_id", message_parts[part_id][:sms_interface_id], 1 | |
IntegrationTest.compare "#{part} high_quality", message_parts[part_id][:high_quality], false | |
part = "1 of 2" | |
part_id = 2 | |
IntegrationTest.compare "#{part} remote_id", message_parts[part_id][:remote_id], "2" | |
IntegrationTest.compare "#{part} source_addr", message_parts[part_id][:source_addr], "spec" | |
IntegrationTest.compare "#{part} destination_addr", message_parts[part_id][:destination_addr], "61414222222" | |
IntegrationTest.compare "#{part} short_message", message_parts[part_id][:short_message], body[0] | |
IntegrationTest.is_not_nil "#{part} routed_at", message_parts[part_id][:routed_at] | |
IntegrationTest.is_not_nil "#{part} submit_sm_sent_at", message_parts[part_id][:submit_sm_sent_at] | |
IntegrationTest.compare "#{part} client_id", message_parts[part_id][:client_id], 1 | |
IntegrationTest.compare "#{part} forced_route", message_parts[part_id][:forced_route], false | |
IntegrationTest.compare "#{part} part_of_a_long_message", message_parts[part_id][:part_of_a_long_message], true | |
IntegrationTest.compare "#{part} udh", message_parts[part_id][:udh], "05:00:03:02:02:01:" | |
IntegrationTest.compare "#{part} sms_interface_id", message_parts[part_id][:sms_interface_id], 1 | |
IntegrationTest.compare "#{part} high_quality", message_parts[part_id][:high_quality], false | |
# message 1 part 2 | |
part = "2 of 2" | |
part_id = 3 | |
IntegrationTest.compare "#{part} remote_id", message_parts[part_id][:remote_id], "2" | |
IntegrationTest.compare "#{part} source_addr", message_parts[part_id][:source_addr], "spec" | |
IntegrationTest.compare "#{part} destination_addr", message_parts[part_id][:destination_addr], "61414222222" | |
IntegrationTest.compare "#{part} short_message", message_parts[part_id][:short_message], body[1] | |
IntegrationTest.is_not_nil "#{part} routed_at", message_parts[part_id][:routed_at] | |
IntegrationTest.is_not_nil "#{part} submit_sm_sent_at", message_parts[part_id][:submit_sm_sent_at] | |
IntegrationTest.compare "#{part} client_id", message_parts[part_id][:client_id], 1 | |
IntegrationTest.compare "#{part} forced_route", message_parts[part_id][:forced_route], false | |
IntegrationTest.compare "#{part} part_of_a_long_message", message_parts[part_id][:part_of_a_long_message], true | |
IntegrationTest.compare "#{part} udh", message_parts[part_id][:udh], "05:00:03:02:02:02:" | |
IntegrationTest.compare "#{part} sms_interface_id", message_parts[part_id][:sms_interface_id], 1 | |
IntegrationTest.compare "#{part} high_quality", message_parts[part_id][:high_quality], false | |
part = "1 of 3" | |
part_id = 4 | |
IntegrationTest.compare "#{part} remote_id", message_parts[part_id][:remote_id], "3" | |
IntegrationTest.compare "#{part} source_addr", message_parts[part_id][:source_addr], "spec" | |
IntegrationTest.compare "#{part} destination_addr", message_parts[part_id][:destination_addr], "61414333333" | |
IntegrationTest.compare "#{part} short_message", message_parts[part_id][:short_message], body[0] | |
IntegrationTest.is_not_nil "#{part} routed_at", message_parts[part_id][:routed_at] | |
IntegrationTest.is_not_nil "#{part} submit_sm_sent_at", message_parts[part_id][:submit_sm_sent_at] | |
IntegrationTest.compare "#{part} client_id", message_parts[part_id][:client_id], 1 | |
IntegrationTest.compare "#{part} forced_route", message_parts[part_id][:forced_route], false | |
IntegrationTest.compare "#{part} part_of_a_long_message", message_parts[part_id][:part_of_a_long_message], true | |
IntegrationTest.compare "#{part} udh", message_parts[part_id][:udh], "05:00:03:03:02:01:" | |
IntegrationTest.compare "#{part} sms_interface_id", message_parts[part_id][:sms_interface_id], 1 | |
IntegrationTest.compare "#{part} high_quality", message_parts[part_id][:high_quality], false | |
# message 1 part 2 | |
part = "2 of 3" | |
part_id = 5 | |
IntegrationTest.compare "#{part} remote_id", message_parts[part_id][:remote_id], "3" | |
IntegrationTest.compare "#{part} source_addr", message_parts[part_id][:source_addr], "spec" | |
IntegrationTest.compare "#{part} destination_addr", message_parts[part_id][:destination_addr], "61414333333" | |
IntegrationTest.compare "#{part} short_message", message_parts[part_id][:short_message], body[1] | |
IntegrationTest.is_not_nil "#{part} routed_at", message_parts[part_id][:routed_at] | |
IntegrationTest.is_not_nil "#{part} submit_sm_sent_at", message_parts[part_id][:submit_sm_sent_at] | |
IntegrationTest.compare "#{part} client_id", message_parts[part_id][:client_id], 1 | |
IntegrationTest.compare "#{part} forced_route", message_parts[part_id][:forced_route], false | |
IntegrationTest.compare "#{part} part_of_a_long_message", message_parts[part_id][:part_of_a_long_message], true | |
IntegrationTest.compare "#{part} udh", message_parts[part_id][:udh], "05:00:03:03:02:02:" | |
IntegrationTest.compare "#{part} sms_interface_id", message_parts[part_id][:sms_interface_id], 1 | |
IntegrationTest.compare "#{part} high_quality", message_parts[part_id][:high_quality], false | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment