lundi 2 novembre 2015

Set ElasticMQ's purgeQueue to be blocking

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));
    }
}

Aucun commentaire:

Enregistrer un commentaire