Тест Spring Spring Mongo Embedded завершается с ошибкой «Нераспознанное имя этапа конвейера:« $ graphLookup »» - PullRequest
0 голосов
/ 10 марта 2019

Мои тесты с использованием Spring Data и встроенного Mongo завершаются неудачно с «Нераспознанное имя этапа конвейера:« $ graphLookup »», которое предполагает, что версия MongoDB составляет <3.4, ​​однако я указал v3.6 при настройке тестов и могу видеть из Журналы, что FeatureCompatibility установлена ​​правильно, и драйвер mongo db выглядит хорошо в версии 3.6.4. Когда я запускаю свой код (не тест) для отдельного экземпляра MongoDB 3.6, он работает как положено - только тесты со встроенным flapdoodle mongo, которые не пройдут. Любые указатели, пожалуйста? </p>

- бревна maven -

[mongod output] 2019-03-10T17:54:01.339+0000 I CONTROL  [initandlisten] db version v3.6.5
[mongod output] 2019-03-10T17:54:01.339+0000 I CONTROL  [initandlisten] git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
[mongod output] 2019-03-10T17:54:01.339+0000 I CONTROL  [initandlisten] allocator: tcmalloc
[mongod output] 2019-03-10T17:54:01.339+0000 I CONTROL  [initandlisten] modules: none
[mongod output] 2019-03-10T17:54:01.339+0000 I CONTROL  [initandlisten] build environment:
[mongod output] 2019-03-10T17:54:01.339+0000 I CONTROL  [initandlisten]     distarch: x86_64
[mongod output] 2019-03-10T17:54:01.339+0000 I CONTROL  [initandlisten]     target_arch: x86_64
[mongod output] 2019-03-10T17:54:01.339+0000 I CONTROL  [initandlisten] options: { net: { bindIp: "127.0.0.1", port: 27018 }, security: { authorization: "disabled" }, storage: { dbPath: "/tmp/embedmongo-db-1cde0ab0-bb3d-4256-8e4c-19401c64337d", journal: { enabled: false }, mmapv1: { preallocDataFiles: false, smallFiles: true }, syncPeriodSecs: 0.0 } }
[mongod output] 2019-03-10T17:54:01.339+0000 I STORAGE  [initandlisten] 

...

[mongod output] 2019-03-10T17:54:02.044+0000 I COMMAND  [initandlisten] setting featureCompatibilityVersion to 3.6

...

rg.springframework.data.mongodb.UncategorizedMongoDbException: Command failed with error 16436: 'Unrecognized pipeline stage name: '$graphLookup'' on server localhost:43425. The full response is { "ok" : 0.0, "errmsg" : "Unrecognized pipeline stage name: '$graphLookup'", "code" : 16436 }; nested exception is com.mongodb.MongoCommandException: Command failed with error 16436: 'Unrecognized pipeline stage name: '$graphLookup'' on server localhost:43425. The full response is { "ok" : 0.0, "errmsg" : "Unrecognized pipeline stage name: '$graphLookup'", "code" : 16436 }
        at team.teamservice.web.team.TeamRepositoryTest.findAncestors(TeamRepositoryTest.java:121)
Caused by: com.mongodb.MongoCommandException: Command failed with error 16436: 'Unrecognized pipeline stage name: '$graphLookup'' on server localhost:43425. The full response is { "ok" : 0.0, "errmsg" : "Unrecognized pipeline stage name: '$graphLookup'", "code" : 16436 }
        at team.teamservice.web.team.TeamRepositoryTest.findAncestors(TeamRepositoryTest.java:121)

- настройка теста -

  @Before
    public void setUp() throws IOException
        {

        String ip = "localhost";
        int port = 27018;

        IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.V3_6)
                .net(new Net(ip, port, Network.localhostIsIPv6()))
                .build();

        MongodStarter starter = MongodStarter.getDefaultInstance();
        mongodExecutable = starter.prepare(mongodConfig);
        mongodExecutable.start();
}

- код репозитория -

@Override
public List<Team> findAncestors(String id)
    {

    TypedAggregation<Team> agg = Aggregation.newAggregation(Team.class,
            match(Criteria.where("id").is(id)),
            Aggregation.graphLookup("team")
                    .startWith("id")
                    .connectFrom("parentId")
                    .connectTo("id")
                    .as("ancestors"));

    AggregationResults<Team> result = mongoTemplate.aggregate(agg, Team.class);

    List<Team> teams = result.getMappedResults();

    return teams;
    }

- зависимость mvn: дерево -

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------< team:web >------------------------------
[INFO] Building web 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:3.0.2:tree (default-cli) @ web ---
[INFO] team:web:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.0.8.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.0.8.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.8.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.19:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.0.8.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.8:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.9.8:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.8:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.8:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.8:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.8.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.37:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.37:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.37:compile
[INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.0.14.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  +- org.springframework:spring-web:jar:5.0.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:5.0.12.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.0.12.RELEASE:compile
[INFO] |     +- org.springframework:spring-aop:jar:5.0.12.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:5.0.12.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-mail:jar:2.0.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:5.0.12.RELEASE:compile
[INFO] |  +- org.springframework:spring-context-support:jar:5.0.12.RELEASE:compile
[INFO] |  \- com.sun.mail:javax.mail:jar:1.6.2:compile
[INFO] |     \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.0.8.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.0.8.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.0.8.RELEASE:test
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:3.9.1:test
[INFO] |  +- org.mockito:mockito-core:jar:2.15.0:test
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.7.11:test
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.7.11:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.6:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-core:jar:5.0.12.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.0.12.RELEASE:compile
[INFO] |  +- org.springframework:spring-test:jar:5.0.12.RELEASE:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.5.1:test
[INFO] +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  +- net.minidev:json-smart:jar:2.3:test
[INFO] |  |  \- net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |     \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-mongodb:jar:2.0.8.RELEASE:compile
[INFO] |  +- org.mongodb:mongodb-driver:jar:3.6.4:compile
[INFO] |  |  +- org.mongodb:bson:jar:3.6.4:compile
[INFO] |  |  \- org.mongodb:mongodb-driver-core:jar:3.6.4:compile
[INFO] |  \- org.springframework.data:spring-data-mongodb:jar:2.0.13.RELEASE:compile
[INFO] |     +- org.springframework:spring-tx:jar:5.0.12.RELEASE:compile
[INFO] |     \- org.springframework.data:spring-data-commons:jar:2.0.13.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-rest:jar:2.0.8.RELEASE:compile
[INFO] |  \- org.springframework.data:spring-data-rest-webmvc:jar:3.0.13.RELEASE:compile
[INFO] |     +- org.springframework.data:spring-data-rest-core:jar:3.0.13.RELEASE:compile
[INFO] |     |  +- org.springframework.hateoas:spring-hateoas:jar:0.25.0.RELEASE:compile
[INFO] |     |  +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
[INFO] |     |  \- org.atteo:evo-inflector:jar:1.2.2:compile
[INFO] |     \- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:2.0.8.RELEASE:compile
[INFO] |  +- org.thymeleaf:thymeleaf-spring5:jar:3.0.11.RELEASE:compile
[INFO] |  \- org.thymeleaf.extras:thymeleaf-extras-java8time:jar:3.0.2.RELEASE:compile
[INFO] +- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:2.3.0:compile
[INFO] |  +- nz.net.ultraq.thymeleaf:thymeleaf-expression-processor:jar:1.1.3:compile
[INFO] |  +- org.codehaus.groovy:groovy:jar:2.4.16:compile
[INFO] |  \- org.thymeleaf:thymeleaf:jar:3.0.11.RELEASE:compile
[INFO] |     +- ognl:ognl:jar:3.1.12:compile
[INFO] |     |  \- org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] |     +- org.attoparser:attoparser:jar:2.0.5.RELEASE:compile
[INFO] |     \- org.unbescape:unbescape:jar:1.1.6.RELEASE:compile
[INFO] +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] |  \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:2.0.8.RELEASE:compile (optional)
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.0.8.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.8.RELEASE:compile
[INFO] +- com.google.visualization:visualization-datasource:jar:1.1.1:compile
[INFO] |  +- commons-lang:commons-lang:jar:2.4:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  +- com.google.guava:guava:jar:r07:compile
[INFO] |  +- com.ibm.icu:icu4j:jar:4.0.1:compile
[INFO] |  \- net.sf.opencsv:opencsv:jar:1.8:compile
[INFO] \- de.flapdoodle.embed:de.flapdoodle.embed.mongo:jar:2.2.0:test
[INFO]    \- de.flapdoodle.embed:de.flapdoodle.embed.process:jar:2.1.2:test
[INFO]       +- org.apache.commons:commons-lang3:jar:3.7:test
[INFO]       +- net.java.dev.jna:jna:jar:4.5.2:test
[INFO]       +- net.java.dev.jna:jna-platform:jar:4.5.2:test
[INFO]       \- org.apache.commons:commons-compress:jar:1.18:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.749 s
[INFO] Finished at: 2019-03-10T18:04:13Z
[INFO] ------------------------------------------------------------------------

1 Ответ

0 голосов
/ 11 марта 2019

Я понял это. Я путал автоматическую настройку пружинной загрузки с ручной настройкой без пружин, и в итоге получилось, что два экземпляра mongodb запускали разные версии на двух разных портах.

Пока в тесте есть аннотация @DataMongoTest, встроенный mongodb настраивается автоматически. Удалите встроенную конфигурацию mongodb из вашей тестовой установки, иначе вы получите параллельные версии mongo, работающие во время тестов.

Чтобы изменить версию, вам просто нужно установить некоторые свойства приложения:

spring.mongodb.embedded.version=3.6.4
spring.mongodb.embedded.features=no_http_interface_arg

Подробнее см. https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo/issues/223 и https://github.com/spring-projects/spring-boot/issues/12575.

...