Return-Path: X-Original-To: apmail-aurora-commits-archive@minotaur.apache.org Delivered-To: apmail-aurora-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 57ECF17950 for ; Fri, 3 Oct 2014 18:17:41 +0000 (UTC) Received: (qmail 16420 invoked by uid 500); 3 Oct 2014 18:17:41 -0000 Delivered-To: apmail-aurora-commits-archive@aurora.apache.org Received: (qmail 16393 invoked by uid 500); 3 Oct 2014 18:17:41 -0000 Mailing-List: contact commits-help@aurora.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aurora.incubator.apache.org Delivered-To: mailing list commits@aurora.incubator.apache.org Received: (qmail 16384 invoked by uid 99); 3 Oct 2014 18:17:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Oct 2014 18:17:41 +0000 X-ASF-Spam-Status: No, hits=-2000.6 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 03 Oct 2014 18:17:39 +0000 Received: (qmail 10749 invoked by uid 99); 3 Oct 2014 18:17:19 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Oct 2014 18:17:19 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 869D1A1FB1A; Fri, 3 Oct 2014 18:17:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: maxim@apache.org To: commits@aurora.incubator.apache.org Date: Fri, 03 Oct 2014 18:17:19 -0000 Message-Id: <7e7846067d834856beb1e326b7486e0b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] Implementing update history pruner. X-Virus-Checked: Checked by ClamAV on apache.org 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> deferredWork = Lists.newArrayList(); - - FakeScheduledExecutor(ScheduledExecutorService mock) { - mock.schedule( - EasyMock.anyObject(), - EasyMock.anyLong(), - EasyMock.eq(TimeUnit.MILLISECONDS)); - expectLastCall().andAnswer(new IAnswer>() { - @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 period) { - super.advance(period); - Iterator> entries = deferredWork.iterator(); - List toExecute = Lists.newArrayList(); - while (entries.hasNext()) { - Pair next = entries.next(); - if (next.getFirst() <= nowMillis()) { - entries.remove(); - toExecute.add(next.getSecond()); - } - } - for (Runnable work : toExecute) { - work.run(); - } - } - - void assertEmpty() { - assertEquals(ImmutableList.>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();