[
https://issues.apache.org/jira/browse/BEAM-4828?focusedWorklogId=129331&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-129331
]
ASF GitHub Bot logged work on BEAM-4828:
----------------------------------------
Author: ASF GitHub Bot
Created on: 31/Jul/18 14:53
Start Date: 31/Jul/18 14:53
Worklog Time Spent: 10m
Work Description: JohnRudolfLewis commented on a change in pull request
#6101: [BEAM-4828] Add Amazon SqsIO
URL: https://github.com/apache/beam/pull/6101#discussion_r206561088
##########
File path:
sdks/java/io/amazon-web-services/src/test/java/org/apache/beam/sdk/io/aws/sqs/SqsIOTest.java
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.aws.sqs;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import com.amazonaws.auth.AWSStaticCredentialsProvider;
+import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.client.builder.AwsClientBuilder;
+import com.amazonaws.services.sqs.AmazonSQS;
+import com.amazonaws.services.sqs.AmazonSQSClientBuilder;
+import com.amazonaws.services.sqs.model.CreateQueueResult;
+import com.amazonaws.services.sqs.model.Message;
+import com.amazonaws.services.sqs.model.ReceiveMessageResult;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.beam.sdk.testing.PAssert;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.transforms.Count;
+import org.apache.beam.sdk.transforms.Create;
+import org.apache.beam.sdk.values.PCollection;
+import org.elasticmq.rest.sqs.SQSRestServer;
+import org.elasticmq.rest.sqs.SQSRestServerBuilder;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExternalResource;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests on {@link SqsIO}. */
+@RunWith(JUnit4.class)
+public class SqsIOTest {
+
+ @Rule public TestPipeline pipeline = TestPipeline.create();
+
+ @Rule public EmbeddedSqsServer embeddedSqsRestServer = new
EmbeddedSqsServer();
+
+ @Test
+ public void testRead() {
+ final AmazonSQS client = embeddedSqsRestServer.getClient();
+ final String queueUrl = embeddedSqsRestServer.getQueueUrl();
+
+ final PCollection<Message> output =
+
pipeline.apply(SqsIO.read().withQueueUrl(queueUrl).withMaxNumRecords(100));
+
+ PAssert.thatSingleton(output.apply(Count.globally())).isEqualTo(100L);
+
+ for (int i = 0; i < 100; i++) {
+ client.sendMessage(queueUrl, "This is a test");
+ }
+ pipeline.run();
+ }
+
+ @Test
+ public void testWrite() {
+ final AmazonSQS client = embeddedSqsRestServer.getClient();
+ final String queueUrl = embeddedSqsRestServer.getQueueUrl();
+
+ List<String> messages = new ArrayList<>();
+ for (int i = 0; i < 100; i++) {
+ messages.add("This is a test " + i);
+ }
+
pipeline.apply(Create.of(messages)).apply(SqsIO.write().withQueueUrl(queueUrl));
+ pipeline.run().waitUntilFinish();
+
+ List<String> received = new ArrayList<>();
+ while (received.size() < 100) {
+ final ReceiveMessageResult receiveMessageResult =
client.receiveMessage(queueUrl);
+
+ if (receiveMessageResult.getMessages() != null) {
+ for (Message message : receiveMessageResult.getMessages()) {
+ received.add(message.getBody());
+ }
+ }
+ }
+ assertEquals(100, received.size());
+ for (String s : received) {
+ assertTrue(s.startsWith("This is a test "));
+ }
Review comment:
no guarantee of ordering with SQS, but the spirit of your comment still
applies, will do
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 129331)
Time Spent: 3h (was: 2h 50m)
> Add Amazon SqsIO
> ----------------
>
> Key: BEAM-4828
> URL: https://issues.apache.org/jira/browse/BEAM-4828
> Project: Beam
> Issue Type: New Feature
> Components: io-java-aws
> Reporter: John Rudolf Lewis
> Assignee: John Rudolf Lewis
> Priority: Major
> Time Spent: 3h
> Remaining Estimate: 0h
>
> Add an SQS source
>
> For people who would like to follow progress or help out:
> [https://github.com/JohnRudolfLewis/beam/tree/Add-SqsIO]
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)