/modeshape-jcr/src/test/java/org/modeshape/jcr/value/binary/MongodbBinaryStoreTest.java

https://github.com/hchiorean/modeshape · Java · 84 lines · 53 code · 9 blank · 22 comment · 0 complexity · bb2ff51f1f53c1092a73e7d07da06d74 MD5 · raw file

  1. /*
  2. * ModeShape (http://www.modeshape.org)
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.modeshape.jcr.value.binary;
  17. import de.flapdoodle.embed.mongo.MongodExecutable;
  18. import de.flapdoodle.embed.mongo.MongodProcess;
  19. import de.flapdoodle.embed.mongo.MongodStarter;
  20. import de.flapdoodle.embed.mongo.config.MongodConfig;
  21. import de.flapdoodle.embed.mongo.config.RuntimeConfig;
  22. import de.flapdoodle.embed.mongo.distribution.Version;
  23. import de.flapdoodle.embed.process.runtime.Network;
  24. import org.junit.AfterClass;
  25. import org.junit.BeforeClass;
  26. import java.io.IOException;
  27. import java.util.UUID;
  28. import java.util.logging.FileHandler;
  29. import java.util.logging.Level;
  30. import java.util.logging.Logger;
  31. /**
  32. * Setup mongodb env and uncomment tests to run.
  33. *
  34. * @author kulikov
  35. * @author Horia Chiorean (hchiorea@redhat.com)
  36. */
  37. public class MongodbBinaryStoreTest extends AbstractBinaryStoreTest {
  38. private static final Logger LOGGER = Logger.getLogger("MongoDBOutput");
  39. private static MongodProcess mongodProcess;
  40. private static MongodExecutable mongodExecutable;
  41. private static MongodbBinaryStore binaryStore;
  42. static {
  43. try {
  44. LOGGER.addHandler(new FileHandler("target/mongoDB_output.txt", false));
  45. LOGGER.setLevel(Level.SEVERE);
  46. } catch (IOException e) {
  47. throw new RuntimeException(e);
  48. }
  49. }
  50. @BeforeClass
  51. public static void setUpClass() throws Exception {
  52. RuntimeConfig config = RuntimeConfig.getInstance(LOGGER);
  53. MongodStarter runtime = MongodStarter.getInstance(config);
  54. int freeServerPort = Network.getFreeServerPort();
  55. mongodExecutable = runtime.prepare(new MongodConfig(Version.Main.V2_3, freeServerPort,
  56. Network.localhostIsIPv6()));
  57. mongodProcess = mongodExecutable.start();
  58. binaryStore = new MongodbBinaryStore("localhost", freeServerPort, "test-" + UUID.randomUUID());
  59. binaryStore.start();
  60. }
  61. @AfterClass
  62. public static void tearDownClass() throws Exception {
  63. try {
  64. binaryStore.shutdown();
  65. mongodExecutable.stop();
  66. mongodProcess.stop();
  67. } catch (Exception e) {
  68. //ignore
  69. }
  70. }
  71. @Override
  72. protected BinaryStore getBinaryStore() {
  73. return binaryStore;
  74. }
  75. }