项目作者: joelittlejohn

项目描述 :
Maven plugin wrapper for the flapdoodle.de embedded MongoDB API
高级语言: Java
项目地址: git://github.com/joelittlejohn/embedmongo-maven-plugin.git
创建时间: 2012-05-30T21:23:30Z
项目社区:https://github.com/joelittlejohn/embedmongo-maven-plugin

开源协议:Apache License 2.0

下载


embedmongo-maven-plugin Build Status Maven Central

Maven plugin wrapper for the flapdoodle.de embedded MongoDB API.

This plugin lets you start and stop an instance of MongoDB during a Maven build, e.g. for integration testing. The Mongo instance isn’t strictly embedded (it’s not running within the JVM of your application), but it is a managed instance that exists only for the lifetime of your build.

Versions

  • For Java 8 and later: <version>0.4.1</version>
  • For Java 6/7: <version>0.3.5</version>

Usage

  1. <plugin>
  2. <groupId>com.github.joelittlejohn.embedmongo</groupId>
  3. <artifactId>embedmongo-maven-plugin</artifactId>
  4. <version>0.4.1</version>
  5. <executions>
  6. <execution>
  7. <id>start</id>
  8. <goals>
  9. <goal>start</goal>
  10. </goals>
  11. <configuration>
  12. <port>37017</port>
  13. <!-- optional, default 27017 -->
  14. <randomPort>true</randomPort>
  15. <!-- optional, default is false, if true allocates a random port and overrides embedmongo.port -->
  16. <version>2.0.4</version>
  17. <!-- optional, default 2.2.1 -->
  18. <features>ONLY_WITH_SSL, ONLY_WINDOWS_2008_SERVER, NO_HTTP_INTERFACE_ARG</features>
  19. <!-- optional, default is none. Enables flapdoodle.embed.mongo features, for example to build Windows download URLs since 3.6 -->
  20. <databaseDirectory>/tmp/mongotest</databaseDirectory>
  21. <!-- optional, default is a new dir in java.io.tmpdir -->
  22. <logging>file</logging>
  23. <!-- optional (file|console|none), default console -->
  24. <logFile>${project.build.directory}/myfile.log</logFile>
  25. <!-- optional, can be used when logging=file, default is ./embedmongo.log -->
  26. <logFileEncoding>utf-8</logFileEncoding>
  27. <!-- optional, can be used when logging=file, default is utf-8 -->
  28. <bindIp>127.0.0.1</bindIp>
  29. <!-- optional, default is to listen on all interfaces -->
  30. <downloadPath>http://internal-mongo-repo/</downloadPath>
  31. <!-- optional, default is http://fastdl.mongodb.org/ -->
  32. <unixSocketPrefix>${user.home}/.embedmongo</unixSocketPrefix>
  33. <!-- optional, default is /tmp -->
  34. <storageEngine>wiredTiger</storageEngine>
  35. <!--optional, one of wiredTiger or mmapv1 (default is mmapv1) -->
  36. <skip>false</skip>
  37. <!-- optional, skips this plugin entirely, use on the command line like -Dembedmongo.skip -->
  38. </configuration>
  39. </execution>
  40. <execution>
  41. <id>mongo-scripts</id>
  42. <goals>
  43. <goal>mongo-scripts</goal>
  44. </goals>
  45. <configuration>
  46. <version>2.0.4</version>
  47. <!-- optional, default 2.2.1 -->
  48. <scriptsDirectory>...</scriptsDirectory>
  49. <!-- a directory containing scripts to run -->
  50. <scriptCharsetEncoding>UTF-8</scriptCharsetEncoding>
  51. <!-- optional, valid charset encoding for loading the scripts. Uses the underlying charset encoding of the platform if not assigned -->
  52. <databaseName>mydb</databaseName>
  53. <!-- the name of the database to run scripts against -->
  54. </configuration>
  55. </execution>
  56. <execution>
  57. <id>mongo-import</id>
  58. <goals>
  59. <goal>mongo-import</goal>
  60. </goals>
  61. <configuration>
  62. <version>2.0.4</version>
  63. <!-- optional, default 2.2.1 -->
  64. <defaultImportDatabase>test</defaultImportDatabase>
  65. <!-- optional, name of the default database to import data -->
  66. <parallel>false</parallel>
  67. <!-- optional, default false, if true it launches in parallel all imports -->
  68. <wait>false</wait>
  69. <!-- optional, default false, if true it will wait forever after it imports the data -->
  70. <imports>
  71. <import>
  72. <database>my_db</database>
  73. <!-- optional, name of the database, if null it will fallback to defaultImportDatabase -->
  74. <collection>col</collection>
  75. <!-- optional, collection to import data into (will use <file> to derive this otherwise) -->
  76. <file>import_file.json</file>
  77. <!-- required, name of the json file to import -->
  78. <upsertOnImport>true</upsertOnImport>
  79. <!-- optional, default true, if true it will do an upsert on each document imported -->
  80. <dropOnImport>false</dropOnImport>
  81. <!-- optional, default true, if true it will do a drop the collection before starts to import -->
  82. <timeout>20000</timeout>
  83. <!-- optional, default 20000, it will fail if it takes more than this time importing a file (time in millis) -->
  84. </import>
  85. <!-- More imports are accepted and it will be executed in strictly order (if parallel is not set) -->
  86. </imports>
  87. </configuration>
  88. </execution>
  89. <execution>
  90. <id>stop</id>
  91. <goals>
  92. <goal>stop</goal>
  93. </goals>
  94. </execution>
  95. </executions>
  96. </plugin>

Notes

  • By default, the start goal is bound to pre-integration-test, the stop goal is bound to post-integration-test. You can of course bind to different phases if required.
  • If you omit/forget the stop goal, any Mongo process spawned by the start goal will be stopped when the JVM terminates.
  • If you want to run Maven builds in parallel you can use randomPort to avoid port conflicts, the value allocated will be available to other plugins in the project as a property embedmongo.port.
    If you’re using Jenkins, you can also try the Port Allocator Plugin.
  • If you need to use a proxy to download MongoDB then you can either use -Dhttp.proxyHost and -Dhttp.proxyPort as additional Maven arguments (this will affect the entire build) or add proxy settings to your settings.xml.
  • If you’re having trouble with Windows firewall rules, try setting the bindIp config property to 127.0.0.1.
  • If you’d like the start goal to start mongodb and wait, you can add -Dembedmongo.wait to your Maven command line arguments or -Dembedmongo.import.wait if you want the imports
  • If you are using a charset encoding to load scripts, refer to the IANA Charset Registry. Accepted charsets are found in the Preferred MIME Name column.