Spring 为构建管道配置嵌入式mongodb活板门
在我的Spring应用程序中,我有一个依赖MongoDb的部分,我必须测试它。Spring 为构建管道配置嵌入式mongodb活板门,spring,mongodb,spring-data-mongodb,spring-test,Spring,Mongodb,Spring Data Mongodb,Spring Test,在我的Spring应用程序中,我有一个依赖MongoDb的部分,我必须测试它。 我希望能够在本地和构建服务器上运行测试 目前我正在尝试这样做,添加 testCompile group: 'de.flapdoodle.embed', name: 'de.flapdoodle.embed.mongo', version: '2.2.0' 作为依赖 这个包从mongodb.org下载mongo可执行文件,提取它们并将它们存储在本地。 虽然这在本地很有效,但在构建服务器上肯定会失败,因为构建服务器无法
我希望能够在本地和构建服务器上运行测试 目前我正在尝试这样做,添加
testCompile group: 'de.flapdoodle.embed', name: 'de.flapdoodle.embed.mongo', version: '2.2.0'
作为依赖
这个包从mongodb.org下载mongo可执行文件,提取它们并将它们存储在本地。
虽然这在本地很有效,但在构建服务器上肯定会失败,因为构建服务器无法访问远程站点
因此,我想更改配置,使用在artifactory repo中找到的可执行文件,或者——如果必要的话——已经添加到项目repo中的可执行文件
一段有趣的代码似乎是
- 它表明可能会使用一些环境变量
嵌入的\u MONGO\u工件
- 它显示默认的下载源,但路径不是绝对的。所以我不知道,我的镜子需要如何构造。访问链接,我将被重定向
private static class PlatformDependentDownloadPath implements IDownloadPath { @Override public String getPath(Distribution distribution) { if (distribution.getPlatform()==Platform.Windows) { return "https://downloads.mongodb.org/"; } return "https://fastdl.mongodb.org/"; } }
简而言之:
- 我需要如何构造我的下载镜像
- 如何配置下载路径以使用镜像,尤其是Spring自动配置
我知道已经有一段时间没有人问这个问题了,但也许这会有所帮助 我设法通过以下@Configuration(在您的测试包中)手动配置它
...
Command command = Command.MongoD;
IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
.defaults(command)
.artifactStore(new ExtractedArtifactStoreBuilder()
.defaults(command)
.download(new DownloadConfigBuilder()
.defaultsForCommand(command)
.downloadPath("http://my.custom.download.domain/")))
.build();
...
@Configuration
public class EmbeddedMongoDBConfig {
@Bean
public IRuntimeConfig embeddedMongoRuntimeConfig() {
final Command command = Command.MongoD;
final IRuntimeConfig runtimeConfig = new RuntimeConfigBuilder()
.defaults(command)
.artifactStore(new ExtractedArtifactStoreBuilder()
.defaults(command)
.downloader(new Downloader())
.download(new DownloadConfigBuilder()
.downloadPath("http://host/path/to/mongodb/server/mongodb/3.5.5/")
.fileNaming(new UserTempNaming())
.downloadPrefix("")
.artifactStorePath(new PlatformTempDir())
.progressListener(new Slf4jProgressListener(log))
.userAgent("")
.packageResolver(new IPackageResolver() {
// this apparently is expected to return the name of the executable (in the download package)
@Override
public FileSet getFileSet(Distribution distribution) {
String filename = (distribution.getPlatform().isUnixLike()) ? "bin/mongod" : "bin/mongod.exe";
return FileSet.builder()
.addEntry(FileType.Executable, filename)
.build();
}
@Override
public ArchiveType getArchiveType(Distribution distribution) {
if(distribution.getPlatform().isUnixLike()) return ArchiveType.TGZ;
else return ArchiveType.ZIP;
}
// the path (appended to the download link above)
@Override
public String getPath(Distribution distribution) {
return (distribution.getPlatform().isUnixLike()) ? "mongodb-3.5.5-linux-x86_64.tgz" : "mongodb-3.5.5-win32-x86_64.zip";
}
})
.build())
.executableNaming(new UserTempNaming())
.build())
.build();
return runtimeConfig;
}