|
@@ -20,9 +20,13 @@ package org.apache.hadoop.metrics2.sink.timeline.availability;
|
|
|
import com.google.gson.Gson;
|
|
|
import junit.framework.Assert;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.curator.CuratorZookeeperClient;
|
|
|
+import org.apache.curator.retry.BoundedExponentialBackoffRetry;
|
|
|
import org.apache.hadoop.metrics2.sink.timeline.AbstractTimelineMetricsSink;
|
|
|
+import org.apache.zookeeper.ZooKeeper;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
+import org.powermock.api.easymock.PowerMock;
|
|
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
|
import org.powermock.modules.junit4.PowerMockRunner;
|
|
|
import java.io.IOException;
|
|
@@ -34,13 +38,14 @@ import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
|
|
|
import static org.easymock.EasyMock.expect;
|
|
|
+import static org.easymock.EasyMock.expectLastCall;
|
|
|
import static org.powermock.api.easymock.PowerMock.createNiceMock;
|
|
|
import static org.powermock.api.easymock.PowerMock.expectNew;
|
|
|
import static org.powermock.api.easymock.PowerMock.replayAll;
|
|
|
import static org.powermock.api.easymock.PowerMock.verifyAll;
|
|
|
|
|
|
@RunWith(PowerMockRunner.class)
|
|
|
-@PrepareForTest({AbstractTimelineMetricsSink.class, URL.class, HttpURLConnection.class})
|
|
|
+@PrepareForTest({AbstractTimelineMetricsSink.class, URL.class, HttpURLConnection.class, MetricCollectorHAHelper.class})
|
|
|
public class MetricCollectorHATest {
|
|
|
|
|
|
@Test
|
|
@@ -71,6 +76,33 @@ public class MetricCollectorHATest {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testEmbeddedModeCollectorZK() throws Exception {
|
|
|
+
|
|
|
+
|
|
|
+ BoundedExponentialBackoffRetry retryPolicyMock = PowerMock.createMock(BoundedExponentialBackoffRetry.class);
|
|
|
+ expectNew(BoundedExponentialBackoffRetry.class, 1000, 10000, 1).andReturn(retryPolicyMock);
|
|
|
+
|
|
|
+ CuratorZookeeperClient clientMock = PowerMock.createMock(CuratorZookeeperClient.class);
|
|
|
+ expectNew(CuratorZookeeperClient.class, "zkQ", 10000, 2000, null, retryPolicyMock)
|
|
|
+ .andReturn(clientMock);
|
|
|
+
|
|
|
+ clientMock.start();
|
|
|
+ expectLastCall().once();
|
|
|
+
|
|
|
+ ZooKeeper zkMock = PowerMock.createMock(ZooKeeper.class);
|
|
|
+ expect(clientMock.getZooKeeper()).andReturn(zkMock).once();
|
|
|
+
|
|
|
+ expect(zkMock.exists("/ambari-metrics-cluster", false)).andReturn(null).once();
|
|
|
+
|
|
|
+ replayAll();
|
|
|
+ MetricCollectorHAHelper metricCollectorHAHelper = new MetricCollectorHAHelper("zkQ", 1, 1000);
|
|
|
+ Collection<String> liveInstances = metricCollectorHAHelper.findLiveCollectorHostsFromZNode();
|
|
|
+ verifyAll();
|
|
|
+ Assert.assertTrue(liveInstances.isEmpty());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void findCollectorUsingKnownCollectorTest() throws Exception {
|
|
|
HttpURLConnection connection = createNiceMock(HttpURLConnection.class);
|