com.amazonaws.services.sqs.model.GetQueueUrlResult Java Examples
The following examples show how to use
com.amazonaws.services.sqs.model.GetQueueUrlResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SQSSessionTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 6 votes |
/** * Test create queue when session is already closed */ @Test public void testCreateQueueWithOwnerAccountId() throws JMSException { GetQueueUrlResult result = new GetQueueUrlResult().withQueueUrl(QUEUE_URL); when(sqsClientJMSWrapper.getQueueUrl(QUEUE_NAME, OWNER_ACCOUNT_ID)) .thenReturn(result); /* * Create queue */ Queue queue = sqsSession.createQueue(QUEUE_NAME, OWNER_ACCOUNT_ID); /* * Verify results */ assert(queue instanceof SQSQueueDestination); assertEquals(QUEUE_NAME, queue.getQueueName()); assertEquals(QUEUE_URL, ((SQSQueueDestination) queue).getQueueUrl()); }
Example #2
Source File: SQSSessionTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 6 votes |
/** * Test create queue when session is already closed */ @Test public void testCreateQueue() throws JMSException { GetQueueUrlResult result = new GetQueueUrlResult().withQueueUrl(QUEUE_URL); when(sqsClientJMSWrapper.getQueueUrl(QUEUE_NAME)) .thenReturn(result); /* * Create queue */ Queue queue = sqsSession.createQueue(QUEUE_NAME); /* * Verify results */ assert(queue instanceof SQSQueueDestination); assertEquals(QUEUE_NAME, queue.getQueueName()); assertEquals(QUEUE_URL, ((SQSQueueDestination) queue).getQueueUrl()); }
Example #3
Source File: AmazonSQSStubTest.java From aws-java-sdk-stubs with Apache License 2.0 | 6 votes |
@Test public void sendAndReceiveMessage() { final String queueName = "bizo"; final String messageBody = "hi everybody"; final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName); sqs.createQueue(createQueueRequest); final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName); final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest); final String queueUrl = getQueueUrlResult.getQueueUrl(); final SendMessageRequest sendMessageRequest = new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(messageBody); sqs.sendMessage(sendMessageRequest); final int maxNumberOfMessages = 10; final ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages); final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest); final List<Message> messages = receiveMessageResult.getMessages(); assertThat(messages.size(), equalTo(1)); assertThat(messages.get(0).getBody(), equalTo(messageBody)); }
Example #4
Source File: AWSSQSClient.java From camel-kafka-connector with Apache License 2.0 | 6 votes |
public boolean deleteQueue(String queue) { GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(queue); if (getQueueUrlResult.getSdkHttpMetadata().getHttpStatusCode() == 404) { return true; } else { if (getQueueUrlResult.getSdkHttpMetadata().getHttpStatusCode() != 200) { LOG.warn("Unable to get queue {} for deletion", queue); return false; } } DeleteQueueResult result = sqs.deleteQueue(getQueueUrlResult.getQueueUrl()); if (result.getSdkHttpMetadata().getHttpStatusCode() != 200) { LOG.warn("Unable to delete queue {}", queue); return false; } return true; }
Example #5
Source File: MessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void testIsActive() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly()); container.setAmazonSqs(mock); container.setMessageHandler(mock(QueueMessageHandler.class)); container.afterPropertiesSet(); when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))) .thenReturn(new GetQueueUrlResult() .withQueueUrl("http://testQueue.amazonaws.com")); container.start(); assertThat(container.isRunning()).isTrue(); container.stop(); assertThat(container.isRunning()).isFalse(); // Container can still be active an restarted later (e.g. paused for a while) assertThat(container.isActive()).isTrue(); }
Example #6
Source File: DynamicQueueUrlDestinationResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void resolveDestination_withResourceIdResolver_nonUrlId_shouldGetUrlByResolvedName() throws Exception { String queueUrl = "http://queue.com"; String resolvedQueueName = "some-queue-name"; AmazonSQS amazonSqs = mock(AmazonSQS.class); when(amazonSqs.getQueueUrl(new GetQueueUrlRequest(resolvedQueueName))) .thenReturn(new GetQueueUrlResult().withQueueUrl(queueUrl)); ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class); when(resourceIdResolver.resolveToPhysicalResourceId(anyString())) .thenReturn(resolvedQueueName); DynamicQueueUrlDestinationResolver dynamicQueueUrlDestinationResolver = new DynamicQueueUrlDestinationResolver( amazonSqs, resourceIdResolver); String physicalResourceId = dynamicQueueUrlDestinationResolver .resolveDestination("testQueue"); assertThat(physicalResourceId).isEqualTo("http://queue.com"); }
Example #7
Source File: DefaultSqsQueueResourceFactoryTest.java From Cheddar with Apache License 2.0 | 6 votes |
@Test public void shouldCreateSqsQueueResource_withName() throws Exception { // Given final String name = randomString(); final String queueUrl = randomString(); final GetQueueUrlResult getQueueUrlResult = new GetQueueUrlResult().withQueueUrl(queueUrl); final GetQueueUrlRequest expectedGetQueueUrlRequest = new GetQueueUrlRequest(name); when(mockAmazonSqsClient.getQueueUrl(expectedGetQueueUrlRequest)).thenReturn(getQueueUrlResult); final SqsQueueResource mockSqsQueueResource = mock(SqsQueueResource.class); whenNew(SqsQueueResource.class).withArguments(name, queueUrl, mockAmazonSqsClient) .thenReturn(mockSqsQueueResource); // When final SqsQueueResource result = factory.createSqsQueueResource(name); // Then assertSame(mockSqsQueueResource, result); }
Example #8
Source File: QueueMessagingTemplateTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
private AmazonSQSAsync createAmazonSqs() { AmazonSQSAsync amazonSqs = mock(AmazonSQSAsync.class); GetQueueUrlResult queueUrl = new GetQueueUrlResult(); queueUrl.setQueueUrl("https://queue-url.com"); when(amazonSqs.getQueueUrl(any(GetQueueUrlRequest.class))).thenReturn(queueUrl); ReceiveMessageResult receiveMessageResult = new ReceiveMessageResult(); com.amazonaws.services.sqs.model.Message message = new com.amazonaws.services.sqs.model.Message(); message.setBody("My message"); receiveMessageResult.withMessages(message); when(amazonSqs.receiveMessage(any(ReceiveMessageRequest.class))) .thenReturn(receiveMessageResult); return amazonSqs; }
Example #9
Source File: DynamicQueueUrlDestinationResolverTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void testNoAutoCreate() throws Exception { AmazonSQS amazonSqs = mock(AmazonSQS.class); String queueUrl = "https://foo/bar"; when(amazonSqs.getQueueUrl(new GetQueueUrlRequest("foo"))) .thenReturn(new GetQueueUrlResult().withQueueUrl(queueUrl)); DynamicQueueUrlDestinationResolver dynamicQueueDestinationResolver = new DynamicQueueUrlDestinationResolver( amazonSqs); assertThat(dynamicQueueDestinationResolver.resolveDestination("foo")) .isEqualTo(queueUrl); }
Example #10
Source File: MessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void testStopCallsDoStopMethodWithRunnable() throws Exception { CountDownLatch countDownLatch = new CountDownLatch(1); AbstractMessageListenerContainer container = new AbstractMessageListenerContainer() { @Override protected void doStart() { // do nothing in this case } @Override protected void doStop() { countDownLatch.countDown(); } }; AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly()); container.setAmazonSqs(mock); container.setMessageHandler(mock(QueueMessageHandler.class)); container.afterPropertiesSet(); when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))) .thenReturn(new GetQueueUrlResult() .withQueueUrl("http://testQueue.amazonaws.com")); container.start(); container.stop(() -> { try { assertThat(countDownLatch.await(10, TimeUnit.MILLISECONDS)).isTrue(); } catch (InterruptedException e) { fail("Expected doStart() method to be called"); } }); }
Example #11
Source File: MessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void testStopCallsDoStopMethod() throws Exception { CountDownLatch countDownLatch = new CountDownLatch(1); AbstractMessageListenerContainer container = new AbstractMessageListenerContainer() { @Override protected void doStart() { // do nothing in this case } @Override protected void doStop() { countDownLatch.countDown(); } }; AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly()); container.setAmazonSqs(mock); container.setMessageHandler(mock(QueueMessageHandler.class)); container.afterPropertiesSet(); when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))) .thenReturn(new GetQueueUrlResult() .withQueueUrl("http://testQueue.amazonaws.com")); container.start(); container.stop(); try { assertThat(countDownLatch.await(10, TimeUnit.MILLISECONDS)).isTrue(); } catch (InterruptedException e) { fail("Expected doStart() method to be called"); } }
Example #12
Source File: MessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void testStartCallsDoStartMethod() throws Exception { CountDownLatch countDownLatch = new CountDownLatch(1); AbstractMessageListenerContainer container = new AbstractMessageListenerContainer() { @Override protected void doStart() { countDownLatch.countDown(); } @Override protected void doStop() { throw new UnsupportedOperationException("not supported yet"); } }; AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly()); container.setAmazonSqs(mock); container.setMessageHandler(mock(QueueMessageHandler.class)); container.afterPropertiesSet(); when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))) .thenReturn(new GetQueueUrlResult() .withQueueUrl("http://testQueue.amazonaws.com")); container.start(); try { assertThat(countDownLatch.await(10, TimeUnit.MILLISECONDS)).isTrue(); } catch (InterruptedException e) { fail("Expected doStart() method to be called"); } }
Example #13
Source File: MessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void receiveMessageRequests_withOneElement_created() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly()); QueueMessageHandler messageHandler = new QueueMessageHandler(); container.setAmazonSqs(mock); container.setMessageHandler(mock(QueueMessageHandler.class)); container.setMessageHandler(messageHandler); StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("messageListener", MessageListener.class); container.setMaxNumberOfMessages(11); container.setVisibilityTimeout(22); container.setWaitTimeOut(33); messageHandler.setApplicationContext(applicationContext); when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))) .thenReturn(new GetQueueUrlResult() .withQueueUrl("http://testQueue.amazonaws.com")); when(mock.getQueueAttributes(any(GetQueueAttributesRequest.class))) .thenReturn(new GetQueueAttributesResult()); messageHandler.afterPropertiesSet(); container.afterPropertiesSet(); container.start(); Map<String, QueueAttributes> registeredQueues = container.getRegisteredQueues(); assertThat(registeredQueues.get("testQueue").getReceiveMessageRequest() .getQueueUrl()).isEqualTo("http://testQueue.amazonaws.com"); assertThat(registeredQueues.get("testQueue").getReceiveMessageRequest() .getMaxNumberOfMessages().longValue()).isEqualTo(11L); assertThat(registeredQueues.get("testQueue").getReceiveMessageRequest() .getVisibilityTimeout().longValue()).isEqualTo(22L); assertThat(registeredQueues.get("testQueue").getReceiveMessageRequest() .getWaitTimeSeconds().longValue()).isEqualTo(33L); }
Example #14
Source File: SimpleMessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void testWithDefaultTaskExecutorAndOneHandler() throws Exception { int testedMaxNumberOfMessages = 10; Map<QueueMessageHandler.MappingInformation, HandlerMethod> messageHandlerMethods = Collections .singletonMap(new QueueMessageHandler.MappingInformation( Collections.singleton("testQueue"), SqsMessageDeletionPolicy.ALWAYS), null); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); QueueMessageHandler mockedHandler = mock(QueueMessageHandler.class); AmazonSQSAsync mockedSqs = mock(AmazonSQSAsync.class, withSettings().stubOnly()); when(mockedSqs.getQueueAttributes(any(GetQueueAttributesRequest.class))) .thenReturn(new GetQueueAttributesResult()); when(mockedSqs.getQueueUrl(any(GetQueueUrlRequest.class))) .thenReturn(new GetQueueUrlResult().withQueueUrl("testQueueUrl")); when(mockedHandler.getHandlerMethods()).thenReturn(messageHandlerMethods); container.setMaxNumberOfMessages(testedMaxNumberOfMessages); container.setAmazonSqs(mockedSqs); container.setMessageHandler(mockedHandler); container.afterPropertiesSet(); int expectedPoolMaxSize = messageHandlerMethods.size() * (testedMaxNumberOfMessages + 1); ThreadPoolTaskExecutor taskExecutor = (ThreadPoolTaskExecutor) container .getTaskExecutor(); assertThat(taskExecutor).isNotNull(); assertThat(taskExecutor.getMaxPoolSize()).isEqualTo(expectedPoolMaxSize); }
Example #15
Source File: DynamicQueueUrlDestinationResolver.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Override public String resolveDestination(String name) throws DestinationResolutionException { String queueName = name; if (this.resourceIdResolver != null) { queueName = this.resourceIdResolver.resolveToPhysicalResourceId(name); } if (isValidQueueUrl(queueName)) { return queueName; } if (this.autoCreate) { // Auto-create is fine to be called even if the queue exists. CreateQueueResult createQueueResult = this.amazonSqs .createQueue(new CreateQueueRequest(queueName)); return createQueueResult.getQueueUrl(); } else { try { GetQueueUrlResult getQueueUrlResult = this.amazonSqs .getQueueUrl(new GetQueueUrlRequest(queueName)); return getQueueUrlResult.getQueueUrl(); } catch (QueueDoesNotExistException e) { throw toDestinationResolutionException(e); } } }
Example #16
Source File: SQSImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public Queue getQueueByName(GetQueueUrlRequest request, ResultCapture<GetQueueUrlResult> extractor) { ActionResult result = service.performAction("GetQueueByName", request, extractor); if (result == null) return null; return new QueueImpl(result.getResource()); }
Example #17
Source File: AmazonSQSStubTest.java From aws-java-sdk-stubs with Apache License 2.0 | 5 votes |
@Test(expected = ReceiptHandleIsInvalidException.class) public void deleteMessageFailsWithInvalidReceiptHandle() { final String queueName = "bizo"; final String messageBody = "hi everybody"; final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName); sqs.createQueue(createQueueRequest); final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName); final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest); final String queueUrl = getQueueUrlResult.getQueueUrl(); final SendMessageRequest sendMessageRequest = new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(messageBody); sqs.sendMessage(sendMessageRequest); final ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest().withQueueUrl(queueUrl); final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest); final List<Message> messages = receiveMessageResult.getMessages(); assertThat(messages.size(), equalTo(1)); final String receiptHandle = "bizo"; final DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest().withQueueUrl(queueUrl).withReceiptHandle(receiptHandle); sqs.deleteMessage(deleteMessageRequest); }
Example #18
Source File: AmazonSQSStubTest.java From aws-java-sdk-stubs with Apache License 2.0 | 5 votes |
@Test public void deleteMessageSucceedsWithValidReceiptHandle() { final String queueName = "bizo"; final String messageBody = "hi everybody"; final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName); sqs.createQueue(createQueueRequest); final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName); final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest); final String queueUrl = getQueueUrlResult.getQueueUrl(); final SendMessageRequest sendMessageRequest = new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(messageBody); sqs.sendMessage(sendMessageRequest); final int maxNumberOfMessages = 10; final ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages); final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest); final List<Message> messages = receiveMessageResult.getMessages(); assertThat(messages.size(), equalTo(1)); final String receiptHandle = messages.get(0).getReceiptHandle(); final DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest().withQueueUrl(queueUrl).withReceiptHandle(receiptHandle); try { sqs.deleteMessage(deleteMessageRequest); } catch (ReceiptHandleIsInvalidException e) { fail("ReceiptHandleIsInvalidException was thrown"); } }
Example #19
Source File: SQSImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
@Override public Queue getQueueByName(String queueName, ResultCapture<GetQueueUrlResult> extractor) { GetQueueUrlRequest request = new GetQueueUrlRequest() .withQueueName(queueName); return getQueueByName(request, extractor); }
Example #20
Source File: AmazonSQSStubTest.java From aws-java-sdk-stubs with Apache License 2.0 | 5 votes |
@Test public void getQueueUrl() { final String queueName = "bizo"; final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName); sqs.createQueue(createQueueRequest); final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName); final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest); final String queueUrl = getQueueUrlResult.getQueueUrl(); assertThat(queueUrl, containsString(queueName)); }
Example #21
Source File: SQSImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public Queue getQueueByName(String queueName) { return getQueueByName(queueName, (ResultCapture<GetQueueUrlResult>)null); }
Example #22
Source File: SQSSessionTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 4 votes |
/** * Test recover */ @Test public void testRecover() throws JMSException, InterruptedException { sqsSession = new SQSSession(parentSQSConnection, AcknowledgeMode.ACK_UNORDERED); when(parentSQSConnection.getNumberOfMessagesToPrefetch()).thenReturn(4); when(sqsClientJMSWrapper.getQueueUrl("queue1")) .thenReturn(new GetQueueUrlResult().withQueueUrl("queueUrl1")); when(sqsClientJMSWrapper.receiveMessage(argThat(new ReceiveRequestMatcher("queueUrl1")))) .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group1", "message1", "queue1-group1-message1"))) .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group2", "message2", "queue1-group2-message2"))) .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group3", "message3", "queue1-group3-message3"))) .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group1", "message4", "queue1-group1-message4"))) .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group2", "message5", "queue1-group2-message5"))) .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group3", "message6", "queue1-group3-message6"))) .thenReturn(new ReceiveMessageResult()); when(sqsClientJMSWrapper.getQueueUrl("queue2")) .thenReturn(new GetQueueUrlResult().withQueueUrl("queueUrl2")); when(sqsClientJMSWrapper.receiveMessage(argThat(new ReceiveRequestMatcher("queueUrl2")))) .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group1", "message1", "queue2-group1-message1"))) .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group2", "message2", "queue2-group2-message2"))) .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group3", "message3", "queue2-group3-message3"))) .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group1", "message4", "queue2-group1-message4"))) .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group2", "message5", "queue2-group2-message5"))) .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group3", "message6", "queue2-group3-message6"))) .thenReturn(new ReceiveMessageResult()); MessageConsumer consumer1 = sqsSession.createConsumer(sqsSession.createQueue("queue1")); MessageConsumer consumer2 = sqsSession.createConsumer(sqsSession.createQueue("queue2")); final CountDownLatch listenerRelease = new CountDownLatch(1); consumer2.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { try { listenerRelease.await(); } catch (InterruptedException e) { } } }); sqsSession.start(); Message message1 = consumer1.receive(); //let's give a moment for the background threads to: //prefetch another message for queue1 //dispatch message to listener for queue2 //prefetch another message for queue2 Thread.sleep(100); /* * Recover */ sqsSession.recover(); //at this point we have two unacked messages: //queue1-group1-message1 //queue2-group1-message1 //and we should have 4 more messages prefetched for queue1: //queue1-group2-message2 //queue1-group3-message3 //queue1-group1-message4 //queue1-group2-message5 //and we should have 4 more callbacks scheduled for queue2: //queue2-group2-message2 //queue2-group3-message3 //queue2-group1-message4 //queue2-group2-message5 //after calling recovery, we should nack the two unacked messages and all other messages for the same queue / group, so these: //queue1-group1-message1 //queue2-group1-message1 //queue1-group1-message4 //queue2-group1-message4 ArgumentCaptor<ChangeMessageVisibilityBatchRequest> changeVisibilityCaptor = ArgumentCaptor.forClass(ChangeMessageVisibilityBatchRequest.class); verify(sqsClientJMSWrapper, times(2)).changeMessageVisibilityBatch(changeVisibilityCaptor.capture()); List<ChangeMessageVisibilityBatchRequest> changeVisibilityRequests = changeVisibilityCaptor.getAllValues(); Set<String> handles = new HashSet<String>(); for (ChangeMessageVisibilityBatchRequest request : changeVisibilityRequests) { for (ChangeMessageVisibilityBatchRequestEntry entry : request.getEntries()) { handles.add(entry.getReceiptHandle()); } } assertEquals(4, handles.size()); assertTrue(handles.contains("queue1-group1-message1")); assertTrue(handles.contains("queue1-group1-message4")); assertTrue(handles.contains("queue2-group1-message1")); assertTrue(handles.contains("queue2-group1-message4")); listenerRelease.countDown(); sqsSession.close(); }
Example #23
Source File: MessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 4 votes |
@Test void receiveMessageRequests_withMultipleElements_created() throws Exception { AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly()); container.setAmazonSqs(mock); StaticApplicationContext applicationContext = new StaticApplicationContext(); QueueMessageHandler messageHandler = new QueueMessageHandler(); messageHandler.setApplicationContext(applicationContext); container.setMessageHandler(messageHandler); applicationContext.registerSingleton("messageListener", MessageListener.class); applicationContext.registerSingleton("anotherMessageListener", AnotherMessageListener.class); container.setMaxNumberOfMessages(11); container.setVisibilityTimeout(22); container.setWaitTimeOut(33); when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))) .thenReturn(new GetQueueUrlResult() .withQueueUrl("http://testQueue.amazonaws.com")); when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("anotherTestQueue"))) .thenReturn(new GetQueueUrlResult() .withQueueUrl("https://anotherTestQueue.amazonaws.com")); when(mock.getQueueAttributes(any(GetQueueAttributesRequest.class))) .thenReturn(new GetQueueAttributesResult()); messageHandler.afterPropertiesSet(); container.afterPropertiesSet(); container.start(); Map<String, QueueAttributes> registeredQueues = container.getRegisteredQueues(); assertThat(registeredQueues.get("testQueue").getReceiveMessageRequest() .getQueueUrl()).isEqualTo("http://testQueue.amazonaws.com"); assertThat(registeredQueues.get("testQueue").getReceiveMessageRequest() .getMaxNumberOfMessages().longValue()).isEqualTo(11L); assertThat(registeredQueues.get("testQueue").getReceiveMessageRequest() .getVisibilityTimeout().longValue()).isEqualTo(22L); assertThat(registeredQueues.get("testQueue").getReceiveMessageRequest() .getWaitTimeSeconds().longValue()).isEqualTo(33L); assertThat(registeredQueues.get("anotherTestQueue").getReceiveMessageRequest() .getQueueUrl()).isEqualTo("https://anotherTestQueue.amazonaws.com"); assertThat(registeredQueues.get("anotherTestQueue").getReceiveMessageRequest() .getMaxNumberOfMessages().longValue()).isEqualTo(11L); assertThat(registeredQueues.get("anotherTestQueue").getReceiveMessageRequest() .getVisibilityTimeout().longValue()).isEqualTo(22L); assertThat(registeredQueues.get("anotherTestQueue").getReceiveMessageRequest() .getWaitTimeSeconds().longValue()).isEqualTo(33L); }
Example #24
Source File: MessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 4 votes |
@Test void receiveMessageRequests_withDestinationResolverThrowingException_shouldLogWarningAndNotCreateRequest() throws Exception { // Arrange AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); Logger loggerMock = container.getLogger(); AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly()); container.setAmazonSqs(mock); StaticApplicationContext applicationContext = new StaticApplicationContext(); QueueMessageHandler messageHandler = new QueueMessageHandler(); messageHandler.setApplicationContext(applicationContext); container.setMessageHandler(messageHandler); applicationContext.registerSingleton("messageListener", MessageListener.class); applicationContext.registerSingleton("anotherMessageListener", AnotherMessageListener.class); String destinationResolutionExceptionMessage = "Queue not found"; when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))) .thenThrow(new DestinationResolutionException( destinationResolutionExceptionMessage)); when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("anotherTestQueue"))) .thenReturn(new GetQueueUrlResult() .withQueueUrl("https://anotherTestQueue.amazonaws.com")); when(mock.getQueueAttributes(any(GetQueueAttributesRequest.class))) .thenReturn(new GetQueueAttributesResult()); messageHandler.afterPropertiesSet(); container.afterPropertiesSet(); // Act container.start(); // Assert ArgumentCaptor<String> logMsgArgCaptor = ArgumentCaptor.forClass(String.class); verify(loggerMock).warn(logMsgArgCaptor.capture()); Map<String, QueueAttributes> registeredQueues = container.getRegisteredQueues(); assertThat(registeredQueues.containsKey("testQueue")).isFalse(); assertThat(logMsgArgCaptor.getValue()) .isEqualTo("Ignoring queue with name 'testQueue': " + destinationResolutionExceptionMessage); assertThat(registeredQueues.get("anotherTestQueue").getReceiveMessageRequest() .getQueueUrl()).isEqualTo("https://anotherTestQueue.amazonaws.com"); }
Example #25
Source File: SimpleMessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 4 votes |
@Override public GetQueueUrlResult getQueueUrl(GetQueueUrlRequest getQueueUrlRequest) throws AmazonClientException { return new GetQueueUrlResult().withQueueUrl( "http://" + getQueueUrlRequest.getQueueName() + ".amazonaws.com"); }
Example #26
Source File: SimpleMessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 4 votes |
private static void mockGetQueueUrl(AmazonSQSAsync sqs, String queueName, String queueUrl) { when(sqs.getQueueUrl(new GetQueueUrlRequest(queueName))) .thenReturn(new GetQueueUrlResult().withQueueUrl(queueUrl)); }
Example #27
Source File: AmazonSQSStubTest.java From aws-java-sdk-stubs with Apache License 2.0 | 4 votes |
@Test public void returnMessage() { final String queueName = "bizo"; final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName); sqs.createQueue(createQueueRequest); final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName); final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest); final String queueUrl = getQueueUrlResult.getQueueUrl(); final SendMessageRequest sendMessageRequest1 = new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody("hi everybody 1"); sqs.sendMessage(sendMessageRequest1); final SendMessageRequest sendMessageRequest2 = new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody("hi everybody 2"); sqs.sendMessage(sendMessageRequest2); final SendMessageRequest sendMessageRequest3 = new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody("hi everybody 3"); sqs.sendMessage(sendMessageRequest3); final int maxNumberOfMessages = 10; final ReceiveMessageRequest receiveMessageRequest1 = new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages); final ReceiveMessageResult receiveMessageResult1 = sqs.receiveMessage(receiveMessageRequest1); final List<Message> messages1 = receiveMessageResult1.getMessages(); final SendMessageRequest sendMessageRequest4 = new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody("hi everybody 4"); sqs.sendMessage(sendMessageRequest4); // "hi everybody 2" should be at the top of the queue after being returned. sqs.returnMessage(queueUrl, messages1.get(1)); final ReceiveMessageRequest receiveMessageRequest2 = new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages); final ReceiveMessageResult receiveMessageResult2 = sqs.receiveMessage(receiveMessageRequest2); final List<Message> messages2 = receiveMessageResult2.getMessages(); final List<String> expectedMessageBodies = Arrays.asList(sendMessageRequest2.getMessageBody(), sendMessageRequest4.getMessageBody()); final List<String> actualMessageBodies = new ArrayList<String>(); for (Message m : messages2) { actualMessageBodies.add(m.getBody()); } assertThat(actualMessageBodies, equalTo(expectedMessageBodies)); }
Example #28
Source File: AmazonSQSStubTest.java From aws-java-sdk-stubs with Apache License 2.0 | 4 votes |
@Test public void receiveMessageOnlyReturnsRequestedAttributes() { final String queueName = "bizo"; final String messageBody = "hi everybody"; final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName); sqs.createQueue(createQueueRequest); final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName); final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest); final String queueUrl = getQueueUrlResult.getQueueUrl(); final Map<String, MessageAttributeValue> messageAttributes = new HashMap<String, MessageAttributeValue>(); messageAttributes.put("key A", new MessageAttributeValue().withDataType("String").withStringValue("value A")); messageAttributes.put("key B", new MessageAttributeValue().withDataType("String").withStringValue("value B")); messageAttributes.put("key C", new MessageAttributeValue().withDataType("String").withStringValue("value C")); messageAttributes.put("key D", new MessageAttributeValue().withDataType("String").withStringValue("value D")); messageAttributes.put("key E", new MessageAttributeValue().withDataType("String").withStringValue("value E")); final SendMessageRequest sendMessageRequest = new SendMessageRequest() .withQueueUrl(queueUrl) .withMessageBody(messageBody) .withMessageAttributes(messageAttributes); sqs.sendMessage(sendMessageRequest); final int maxNumberOfMessages = 10; final ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest() .withQueueUrl(queueUrl) .withMaxNumberOfMessages(maxNumberOfMessages) .withMessageAttributeNames("key B", "key E"); final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest); final List<Message> messages = receiveMessageResult.getMessages(); assertThat(messages.size(), equalTo(1)); Message m = messages.get(0); assertThat(m.getBody(), equalTo(messageBody)); final Map<String, MessageAttributeValue> expectedMessageAttributes = new HashMap<String, MessageAttributeValue>(messageAttributes); expectedMessageAttributes.keySet().retainAll(Arrays.asList("key B", "key E")); assertThat(m.getMessageAttributes(), equalTo(expectedMessageAttributes)); }
Example #29
Source File: AmazonSQSStubTest.java From aws-java-sdk-stubs with Apache License 2.0 | 4 votes |
@Test public void receiveMessageReturnsMaxNumberOfMessages() { final String queueName = "bizo"; final String baseMessageBody = "hi everybody"; final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName); sqs.createQueue(createQueueRequest); final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName); final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest); final String queueUrl = getQueueUrlResult.getQueueUrl(); final List<String> sentMessageBodies = new ArrayList<String>(); final int numMessages = 7; for (int i = 0; i < numMessages; i++) { sentMessageBodies.add(baseMessageBody + " " + i); } for (String messageBody : sentMessageBodies) { final SendMessageRequest sendMessageRequest = new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(messageBody); sqs.sendMessage(sendMessageRequest); } final int maxNumberOfMessages = 5; final List<String> expectedMessageBodies = sentMessageBodies.subList(0, maxNumberOfMessages); final ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages); final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest); final List<Message> messages = receiveMessageResult.getMessages(); assertThat(messages.size(), equalTo(maxNumberOfMessages)); final List<String> actualMessageBodies = new ArrayList<String>(); for (Message m : messages) { actualMessageBodies.add(m.getBody()); } assertThat(actualMessageBodies, equalTo(expectedMessageBodies)); }
Example #30
Source File: AbstractAmazonSQSClientWrapper.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 4 votes |
@Override public GetQueueUrlResult getQueueUrl(GetQueueUrlRequest request) { request.getRequestClientOptions().appendUserAgent(userAgent); return amazonSqsToBeExtended.getQueueUrl(request); }