aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject [1/2] aurora git commit: Add PMD coverage for test sources.
Date Wed, 16 Dec 2015 00:04:49 GMT
Repository: aurora
Updated Branches:
  refs/heads/master fe9b46023 -> fb8155d05


http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/sla/SlaAlgorithmTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/sla/SlaAlgorithmTest.java b/src/test/java/org/apache/aurora/scheduler/sla/SlaAlgorithmTest.java
index d36f565..90ea3a1 100644
--- a/src/test/java/org/apache/aurora/scheduler/sla/SlaAlgorithmTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/sla/SlaAlgorithmTest.java
@@ -48,7 +48,7 @@ import static org.junit.Assert.assertEquals;
 public class SlaAlgorithmTest {
 
   @Test
-  public void MedianTimeToAssignedEvenTest() {
+  public void testMedianTimeToAssignedEven() {
     Number actual = MEDIAN_TIME_TO_ASSIGNED.getAlgorithm().calculate(
         ImmutableSet.of(
             makeTask(ImmutableMap.of(50L, PENDING, 200L, ASSIGNED, 250L, KILLED)),
@@ -59,7 +59,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void MedianTimeToAssignedOddTest() {
+  public void testMedianTimeToAssignedOdd() {
     Number actual = MEDIAN_TIME_TO_ASSIGNED.getAlgorithm().calculate(
         ImmutableSet.of(
             makeTask(ImmutableMap.of(50L, PENDING, 200L, ASSIGNED, 250L, RUNNING)),
@@ -70,7 +70,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void MedianTimeToAssignedZeroTest() {
+  public void testMedianTimeToAssignedZero() {
     Number actual = MEDIAN_TIME_TO_ASSIGNED.getAlgorithm().calculate(
         ImmutableSet.of(
             makeTask(ImmutableMap.of(50L, PENDING)),
@@ -80,7 +80,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void MedianTimeToAssignedOneTest() {
+  public void testMedianTimeToAssignedOne() {
     Number actual = MEDIAN_TIME_TO_ASSIGNED.getAlgorithm().calculate(
         ImmutableSet.of(
             makeTask(ImmutableMap.of(50L, PENDING)),
@@ -90,7 +90,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test(expected = IllegalArgumentException.class)
-  public void MedianTimeToAssignedNoPendingTest() {
+  public void testMedianTimeToAssignedNoPending() {
     MEDIAN_TIME_TO_ASSIGNED.getAlgorithm().calculate(
         ImmutableSet.of(
             makeTask(ImmutableMap.of(50L, ASSIGNED))),
@@ -98,7 +98,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void MedianTimeToRunningEvenTest() {
+  public void testMedianTimeToRunningEven() {
     Number actual = MEDIAN_TIME_TO_RUNNING.getAlgorithm().calculate(
         ImmutableSet.of(
             makeTask(ImmutableMap.of(50L, PENDING)), // Ignored as not RUNNING
@@ -115,7 +115,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void MedianTimeToRunningOddTest() {
+  public void testMedianTimeToRunningOdd() {
     Number actual = MEDIAN_TIME_TO_RUNNING.getAlgorithm().calculate(
         ImmutableSet.of(
             makeTask(ImmutableMap.of(50L, PENDING)), // Ignored as not RUNNING
@@ -127,7 +127,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void MedianTimeToRunningZeroTest() {
+  public void testMedianTimeToRunningZero() {
     Number actual = MEDIAN_TIME_TO_RUNNING.getAlgorithm().calculate(
         ImmutableSet.of(
             makeTask(ImmutableMap.of(50L, PENDING)),
@@ -137,7 +137,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void MedianTimeEventsOutsideTimeRangeIgnored() {
+  public void testMedianTimeEventsOutsideTimeRangeIgnored() {
     Number actual = MEDIAN_TIME_TO_ASSIGNED.getAlgorithm().calculate(
         ImmutableSet.of(
             makeTask(ImmutableMap.of(50L, PENDING)),
@@ -151,7 +151,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void JobUptime50Test() {
+  public void testJobUptime50() {
     long now = System.currentTimeMillis();
     Number actual = JOB_UPTIME_50.getAlgorithm().calculate(
         makeUptimeTasks(100, now),
@@ -160,7 +160,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void JobUptime75Test() {
+  public void testJobUptime75() {
     long now = System.currentTimeMillis();
     Number actual = JOB_UPTIME_75.getAlgorithm().calculate(
         makeUptimeTasks(100, now),
@@ -169,7 +169,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void JobUptime90Test() {
+  public void testJobUptime90() {
     long now = System.currentTimeMillis();
     Number actual = JOB_UPTIME_90.getAlgorithm().calculate(
         makeUptimeTasks(100, now),
@@ -178,7 +178,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void JobUptime95Test() {
+  public void testJobUptime95() {
     long now = System.currentTimeMillis();
     Number actual = JOB_UPTIME_95.getAlgorithm().calculate(
         makeUptimeTasks(100, now),
@@ -187,7 +187,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void JobUptime99Test() {
+  public void testJobUptime99() {
     long now = System.currentTimeMillis();
     Number actual = JOB_UPTIME_99.getAlgorithm().calculate(
         makeUptimeTasks(100, now),
@@ -196,7 +196,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void JobUptimeEmptyTest() {
+  public void testJobUptimeEmpty() {
     long now = System.currentTimeMillis();
     Number actual = JOB_UPTIME_99.getAlgorithm().calculate(
         new LinkedList<IScheduledTask>(),
@@ -205,7 +205,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void JobUptimeNonTerminalIgnoredTest() {
+  public void testJobUptimeNonTerminalIgnored() {
     long now = System.currentTimeMillis();
     Set<IScheduledTask> instances = makeUptimeTasks(100, now);
     instances.add(makeTask(ImmutableMap.of(now - 5000, RUNNING, now - 3000, KILLED)));
@@ -214,7 +214,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void JobUptimeLiveNonTerminalIgnoredTest() {
+  public void testJobUptimeLiveNonTerminalIgnored() {
     long now = System.currentTimeMillis();
     Set<IScheduledTask> instances = makeUptimeTasks(100, now);
     instances.add(makeTask(ImmutableMap.of(now - 5000, RUNNING, now - 3000, RESTARTING)));
@@ -223,7 +223,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void AggregatePlatformUptimeTest() {
+  public void testAggregatePlatformUptime() {
     Number actual = AGGREGATE_PLATFORM_UPTIME.getAlgorithm().calculate(
         ImmutableSet.of(
             makeTask(ImmutableMap.of(100L, PENDING), 0), // Ignored.
@@ -245,7 +245,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void AggregatePlatformUptimeRecoveredFromDownTest() {
+  public void testAggregatePlatformUptimeRecoveredFromDown() {
     Number actual = AGGREGATE_PLATFORM_UPTIME.getAlgorithm().calculate(
         ImmutableSet.of(
             makeTask(ImmutableMap.of(50L, RUNNING, 300L, LOST, 310L, KILLED), 0), // DOWN
mid range.
@@ -259,7 +259,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void AggregatePlatformUptimeKilledByPlatformTest() {
+  public void testAggregatePlatformUptimeKilledByPlatform() {
     Number actual = AGGREGATE_PLATFORM_UPTIME.getAlgorithm().calculate(
         ImmutableSet.of(makeTask(ImmutableMap.of(50L, RUNNING, 300L, KILLED), 0)),
         Range.closedOpen(100L, 500L));
@@ -267,7 +267,7 @@ public class SlaAlgorithmTest {
   }
 
   @Test
-  public void AggregatePlatformUptimeEmptyTest() {
+  public void testAggregatePlatformUptimeEmpty() {
     Number actual = AGGREGATE_PLATFORM_UPTIME.getAlgorithm().calculate(
         ImmutableSet.of(makeTask(ImmutableMap.of(50L, PENDING), 0)),
         Range.closedOpen(100L, 500L));

http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/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 c51d9f9..6d42689 100644
--- a/src/test/java/org/apache/aurora/scheduler/state/StateManagerImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/state/StateManagerImplTest.java
@@ -137,8 +137,8 @@ public class StateManagerImplTest extends EasyMockTest {
 
       TaskStateChange change = (TaskStateChange) argument;
       return taskId.equals(Tasks.id(change.getTask()))
-          && (from == change.getOldState().get())
-          && (to == change.getNewState());
+          && from == change.getOldState().get()
+          && to == change.getNewState();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/state/TaskStateMachineTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/state/TaskStateMachineTest.java b/src/test/java/org/apache/aurora/scheduler/state/TaskStateMachineTest.java
index c3a803e..d0a6cd6 100644
--- a/src/test/java/org/apache/aurora/scheduler/state/TaskStateMachineTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/state/TaskStateMachineTest.java
@@ -113,13 +113,14 @@ public class TaskStateMachineTest {
 
         default:
           fail("Unknown state " + endState);
+          break;
       }
 
       expectUpdateStateOnTransitionTo(PENDING, ASSIGNED, STARTING, RUNNING);
       legalTransition(TaskState.valueOf(endState.name()), finalActions);
 
       for (ScheduleStatus badTransition : Tasks.TERMINAL_STATES) {
-        if (endState == badTransition) {
+        if (endState.equals(badTransition)) {
           assertEquals(NOOP, stateMachine.updateState(Optional.of(badTransition)).getResult());
         } else {
           illegalTransition(TaskState.valueOf(badTransition.name()));
@@ -153,6 +154,7 @@ public class TaskStateMachineTest {
 
         default:
           fail("Unknown state " + endState);
+          break;
       }
 
       expectUpdateStateOnTransitionTo(
@@ -379,9 +381,9 @@ public class TaskStateMachineTest {
       }
 
       TestCase other = (TestCase) o;
-      return (taskPresent == other.taskPresent)
-          && (from == other.from)
-          && (to == other.to);
+      return taskPresent == other.taskPresent
+          && from == other.from
+          && to == other.to;
     }
 
     @Override
@@ -533,7 +535,7 @@ public class TaskStateMachineTest {
 
           TransitionResult expectation = EXPECTATIONS.get(testCase);
           if (expectation == null) {
-            if (taskPresent && from == to || !taskPresent && to == DELETED)
{
+            if (taskPresent && from.equals(to) || !taskPresent && to.equals(DELETED))
{
               expectation = new TransitionResult(NOOP, ImmutableSet.of());
             } else {
               expectation = new TransitionResult(ILLEGAL, ImmutableSet.of());
@@ -543,7 +545,7 @@ public class TaskStateMachineTest {
           TaskStateMachine machine;
           if (taskPresent) {
             // Cannot create a state machine for an DELETED task that is in the store.
-            boolean expectException = from == DELETED;
+            boolean expectException = from.equals(DELETED);
             try {
               machine = new TaskStateMachine(
                   IScheduledTask.build(makeTask(false).setStatus(from.getStatus().get())));
@@ -551,10 +553,11 @@ public class TaskStateMachineTest {
                 fail();
               }
             } catch (IllegalStateException e) {
-              if (!expectException) {
-                throw e;
-              } else {
+              if (expectException) {
                 continue;
+              } else {
+                throw e;
+
               }
             }
           } else {

http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/stats/SlotSizeCounterTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/stats/SlotSizeCounterTest.java b/src/test/java/org/apache/aurora/scheduler/stats/SlotSizeCounterTest.java
index c29a044..6af1fff 100644
--- a/src/test/java/org/apache/aurora/scheduler/stats/SlotSizeCounterTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/stats/SlotSizeCounterTest.java
@@ -46,14 +46,14 @@ public class SlotSizeCounterTest extends EasyMockTest {
   private StatsProvider statsProvider;
   private Runnable slotCounter;
 
-  private AtomicLong smallCounter = new AtomicLong();
-  private AtomicLong smallDedicatedCounter = new AtomicLong();
-  private AtomicLong smallRevocableCounter = new AtomicLong();
-  private AtomicLong smallDedicatedRevocableCounter = new AtomicLong();
-  private AtomicLong largeCounter = new AtomicLong();
-  private AtomicLong largeDedicatedCounter = new AtomicLong();
-  private AtomicLong largeRevocableCounter = new AtomicLong();
-  private AtomicLong largeDedicatedRevocableCounter = new AtomicLong();
+  private final AtomicLong smallCounter = new AtomicLong();
+  private final AtomicLong smallDedicatedCounter = new AtomicLong();
+  private final AtomicLong smallRevocableCounter = new AtomicLong();
+  private final AtomicLong smallDedicatedRevocableCounter = new AtomicLong();
+  private final AtomicLong largeCounter = new AtomicLong();
+  private final AtomicLong largeDedicatedCounter = new AtomicLong();
+  private final AtomicLong largeRevocableCounter = new AtomicLong();
+  private final AtomicLong largeDedicatedRevocableCounter = new AtomicLong();
 
   @Before
   public void setUp() {

http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/storage/AbstractTaskStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/AbstractTaskStoreTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/AbstractTaskStoreTest.java
index c025f4e..3dba286 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/AbstractTaskStoreTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/AbstractTaskStoreTest.java
@@ -571,9 +571,9 @@ public abstract class AbstractTaskStoreTest extends TearDownTestCase {
     ITaskConfig nullMetadata =
         ITaskConfig.build(TaskTestUtil.makeConfig(TaskTestUtil.JOB).newBuilder().setMetadata(null));
 
-    IScheduledTask a = TaskTestUtil.makeTask("a", nullMetadata);
-    IScheduledTask b = TaskTestUtil.makeTask("a", nullMetadata);
-    IScheduledTask c = TaskTestUtil.makeTask("a", nullMetadata);
+    IScheduledTask a = makeTask("a", nullMetadata);
+    IScheduledTask b = makeTask("a", nullMetadata);
+    IScheduledTask c = makeTask("a", nullMetadata);
     saveTasks(a);
     saveTasks(b);
     saveTasks(c);

http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/storage/db/DbAttributeStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/db/DbAttributeStoreTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/db/DbAttributeStoreTest.java
index f5f5bda..f47f4a8 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/db/DbAttributeStoreTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/db/DbAttributeStoreTest.java
@@ -148,8 +148,7 @@ public class DbAttributeStoreTest {
     storage.write((NoResult.Quiet)
         storeProvider -> storeProvider.getUnsafeTaskStore().saveTasks(ImmutableSet.of(taskA)));
 
-    HostAttributes attributeBuilder = HOST_A_ATTRS.newBuilder()
-        .setMode(MaintenanceMode.DRAINED);
+    HostAttributes attributeBuilder = HOST_A_ATTRS.newBuilder().setMode(DRAINED);
     attributeBuilder.addToAttributes(new Attribute("newAttr", ImmutableSet.of("a", "b")));
     IHostAttributes hostAUpdated = IHostAttributes.build(attributeBuilder);
     insert(hostAUpdated);

http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/storage/db/DbStorageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/db/DbStorageTest.java b/src/test/java/org/apache/aurora/scheduler/storage/db/DbStorageTest.java
index 214e287..3ab95c6 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/db/DbStorageTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/db/DbStorageTest.java
@@ -42,7 +42,6 @@ public class DbStorageTest extends EasyMockTest {
 
   private SqlSessionFactory sessionFactory;
   private SqlSession session;
-  private EnumValueMapper enumMapper;
   private GatedWorkQueue gatedWorkQueue;
   private Work.Quiet<String> readWork;
   private MutateWork.NoResult.Quiet writeWork;
@@ -53,14 +52,13 @@ public class DbStorageTest extends EasyMockTest {
   public void setUp() {
     sessionFactory = createMock(SqlSessionFactory.class);
     session = createMock(SqlSession.class);
-    enumMapper = createMock(EnumValueMapper.class);
     gatedWorkQueue = createMock(GatedWorkQueue.class);
     readWork = createMock(new Clazz<Work.Quiet<String>>() { });
     writeWork = createMock(new Clazz<MutateWork.NoResult.Quiet>() { });
 
     storage = new DbStorage(
         sessionFactory,
-        enumMapper,
+        createMock(EnumValueMapper.class),
         gatedWorkQueue,
         createMock(CronJobStore.Mutable.class),
         createMock(TaskStore.Mutable.class),

http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/storage/log/LogManagerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/log/LogManagerTest.java b/src/test/java/org/apache/aurora/scheduler/storage/log/LogManagerTest.java
index 9cae0c4..692ace0 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/log/LogManagerTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/log/LogManagerTest.java
@@ -76,7 +76,7 @@ public class LogManagerTest extends EasyMockTest {
   private static final Amount<Integer, Data> NO_FRAMES_EVER_SIZE =
       Amount.of(Integer.MAX_VALUE, Data.GB);
 
-  private static final Function<LogEntry, byte[]> ENCODE = entry -> {
+  private static final Function<LogEntry, byte[]> ENCODER = entry -> {
     try {
       return encode(entry);
     } catch (CodingException e) {
@@ -211,7 +211,7 @@ public class LogManagerTest extends EasyMockTest {
 
   private static byte[] entryEq(LogEntry expected) {
     EasyMock.reportMatcher(new LogEntryMatcher(expected));
-    return null;
+    return new byte[] {};
   }
 
   @Test
@@ -356,9 +356,9 @@ public class LogManagerTest extends EasyMockTest {
     List<byte[]> expectedAppends =
         ImmutableList.<byte[]>builder()
             .add(encode(message1.header))
-            .addAll(Iterables.transform(message1.chunks, ENCODE))
+            .addAll(Iterables.transform(message1.chunks, ENCODER))
             .add(encode(message2.header))
-            .addAll(Iterables.transform(message2.chunks, ENCODE))
+            .addAll(Iterables.transform(message2.chunks, ENCODER))
             .build();
 
     final Deque<byte[]> actualAppends = new LinkedBlockingDeque<>();

http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java b/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java
index 6f31206..216f92f 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java
@@ -13,6 +13,7 @@
  */
 package org.apache.aurora.scheduler.storage.log;
 
+import java.util.Collections;
 import java.util.EnumSet;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -23,7 +24,6 @@ import com.google.common.base.Functions;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterators;
 import com.google.common.collect.Sets;
 import com.google.common.hash.HashFunction;
 import com.google.common.hash.Hashing;
@@ -137,13 +137,12 @@ public class LogStorageTest extends EasyMockTest {
   private SchedulingService schedulingService;
   private SnapshotStore<Snapshot> snapshotStore;
   private StorageTestUtil storageUtil;
-  private SnapshotDeduplicator snapshotDeduplicator;
   private EventSink eventSink;
 
   @Before
   public void setUp() {
     log = createMock(Log.class);
-    snapshotDeduplicator = createMock(SnapshotDeduplicator.class);
+    SnapshotDeduplicator snapshotDeduplicator = createMock(SnapshotDeduplicator.class);
 
     StreamManagerFactory streamManagerFactory = logStream -> {
       HashFunction md5 = Hashing.md5();
@@ -194,28 +193,28 @@ public class LogStorageTest extends EasyMockTest {
 
     // Our start should recover the log and then forward to the underlying storage start
of the
     // supplied initialization logic.
-    final AtomicBoolean initialized = new AtomicBoolean(false);
+    AtomicBoolean initialized = new AtomicBoolean(false);
     MutateWork.NoResult.Quiet initializationLogic = provider -> {
       // Creating a mock and expecting apply(storeProvider) does not work here for whatever
       // reason.
       initialized.set(true);
     };
 
-    final Capture<MutateWork.NoResult.Quiet> recoverAndInitializeWork = createCapture();
+    Capture<MutateWork.NoResult.Quiet> recoverAndInitializeWork = createCapture();
     storageUtil.storage.write(capture(recoverAndInitializeWork));
     expectLastCall().andAnswer(() -> {
       recoverAndInitializeWork.getValue().apply(storageUtil.mutableStoreProvider);
       return null;
     });
 
-    final Capture<MutateWork<Void, RuntimeException>> recoveryWork = createCapture();
+    Capture<MutateWork<Void, RuntimeException>> recoveryWork = createCapture();
     expect(storageUtil.storage.write(capture(recoveryWork))).andAnswer(
         () -> {
           recoveryWork.getValue().apply(storageUtil.mutableStoreProvider);
           return null;
         });
 
-    final Capture<MutateWork<Void, RuntimeException>> initializationWork = createCapture();
+    Capture<MutateWork<Void, RuntimeException>> initializationWork = createCapture();
     expect(storageUtil.storage.write(capture(initializationWork))).andAnswer(
         () -> {
           initializationWork.getValue().apply(storageUtil.mutableStoreProvider);
@@ -234,7 +233,7 @@ public class LogStorageTest extends EasyMockTest {
     expect(snapshotStore.createSnapshot()).andReturn(snapshotContents);
     streamMatcher.expectSnapshot(snapshotContents).andReturn(position);
     stream.truncateBefore(position);
-    final Capture<MutateWork<Void, RuntimeException>> snapshotWork = createCapture();
+    Capture<MutateWork<Void, RuntimeException>> snapshotWork = createCapture();
     expect(storageUtil.storage.write(capture(snapshotWork))).andAnswer(
         () -> {
           snapshotWork.getValue().apply(storageUtil.mutableStoreProvider);
@@ -379,10 +378,10 @@ public class LogStorageTest extends EasyMockTest {
     expect(stream.readAll()).andReturn(entryBuilder.build().iterator());
   }
 
-  abstract class StorageTestFixture {
+  abstract class AbstractStorageFixture {
     private final AtomicBoolean runCalled = new AtomicBoolean(false);
 
-    StorageTestFixture() {
+    AbstractStorageFixture() {
       // Prevent otherwise silent noop tests that forget to call run().
       addTearDown(new TearDown() {
         @Override
@@ -408,7 +407,7 @@ public class LogStorageTest extends EasyMockTest {
         // No-op.
       };
 
-      final Capture<MutateWork.NoResult.Quiet> recoverAndInitializeWork = createCapture();
+      Capture<MutateWork.NoResult.Quiet> recoverAndInitializeWork = createCapture();
       storageUtil.storage.write(capture(recoverAndInitializeWork));
       expectLastCall().andAnswer(() -> {
         recoverAndInitializeWork.getValue().apply(storageUtil.mutableStoreProvider);
@@ -421,8 +420,8 @@ public class LogStorageTest extends EasyMockTest {
         work.apply(storageUtil.mutableStoreProvider);
         return null;
       });
-      expect(stream.readAll()).andReturn(Iterators.emptyIterator());
-      final Capture<MutateWork<Void, RuntimeException>> recoveryWork = createCapture();
+      expect(stream.readAll()).andReturn(Collections.emptyIterator());
+      Capture<MutateWork<Void, RuntimeException>> recoveryWork = createCapture();
       expect(storageUtil.storage.write(capture(recoveryWork))).andAnswer(
           () -> {
             recoveryWork.getValue().apply(storageUtil.mutableStoreProvider);
@@ -452,10 +451,10 @@ public class LogStorageTest extends EasyMockTest {
     protected abstract void runTest();
   }
 
-  abstract class MutationFixture extends StorageTestFixture {
+  abstract class AbstractMutationFixture extends AbstractStorageFixture {
     @Override
     protected void runTest() {
-      logStorage.write((Quiet) MutationFixture.this::performMutations);
+      logStorage.write((Quiet) AbstractMutationFixture.this::performMutations);
     }
 
     protected abstract void performMutations(MutableStoreProvider storeProvider);
@@ -463,8 +462,8 @@ public class LogStorageTest extends EasyMockTest {
 
   @Test
   public void testSaveFrameworkId() throws Exception {
-    final String frameworkId = "bob";
-    new MutationFixture() {
+    String frameworkId = "bob";
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws CodingException {
         storageUtil.expectWrite();
@@ -482,9 +481,9 @@ public class LogStorageTest extends EasyMockTest {
 
   @Test
   public void testSaveAcceptedJob() throws Exception {
-    final IJobConfiguration jobConfig =
+    IJobConfiguration jobConfig =
         IJobConfiguration.build(new JobConfiguration().setKey(JOB_KEY.newBuilder()));
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -503,7 +502,7 @@ public class LogStorageTest extends EasyMockTest {
 
   @Test
   public void testRemoveJob() throws Exception {
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -522,8 +521,8 @@ public class LogStorageTest extends EasyMockTest {
 
   @Test
   public void testSaveTasks() throws Exception {
-    final Set<IScheduledTask> tasks = ImmutableSet.of(task("a", ScheduleStatus.INIT));
-    new MutationFixture() {
+    Set<IScheduledTask> tasks = ImmutableSet.of(task("a", ScheduleStatus.INIT));
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -542,11 +541,10 @@ public class LogStorageTest extends EasyMockTest {
 
   @Test
   public void testMutateTasks() throws Exception {
-    final Query.Builder query = Query.taskScoped("fred");
-    final Function<IScheduledTask, IScheduledTask> mutation = Functions.identity();
-    final ImmutableSet<IScheduledTask> mutated =
-        ImmutableSet.of(task("a", ScheduleStatus.STARTING));
-    new MutationFixture() {
+    Query.Builder query = Query.taskScoped("fred");
+    Function<IScheduledTask, IScheduledTask> mutation = Functions.identity();
+    ImmutableSet<IScheduledTask> mutated = ImmutableSet.of(task("a", ScheduleStatus.STARTING));
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -565,11 +563,10 @@ public class LogStorageTest extends EasyMockTest {
 
   @Test
   public void testUnsafeModifyInPlace() throws Exception {
-    final String taskId = "wilma";
-    final String taskId2 = "barney";
-    final ITaskConfig updatedConfig =
-        task(taskId, ScheduleStatus.RUNNING).getAssignedTask().getTask();
-    new MutationFixture() {
+    String taskId = "wilma";
+    String taskId2 = "barney";
+    ITaskConfig updatedConfig = task(taskId, ScheduleStatus.RUNNING).getAssignedTask().getTask();
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -590,13 +587,12 @@ public class LogStorageTest extends EasyMockTest {
 
   @Test
   public void testNestedTransactions() throws Exception {
-    final Query.Builder query = Query.taskScoped("fred");
-    final Function<IScheduledTask, IScheduledTask> mutation = Functions.identity();
-    final ImmutableSet<IScheduledTask> mutated =
-        ImmutableSet.of(task("a", ScheduleStatus.STARTING));
-    final ImmutableSet<String> tasksToRemove = ImmutableSet.of("b");
+    Query.Builder query = Query.taskScoped("fred");
+    Function<IScheduledTask, IScheduledTask> mutation = Functions.identity();
+    ImmutableSet<IScheduledTask> mutated = ImmutableSet.of(task("a", ScheduleStatus.STARTING));
+    ImmutableSet<String> tasksToRemove = ImmutableSet.of("b");
 
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -627,7 +623,7 @@ public class LogStorageTest extends EasyMockTest {
     Set<IScheduledTask> saved = ImmutableSet.of(task("a", ScheduleStatus.INIT));
     ImmutableSet<IScheduledTask> mutated = ImmutableSet.of(task("a", ScheduleStatus.PENDING));
 
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -657,7 +653,7 @@ public class LogStorageTest extends EasyMockTest {
     Set<IScheduledTask> saved = ImmutableSet.of(task("b", ScheduleStatus.INIT));
     ImmutableSet<IScheduledTask> mutated = ImmutableSet.of(task("a", ScheduleStatus.PENDING));
 
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -688,7 +684,7 @@ public class LogStorageTest extends EasyMockTest {
   public void testRemoveTasksQuery() throws Exception {
     IScheduledTask task = task("a", ScheduleStatus.FINISHED);
     Set<String> taskIds = Tasks.ids(task);
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -707,7 +703,7 @@ public class LogStorageTest extends EasyMockTest {
   @Test
   public void testRemoveTasksIds() throws Exception {
     Set<String> taskIds = ImmutableSet.of("42");
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -728,7 +724,7 @@ public class LogStorageTest extends EasyMockTest {
     String role = "role";
     IResourceAggregate quota = IResourceAggregate.build(new ResourceAggregate(1.0, 128L,
1024L));
 
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -747,7 +743,7 @@ public class LogStorageTest extends EasyMockTest {
   @Test
   public void testRemoveQuota() throws Exception {
     String role = "role";
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -769,7 +765,7 @@ public class LogStorageTest extends EasyMockTest {
         .setToken("testLockId")
         .setUser("testUser")
         .setTimestampMs(12345L));
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -788,7 +784,7 @@ public class LogStorageTest extends EasyMockTest {
   @Test
   public void testRemoveLock() throws Exception {
     ILockKey lockKey = ILockKey.build(LockKey.job(JOB_KEY.newBuilder()));
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -814,7 +810,7 @@ public class LogStorageTest extends EasyMockTest {
             .setHost(host)
             .setAttributes(attributes)));
 
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -875,7 +871,7 @@ public class LogStorageTest extends EasyMockTest {
                 .setInstances(ImmutableSet.of(new Range(0, 3)))))
             .setSettings(new JobUpdateSettings())));
 
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -898,7 +894,7 @@ public class LogStorageTest extends EasyMockTest {
         .setStatus(JobUpdateStatus.ROLLING_BACK)
         .setTimestampMs(12345L));
 
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -922,7 +918,7 @@ public class LogStorageTest extends EasyMockTest {
         .setTimestampMs(12345L)
         .setInstanceId(0));
 
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();
@@ -947,7 +943,7 @@ public class LogStorageTest extends EasyMockTest {
         .setHistoryPruneThresholdMs(1L)
         .setPerJobRetainCount(1);
 
-    new MutationFixture() {
+    new AbstractMutationFixture() {
       @Override
       protected void setupExpectations() throws Exception {
         storageUtil.expectWrite();

http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/storage/log/WriteAheadStorageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/log/WriteAheadStorageTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/log/WriteAheadStorageTest.java
index 269e89a..d09178a 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/log/WriteAheadStorageTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/log/WriteAheadStorageTest.java
@@ -57,11 +57,7 @@ import static org.junit.Assert.assertTrue;
 public class WriteAheadStorageTest extends EasyMockTest {
 
   private LogStorage.TransactionManager transactionManager;
-  private SchedulerStore.Mutable schedulerStore;
-  private CronJobStore.Mutable jobStore;
   private TaskStore.Mutable taskStore;
-  private LockStore.Mutable lockStore;
-  private QuotaStore.Mutable quotaStore;
   private AttributeStore.Mutable attributeStore;
   private JobUpdateStore.Mutable jobUpdateStore;
   private Logger log;
@@ -71,11 +67,7 @@ public class WriteAheadStorageTest extends EasyMockTest {
   @Before
   public void setUp() {
     transactionManager = createMock(LogStorage.TransactionManager.class);
-    schedulerStore = createMock(SchedulerStore.Mutable.class);
-    jobStore = createMock(CronJobStore.Mutable.class);
     taskStore = createMock(TaskStore.Mutable.class);
-    lockStore = createMock(LockStore.Mutable.class);
-    quotaStore = createMock(QuotaStore.Mutable.class);
     attributeStore = createMock(AttributeStore.Mutable.class);
     jobUpdateStore = createMock(JobUpdateStore.Mutable.class);
     log = createMock(Logger.class);
@@ -83,11 +75,11 @@ public class WriteAheadStorageTest extends EasyMockTest {
 
     storage = new WriteAheadStorage(
         transactionManager,
-        schedulerStore,
-        jobStore,
+        createMock(SchedulerStore.Mutable.class),
+        createMock(CronJobStore.Mutable.class),
         taskStore,
-        lockStore,
-        quotaStore,
+        createMock(LockStore.Mutable.class),
+        createMock(QuotaStore.Mutable.class),
         attributeStore,
         jobUpdateStore,
         log,

http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageEntityUtil.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageEntityUtil.java
b/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageEntityUtil.java
index 5e054a7..5af2813 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageEntityUtil.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/testing/StorageEntityUtil.java
@@ -62,32 +62,41 @@ public final class StorageEntityUtil {
     } else if (!(object instanceof String) && !(object instanceof Enum)) {
       for (Field field : object.getClass().getDeclaredFields()) {
         if (!Modifier.isStatic(field.getModifiers())) {
-          try {
-            field.setAccessible(true);
-            String fullName = name + "." + field.getName();
-            Object fieldValue = field.get(object);
-            boolean mustBeSet = !ignoredFields.contains(field);
-            if (mustBeSet) {
-              assertNotNull(fullName + " is null", fieldValue);
-            }
-            if (fieldValue != null) {
-              if (Primitives.isWrapperType(fieldValue.getClass())) {
-                // Special-case the mutable hash code field.
-                if (mustBeSet && !fullName.endsWith("cachedHashCode")) {
-                  assertNotEquals(
-                      "Primitive value must not be default: " + fullName,
-                      Defaults.defaultValue(Primitives.unwrap(fieldValue.getClass())),
-                      fieldValue);
-                }
-              } else {
-                assertFullyPopulated(fullName, fieldValue, ignoredFields);
-              }
-            }
-          } catch (IllegalAccessException e) {
-            throw Throwables.propagate(e);
+          validateField(name, object, field, ignoredFields);
+        }
+      }
+    }
+  }
+
+  private static void validateField(
+      String name,
+      Object object,
+      Field field,
+      Set<Field> ignoredFields) {
+
+    try {
+      field.setAccessible(true);
+      String fullName = name + "." + field.getName();
+      Object fieldValue = field.get(object);
+      boolean mustBeSet = !ignoredFields.contains(field);
+      if (mustBeSet) {
+        assertNotNull(fullName + " is null", fieldValue);
+      }
+      if (fieldValue != null) {
+        if (Primitives.isWrapperType(fieldValue.getClass())) {
+          // Special-case the mutable hash code field.
+          if (mustBeSet && !fullName.endsWith("cachedHashCode")) {
+            assertNotEquals(
+                "Primitive value must not be default: " + fullName,
+                Defaults.defaultValue(Primitives.unwrap(fieldValue.getClass())),
+                fieldValue);
           }
+        } else {
+          assertFullyPopulated(fullName, fieldValue, ignoredFields);
         }
       }
+    } catch (IllegalAccessException e) {
+      throw Throwables.propagate(e);
     }
   }
 


Mime
View raw message