MapReduce2JobHistoryStatePreservingCheck extends AbstractCheckDescriptor { @Override public boolean isApplicable(PrereqCheckRequest request) throws AmbariException { return super.isApplicable(request, Arrays.asList("MAPREDUCE2"), true); } MapReduce2JobHistoryStatePreservingCheck(); @Override boolean isApplicable(PrereqCheckRequest request); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request);  }
@Test public void testIsApplicable() throws Exception { final Cluster cluster = Mockito.mock(Cluster.class); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.3")); Map<String, Service> services = new HashMap<String, Service>(); Mockito.when(cluster.getServices()).thenReturn(services); ClusterVersionEntity clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class); Mockito.when(cluster.getCurrentClusterVersion()).thenReturn(clusterVersionEntity); PrereqCheckRequest request = new PrereqCheckRequest("cluster"); request.setTargetStackId(new StackId("HDP", "2.3.1.1")); request.setSourceStackId(new StackId("HDP", "2.3.0.0")); Assert.assertFalse(m_check.isApplicable(request)); services.put("MAPREDUCE2", Mockito.mock(Service.class)); Assert.assertTrue(m_check.isApplicable(request)); }
@SuppressWarnings("serial") @Test public void testIsApplicableMinimumStackVersion() throws Exception { final Cluster cluster = Mockito.mock(Cluster.class); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(cluster.getServices()).thenReturn(new HashMap<String, Service>() { { put("MAPREDUCE2", null); } }); Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("MYSTACK-12.2")); ClusterVersionEntity clusterVersionEntity = Mockito.mock(ClusterVersionEntity.class); Mockito.when(cluster.getCurrentClusterVersion()).thenReturn(clusterVersionEntity); RepositoryVersionEntity repositoryVersionEntity = Mockito.mock(RepositoryVersionEntity.class); Mockito.when(clusterVersionEntity.getRepositoryVersion()).thenReturn(repositoryVersionEntity); Mockito.when(m_clusters.getCluster("c1")).thenReturn(cluster); PrereqCheckRequest request = new PrereqCheckRequest("c1"); Mockito.when(repositoryVersionEntity.getVersion()).thenReturn("2.0.0.1"); boolean isApplicable = m_check.isApplicable(request); Assert.assertTrue(isApplicable); }