brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [06/26] git commit: HA manager: loadManagementPlaneSyncRecord avoid NPE if persister null
Date Tue, 10 Jun 2014 02:25:27 GMT
HA manager: loadManagementPlaneSyncRecord avoid NPE if persister null

- return an empty ManagementPlaneSyncRecordImpl


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

Branch: refs/heads/master
Commit: ac87e04680f1179d8e0b32c189389ee9353032bf
Parents: 37a5e32
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Jun 3 01:41:35 2014 +0200
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Fri Jun 6 15:33:57 2014 +0200

----------------------------------------------------------------------
 .../ha/HighAvailabilityManagerImpl.java         |  5 +++++
 .../ha/HighAvailabilityManagerTest.java         | 20 +++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac87e046/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java b/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java
index 81693e9..f19dcec 100644
--- a/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java
+++ b/core/src/main/java/brooklyn/management/ha/HighAvailabilityManagerImpl.java
@@ -436,6 +436,11 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager
{
             }
             return builder.build();
         }
+        if (persister == null) {
+            // e.g. web-console may be polling before we've started up
+            LOG.debug("High availablity manager has no persister; returning empty record");
+            return ManagementPlaneSyncRecordImpl.builder().build();
+        }
         
         int maxLoadAttempts = 5;
         Exception lastException = null;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac87e046/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerTest.java b/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerTest.java
index 4373c75..491e633 100644
--- a/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerTest.java
+++ b/core/src/test/java/brooklyn/management/ha/HighAvailabilityManagerTest.java
@@ -2,6 +2,7 @@ package brooklyn.management.ha;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 
 import java.util.List;
@@ -69,6 +70,23 @@ public class HighAvailabilityManagerTest {
         if (managementContext != null) Entities.destroyAll(managementContext);
     }
     
+    // The web-console could still be polling (e.g. if have just restarted brooklyn), before
the persister is set.
+    // Must not throw NPE, but instead return something sensible (e.g. an empty state record).
+    @Test
+    public void testGetManagementPlaneSyncStateDoesNotThrowNpeBeforePersisterSet() throws
Exception {
+        HighAvailabilityManagerImpl manager2 = new HighAvailabilityManagerImpl(managementContext)
+            .setPollPeriod(Duration.of(10, TimeUnit.MILLISECONDS))
+            .setHeartbeatTimeout(Duration.THIRTY_SECONDS)
+            .setPromotionListener(promotionListener)
+            .setTicker(ticker);
+        try {
+            ManagementPlaneSyncRecord state = manager2.getManagementPlaneSyncState();
+            assertNotNull(state);
+        } finally {
+            manager2.stop();
+        }
+
+    }
     // Can get a log.error about our management node's heartbeat being out of date. Caused
by
     // poller first writing a heartbeat record, and then the clock being incremented. But
the
     // next poll fixes it.
@@ -140,7 +158,7 @@ public class HighAvailabilityManagerTest {
     }
     
     private long incrementClock(long increment, TimeUnit unit) {
-        currentTime.addAndGet(unit.toNanos(increment));
+        currentTime.addAndGet(unit.toMillis(increment));
         return currentTimeMillis();
     }
     


Mime
View raw message