localstack / localstack-java-utils

☕ Java utilities and JUnit integration for LocalStack
Apache License 2.0
75 stars 43 forks source link

Unknown port mapping for service: sqs #72

Closed mmartinsky closed 3 years ago

mmartinsky commented 3 years ago

Version: 0.2.7 OS: MacOS Catalina

Cloned a repo with LocalStack related SQS tests, but seeing issues with the below test:

@ExtendWith(LocalstackDockerExtension.class)
@LocalstackDockerProperties(services = {"sqs"})
@EnabledOnOs({OS.MAC})
public class SqsStreamClientTest {

    @Test
    public void it_should_get_queue_url() throws ExecutionException, InterruptedException {
        //Arrange
        SqsAsyncClient sqsAsyncClient = TestUtils.getClientSQSAsyncV2();
        String queueName = "test-queue";
        sqsAsyncClient.createQueue(CreateQueueRequest.builder().queueName(queueName).build()).get();
        SqsStreamClient target = new SqsStreamClient(sqsAsyncClient);

        //Act
        String queueUrl = target.getQueueUrl(queueName, sqsAsyncClient);

        //Assert
        assertEquals("http://localhost:4566/000000000000/test-queue", queueUrl);
    }
}

Error:

Unknown port mapping for service: sqs
java.lang.IllegalArgumentException: Unknown port mapping for service: sqs
    at cloud.localstack.Localstack.getServicePort(Localstack.java:223)
    at cloud.localstack.Localstack.endpointForService(Localstack.java:214)
    at cloud.localstack.Localstack.getEndpointSQS(Localstack.java:166)
    at cloud.localstack.awssdkv2.TestUtils.getClientSQSAsyncV2(TestUtils.java:38)
    at com.trp.dit.lux.core.infrastructure.SqsStreamClientTest.it_should_get_queue_url(SqsStreamClientTest.java:24)
       ....

Debugging into

private void loadServiceToPortMap() {
        String localStackPortConfig = localStackContainer.executeCommand(Arrays.asList("cat", PORT_CONFIG_FILENAME));

        int edgePort = getEdgePort();
        Map<String, Integer> ports = new RegexStream(DEFAULT_PORT_PATTERN.matcher(localStackPortConfig)).stream()
                .collect(Collectors.toMap(match -> match.group(1), match -> edgePort));

        serviceToPortMap = Collections.unmodifiableMap(ports);
    }

localStackPortConfig = 'cat: can't open '/opt/code/localstack/.venv/lib/python3.8/site-packages/localstack_client/config.py': No such file or directory'

When I run localStackContainer.executeCommand(Arrays.asList("ls", "/opt/code/localstack/.venv/lib")), I see "python3.7" returned - how should I fix this mismatching version?

It seems related to https://github.com/localstack/localstack/issues/2082.

mmartinsky commented 3 years ago

Solved by upgrading version to 0.2.14