softwaremill / elasticmq

In-memory message queue with an Amazon SQS-compatible interface. Runs stand-alone or embedded.
https://softwaremill.com/open-source/
Apache License 2.0
2.51k stars 194 forks source link

SQSRestServer exposes ephemeral port number bound #31

Closed stevenzwu closed 9 years ago

stevenzwu commented 9 years ago

ElasticMQ can be an excellent choice for in-memory SQS replacement for unit test. For testing, I don't want to specify a specific/static port number. I would rather let system pick a ephemeral port number when passing port number zero to SQSRestServerBuilder. This way, I can avoid potential port number conflict.

But I would need SQSRestServer to expose the actual ephemeral port bound by http server listener, so that I can construct the proper endpoint for SQS client.

stevenzwu commented 9 years ago

never mind. I think I can get the ephemeral port already. here is the java code snippet.

    SQSRestServer sqsServer = SQSRestServerBuilder
            .withInterface(hostname)
            .withPort(port)
            .start();
    sqsServer.waitUntilStarted();
    System.out.println("foo");
    Try<Object> tryVal = sqsServer.startFuture().value().get();
    if(tryVal.isSuccess()) {
        Tcp.Bound bound = (Tcp.Bound) tryVal.get();
        port = bound.localAddress().getPort();
        System.out.println("port: " + bound.localAddress().getPort());
    } else {
        throw new RuntimeException("startup failed");
    }

But my test still fail, because qetQueueUrl still returns port 9324. I will file a different issue for that problem.

adamw commented 9 years ago

Maybe you could post where port comes from for future reference?