Repository: incubator-wave
Updated Branches:
  refs/heads/master 5abfce6c7 -> 0858e0c60


Deltas migration tool from file to mongodb store 
https://reviews.apache.org/r/20371


Project: http://git-wip-us.apache.org/repos/asf/incubator-wave/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-wave/commit/0858e0c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-wave/tree/0858e0c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-wave/diff/0858e0c6

Branch: refs/heads/master
Commit: 0858e0c60b42e2cac38aed44d8b16f9e8bcb377a
Parents: 5abfce6
Author: Pablo Ojanguren <[email protected]>
Authored: Mon Jun 30 19:34:27 2014 +0300
Committer: Yuri Zelikov <[email protected]>
Committed: Wed Jul 9 22:03:13 2014 +0300

----------------------------------------------------------------------
 run-data-migration.sh                           |  28 +++
 .../waveprotocol/box/server/CoreSettings.java   |  17 +-
 .../box/server/DataMigrationTool.java           | 219 +++++++++++++++++++
 .../server/persistence/PersistenceModule.java   |  17 +-
 .../persistence/migration/DeltaMigrator.java    | 142 ++++++++++++
 .../persistence/mongodb/MongoDbProvider.java    |  61 +-----
 .../persistence/mongodb/AccountStoreTest.java   |   4 +-
 .../mongodb/AttachmentStoreTest.java            |   4 +-
 .../persistence/mongodb/CertPathStoreTest.java  |   2 +-
 9 files changed, 436 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/0858e0c6/run-data-migration.sh
----------------------------------------------------------------------
diff --git a/run-data-migration.sh b/run-data-migration.sh
new file mode 100755
index 0000000..b48eb22
--- /dev/null
+++ b/run-data-migration.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# This script will start the data migration between two different store types
+# Initially this tool is intended to migrate deltas from file to mongodb store
+# Run "ant dist-server" before to use this script
+
+# The version of Wave in a Box, extracted from the build.properties file
+WAVEINABOX_VERSION=`sed "s/[\\t ]*=[\\t ]*/=/g" build.properties | grep 
^waveinabox.version= | cut -f2 -d=`
+echo wave-in-a-box-server-$WAVEINABOX_VERSION.jar
+
+exec java -cp dist/wave-in-a-box-server-$WAVEINABOX_VERSION.jar 
org.waveprotocol.box.server.DataMigrationTool $*

http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/0858e0c6/src/org/waveprotocol/box/server/CoreSettings.java
----------------------------------------------------------------------
diff --git a/src/org/waveprotocol/box/server/CoreSettings.java 
b/src/org/waveprotocol/box/server/CoreSettings.java
index 1145400..7a43829 100644
--- a/src/org/waveprotocol/box/server/CoreSettings.java
+++ b/src/org/waveprotocol/box/server/CoreSettings.java
@@ -74,6 +74,9 @@ public class CoreSettings {
   public static final String THUMBNAIL_PATTERNS_DIRECTORY = 
"thumbnail_patterns_directory";
   public static final String PROFILE_FETCHER_TYPE = "profile_fetcher_type";
   public static final String ENABLE_PROFILING  = "enable_profiling";
+  public static final String MONGODB_HOST = "mongodb_host";
+  public static final String MONGODB_PORT = "mongodb_port";
+  public static final String MONGODB_DATABASE = "mongodb_database";
 
   @Setting(name = WAVE_SERVER_DOMAIN)
   private static String waveServerDomain;
@@ -152,7 +155,7 @@ public class CoreSettings {
   @Setting(name = SESSIONS_STORE_DIRECTORY,
       description = "Location on disk where the user sessions are persisted. 
Must be writeable by the "
           + "wave-in-a-box process.",
-      defaultValue = "_sessions")
+ defaultValue = "_sessions")
   private static String sessionsStoreDirectory;
 
   @Setting(name = SESSION_COOKIE_MAX_AGE,
@@ -275,4 +278,16 @@ public class CoreSettings {
       description = "Enable profiling statistic",
       defaultValue = "false")
   private static boolean enableProfiling;
+
+  @Setting(name = MONGODB_HOST, description = "The host address for the 
MongoDB server",
+      defaultValue = "127.0.0.1")
+  private static String mongoDBhost;
+
+  @Setting(name = MONGODB_PORT, description = "The port number of the MongoDB 
server",
+      defaultValue = "27017")
+  private static String mongoDBport;
+
+  @Setting(name = MONGODB_DATABASE, description = "The database name used in 
the MongoDB server",
+      defaultValue = "wiab")
+  private static String mongoDBdatabase;
 }

http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/0858e0c6/src/org/waveprotocol/box/server/DataMigrationTool.java
----------------------------------------------------------------------
diff --git a/src/org/waveprotocol/box/server/DataMigrationTool.java 
b/src/org/waveprotocol/box/server/DataMigrationTool.java
new file mode 100644
index 0000000..32e0d50
--- /dev/null
+++ b/src/org/waveprotocol/box/server/DataMigrationTool.java
@@ -0,0 +1,219 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.waveprotocol.box.server;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.Module;
+import com.google.inject.name.Names;
+
+import org.waveprotocol.box.server.persistence.PersistenceModule;
+import org.waveprotocol.box.server.persistence.migration.DeltaMigrator;
+import org.waveprotocol.box.server.waveserver.DeltaStore;
+import org.waveprotocol.wave.util.logging.Log;
+import org.waveprotocol.wave.util.settings.Setting;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A cmd line utility to perform data migration from a store type to another
+ * one. Initially developed to replicate deltas from a file store to a mongodb
+ * store.
+ *
+ *
+ * @author [email protected] (Pablo Ojanguren)
+ *
+ */
+public class DataMigrationTool {
+
+  private static final Log LOG = Log.get(DataMigrationTool.class);
+
+
+
+  private static void runDeltasMigration(Injector sourceInjector, Injector 
targetInjector) {
+
+    // We can migrate data from-to any store type,
+    // but it is not allowed migrate from-to the same type
+    String sourceDeltaStoreType =
+        sourceInjector
+            .getInstance(Key.get(String.class, 
Names.named(CoreSettings.DELTA_STORE_TYPE)));
+
+    String targetDeltaStoreType =
+        targetInjector
+            .getInstance(Key.get(String.class, 
Names.named(CoreSettings.DELTA_STORE_TYPE)));
+
+    if (sourceDeltaStoreType.equalsIgnoreCase(targetDeltaStoreType))
+      usageError("Source and Target Delta store types must be different");
+
+
+    DeltaMigrator dm =
+        new DeltaMigrator(sourceInjector.getInstance(DeltaStore.class),
+            targetInjector.getInstance(DeltaStore.class));
+
+    dm.run();
+
+  }
+
+  private static Map<Setting, Field> getCoreSettings() {
+
+    // Get all method fields
+    Field[] coreSettingFields = CoreSettings.class.getDeclaredFields();
+
+    // Filter only annotated fields
+    Map<Setting, Field> settings = new HashMap<Setting, Field>();
+
+    for (Field f : coreSettingFields) {
+      if (f.isAnnotationPresent(Setting.class)) {
+        Setting setting = f.getAnnotation(Setting.class);
+        settings.put(setting, f);
+      }
+    }
+
+    return settings;
+
+  }
+
+  private static Module bindCmdLineSettings(String cmdLineProperties) {
+
+    // Get settings from cmd line, e.g.
+    // Key = delta_store_type
+    // Value = mongodb
+    final Map<String, String> propertyMap = new HashMap<String, String>();
+
+    for (String arg : cmdLineProperties.split(",")) {
+      String[] argTokens = arg.split("=");
+      propertyMap.put(argTokens[0], argTokens[1]);
+    }
+
+    // Validate settings against CoreSettings
+    final Map<Setting, Field> coreSettings = getCoreSettings();
+
+    // Set a suitable map to match cmd line settings
+    final Map<String, Setting> propertyToSettingMap = new HashMap<String, 
Setting>();
+    for (Setting s : coreSettings.keySet()) {
+      propertyToSettingMap.put(s.name(), s);
+    }
+
+    for (String propertyKey : propertyMap.keySet()) {
+      if (!propertyToSettingMap.containsKey(propertyKey))
+        usageError("Wrong setting '" + propertyKey + "'");
+    }
+
+
+
+    return new AbstractModule() {
+
+      @Override
+      protected void configure() {
+
+        // We must iterate the settings when binding.
+        // Note: do not collapse these loops as that will damage
+        // early error detection. The runtime is still O(n) in setting count.
+        for (Map.Entry<Setting, Field> entry : coreSettings.entrySet()) {
+
+          Setting setting = entry.getKey();
+          Class<?> type = entry.getValue().getType();
+          String value =
+              propertyMap.containsKey(setting.name()) ? 
propertyMap.get(setting.name()) : setting
+                  .defaultValue();
+          if (int.class.equals(type)) {
+            // Integer defaultValue = null;
+            // if (!setting.defaultValue().isEmpty()) {
+            // defaultValue = Integer.parseInt(setting.defaultValue());
+            // }
+            
bindConstant().annotatedWith(Names.named(setting.name())).to(Integer.parseInt(value));
+          } else if (boolean.class.equals(type)) {
+            // Boolean defaultValue = null;
+            // if (!setting.defaultValue().isEmpty()) {
+            // defaultValue = Boolean.parseBoolean(setting.defaultValue());
+            // }
+            bindConstant().annotatedWith(Names.named(setting.name())).to(
+                Boolean.parseBoolean(value));
+          } else if (String.class.equals(type)) {
+            
bindConstant().annotatedWith(Names.named(setting.name())).to(value);
+          } else {
+            /** Not supported **/
+            /*
+             * String[] value = config.getStringArray(setting.name()); if
+             * (value.length == 0 && !setting.defaultValue().isEmpty()) { value
+             * = setting.defaultValue().split(","); } bind(new
+             * TypeLiteral<List<String>>()
+             * {}).annotatedWith(Names.named(setting.name()))
+             * .toInstance(ImmutableList.copyOf(value));
+             */
+          }
+        }
+      }
+
+
+    };
+
+  }
+
+  public static void usageError() {
+    usageError("");
+  }
+
+  public static void usageError(String msg) {
+    System.out.println(msg + "\n");
+    System.out.println("Use: DataMigrationTool <data type> <source options> 
<target options>\n");
+    System.out.println("supported data types : deltas");
+    System.out
+        .println("source options example : 
delta_store_type=file,delta_store_directory=./_deltas");
+    System.out
+        .println("target options example : 
delta_store_type=mongodb,mongodb_host=127.0.0.1,mongodb_port=27017,mongodb_database=wiab");
+    System.exit(1);
+  }
+
+  public static void main(String... args) {
+
+    if (args.length != 3) usageError();
+
+    String dataType = args[0];
+
+    Module sourceSettings = bindCmdLineSettings(args[1]);
+    Injector sourceSettingsInjector = Guice.createInjector(sourceSettings);
+    Module sourcePersistenceModule = 
sourceSettingsInjector.getInstance(PersistenceModule.class);
+    Injector sourceInjector = 
sourceSettingsInjector.createChildInjector(sourcePersistenceModule);
+
+
+    Module targetSettings = bindCmdLineSettings(args[2]);
+    Injector targetSettingsInjector = Guice.createInjector(targetSettings);
+    Module targetPersistenceModule = 
targetSettingsInjector.getInstance(PersistenceModule.class);
+    Injector targetInjector = 
targetSettingsInjector.createChildInjector(targetPersistenceModule);
+
+
+    if (dataType.equals("deltas")) {
+
+      runDeltasMigration(sourceInjector, targetInjector);
+
+
+    } else {
+      usageError("Wrong data type");
+    }
+
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/0858e0c6/src/org/waveprotocol/box/server/persistence/PersistenceModule.java
----------------------------------------------------------------------
diff --git a/src/org/waveprotocol/box/server/persistence/PersistenceModule.java 
b/src/org/waveprotocol/box/server/persistence/PersistenceModule.java
index 14c6453..3016671 100644
--- a/src/org/waveprotocol/box/server/persistence/PersistenceModule.java
+++ b/src/org/waveprotocol/box/server/persistence/PersistenceModule.java
@@ -61,15 +61,28 @@ public class PersistenceModule extends AbstractModule {
 
   private MongoDbProvider mongoDbProvider;
 
+  private final String mongoDBHost;
+
+  private final String mongoDBPort;
+
+  private final String mongoDBdatabase;
+
+
   @Inject
   public PersistenceModule(@Named(CoreSettings.SIGNER_INFO_STORE_TYPE) String 
signerInfoStoreType,
       @Named(CoreSettings.ATTACHMENT_STORE_TYPE) String attachmentStoreType,
       @Named(CoreSettings.ACCOUNT_STORE_TYPE) String accountStoreType,
-      @Named(CoreSettings.DELTA_STORE_TYPE) String deltaStoreType) {
+      @Named(CoreSettings.DELTA_STORE_TYPE) String deltaStoreType,
+      @Named(CoreSettings.MONGODB_HOST) String mongoDBHost,
+      @Named(CoreSettings.MONGODB_PORT) String mongoDBPort,
+      @Named(CoreSettings.MONGODB_DATABASE) String mongoDBdatabase) {
     this.signerInfoStoreType = signerInfoStoreType;
     this.attachmentStoreType = attachmentStoreType;
     this.accountStoreType = accountStoreType;
     this.deltaStoreType = deltaStoreType;
+    this.mongoDBHost = mongoDBHost;
+    this.mongoDBPort = mongoDBPort;
+    this.mongoDBdatabase = mongoDBdatabase;
   }
 
   /**
@@ -77,7 +90,7 @@ public class PersistenceModule extends AbstractModule {
    */
   public MongoDbProvider getMongoDbProvider() {
     if (mongoDbProvider == null) {
-      mongoDbProvider = new MongoDbProvider();
+      mongoDbProvider = new MongoDbProvider(mongoDBHost, mongoDBPort, 
mongoDBdatabase);
     }
     return mongoDbProvider;
   }

http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/0858e0c6/src/org/waveprotocol/box/server/persistence/migration/DeltaMigrator.java
----------------------------------------------------------------------
diff --git 
a/src/org/waveprotocol/box/server/persistence/migration/DeltaMigrator.java 
b/src/org/waveprotocol/box/server/persistence/migration/DeltaMigrator.java
new file mode 100644
index 0000000..3b68937
--- /dev/null
+++ b/src/org/waveprotocol/box/server/persistence/migration/DeltaMigrator.java
@@ -0,0 +1,142 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.waveprotocol.box.server.persistence.migration;
+
+import com.google.common.collect.ImmutableSet;
+
+import org.waveprotocol.box.common.ExceptionalIterator;
+import org.waveprotocol.box.server.persistence.PersistenceException;
+import org.waveprotocol.box.server.waveserver.DeltaStore;
+import org.waveprotocol.box.server.waveserver.DeltaStore.DeltasAccess;
+import org.waveprotocol.box.server.waveserver.WaveletDeltaRecord;
+import org.waveprotocol.wave.model.id.WaveId;
+import org.waveprotocol.wave.model.id.WaveletId;
+import org.waveprotocol.wave.model.id.WaveletName;
+import org.waveprotocol.wave.model.version.HashedVersion;
+import org.waveprotocol.wave.util.logging.Log;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+/**
+ *
+ * An utility class to copy all deltas between storages. Already existing Waves
+ * in the target store wont be changed.
+ *
+ * It is NOT an incremental process.
+ *
+ * @author [email protected] (Pablo Ojanguren)
+ *
+ */
+public class DeltaMigrator {
+
+  private static final Log LOG = Log.get(DeltaMigrator.class);
+
+  protected DeltaStore sourceStore = null;
+  protected DeltaStore targetStore = null;
+
+
+  public DeltaMigrator(DeltaStore sourceStore, DeltaStore targetStore) {
+    this.sourceStore = sourceStore;
+    this.targetStore = targetStore;
+  }
+
+
+
+  public void run() {
+
+
+    LOG.info("Starting Wave migration from " + 
sourceStore.getClass().getSimpleName() + " to "
+        + targetStore.getClass().getSimpleName());
+
+    long startTime = System.currentTimeMillis();
+
+
+    try {
+
+      ExceptionalIterator<WaveId, PersistenceException> srcItr = 
sourceStore.getWaveIdIterator();
+
+      // Waves
+      while (srcItr.hasNext()) {
+
+        WaveId waveId = srcItr.next();
+
+        ImmutableSet<WaveletId> waveletIds = sourceStore.lookup(waveId);
+
+        if (!targetStore.lookup(waveId).isEmpty()) {
+          LOG.info("Skipping Wave because it's found in target store : " + 
waveId.toString());
+          continue;
+        }
+
+        LOG.info("Migrating Wave : " + waveId.toString() + " with " + 
waveletIds.size()
+            + " wavelets");
+
+        int waveletsTotal = waveletIds.size();
+        int waveletsCount = 0;
+
+        // Wavelets
+        for (WaveletId waveletId : waveletIds) {
+
+          waveletsCount++;
+
+          LOG.info("Migrating wavelet " + waveletsCount + "/" + waveletsTotal 
+ " : "
+              + waveletId.toString());
+
+          DeltasAccess sourceDeltas = sourceStore.open(WaveletName.of(waveId, 
waveletId));
+          DeltasAccess targetDeltas = targetStore.open(WaveletName.of(waveId, 
waveletId));
+
+          // Get all deltas from last version to initial version (0): reverse
+          // order
+          int deltasCount = 0;
+
+          ArrayList<WaveletDeltaRecord> deltas = new 
ArrayList<WaveletDeltaRecord>();
+          HashedVersion deltaResultingVersion = sourceDeltas.getEndVersion();
+
+          // Deltas
+          while (deltaResultingVersion != null && 
deltaResultingVersion.getVersion() != 0) {
+            deltasCount++;
+            WaveletDeltaRecord deltaRecord =
+                
sourceDeltas.getDeltaByEndVersion(deltaResultingVersion.getVersion());
+            deltas.add(deltaRecord);
+            // get the previous delta, this is the appliedAt
+            deltaResultingVersion = deltaRecord.getAppliedAtVersion();
+          }
+          LOG.info("Appending " + deltasCount + "deltas to target");
+          targetDeltas.append(deltas);
+        }
+      } // While Waves
+
+      long endTime = System.currentTimeMillis();
+
+      LOG.info("Migration completed. Total time = " + (endTime - startTime) + 
"ms");
+
+    } catch (PersistenceException e) {
+
+      throw new RuntimeException(e);
+
+    } catch (IOException e) {
+
+      throw new RuntimeException(e);
+
+    }
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/0858e0c6/src/org/waveprotocol/box/server/persistence/mongodb/MongoDbProvider.java
----------------------------------------------------------------------
diff --git 
a/src/org/waveprotocol/box/server/persistence/mongodb/MongoDbProvider.java 
b/src/org/waveprotocol/box/server/persistence/mongodb/MongoDbProvider.java
index 4e29077..8ff53ca 100644
--- a/src/org/waveprotocol/box/server/persistence/mongodb/MongoDbProvider.java
+++ b/src/org/waveprotocol/box/server/persistence/mongodb/MongoDbProvider.java
@@ -30,9 +30,7 @@ import com.mongodb.MongoException;
 import org.waveprotocol.box.server.persistence.PersistenceStartException;
 import org.waveprotocol.wave.util.logging.Log;
 
-import java.io.IOException;
 import java.net.UnknownHostException;
-import java.util.Properties;
 
 /**
  * Class to lazily setup and manage the MongoDb connection.
@@ -43,18 +41,11 @@ import java.util.Properties;
 public class MongoDbProvider {
   private static final Log LOG = Log.get(MongoDbProvider.class);
 
-  /** Location of the MongoDB properties file in the classpath. */
-  private static final String PROPERTIES_LOC =
-      "org/waveprotocol/box/server/persistence/mongodb/mongodb.properties";
+  private String dbHost;
 
-  /** Name of the property that stores the host. */
-  private static final String HOST_PROPERTY = "mongoDbHost";
+  private String dbPort;
 
-  /** Name of the property that stores the port. */
-  private static final String PORT_PROPERTY = "mongoDbPort";
-
-  /** Name of the property that stores the name of the database. */
-  private static final String DATABASE_NAME_PROPERTY = "mongoDbDatabase";
+  private String dbName;
 
   /**
    * Our {@link MongoClient} instance, should be accessed by getMongo unless 
during
@@ -63,11 +54,6 @@ public class MongoDbProvider {
   private Mongo mongo;
 
   /**
-   * Our lazily loaded {@link Properties} instance.
-   */
-  private Properties properties;
-
-  /**
    * Lazily instantiated {@link MongoDbStore}.
    */
   private MongoDbStore mongoDbStore;
@@ -83,7 +69,10 @@ public class MongoDbProvider {
   /**
    * Constructs a new empty {@link MongoDbProvider}.
    */
-  public MongoDbProvider() {
+  public MongoDbProvider(String dbHost, String dbPort, String dbName) {
+    this.dbHost = dbHost;
+    this.dbPort = dbPort;
+    this.dbName = dbName;
   }
 
   /**
@@ -95,10 +84,8 @@ public class MongoDbProvider {
   private void start() {
     Preconditions.checkState(!isRunning(), "Can't start after a connection has 
been established");
 
-    ensurePropertiesLoaded();
-
-    String host = properties.getProperty(HOST_PROPERTY);
-    int port = Integer.parseInt(properties.getProperty(PORT_PROPERTY));
+    String host = dbHost;
+    int port = Integer.parseInt(dbPort);
     try {
       // New MongoDB Client, see 
http://docs.mongodb.org/manual/release-notes/drivers-write-concern/
       mongo = new MongoClient(host, port);
@@ -108,7 +95,7 @@ public class MongoDbProvider {
 
     try {
       // Check to see if we are alive
-      mongo.getDB(getDatabaseName()).command("ping");
+      mongo.getDB(dbName).command("ping");
     } catch (MongoException e) {
       throw new PersistenceStartException("Can't ping MongoDb", e);
     }
@@ -117,39 +104,13 @@ public class MongoDbProvider {
     LOG.info("Started MongoDb persistence");
   }
 
-  /**
-   * Ensures that the properties for MongoDb are loaded.
-   *
-   * @throws PersistenceStartException if the properties can not be loaded.
-   */
-  private void ensurePropertiesLoaded() {
-    if (properties != null) {
-      // Already loaded
-      return;
-    }
-    Properties properties = new Properties();
-    try {
-      properties.load(ClassLoader.getSystemResourceAsStream(PROPERTIES_LOC));
-    } catch (IOException e) {
-      throw new PersistenceStartException("Unable to load Properties for 
MongoDb", e);
-    }
-    this.properties = properties;
-  }
 
   /**
    * Returns the {@link DB} with the name that is specified in the properties
    * file.
    */
   private DB getDatabase() {
-    return getDatabaseForName(getDatabaseName());
-  }
-
-  /**
-   * Returns the name of the database as specified in the properties file.
-   */
-  private String getDatabaseName() {
-    ensurePropertiesLoaded();
-    return properties.getProperty(DATABASE_NAME_PROPERTY);
+    return getDatabaseForName(dbName);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/0858e0c6/test/org/waveprotocol/box/server/persistence/mongodb/AccountStoreTest.java
----------------------------------------------------------------------
diff --git 
a/test/org/waveprotocol/box/server/persistence/mongodb/AccountStoreTest.java 
b/test/org/waveprotocol/box/server/persistence/mongodb/AccountStoreTest.java
index df79f79..368ed91 100644
--- a/test/org/waveprotocol/box/server/persistence/mongodb/AccountStoreTest.java
+++ b/test/org/waveprotocol/box/server/persistence/mongodb/AccountStoreTest.java
@@ -40,7 +40,7 @@ public class AccountStoreTest extends AccountStoreTestBase {
    * Initializes the MongoDB version of a {@link AccountStoreTestBase}.
    */
   public AccountStoreTest() throws Exception {
-    MongoDbProvider mongoDbProvider = new MongoDbProvider();
+    MongoDbProvider mongoDbProvider = new MongoDbProvider("127.0.0.1", 
"27017", "wiab_test");
     this.database = mongoDbProvider.getDatabaseForName(TEST_DATABASE);
     store = new MongoDbStore(database);
   }
@@ -50,7 +50,7 @@ public class AccountStoreTest extends AccountStoreTestBase {
     super.tearDown();
     database.dropDatabase();
   }
-  
+
   @Override
   protected AccountStore newAccountStore() {
     database.dropDatabase();

http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/0858e0c6/test/org/waveprotocol/box/server/persistence/mongodb/AttachmentStoreTest.java
----------------------------------------------------------------------
diff --git 
a/test/org/waveprotocol/box/server/persistence/mongodb/AttachmentStoreTest.java 
b/test/org/waveprotocol/box/server/persistence/mongodb/AttachmentStoreTest.java
index 46dd70b..6d111ae 100644
--- 
a/test/org/waveprotocol/box/server/persistence/mongodb/AttachmentStoreTest.java
+++ 
b/test/org/waveprotocol/box/server/persistence/mongodb/AttachmentStoreTest.java
@@ -38,7 +38,7 @@ public class AttachmentStoreTest extends 
AttachmentStoreTestBase {
    * Initializes the MongoDB version of a {@link AttachmentStoreTestBase}.
    */
   public AttachmentStoreTest() throws Exception {
-    MongoDbProvider mongoDbProvider = new MongoDbProvider();
+    MongoDbProvider mongoDbProvider = new MongoDbProvider("127.0.0.1", 
"27017", "wiab_test");
     this.database = mongoDbProvider.getDatabaseForName(TEST_DATABASE);
     store = new MongoDbStore(database);
   }
@@ -48,7 +48,7 @@ public class AttachmentStoreTest extends 
AttachmentStoreTestBase {
     super.tearDown();
     database.dropDatabase();
   }
-  
+
   @Override
   protected AttachmentStore newAttachmentStore() {
     database.dropDatabase();

http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/0858e0c6/test/org/waveprotocol/box/server/persistence/mongodb/CertPathStoreTest.java
----------------------------------------------------------------------
diff --git 
a/test/org/waveprotocol/box/server/persistence/mongodb/CertPathStoreTest.java 
b/test/org/waveprotocol/box/server/persistence/mongodb/CertPathStoreTest.java
index 62bcd74..631c6ad 100644
--- 
a/test/org/waveprotocol/box/server/persistence/mongodb/CertPathStoreTest.java
+++ 
b/test/org/waveprotocol/box/server/persistence/mongodb/CertPathStoreTest.java
@@ -42,7 +42,7 @@ public class CertPathStoreTest extends CertPathStoreTestBase {
    * Initializes the MongoDB version of a {@link CertPathStoreTestBase}.
    */
   public CertPathStoreTest() throws Exception {
-    MongoDbProvider mongoDbProvider = new MongoDbProvider();
+    MongoDbProvider mongoDbProvider = new MongoDbProvider("127.0.0.1", 
"27017", "wiab_test");
     this.database = mongoDbProvider.getDatabaseForName(TEST_DATABASE);
     certPathStore = new MongoDbStore(database);
   }

Reply via email to