You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by wf...@apache.org on 2014/10/30 01:45:32 UTC

git commit: Add explicit test coverage for stat gauge in TaskSchedulerImpl.

Repository: incubator-aurora
Updated Branches:
  refs/heads/master 6b30cf72f -> 0f63e8fc4


Add explicit test coverage for stat gauge in TaskSchedulerImpl.

Bugs closed: AURORA-884

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


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

Branch: refs/heads/master
Commit: 0f63e8fc47d4ffeac737d4dea2566e2f5010fef1
Parents: 6b30cf7
Author: Bill Farner <wf...@apache.org>
Authored: Wed Oct 29 17:45:04 2014 -0700
Committer: Bill Farner <wf...@apache.org>
Committed: Wed Oct 29 17:45:04 2014 -0700

----------------------------------------------------------------------
 .../aurora/scheduler/async/TaskScheduler.java   | 29 +++++++++++++-------
 .../scheduler/async/TaskSchedulerImplTest.java  |  3 ++
 .../scheduler/async/TaskSchedulerTest.java      | 15 +++++++++-
 3 files changed, 36 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0f63e8fc/src/main/java/org/apache/aurora/scheduler/async/TaskScheduler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/async/TaskScheduler.java b/src/main/java/org/apache/aurora/scheduler/async/TaskScheduler.java
index 5739c39..b23457e 100644
--- a/src/main/java/org/apache/aurora/scheduler/async/TaskScheduler.java
+++ b/src/main/java/org/apache/aurora/scheduler/async/TaskScheduler.java
@@ -37,8 +37,8 @@ import com.google.common.eventbus.Subscribe;
 import com.twitter.common.inject.TimedInterceptor.Timed;
 import com.twitter.common.quantity.Amount;
 import com.twitter.common.quantity.Time;
-import com.twitter.common.stats.StatImpl;
 import com.twitter.common.stats.Stats;
+import com.twitter.common.stats.StatsProvider;
 import com.twitter.common.util.Clock;
 
 import org.apache.aurora.scheduler.base.Query;
@@ -116,14 +116,15 @@ public interface TaskScheduler extends EventSubscriber {
         OfferQueue offerQueue,
         Preemptor preemptor,
         @ReservationDuration Amount<Long, Time> reservationDuration,
-        final Clock clock) {
+        final Clock clock,
+        StatsProvider statsProvider) {
 
       this.storage = requireNonNull(storage);
       this.stateManager = requireNonNull(stateManager);
       this.assigner = requireNonNull(assigner);
       this.offerQueue = requireNonNull(offerQueue);
       this.preemptor = requireNonNull(preemptor);
-      this.reservations = new Reservations(reservationDuration, clock);
+      this.reservations = new Reservations(statsProvider, reservationDuration, clock);
     }
 
     private Function<HostOffer, Optional<TaskInfo>> getAssignerFunction(
@@ -241,10 +242,16 @@ public interface TaskScheduler extends EventSubscriber {
       }
     }
 
+    @VisibleForTesting
+    static final String RESERVATIONS_CACHE_SIZE_STAT = "reservation_cache_size";
+
     private static class Reservations {
       private final Cache<SlaveID, String> reservations;
 
-      Reservations(final Amount<Long, Time> duration, final Clock clock) {
+      Reservations(
+          StatsProvider statsProvider,
+          Amount<Long, Time> duration,
+          final Clock clock) {
         requireNonNull(duration);
         requireNonNull(clock);
         this.reservations = CacheBuilder.newBuilder()
@@ -256,12 +263,14 @@ public interface TaskScheduler extends EventSubscriber {
               }
             })
             .build();
-        Stats.export(new StatImpl<Long>("reservation_cache_size") {
-          @Override
-          public Long read() {
-            return reservations.size();
-          }
-        });
+        statsProvider.makeGauge(
+            RESERVATIONS_CACHE_SIZE_STAT,
+            new Supplier<Long>() {
+              @Override
+              public Long get() {
+                return reservations.size();
+              }
+            });
       }
 
       private synchronized void add(SlaveID slaveId, String taskId) {

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0f63e8fc/src/test/java/org/apache/aurora/scheduler/async/TaskSchedulerImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/async/TaskSchedulerImplTest.java b/src/test/java/org/apache/aurora/scheduler/async/TaskSchedulerImplTest.java
index 5d12df9..2f52510 100644
--- a/src/test/java/org/apache/aurora/scheduler/async/TaskSchedulerImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/async/TaskSchedulerImplTest.java
@@ -22,6 +22,8 @@ import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.twitter.common.quantity.Amount;
 import com.twitter.common.quantity.Time;
+import com.twitter.common.stats.Stats;
+import com.twitter.common.stats.StatsProvider;
 import com.twitter.common.testing.easymock.EasyMockTest;
 import com.twitter.common.util.Clock;
 import com.twitter.common.util.testing.FakeClock;
@@ -113,6 +115,7 @@ public class TaskSchedulerImplTest extends EasyMockTest {
         bind(TaskAssigner.class).toInstance(assigner);
         bind(Clock.class).toInstance(clock);
         bind(Storage.class).toInstance(storageImpl);
+        bind(StatsProvider.class).toInstance(Stats.STATS_PROVIDER);
       }
     });
   }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0f63e8fc/src/test/java/org/apache/aurora/scheduler/async/TaskSchedulerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/async/TaskSchedulerTest.java b/src/test/java/org/apache/aurora/scheduler/async/TaskSchedulerTest.java
index fe57375..1caaf14 100644
--- a/src/test/java/org/apache/aurora/scheduler/async/TaskSchedulerTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/async/TaskSchedulerTest.java
@@ -19,12 +19,15 @@ import java.util.concurrent.TimeUnit;
 
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
+import com.google.common.base.Supplier;
 import com.google.common.base.Suppliers;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.util.concurrent.RateLimiter;
 import com.twitter.common.quantity.Amount;
 import com.twitter.common.quantity.Time;
+import com.twitter.common.stats.Stat;
+import com.twitter.common.stats.StatsProvider;
 import com.twitter.common.testing.easymock.EasyMockTest;
 import com.twitter.common.util.BackoffStrategy;
 import com.twitter.common.util.testing.FakeClock;
@@ -111,6 +114,7 @@ public class TaskSchedulerTest extends EasyMockTest {
   private OfferQueue offerQueue;
   private TaskGroups taskGroups;
   private FakeClock clock;
+  private StatsProvider statsProvider;
   private RescheduleCalculator rescheduleCalculator;
   private Preemptor preemptor;
   private AttributeAggregate emptyJob;
@@ -129,6 +133,7 @@ public class TaskSchedulerTest extends EasyMockTest {
     returnDelay = createMock(OfferReturnDelay.class);
     clock = new FakeClock();
     clock.setNowMillis(0);
+    statsProvider = createMock(StatsProvider.class);
     rescheduleCalculator = createMock(RescheduleCalculator.class);
     preemptor = createMock(Preemptor.class);
     emptyJob = new AttributeAggregate(
@@ -137,6 +142,12 @@ public class TaskSchedulerTest extends EasyMockTest {
   }
 
   private void replayAndCreateScheduler() {
+    Capture<Supplier<Long>> cacheSizeSupplier = createCapture();
+    Stat<Long> stat = createMock(new Clazz<Stat<Long>>() { });
+    expect(statsProvider.makeGauge(
+        EasyMock.eq(TaskSchedulerImpl.RESERVATIONS_CACHE_SIZE_STAT),
+        capture(cacheSizeSupplier))).andReturn(stat);
+
     control.replay();
     offerQueue = new OfferQueueImpl(driver, returnDelay, executor, maintenance);
     TaskScheduler scheduler = new TaskSchedulerImpl(storage,
@@ -145,7 +156,8 @@ public class TaskSchedulerTest extends EasyMockTest {
         offerQueue,
         preemptor,
         reservationDuration,
-        clock);
+        clock,
+        statsProvider);
     taskGroups = new TaskGroups(
         executor,
         Amount.of(FIRST_SCHEDULE_DELAY_MS, Time.MILLISECONDS),
@@ -153,6 +165,7 @@ public class TaskSchedulerTest extends EasyMockTest {
         RateLimiter.create(100),
         scheduler,
         rescheduleCalculator);
+    assertEquals(0L, (long) cacheSizeSupplier.getValue().get());
   }
 
   private Capture<Runnable> expectOffer() {