Set ElasticMQ's purgeQueue to be blocking

86 views
Skip to first unread message

Collin Scangarella

unread,
Nov 2, 2015, 6:45:13 PM11/2/15
to ElasticMQ

I'm using ElasticMQ to test classes which use AWS SQS. Because my unit tests are atomic I'd like to ensure that the SQS queue on which they operate is empty at the start of every test. However, as ElasticMQ is asynchronous and non-blocking, this can't be ensured before every test. Is there any way to set the behaviour of ElasticMQ (or even just purgeQueue) to be blocking? I'm currently using embedded ElasticMQ. Here's an example of my test class which runs into this issue:


public class QueuerTest extends AbstractServiceTest {
    private static ASyncConsumerService<String> aSyncConsumerService = new ASyncConsumerService<>(QueueName.VALID);
    private static Queuer queuer = new Queuer();
    private static SQSRestServer server = SQSRestServerBuilder.start();
    @BeforeClass
    public static void beforeClass() {
        queuerTest.init();
        aSyncConsumerService.setEndpoint("http://localhost:9324");
    }
    @Before
    public void before() {
        aSyncConsumerService.purgeQueue();
    }
    @AfterClass
    public static void afterClass() {
        server.stopAndWait();
    }
    @Test
    public void testWriteValid() {
        queuer.writeDataToQueueIfValid("valid");
        assertEquals("valid", aSyncConsumerService.receive());
    }
    @Test
    public void testWriteInvalid() {
        queuer.writeDataToQueueIfValid("invalid");
        assertNull(aSyncConsumerService.receive(1000));
    }
}

Adam Warski

unread,
Nov 3, 2015, 5:29:43 AM11/3/15
to elas...@googlegroups.com
The implementation of ElasticMQ is asynchronous, but most HTTP operations only return a result when the operation is complete (so synchronously from the perspective of the operation). I think your problems come from the fact that you are using an “ASyncConsumerService” - I suppose that’s your custom class in which you would have to do some waiting to make sure the operations complete.

Adam

--

---
You received this message because you are subscribed to the Google Groups "ElasticMQ" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticmq+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Message has been deleted

cscan

unread,
Nov 3, 2015, 11:57:46 AM11/3/15
to ElasticMQ
I looked into some of my implementation - the issue is that it was actually still using SQS instead of elasticMQ after I set the endpoint. Thanks for your help.
Reply all
Reply to author
Forward
0 new messages