### Question:
HiveMultipleMetastoreCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { final String clusterName = request.getClusterName(); final Cluster cluster = clustersProvider.get().getCluster(clusterName); try { Service hive = cluster.getService("HIVE"); ServiceComponent metastore = hive.getServiceComponent("HIVE_METASTORE"); Map<String, ServiceComponentHost> metastores = metastore.getServiceComponentHosts(); if (metastores.size() < 2) { prerequisiteCheck.getFailedOn().add("HIVE"); prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); } } catch (ServiceComponentNotFoundException scnfe) { prerequisiteCheck.getFailedOn().add("HIVE"); prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); } } HiveMultipleMetastoreCheck(); @Override Set<String> getApplicableServices(); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request);  }### Answer:
@Test public void testPerform() throws Exception { final Cluster cluster = Mockito.mock(Cluster.class); Service hive = Mockito.mock(Service.class); ServiceComponent metastore = Mockito.mock(ServiceComponent.class); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); Mockito.when(cluster.getService("HIVE")).thenReturn(hive); Mockito.when(hive.getServiceComponent("HIVE_METASTORE")).thenReturn(metastore); Map<String, ServiceComponentHost> metastores = new HashMap<>(); Mockito.when(metastore.getServiceComponentHosts()).thenReturn(metastores); PrerequisiteCheck check = new PrerequisiteCheck(null, null); PrereqCheckRequest request = new PrereqCheckRequest("cluster"); request.setTargetRepositoryVersion(m_repositoryVersion); m_check.perform(check, request); Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); metastores.put("c6401", Mockito.mock(ServiceComponentHost.class)); metastores.put("c6402", Mockito.mock(ServiceComponentHost.class)); check = new PrerequisiteCheck(null, null); m_check.perform(check, request); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); }
@Test public void testPerformFail() throws Exception{ final Cluster cluster = Mockito.mock(Cluster.class); final LinkedHashSet<String> failedOnExpected = new LinkedHashSet<>(); Service hive = Mockito.mock(Service.class); ServiceComponent metastore = Mockito.mock(ServiceComponent.class); Map<String, ServiceComponentHost> metastores = new HashMap<>(); failedOnExpected.add("HIVE"); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); Mockito.when(cluster.getService("HIVE")).thenReturn(hive); Mockito.when(hive.getServiceComponent("HIVE_METASTORE")).thenReturn(metastore); Mockito.when(metastore.getServiceComponentHosts()).thenReturn(metastores); PrerequisiteCheck check = new PrerequisiteCheck(null, null); PrereqCheckRequest request = new PrereqCheckRequest("cluster"); request.setTargetRepositoryVersion(m_repositoryVersion); m_check.perform(check, request); Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); check = new PrerequisiteCheck(null, null); m_check.perform(check, request); Assert.assertEquals(failedOnExpected, check.getFailedOn()); Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); }