aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kevi...@apache.org
Subject [7/9] git commit: Fixing error message for a held lock.
Date Thu, 05 Dec 2013 19:58:19 GMT
Fixing error message for a held lock.


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

Branch: refs/heads/master
Commit: 24c99066791698274f8eb6f9669d58590fd2ac19
Parents: e7b3da9
Author: Maxim Khutornenko <mkhutornenko@twitter.com>
Authored: Thu Dec 5 10:51:16 2013 -0800
Committer: Maxim Khutornenko <mkhutornenko@twitter.com>
Committed: Thu Dec 5 10:51:16 2013 -0800

----------------------------------------------------------------------
 .../aurora/scheduler/state/LockManagerImpl.java | 17 ++++++++++---
 .../scheduler/state/LockManagerImplTest.java    | 25 ++++++++++++++++----
 2 files changed, 34 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/24c99066/src/main/java/com/twitter/aurora/scheduler/state/LockManagerImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/twitter/aurora/scheduler/state/LockManagerImpl.java b/src/main/java/com/twitter/aurora/scheduler/state/LockManagerImpl.java
index 46aed98..4667f9f 100644
--- a/src/main/java/com/twitter/aurora/scheduler/state/LockManagerImpl.java
+++ b/src/main/java/com/twitter/aurora/scheduler/state/LockManagerImpl.java
@@ -22,6 +22,7 @@ import javax.inject.Inject;
 import com.google.common.base.Optional;
 
 import com.twitter.aurora.gen.Lock;
+import com.twitter.aurora.scheduler.base.JobKeys;
 import com.twitter.aurora.scheduler.storage.LockStore;
 import com.twitter.aurora.scheduler.storage.Storage;
 import com.twitter.aurora.scheduler.storage.Storage.MutableStoreProvider;
@@ -62,7 +63,7 @@ class LockManagerImpl implements LockManager {
         if (existingLock.isPresent()) {
           throw new LockException(String.format(
               "Operation for: %s is already in progress. Started at: %s. Current owner: %s.",
-              lockKey,
+              formatLockKey(lockKey),
               new Date(existingLock.get().getTimestampMs()).toString(),
               existingLock.get().getUser()));
         }
@@ -110,10 +111,20 @@ class LockManagerImpl implements LockManager {
       if (stored.isPresent()) {
         throw new LockException(String.format(
             "Unable to perform operation for: %s. Use override/cancel option.",
-            context));
+            formatLockKey(context)));
       } else if (heldLock.isPresent()) {
-        throw new LockException(String.format("Invalid operation context: %s", context));
+        throw new LockException(
+            String.format("Invalid operation context: %s", formatLockKey(context)));
       }
     }
   }
+
+  private static String formatLockKey(ILockKey lockKey) {
+    switch (lockKey.getSetField()) {
+      case JOB:
+        return JobKeys.toPath(lockKey.getJob());
+      default:
+        return "Unknown lock key type: " + lockKey.getSetField();
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/24c99066/src/test/java/com/twitter/aurora/scheduler/state/LockManagerImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/com/twitter/aurora/scheduler/state/LockManagerImplTest.java b/src/test/java/com/twitter/aurora/scheduler/state/LockManagerImplTest.java
index cc6f3b7..ec0c8dd 100644
--- a/src/test/java/com/twitter/aurora/scheduler/state/LockManagerImplTest.java
+++ b/src/test/java/com/twitter/aurora/scheduler/state/LockManagerImplTest.java
@@ -21,7 +21,9 @@ import com.google.common.base.Optional;
 
 import org.easymock.EasyMock;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 import com.twitter.aurora.gen.Identity;
 import com.twitter.aurora.gen.Lock;
@@ -52,6 +54,9 @@ public class LockManagerImplTest extends EasyMockTest {
   private LockManager lockManager;
   private long timestampMs;
 
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
   @Before
   public void setUp() throws Exception {
     FakeClock clock = new FakeClock();
@@ -77,8 +82,9 @@ public class LockManagerImplTest extends EasyMockTest {
     assertEquals(expected, actual);
   }
 
-  @Test(expected = LockException.class)
+  @Test
   public void testAcquireLockInProgress() throws Exception {
+    expectLockException(JOB_KEY);
     lockManager.acquireLock(LOCK_KEY, USER);
     lockManager.acquireLock(LOCK_KEY, USER);
   }
@@ -103,23 +109,32 @@ public class LockManagerImplTest extends EasyMockTest {
     lockManager.validateIfLocked(LOCK_KEY, Optional.<ILock>absent());
   }
 
-  @Test(expected = LockException.class)
+  @Test
   public void testValidateLockStoredNotEqualHeld() throws Exception {
+    expectLockException(JOB_KEY);
     ILock lock = lockManager.acquireLock(LOCK_KEY, USER);
     lock = ILock.build(lock.newBuilder().setUser("bob"));
     lockManager.validateIfLocked(LOCK_KEY, Optional.of(lock));
   }
 
-  @Test(expected = LockException.class)
+  @Test
   public void testValidateLockStoredNotEqualHeldWithHeldNull() throws Exception {
+    expectLockException(JOB_KEY);
     lockManager.acquireLock(LOCK_KEY, USER);
     lockManager.validateIfLocked(LOCK_KEY, Optional.<ILock>absent());
   }
 
-  @Test(expected = LockException.class)
+  @Test
   public void testValidateLockNotStoredHeld() throws Exception {
+    IJobKey jobKey = JobKeys.from("r", "e", "n");
+    expectLockException(jobKey);
     ILock lock = lockManager.acquireLock(LOCK_KEY, USER);
-    ILockKey key = ILockKey.build(LockKey.job(JobKeys.from("r", "e", "n").newBuilder()));
+    ILockKey key = ILockKey.build(LockKey.job(jobKey.newBuilder()));
     lockManager.validateIfLocked(key, Optional.of(lock));
   }
+
+  private void expectLockException(IJobKey key) {
+    expectedException.expect(LockException.class);
+    expectedException.expectMessage(JobKeys.toPath(key));
+  }
 }


Mime
View raw message