aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [1/2] Implementing update history pruner.
Date Fri, 03 Oct 2014 18:17:19 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master de47abafe -> 9834b316a


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9834b316/src/test/java/org/apache/aurora/scheduler/updater/FakeScheduledExecutor.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/updater/FakeScheduledExecutor.java
b/src/test/java/org/apache/aurora/scheduler/updater/FakeScheduledExecutor.java
deleted file mode 100644
index e35fe23..0000000
--- a/src/test/java/org/apache/aurora/scheduler/updater/FakeScheduledExecutor.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * Licensed 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.apache.aurora.scheduler.updater;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Lists;
-import com.twitter.common.collections.Pair;
-import com.twitter.common.quantity.Amount;
-import com.twitter.common.quantity.Time;
-import com.twitter.common.util.testing.FakeClock;
-
-import org.easymock.EasyMock;
-import org.easymock.IAnswer;
-
-import static org.easymock.EasyMock.expectLastCall;
-import static org.junit.Assert.assertEquals;
-
-/**
- * A simulated scheduled executor that records scheduled work and executes it when the clock
is
- * advanced past their execution time.
- */
-class FakeScheduledExecutor extends FakeClock {
-
-  private final List<Pair<Long, Runnable>> deferredWork = Lists.newArrayList();
-
-  FakeScheduledExecutor(ScheduledExecutorService mock) {
-    mock.schedule(
-        EasyMock.<Runnable>anyObject(),
-        EasyMock.anyLong(),
-        EasyMock.eq(TimeUnit.MILLISECONDS));
-    expectLastCall().andAnswer(new IAnswer<ScheduledFuture<?>>() {
-      @Override
-      public ScheduledFuture<?> answer() {
-        Object[] args = EasyMock.getCurrentArguments();
-        Runnable work = (Runnable) args[0];
-        long millis = (Long) args[1];
-        Preconditions.checkArgument(millis > 0);
-        deferredWork.add(Pair.of(nowMillis() + millis, work));
-        return null;
-      }
-    }).anyTimes();
-  }
-
-  @Override
-  public void setNowMillis(long nowMillis) {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public void advance(Amount<Long, Time> period) {
-    super.advance(period);
-    Iterator<Pair<Long, Runnable>> entries = deferredWork.iterator();
-    List<Runnable> toExecute = Lists.newArrayList();
-    while (entries.hasNext()) {
-      Pair<Long, Runnable> next = entries.next();
-      if (next.getFirst() <= nowMillis()) {
-        entries.remove();
-        toExecute.add(next.getSecond());
-      }
-    }
-    for (Runnable work : toExecute) {
-      work.run();
-    }
-  }
-
-  void assertEmpty() {
-    assertEquals(ImmutableList.<Pair<Long, Runnable>>of(), deferredWork);
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9834b316/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java b/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
index 6758b7b..f739e6d 100644
--- a/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
@@ -90,6 +90,7 @@ import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
 import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
 import org.apache.aurora.scheduler.storage.mem.MemStorage.Delegated;
 import org.apache.aurora.scheduler.storage.mem.MemStorageModule;
+import org.apache.aurora.scheduler.testing.FakeScheduledExecutor;
 import org.easymock.EasyMock;
 import org.easymock.IExpectationSetters;
 import org.junit.After;
@@ -151,7 +152,7 @@ public class JobUpdaterIT extends EasyMockTest {
     // Avoid console spam due to stats registered multiple times.
     Stats.flush();
     final ScheduledExecutorService executor = createMock(ScheduledExecutorService.class);
-    clock = new FakeScheduledExecutor(executor);
+    clock = FakeScheduledExecutor.scheduleExecutor(executor);
     driver = createMock(Driver.class);
     eventBus = new EventBus();
 


Mime
View raw message