From f25e1d245082d6fcce601d600e219f52710ca21c Mon Sep 17 00:00:00 2001 From: "Heiko W. Rupp" Date: Wed, 25 Feb 2015 15:01:03 +0100 Subject: [PATCH 1/2] When a destination is added, immediately ping it, so first result is in quicker. --- .../component/pinger/PingManager.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/pinger/src/main/java/org/hawkular/component/pinger/PingManager.java b/modules/pinger/src/main/java/org/hawkular/component/pinger/PingManager.java index 6363a9fd..4df99b3f 100644 --- a/modules/pinger/src/main/java/org/hawkular/component/pinger/PingManager.java +++ b/modules/pinger/src/main/java/org/hawkular/component/pinger/PingManager.java @@ -100,6 +100,14 @@ public void scheduleWork() { return; } + doThePing(destinations); + } + + /** + * Runs the pinging work on the provided list of destinations + * @param destinations Set of destinations to ping + */ + private void doThePing(Set destinations) { List results = new ArrayList<>(destinations.size()); List> futures = new ArrayList<>(destinations.size()); @@ -109,7 +117,6 @@ public void scheduleWork() { } - int round = 1; while (!futures.isEmpty() && round < 20) { Iterator> iterator = futures.iterator(); @@ -198,8 +205,16 @@ private void addDataItem(List> mMetrics, PingStatus status, mMetrics.add(outer); } - public void addDestination(PingDestination s) { - destinations.add(s); + /** + * Add a new destination into the system. This triggers an immediate + * ping and then adding to the list of destinations. + * @param pd new Destination + */ + public void addDestination(PingDestination pd) { + Set oneTimeDestinations = new HashSet<>(1); + oneTimeDestinations.add(pd); + doThePing(oneTimeDestinations); + destinations.add(pd); } public List getDestinations() { From 02dcc07821e029cd71c60c4e1a0b44dd66854853 Mon Sep 17 00:00:00 2001 From: "Heiko W. Rupp" Date: Wed, 25 Feb 2015 16:56:56 +0100 Subject: [PATCH 2/2] Tests should be less depending on running inventory now. --- .../component/pinger/test/PingerTest.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/modules/pinger/src/test/java/org/hawkular/component/pinger/test/PingerTest.java b/modules/pinger/src/test/java/org/hawkular/component/pinger/test/PingerTest.java index 6dd4ae1a..001de811 100644 --- a/modules/pinger/src/test/java/org/hawkular/component/pinger/test/PingerTest.java +++ b/modules/pinger/src/test/java/org/hawkular/component/pinger/test/PingerTest.java @@ -21,9 +21,11 @@ import org.hawkular.component.pinger.PingManager; import org.hawkular.component.pinger.PingStatus; import org.hawkular.component.pinger.Pinger; +import org.hawkular.metrics.client.common.SingleMetric; import org.junit.Test; import java.util.List; +import java.util.Map; /** * Simple test for the pinger @@ -49,6 +51,7 @@ public void testPingManagerSimple() throws Exception { PingManager manager = new PingManager(); manager.pinger = new Pinger(); + manager.metricPublisher = new NoOpMetricPublisher(); PingDestination destination = new PingDestination("123","http://hawkular.github.io"); manager.addDestination(destination); manager.metricPublisher = new MetricPublisher(); @@ -65,14 +68,31 @@ public void testPingManagerSimple() throws Exception { * running inventory instance * @throws Exception */ -// @Test + @Test public void testPingManagerStartup() throws Exception { PingManager manager = new PingManager(); - manager.startUp(); + try { + manager.startUp(); + } catch (javax.ws.rs.ProcessingException e) { + // It's ok, as we may not have the full Jax-RS client stack available + } List destinations = manager.getDestinations(); manager.pinger = new Pinger(); manager.scheduleWork(); } + + + private class NoOpMetricPublisher extends MetricPublisher { + @Override + public void sendToMetricsViaRest(String tenantId, List> metrics) { + + } + + @Override + public void publishToTopic(String tenantId, List metrics) { + + } + } }