use of com.amazonaws.services.sqs.model.ReceiveMessageRequest in project nifi by apache.
the class TestGetSQS method testGetNoMessages.
@Test
public void testGetNoMessages() {
runner.setProperty(GetSQS.QUEUE_URL, "https://sqs.us-west-2.amazonaws.com/123456789012/test-queue-000000000");
ReceiveMessageResult receiveMessageResult = new ReceiveMessageResult();
Mockito.when(mockSQSClient.receiveMessage(Mockito.any(ReceiveMessageRequest.class))).thenReturn(receiveMessageResult);
runner.run(1);
ArgumentCaptor<ReceiveMessageRequest> captureRequest = ArgumentCaptor.forClass(ReceiveMessageRequest.class);
Mockito.verify(mockSQSClient, Mockito.times(1)).receiveMessage(captureRequest.capture());
ReceiveMessageRequest request = captureRequest.getValue();
assertEquals("https://sqs.us-west-2.amazonaws.com/123456789012/test-queue-000000000", request.getQueueUrl());
runner.assertAllFlowFilesTransferred(GetSQS.REL_SUCCESS, 0);
}
use of com.amazonaws.services.sqs.model.ReceiveMessageRequest in project glacier-cli by carlossg.
the class Glacier method waitForJobToComplete.
private Boolean waitForJobToComplete(String jobId, String sqsQueueUrl) throws InterruptedException, JsonParseException, IOException {
Boolean messageFound = false;
Boolean jobSuccessful = false;
ObjectMapper mapper = new ObjectMapper();
JsonFactory factory = mapper.getJsonFactory();
Date start = new Date();
while (!messageFound) {
long minutes = (new Date().getTime() - start.getTime()) / 1000 / 60;
System.out.println("Checking for messages: " + minutes + " elapsed");
List<Message> msgs = sqsClient.receiveMessage(new ReceiveMessageRequest(sqsQueueUrl).withMaxNumberOfMessages(10)).getMessages();
if (msgs.size() > 0) {
for (Message m : msgs) {
JsonParser jpMessage = factory.createJsonParser(m.getBody());
JsonNode jobMessageNode = mapper.readTree(jpMessage);
String jobMessage = jobMessageNode.get("Message").getTextValue();
JsonParser jpDesc = factory.createJsonParser(jobMessage);
JsonNode jobDescNode = mapper.readTree(jpDesc);
String retrievedJobId = jobDescNode.get("JobId").getTextValue();
String statusCode = jobDescNode.get("StatusCode").getTextValue();
if (retrievedJobId.equals(jobId)) {
messageFound = true;
if (statusCode.equals("Succeeded")) {
jobSuccessful = true;
}
}
}
} else {
Thread.sleep(sleepTime * 1000);
}
}
return (messageFound && jobSuccessful);
}
use of com.amazonaws.services.sqs.model.ReceiveMessageRequest in project java by wavefrontHQ.
the class SQSSubmissionQueueTest method testTaskRead.
@Test
public void testTaskRead() throws IOException {
SQSSubmissionQueue queue = getTaskQueue();
UUID proxyId = UUID.randomUUID();
DataSubmissionTask<? extends DataSubmissionTask<?>> task;
if (this.expectedTask instanceof LineDelimitedDataSubmissionTask) {
task = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item1", "item2", "item3"), time::get);
} else if (this.expectedTask instanceof EventDataSubmissionTask) {
task = new EventDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "2878", ImmutableList.of(new Event(ReportEvent.newBuilder().setStartTime(time.get() * 1000).setEndTime(time.get() * 1000 + 1).setName("Event name for testing").setHosts(ImmutableList.of("host1", "host2")).setDimensions(ImmutableMap.of("multi", ImmutableList.of("bar", "baz"))).setAnnotations(ImmutableMap.of("severity", "INFO")).setTags(ImmutableList.of("tag1")).build())), time::get);
} else {
task = null;
}
expect(client.sendMessage(new SendMessageRequest(queueUrl, queue.encodeMessageForDelivery(this.expectedTask)))).andReturn(null);
replay(client);
task.enqueue(QueueingReason.RETRY);
reset(client);
ReceiveMessageRequest msgRequest = new ReceiveMessageRequest().withMaxNumberOfMessages(1).withWaitTimeSeconds(1).withQueueUrl(queueUrl);
ReceiveMessageResult msgResult = new ReceiveMessageResult().withMessages(new Message().withBody(queue.encodeMessageForDelivery(task)).withReceiptHandle("handle1"));
expect(client.receiveMessage(msgRequest)).andReturn(msgResult);
replay(client);
if (this.expectedTask instanceof LineDelimitedDataSubmissionTask) {
LineDelimitedDataSubmissionTask readTask = (LineDelimitedDataSubmissionTask) queue.peek();
assertEquals(((LineDelimitedDataSubmissionTask) task).payload(), readTask.payload());
assertEquals(((LineDelimitedDataSubmissionTask) this.expectedTask).payload(), readTask.payload());
assertEquals(77777, readTask.getEnqueuedMillis());
}
if (this.expectedTask instanceof EventDataSubmissionTask) {
EventDataSubmissionTask readTask = (EventDataSubmissionTask) queue.peek();
assertEquals(((EventDataSubmissionTask) task).payload(), readTask.payload());
assertEquals(((EventDataSubmissionTask) this.expectedTask).payload(), readTask.payload());
assertEquals(77777, readTask.getEnqueuedMillis());
}
}
Aggregations