0

我正在使用测试容器(https://www.testcontainers.org/)编写一个 junit 测试。当我运行测试时,我得到以下堆栈跟踪。

com.github.dockerjava.api.exception.UnauthorizedException: Status 401: {"message":"Get https://registry-1.docker.io/v2/testcontainers/ryuk/manifests/0.3.1: unauthorized: incorrect username or password"}

    at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:239)
    at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:269)
    at java.lang.Thread.run(Thread.java:748)

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 6.797 sec <<< FAILURE! - in com.openmind.primecast.web.rest.MessageHistoryReportingResourceIntTest
com.openmind.primecast.web.rest.MessageHistoryReportingResourceIntTest  Time elapsed: 6.796 sec  <<< ERROR!
org.testcontainers.containers.ContainerFetchException: Can't get Docker image: RemoteDockerImage(imageName=docker.elastic.co/elasticsearch/elasticsearch:7.11.2, imagePullPolicy=DefaultPullPolicy())
    at org.testcontainers.containers.GenericContainer.getDockerImageName(GenericContainer.java:1286)
    at org.testcontainers.containers.GenericContainer.logger(GenericContainer.java:615)
    at org.testcontainers.elasticsearch.ElasticsearchContainer.<init>(ElasticsearchContainer.java:73)
    at com.openmind.primecast.web.rest.MessageHistoryReportingResourceIntTest.startElasticServer(MessageHistoryReportingResourceIntTest.java:132)
Caused by: com.github.dockerjava.api.exception.UnauthorizedException: Status 401: {"message":"Get https://registry-1.docker.io/v2/testcontainers/ryuk/manifests/0.3.1: unauthorized: incorrect username or password"}

    at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.execute(DefaultInvocationBuilder.java:239)
    at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:269)
    at java.lang.Thread.run(Thread.java:748)

2021-03-24 20:30:31.584  WARN   --- [r1-nio-worker-1] io.netty.channel.DefaultChannelPipeline  : An exception '{}' [enable DEBUG level for full stacktrace] was thrown by a user handler's exceptionCaught() method while handling the following exception:

这是我的 junit 测试中的代码。基本上它试图下载版本为 7.11.2 的弹性搜索泊坞窗图像。但是我无法这样做,并且当我运行我的 junit 测试时,控制台上会抛出一个错误。

public class MessageHistoryReportingResourceIntTest extends AbstractCassandraTest {

    /**
     * Elasticsearch version which should be used for the Tests
     */
    private static final String ELASTICSEARCH_VERSION = "7.11.2";

    private static final DockerImageName ELASTICSEARCH_IMAGE = DockerImageName
            .parse("docker.elastic.co/elasticsearch/elasticsearch").withTag(ELASTICSEARCH_VERSION);

    @BeforeClass
    public static void startElasticServer() throws Exception {
    container = new ElasticsearchContainer(ELASTICSEARCH_IMAGE);
        container.start();
   }
}

这是我的码头工人版本

-bash-4.2$ docker --version
Docker version 17.03.1-ce_omn3, build 9b1cd46

在 pom.xml 我添加了库

    <dependency>
        <groupId>org.testcontainers</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>1.15.2</version>
        <scope>test</scope>
    </dependency>

如果你能帮忙谢谢谢谢

4

0 回答 0