### Question:
KubeService implements Runnable { public Set<String> fetchPodNamesFromMetadata() throws IOException { LOG.debug("Attempting to make pod md request"); String response = SingerUtils.makeGetRequest(PODS_MD_URL); LOG.debug("Received pod md response:" + response); Gson gson = new Gson(); JsonObject obj = gson.fromJson(response, JsonObject.class); LOG.debug("Finished parsing kubelet response for PODs; now extracting POD names"); Set<String> podNames = new HashSet<>(); if (obj != null && obj.has("items")) { JsonArray ary = obj.get("items").getAsJsonArray(); for (int i = 0; i < ary.size(); i++) { JsonObject metadata = ary.get(i).getAsJsonObject().get("metadata").getAsJsonObject(); String name = metadata.get("name").getAsString(); podNames.add(name); String namespace = metadata.get("namespace").getAsString(); podNames.add(namespace + "_" + name); LOG.debug("Found active POD name in JSON:" + name); } } LOG.debug("Pod names from kubelet:" + podNames); return podNames; } private  KubeService(); @VisibleForTesting protected  KubeService(KubeConfig kubeConfig); synchronized static KubeService getInstance(); @Override void run(); void updatePodNames(); void updatePodWatchers(String podName, boolean isDelete); Set<String> fetchPodNamesFromMetadata(); int getPollFrequency(); Set<String> getActivePodSet(); synchronized void addWatcher(PodWatcher watcher); synchronized void removeWatcher(PodWatcher watcher); void start(); void stop(); void checkAndProcessFsEvents(); static void reset();  }### Answer:
@Test public void testBadPodFetch() throws KeyManagementException, ClientProtocolException, NoSuchAlgorithmException, KeyStoreException, MalformedURLException, IOException { registerBadResponse(); KubeConfig kubeConfig = new KubeConfig(); KubeService kubeService = new KubeService(kubeConfig); Set<String> fetchPodIdsFromMetadata = kubeService.fetchPodNamesFromMetadata(); assertEquals(0, fetchPodIdsFromMetadata.size()); }
@Test public void testGoodPodFetch() throws KeyManagementException, ClientProtocolException, NoSuchAlgorithmException, KeyStoreException, MalformedURLException, IOException { registerGoodResponse(); KubeConfig kubeConfig = new KubeConfig(); KubeService poll = new KubeService(kubeConfig); Set<String> fetchPodNamesFromMetadata = poll.fetchPodNamesFromMetadata(); assertEquals(12, fetchPodNamesFromMetadata.size()); Map<String, String> podToNamespaceMap = new HashMap<>(); podToNamespaceMap.put("enimanager-ppl56", "default"); podToNamespaceMap.put("zk-update-monitor-r1vlt", "default"); podToNamespaceMap.put("tcollector-q4qx8", "default"); podToNamespaceMap.put("metrics-agent-8vm9g", "default"); podToNamespaceMap.put("kubernetes-dashboard-1835568627-hhfhj", "kube-system"); podToNamespaceMap.put("test-ci-0", "kubernetes-plugin"); for (Entry<String, String> entry : podToNamespaceMap.entrySet()) { String name = entry.getKey(); String namespace = entry.getValue(); assertTrue(fetchPodNamesFromMetadata.contains(name)); assertTrue(fetchPodNamesFromMetadata.contains(namespace + "_" + name)); } }