yandex qatools postgresql嵌入.它需要在机器上安装postgres吗


使用的依赖项:ru.yandex.qatools.embed-postgresql-embedded-2.5.jar

代码:

final File dbDir = new File("/tmp/embeddedinstallation" + port);
String postgresInfo = embeddedPostgres.start(EmbeddedPostgres.cachedRuntimeConfig((dbDir).toPath()), "localhost", port, "db", "uname", "psswd", new ArrayList<String>());

获取此错误:

java.lang.NullPointerException: null
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1209)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at de.flapdoodle.embed.process.store.Downloader.downloadInputStream(Downloader.java:127)
at de.flapdoodle.embed.process.store.Downloader.download(Downloader.java:69)
at de.flapdoodle.embed.process.store.PostgresArtifactStore.checkDistribution(PostgresArtifactStore.java:66)
at de.flapdoodle.embed.process.runtime.Starter.prepare(Starter.java:56)
at de.flapdoodle.embed.process.runtime.Starter.prepare(Starter.java:49)
at ru.yandex.qatools.embed.postgresql.EmbeddedPostgres.start(EmbeddedPostgres.java:139)
at com.ge.data.gold.MockDbServer.startDbOnPort(MockDbServer.java:210)
at com.ge.data.gold.MockDbServer.initPostgres(MockDbServer.java:184)
at com.ge.data.gold.GoldUtil.setupTestEnv(GoldUtil.java:25)

参考:https://github.com/yandex-qatools/postgresql-embedded

它并没有提到postgres需要安装在机器中。但我看到代码访问命令:

package ru.yandex.qatools.embed.postgresql;
import ru.yandex.qatools.embed.postgresql.config.PostgresConfig;
public enum Command {
Postgres("postgres", PostgresExecutable.class),
InitDb("initdb", InitDbExecutable.class),
CreateDb("createdb", CreateDbExecutable.class),
PgCtl("pg_ctl", PgCtlExecutable.class),
Psql("psql", PsqlExecutable.class),
PgDump("pg_dump", PsqlExecutable.class),
PgRestore("pg_restore", PsqlExecutable.class),
Createuser("createuser", PsqlExecutable.class),
;

它需要在机器上安装postgres吗?还是我做了不正确的事情?

我发现了,它确实将postgres下载到了指定的位置。

/**
* Initializes runtime configuration for cached directory.
* If a provided directory is empty, postgres will be extracted into it.
*
* @param cachedPath path where postgres is supposed to be extracted
* @return runtime configuration required for postgres to start
*/
public static IRuntimeConfig cachedRuntimeConfig(Path cachedPath) {
final Command cmd = Command.Postgres;
final FixedPath cachedDir = new FixedPath(cachedPath.toString());
return new RuntimeConfigBuilder()
.defaults(cmd)
.artifactStore(new PostgresArtifactStoreBuilder()
.defaults(cmd)
.tempDir(cachedDir)
**.download(new PostgresDownloadConfigBuilder()
.defaultsForCommand(cmd)
.packageResolver(new PackagePaths(cmd, cachedDir))
.build()))**
.build();
}

最新更新