aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject [1/2] Replace StorageStarted event with TaskStateChange events.
Date Sat, 04 Jan 2014 01:14:33 GMT
Updated Branches:
  refs/heads/master 9f3558645 -> d0b46fc3b


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d0b46fc3/src/test/java/org/apache/aurora/scheduler/events/NotifyingSchedulingFilterTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/events/NotifyingSchedulingFilterTest.java
b/src/test/java/org/apache/aurora/scheduler/events/NotifyingSchedulingFilterTest.java
index ea6d342..c5379fe 100644
--- a/src/test/java/org/apache/aurora/scheduler/events/NotifyingSchedulingFilterTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/events/NotifyingSchedulingFilterTest.java
@@ -18,7 +18,6 @@ package org.apache.aurora.scheduler.events;
 import java.util.Set;
 
 import com.google.common.collect.ImmutableSet;
-import com.twitter.common.base.Closure;
 import com.twitter.common.testing.easymock.EasyMockTest;
 
 import org.apache.aurora.gen.TaskConfig;
@@ -48,13 +47,13 @@ public class NotifyingSchedulingFilterTest extends EasyMockTest {
 
   private SchedulingFilter filter;
 
-  private Closure<PubsubEvent> eventSink;
+  private EventSink eventSink;
   private SchedulingFilter delegate;
 
   @Before
   public void setUp() {
     delegate = createMock(SchedulingFilter.class);
-    eventSink = createMock(new Clazz<Closure<PubsubEvent>>() { });
+    eventSink = createMock(EventSink.class);
     filter = new NotifyingSchedulingFilter(delegate, eventSink);
   }
 
@@ -62,7 +61,7 @@ public class NotifyingSchedulingFilterTest extends EasyMockTest {
   public void testEvents() {
     Set<Veto> vetoes = ImmutableSet.of(VETO_1, VETO_2);
     expect(delegate.filter(TASK_RESOURCES, SLAVE, TASK, TASK_ID)).andReturn(vetoes);
-    eventSink.execute(new Vetoed(TASK_ID, vetoes));
+    eventSink.post(new Vetoed(TASK_ID, vetoes));
 
     control.replay();
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d0b46fc3/src/test/java/org/apache/aurora/scheduler/metadata/NearestFitTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/metadata/NearestFitTest.java b/src/test/java/org/apache/aurora/scheduler/metadata/NearestFitTest.java
index 67d909f..b770a7a 100644
--- a/src/test/java/org/apache/aurora/scheduler/metadata/NearestFitTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/metadata/NearestFitTest.java
@@ -107,7 +107,7 @@ public class NearestFitTest {
     IScheduledTask task = IScheduledTask.build(new ScheduledTask()
         .setStatus(ScheduleStatus.ASSIGNED)
         .setAssignedTask(new AssignedTask().setTaskId(TASK)));
-    nearest.stateChanged(new TaskStateChange(task, ScheduleStatus.PENDING));
+    nearest.stateChanged(TaskStateChange.transition(task, ScheduleStatus.PENDING));
     assertNearest();
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d0b46fc3/src/test/java/org/apache/aurora/scheduler/state/BaseSchedulerCoreImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/state/BaseSchedulerCoreImplTest.java
b/src/test/java/org/apache/aurora/scheduler/state/BaseSchedulerCoreImplTest.java
index fcd1e26..720d0c8 100644
--- a/src/test/java/org/apache/aurora/scheduler/state/BaseSchedulerCoreImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/state/BaseSchedulerCoreImplTest.java
@@ -39,7 +39,6 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.Range;
 import com.google.common.collect.Sets;
 import com.twitter.common.application.ShutdownRegistry;
-import com.twitter.common.base.Closure;
 import com.twitter.common.collections.Pair;
 import com.twitter.common.testing.easymock.EasyMockTest;
 import com.twitter.common.util.testing.FakeClock;
@@ -68,6 +67,7 @@ import org.apache.aurora.scheduler.configuration.ConfigurationManager;
 import org.apache.aurora.scheduler.configuration.ConfigurationManager.TaskDescriptionException;
 import org.apache.aurora.scheduler.configuration.SanitizedConfiguration;
 import org.apache.aurora.scheduler.cron.CronScheduler;
+import org.apache.aurora.scheduler.events.EventSink;
 import org.apache.aurora.scheduler.events.PubsubEvent;
 import org.apache.aurora.scheduler.state.JobFilter.JobFilterResult;
 import org.apache.aurora.scheduler.storage.Storage;
@@ -136,7 +136,7 @@ public abstract class BaseSchedulerCoreImplTest extends EasyMockTest {
   private CronScheduler cronScheduler;
   private CronJobManager cron;
   private FakeClock clock;
-  private Closure<PubsubEvent> eventSink;
+  private EventSink eventSink;
   private ShutdownRegistry shutdownRegistry;
   private JobFilter jobFilter;
 
@@ -152,8 +152,8 @@ public abstract class BaseSchedulerCoreImplTest extends EasyMockTest {
   public void setUp() throws Exception {
     driver = createMock(Driver.class);
     clock = new FakeClock();
-    eventSink = createMock(new Clazz<Closure<PubsubEvent>>() { });
-    eventSink.execute(EasyMock.<PubsubEvent>anyObject());
+    eventSink = createMock(EventSink.class);
+    eventSink.post(EasyMock.<PubsubEvent>anyObject());
     cronScheduler = createMock(CronScheduler.class);
     shutdownRegistry = createMock(ShutdownRegistry.class);
     jobFilter = createMock(JobFilter.class);

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d0b46fc3/src/test/java/org/apache/aurora/scheduler/state/CronJobManagerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/state/CronJobManagerTest.java b/src/test/java/org/apache/aurora/scheduler/state/CronJobManagerTest.java
index a442549..c679123 100644
--- a/src/test/java/org/apache/aurora/scheduler/state/CronJobManagerTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/state/CronJobManagerTest.java
@@ -25,7 +25,6 @@ import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.twitter.common.application.ShutdownRegistry;
-import com.twitter.common.base.Closure;
 import com.twitter.common.base.ExceptionalCommand;
 import com.twitter.common.testing.easymock.EasyMockTest;
 
@@ -41,8 +40,8 @@ import org.apache.aurora.scheduler.base.Query;
 import org.apache.aurora.scheduler.base.ScheduleException;
 import org.apache.aurora.scheduler.configuration.SanitizedConfiguration;
 import org.apache.aurora.scheduler.cron.CronScheduler;
-import org.apache.aurora.scheduler.events.PubsubEvent;
-import org.apache.aurora.scheduler.events.PubsubEvent.StorageStarted;
+import org.apache.aurora.scheduler.events.EventSink;
+import org.apache.aurora.scheduler.events.PubsubEvent.SchedulerActive;
 import org.apache.aurora.scheduler.storage.Storage;
 import org.apache.aurora.scheduler.storage.entities.IJobConfiguration;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
@@ -145,8 +144,8 @@ public class CronJobManagerTest extends EasyMockTest {
       }
     });
     cron = injector.getInstance(CronJobManager.class);
-    Closure<PubsubEvent> eventSink = PubsubTestUtil.startPubsub(injector);
-    eventSink.execute(new StorageStarted());
+    EventSink eventSink = PubsubTestUtil.startPubsub(injector);
+    eventSink.post(new SchedulerActive());
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d0b46fc3/src/test/java/org/apache/aurora/scheduler/state/MaintenanceControllerImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/state/MaintenanceControllerImplTest.java
b/src/test/java/org/apache/aurora/scheduler/state/MaintenanceControllerImplTest.java
index 3561ce3..c0addd6 100644
--- a/src/test/java/org/apache/aurora/scheduler/state/MaintenanceControllerImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/state/MaintenanceControllerImplTest.java
@@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableSet;
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.twitter.common.base.Closure;
 import com.twitter.common.testing.easymock.EasyMockTest;
 
 import org.apache.aurora.gen.AssignedTask;
@@ -34,8 +33,8 @@ import org.apache.aurora.gen.ScheduleStatus;
 import org.apache.aurora.gen.ScheduledTask;
 import org.apache.aurora.gen.TaskConfig;
 import org.apache.aurora.scheduler.base.Query;
+import org.apache.aurora.scheduler.events.EventSink;
 import org.apache.aurora.scheduler.events.PubsubEvent;
-import org.apache.aurora.scheduler.events.PubsubEvent.StorageStarted;
 import org.apache.aurora.scheduler.events.PubsubEvent.TaskStateChange;
 import org.apache.aurora.scheduler.storage.Storage;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
@@ -62,7 +61,7 @@ public class MaintenanceControllerImplTest extends EasyMockTest {
   private StorageTestUtil storageUtil;
   private StateManager stateManager;
   private MaintenanceController maintenance;
-  private Closure<PubsubEvent> eventSink;
+  private EventSink eventSink;
 
   @Before
   public void setUp() throws Exception {
@@ -119,7 +118,8 @@ public class MaintenanceControllerImplTest extends EasyMockTest {
 
     assertStatus(HOST_A, SCHEDULED, maintenance.startMaintenance(A));
     assertStatus(HOST_A, DRAINING, maintenance.drain(A));
-    eventSink.execute(new TaskStateChange(IScheduledTask.build(task.setStatus(FINISHED)),
RUNNING));
+    eventSink.post(
+        TaskStateChange.transition(IScheduledTask.build(task.setStatus(FINISHED)), RUNNING));
     assertStatus(HOST_A, NONE, maintenance.endMaintenance(A));
   }
 
@@ -162,36 +162,11 @@ public class MaintenanceControllerImplTest extends EasyMockTest {
 
     // Make sure a later transition on the host does not cause any ill effects that could
surface
     // from stale internal state.
-    eventSink.execute(new TaskStateChange(
+    eventSink.post(TaskStateChange.transition(
         IScheduledTask.build(makeTask(HOST_A, "taskA").setStatus(FINISHED)), RUNNING));
   }
 
   @Test
-  public void testStorageStart() {
-    ScheduledTask taskA = makeTask(HOST_A, "taskA").setStatus(ScheduleStatus.RESTARTING);
-
-    expect(storageUtil.attributeStore.getHostAttributes())
-        .andReturn(ImmutableSet.of(
-            new HostAttributes().setHost(HOST_A).setMode(DRAINING),
-            new HostAttributes().setHost(HOST_B).setMode(DRAINING)));
-    expectFetchTasksByHost(HOST_A, ImmutableSet.of(taskA));
-    expectFetchTasksByHost(HOST_B, ImmutableSet.<ScheduledTask>of());
-    expectMaintenanceModeChange(HOST_B, DRAINED);
-    expectMaintenanceModeChange(HOST_A, DRAINING);
-    expect(storageUtil.attributeStore.getHostAttributes(HOST_A))
-        .andReturn(Optional.of(new HostAttributes().setHost(HOST_A).setMode(DRAINING)));
-    // TaskA is FINISHED and therefore no longer active
-    expectFetchTasksByHost(HOST_A, ImmutableSet.<ScheduledTask>of());
-    expectMaintenanceModeChange(HOST_A, DRAINED);
-
-    control.replay();
-
-    eventSink.execute(new StorageStarted());
-    eventSink.execute(
-        new TaskStateChange(IScheduledTask.build(taskA.setStatus(FINISHED)), RUNNING));
-  }
-
-  @Test
   public void testGetMode() {
     expect(storageUtil.attributeStore.getHostAttributes(HOST_A))
         .andReturn(Optional.of(new HostAttributes().setHost(HOST_A).setMode(DRAINING)));
@@ -211,7 +186,7 @@ public class MaintenanceControllerImplTest extends EasyMockTest {
 
   private void expectMaintenanceModeChange(String hostName, MaintenanceMode mode) {
     expect(storageUtil.attributeStore.setMaintenanceMode(hostName, mode)).andReturn(true);
-    eventSink.execute(
+    eventSink.post(
         new PubsubEvent.HostMaintenanceStateChange(
             new HostStatus().setHost(hostName).setMode(mode)));
   }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d0b46fc3/src/test/java/org/apache/aurora/scheduler/state/PubsubTestUtil.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/state/PubsubTestUtil.java b/src/test/java/org/apache/aurora/scheduler/state/PubsubTestUtil.java
index e022767..cb27532 100644
--- a/src/test/java/org/apache/aurora/scheduler/state/PubsubTestUtil.java
+++ b/src/test/java/org/apache/aurora/scheduler/state/PubsubTestUtil.java
@@ -22,10 +22,9 @@ import com.google.inject.Injector;
 import com.google.inject.Key;
 import com.google.inject.TypeLiteral;
 import com.twitter.common.application.StartupStage;
-import com.twitter.common.base.Closure;
 import com.twitter.common.base.ExceptionalCommand;
 
-import org.apache.aurora.scheduler.events.PubsubEvent;
+import org.apache.aurora.scheduler.events.EventSink;
 import org.apache.aurora.scheduler.events.PubsubEventModule;
 
 /**
@@ -54,7 +53,7 @@ public final class PubsubTestUtil {
    * @return The pubsub event sink.
    * @throws Exception If the pubsub system failed to start.
    */
-  public static Closure<PubsubEvent> startPubsub(Injector injector) throws Exception
{
+  public static EventSink startPubsub(Injector injector) throws Exception {
     // TODO(wfarner): Make it easier to write a unit test wired for pubsub events.
     // In this case, a trade-off was made to avoid installing several distant modules and
providing
     // required bindings that seem unrelated from this code.
@@ -64,6 +63,6 @@ public final class PubsubTestUtil {
     for (ExceptionalCommand<?> command : startupCommands) {
       command.execute();
     }
-    return injector.getInstance(Key.get(new TypeLiteral<Closure<PubsubEvent>>()
{ }));
+    return injector.getInstance(EventSink.class);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d0b46fc3/src/test/java/org/apache/aurora/scheduler/state/StateManagerImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/state/StateManagerImplTest.java b/src/test/java/org/apache/aurora/scheduler/state/StateManagerImplTest.java
index 2075ed0..b17b983 100644
--- a/src/test/java/org/apache/aurora/scheduler/state/StateManagerImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/state/StateManagerImplTest.java
@@ -25,7 +25,6 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterators;
 import com.google.common.collect.PeekingIterator;
-import com.twitter.common.base.Closure;
 import com.twitter.common.testing.easymock.EasyMockTest;
 import com.twitter.common.util.testing.FakeClock;
 
@@ -39,6 +38,7 @@ import org.apache.aurora.scheduler.Driver;
 import org.apache.aurora.scheduler.TaskIdGenerator;
 import org.apache.aurora.scheduler.base.Query;
 import org.apache.aurora.scheduler.base.Tasks;
+import org.apache.aurora.scheduler.events.EventSink;
 import org.apache.aurora.scheduler.events.PubsubEvent;
 import org.apache.aurora.scheduler.events.PubsubEvent.TaskStateChange;
 import org.apache.aurora.scheduler.events.PubsubEvent.TasksDeleted;
@@ -74,7 +74,7 @@ public class StateManagerImplTest extends EasyMockTest {
 
   private Driver driver;
   private TaskIdGenerator taskIdGenerator;
-  private Closure<PubsubEvent> eventSink;
+  private EventSink eventSink;
   private StateManagerImpl stateManager;
   private final FakeClock clock = new FakeClock();
   private Storage storage;
@@ -83,7 +83,7 @@ public class StateManagerImplTest extends EasyMockTest {
   public void setUp() throws Exception {
     taskIdGenerator = createMock(TaskIdGenerator.class);
     driver = createMock(Driver.class);
-    eventSink = createMock(new Clazz<Closure<PubsubEvent>>() { });
+    eventSink = createMock(EventSink.class);
     // TODO(William Farner): Use a mocked storage.
     storage = MemStorage.newEmptyStorage();
     stateManager = new StateManagerImpl(storage, clock, driver, taskIdGenerator, eventSink);
@@ -113,7 +113,7 @@ public class StateManagerImplTest extends EasyMockTest {
 
       TaskStateChange change = (TaskStateChange) argument;
       return taskId.equals(Tasks.id(change.getTask()))
-          && (from == change.getOldState())
+          && (from == change.getOldState().get())
           && (to == change.getNewState());
     }
 
@@ -186,7 +186,7 @@ public class StateManagerImplTest extends EasyMockTest {
     String taskId = "a";
     expect(taskIdGenerator.generate(task, 0)).andReturn(taskId);
     expectStateTransitions(taskId, INIT, PENDING);
-    eventSink.execute(matchTasksDeleted(taskId));
+    eventSink.post(matchTasksDeleted(taskId));
 
     control.replay();
 
@@ -201,7 +201,7 @@ public class StateManagerImplTest extends EasyMockTest {
     String taskId = "a";
     expect(taskIdGenerator.generate(task, 0)).andReturn(taskId);
     expectStateTransitions(taskId, INIT, PENDING, ASSIGNED, RUNNING, KILLING);
-    eventSink.execute(matchTasksDeleted(taskId));
+    eventSink.post(matchTasksDeleted(taskId));
 
     driver.killTask(EasyMock.<String>anyObject());
 
@@ -222,7 +222,7 @@ public class StateManagerImplTest extends EasyMockTest {
     expect(taskIdGenerator.generate(task, 0)).andReturn(id);
 
     // Trigger an event that produces a side-effect and a PubSub event .
-    eventSink.execute(matchStateChange(id, INIT, PENDING));
+    eventSink.post(matchStateChange(id, INIT, PENDING));
     expectLastCall().andAnswer(new IAnswer<Void>() {
       @Override public Void answer() throws Throwable {
         stateManager.changeState(
@@ -245,7 +245,7 @@ public class StateManagerImplTest extends EasyMockTest {
     String taskId = "a";
     expect(taskIdGenerator.generate(task, 0)).andReturn(taskId);
     expectStateTransitions(taskId, INIT, PENDING);
-    eventSink.execute(matchTasksDeleted(taskId));
+    eventSink.post(matchTasksDeleted(taskId));
 
     control.replay();
 
@@ -268,7 +268,7 @@ public class StateManagerImplTest extends EasyMockTest {
     while (it.hasNext()) {
       ScheduleStatus cur = it.next();
       try {
-        eventSink.execute(matchStateChange(taskId, cur, it.peek()));
+        eventSink.post(matchStateChange(taskId, cur, it.peek()));
       } catch (NoSuchElementException e) {
         // Expected.
       }


Mime
View raw message