aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject aurora git commit: Enabling TemporaryStorage to use flagged task store.
Date Thu, 28 May 2015 16:16:19 GMT
Repository: aurora
Updated Branches:
  refs/heads/master 572409967 -> 13ac06ab8


Enabling TemporaryStorage to use flagged task store.

Bugs closed: AURORA-1322

Reviewed at https://reviews.apache.org/r/34501/


Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/13ac06ab
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/13ac06ab
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/13ac06ab

Branch: refs/heads/master
Commit: 13ac06ab8f7a96461f5720fc0b9c2d3b5859f0ef
Parents: 5724099
Author: Maxim Khutornenko <maxim@apache.org>
Authored: Thu May 28 09:13:20 2015 -0700
Committer: Maxim Khutornenko <maxim@apache.org>
Committed: Thu May 28 09:13:20 2015 -0700

----------------------------------------------------------------------
 .../aurora/benchmark/SnapshotBenchmarks.java    |  3 +-
 .../aurora/benchmark/UpdateStoreBenchmarks.java | 20 ++---------
 .../storage/backup/TemporaryStorage.java        |  2 +-
 .../aurora/scheduler/storage/db/DbModule.java   | 36 +++++++-------------
 .../aurora/scheduler/storage/db/DbUtil.java     | 27 +++++++++++----
 .../storage/db/DbJobUpdateStoreTest.java        |  2 +-
 .../storage/mem/InMemTaskStoreTest.java         |  6 ++--
 7 files changed, 44 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/13ac06ab/src/jmh/java/org/apache/aurora/benchmark/SnapshotBenchmarks.java
----------------------------------------------------------------------
diff --git a/src/jmh/java/org/apache/aurora/benchmark/SnapshotBenchmarks.java b/src/jmh/java/org/apache/aurora/benchmark/SnapshotBenchmarks.java
index 03dd5d9..2bb1768 100644
--- a/src/jmh/java/org/apache/aurora/benchmark/SnapshotBenchmarks.java
+++ b/src/jmh/java/org/apache/aurora/benchmark/SnapshotBenchmarks.java
@@ -19,6 +19,7 @@ import java.util.concurrent.TimeUnit;
 
 import javax.inject.Singleton;
 
+import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableSet;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
@@ -100,7 +101,7 @@ public class SnapshotBenchmarks {
             bind(SnapshotStoreImpl.class).in(Singleton.class);
           }
         },
-        DbModule.testModule(new DbModule.TaskStoreModule(keyFactory), keyFactory));
+        DbModule.testModule(keyFactory, Optional.of(new DbModule.TaskStoreModule(keyFactory))));
 
     Storage storage = injector.getInstance(Key.get(Storage.class, Storage.Volatile.class));
     storage.prepare();

http://git-wip-us.apache.org/repos/asf/aurora/blob/13ac06ab/src/jmh/java/org/apache/aurora/benchmark/UpdateStoreBenchmarks.java
----------------------------------------------------------------------
diff --git a/src/jmh/java/org/apache/aurora/benchmark/UpdateStoreBenchmarks.java b/src/jmh/java/org/apache/aurora/benchmark/UpdateStoreBenchmarks.java
index f361caa..cc42741 100644
--- a/src/jmh/java/org/apache/aurora/benchmark/UpdateStoreBenchmarks.java
+++ b/src/jmh/java/org/apache/aurora/benchmark/UpdateStoreBenchmarks.java
@@ -20,18 +20,12 @@ import java.util.concurrent.TimeUnit;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.twitter.common.stats.StatsProvider;
-import com.twitter.common.util.Clock;
 
-import org.apache.aurora.benchmark.fakes.FakeStatsProvider;
 import org.apache.aurora.gen.Lock;
 import org.apache.aurora.gen.LockKey;
 import org.apache.aurora.scheduler.storage.JobUpdateStore;
 import org.apache.aurora.scheduler.storage.Storage;
-import org.apache.aurora.scheduler.storage.db.DbModule;
+import org.apache.aurora.scheduler.storage.db.DbUtil;
 import org.apache.aurora.scheduler.storage.entities.IJobInstanceUpdateEvent;
 import org.apache.aurora.scheduler.storage.entities.IJobUpdateDetails;
 import org.apache.aurora.scheduler.storage.entities.IJobUpdateEvent;
@@ -70,17 +64,7 @@ public class UpdateStoreBenchmarks {
 
     @Setup(Level.Trial)
     public void setUp() {
-      Injector injector = Guice.createInjector(
-          new AbstractModule() {
-            @Override
-            protected void configure() {
-              bind(Clock.class).toInstance(Clock.SYSTEM_CLOCK);
-              bind(StatsProvider.class).toInstance(new FakeStatsProvider());
-            }
-          },
-          DbModule.testModule());
-      storage = injector.getInstance(Storage.class);
-      storage.prepare();
+      storage = DbUtil.createStorage();
     }
 
     @Setup(Level.Iteration)

http://git-wip-us.apache.org/repos/asf/aurora/blob/13ac06ab/src/main/java/org/apache/aurora/scheduler/storage/backup/TemporaryStorage.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/backup/TemporaryStorage.java
b/src/main/java/org/apache/aurora/scheduler/storage/backup/TemporaryStorage.java
index 23c0c1e..d0156d3 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/backup/TemporaryStorage.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/backup/TemporaryStorage.java
@@ -66,7 +66,7 @@ interface TemporaryStorage {
   class TemporaryStorageFactory implements Function<Snapshot, TemporaryStorage> {
     @Override
     public TemporaryStorage apply(Snapshot snapshot) {
-      final Storage storage = DbUtil.createStorage();
+      final Storage storage = DbUtil.createFlaggedStorage();
       FakeClock clock = new FakeClock();
       clock.setNowMillis(snapshot.getTimestamp());
       final SnapshotStore<Snapshot> snapshotStore = new SnapshotStoreImpl(clock, storage);

http://git-wip-us.apache.org/repos/asf/aurora/blob/13ac06ab/src/main/java/org/apache/aurora/scheduler/storage/db/DbModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/DbModule.java b/src/main/java/org/apache/aurora/scheduler/storage/db/DbModule.java
index 436d384..2dc3034 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/DbModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/DbModule.java
@@ -19,6 +19,7 @@ import java.util.UUID;
 import javax.inject.Singleton;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.inject.Key;
@@ -99,27 +100,22 @@ public final class DbModule extends PrivateModule {
    * @return A new database module for production.
    */
   public static Module productionModule(KeyFactory keyFactory) {
-    return new DbModule(
-        keyFactory,
-        USE_DB_TASK_STORE.get()
-            ? new TaskStoreModule(keyFactory)
-            : new InMemStoresModule.TaskStoreModule(keyFactory),
-        "aurora;DB_CLOSE_DELAY=-1");
+    return new DbModule(keyFactory, getTaskStoreModule(keyFactory), "aurora;DB_CLOSE_DELAY=-1");
   }
 
   /**
    * Creates a module that will prepare a private in-memory database, using a specific task
store
-   * implementation bound within the provided module and a key factory.
+   * implementation bound within the key factory and provided module.
    *
-   * @param taskStoreModule Module providing task store bindings.
    * @param keyFactory Key factory to use.
+   * @param taskStoreModule Module providing task store bindings.
    * @return A new database module for testing.
    */
   @VisibleForTesting
-  public static Module testModule(Module taskStoreModule, KeyFactory keyFactory) {
+  public static Module testModule(KeyFactory keyFactory, Optional<Module> taskStoreModule)
{
     return new DbModule(
         keyFactory,
-        taskStoreModule,
+        taskStoreModule.isPresent() ? taskStoreModule.get() : getTaskStoreModule(keyFactory),
         // A non-zero close delay is used here to avoid eager database cleanup in tests that
         // make use of multiple threads.  Since all test databases are separately scoped
by the
         // included UUID, multiple DB instances will overlap in time but they should be distinct
@@ -128,25 +124,19 @@ public final class DbModule extends PrivateModule {
   }
 
   /**
-   * Creates a module that will prepare a private in-memory database using specific task
store
-   * module.
+   * Same as {@link #testModule(KeyFactory, Optional)} but with default task store and key
factory.
    *
-   * @param taskStoreModule Module providing task store bindings.
    * @return A new database module for testing.
    */
   @VisibleForTesting
-  public static Module testModule(Module taskStoreModule) {
-    return testModule(taskStoreModule, KeyFactory.PLAIN);
+  public static Module testModule() {
+    return testModule(KeyFactory.PLAIN, Optional.of(new TaskStoreModule(KeyFactory.PLAIN)));
   }
 
-  /**
-   * Creates a module that will prepare a private in-memory database.
-   *
-   * @return A new database module for testing.
-   */
-  @VisibleForTesting
-  public static Module testModule() {
-    return testModule(new DbModule.TaskStoreModule(KeyFactory.PLAIN));
+  private static Module getTaskStoreModule(KeyFactory keyFactory) {
+    return USE_DB_TASK_STORE.get()
+        ? new TaskStoreModule(keyFactory)
+        : new InMemStoresModule.TaskStoreModule(keyFactory);
   }
 
   private <T> void bindStore(Class<T> binding, Class<? extends T> impl)
{

http://git-wip-us.apache.org/repos/asf/aurora/blob/13ac06ab/src/main/java/org/apache/aurora/scheduler/storage/db/DbUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/DbUtil.java b/src/main/java/org/apache/aurora/scheduler/storage/db/DbUtil.java
index fe8e3f8..3a86614 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/DbUtil.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/DbUtil.java
@@ -13,9 +13,11 @@
  */
 package org.apache.aurora.scheduler.storage.db;
 
+import com.google.common.base.Optional;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
+import com.google.inject.Module;
 import com.twitter.common.stats.StatsProvider;
 import com.twitter.common.util.Clock;
 import com.twitter.common.util.testing.FakeClock;
@@ -23,6 +25,10 @@ import com.twitter.common.util.testing.FakeClock;
 import org.apache.aurora.scheduler.storage.Storage;
 import org.apache.aurora.scheduler.testing.FakeStatsProvider;
 
+import static com.twitter.common.inject.Bindings.KeyFactory.PLAIN;
+
+import static org.apache.aurora.scheduler.storage.db.DbModule.testModule;
+
 /**
  * Utility class for creating ad-hoc storage instances.
  */
@@ -33,14 +39,14 @@ public final class DbUtil {
   }
 
   /**
-   * Creates a new, empty storage system.  Identical to {@link #createStorage()}, except
this
-   * returns the {@link Injector} that has bindings for the new storage.
+   * Creates a new, empty storage system with bindings for the new storage.
    *
+   * @param dbModule {@link DbModule} to install.
    * @return An injector with bindings necessary for a storage system.
    */
-  public static Injector createStorageInjector() {
+  public static Injector createStorageInjector(Module dbModule) {
     Injector injector = Guice.createInjector(
-        DbModule.testModule(),
+        dbModule,
         new AbstractModule() {
           @Override
           protected void configure() {
@@ -56,11 +62,20 @@ public final class DbUtil {
   }
 
   /**
-   * Creates a new, empty storage system.
+   * Creates a new, empty test storage system.
    *
    * @return A new storage instance.
    */
   public static Storage createStorage() {
-    return createStorageInjector().getInstance(Storage.class);
+    return createStorageInjector(testModule()).getInstance(Storage.class);
+  }
+
+  /**
+   * Creates a new, empty storage system with a task store defined by the command line flag.
+   *
+   * @return A new storage instance.
+   */
+  public static Storage createFlaggedStorage() {
+    return createStorageInjector(testModule(PLAIN, Optional.absent())).getInstance(Storage.class);
   }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/13ac06ab/src/test/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStoreTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStoreTest.java
index 177d720..d1d7e79 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStoreTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/db/DbJobUpdateStoreTest.java
@@ -98,7 +98,7 @@ public class DbJobUpdateStoreTest {
 
   @Before
   public void setUp() throws Exception {
-    Injector injector = DbUtil.createStorageInjector();
+    Injector injector = DbUtil.createStorageInjector(DbModule.testModule());
     storage = injector.getInstance(Storage.class);
     stats = injector.getInstance(FakeStatsProvider.class);
   }

http://git-wip-us.apache.org/repos/asf/aurora/blob/13ac06ab/src/test/java/org/apache/aurora/scheduler/storage/mem/InMemTaskStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/mem/InMemTaskStoreTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/mem/InMemTaskStoreTest.java
index 999d5e8..2ed7483 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/mem/InMemTaskStoreTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/mem/InMemTaskStoreTest.java
@@ -13,11 +13,11 @@
  */
 package org.apache.aurora.scheduler.storage.mem;
 
+import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableSet;
 import com.google.inject.AbstractModule;
 import com.google.inject.Module;
 import com.google.inject.util.Modules;
-import com.twitter.common.inject.Bindings.KeyFactory;
 import com.twitter.common.stats.StatsProvider;
 
 import org.apache.aurora.scheduler.base.Tasks;
@@ -28,6 +28,8 @@ import org.apache.aurora.scheduler.storage.db.DbModule;
 import org.apache.aurora.scheduler.testing.FakeStatsProvider;
 import org.junit.Test;
 
+import static com.twitter.common.inject.Bindings.KeyFactory.PLAIN;
+
 import static org.junit.Assert.assertEquals;
 
 public class InMemTaskStoreTest extends AbstractTaskStoreTest {
@@ -38,7 +40,7 @@ public class InMemTaskStoreTest extends AbstractTaskStoreTest {
   protected Module getStorageModule() {
     statsProvider = new FakeStatsProvider();
     return Modules.combine(
-        DbModule.testModule(new InMemStoresModule.TaskStoreModule(KeyFactory.PLAIN)),
+        DbModule.testModule(PLAIN, Optional.of(new InMemStoresModule.TaskStoreModule(PLAIN))),
         new AbstractModule() {
           @Override
           protected void configure() {


Mime
View raw message