Repository: ambari
Updated Branches:
  refs/heads/trunk 10c7595a4 -> 9b9a2c07c


AMBARI-18601 : Analyze and Optimize Ambari Server Unit Tests - Group 4 (Commit 
1) (avijayan)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9b9a2c07
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9b9a2c07
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9b9a2c07

Branch: refs/heads/trunk
Commit: 9b9a2c07c7fa06f6575997b46583fc1dcafbfb08
Parents: 10c7595
Author: Aravindan Vijayan <avija...@hortonworks.com>
Authored: Fri Oct 14 11:28:22 2016 -0700
Committer: Aravindan Vijayan <avija...@hortonworks.com>
Committed: Fri Oct 14 11:28:22 2016 -0700

----------------------------------------------------------------------
 .../timeline/AMSPropertyProviderTest.java       |  95 ++++++-------
 .../ambari/server/state/ConfigHelperTest.java   | 139 ++++++++++++++-----
 .../server/upgrade/UpgradeCatalog220Test.java   |  20 +--
 3 files changed, 156 insertions(+), 98 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9b9a2c07/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java
index 05fa880..251327f 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java
@@ -40,6 +40,7 @@ import org.apache.ambari.server.controller.spi.TemporalInfo;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
+import 
org.apache.ambari.server.security.authorization.internal.InternalAuthenticationToken;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ComponentInfo;
@@ -47,8 +48,11 @@ import org.apache.ambari.server.state.StackId;
 import org.apache.http.client.utils.URIBuilder;
 import org.easymock.EasyMock;
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Matchers;
@@ -112,75 +116,41 @@ public class AMSPropertyProviderTest {
   @Before
   public void setupCache() {
     cacheEntryFactory = new TimelineMetricCacheEntryFactory(new 
Configuration());
+    InternalAuthenticationToken authenticationToken = new 
InternalAuthenticationToken("admin");
+    authenticationToken.setAuthenticated(true);
+    SecurityContextHolder.getContext().setAuthentication(authenticationToken);
   }
 
-  @After
-  public void clearAuthentication() {
-    SecurityContextHolder.getContext().setAuthentication(null);
-  }
+  //    SecurityContextHolder.getContext().setAuthentication(null);
 
   @Test
-  public void testAMSPropertyProviderAsClusterAdministrator() throws Exception 
{
-    //Setup user with Role 'ClusterAdministrator'.
-    
SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createClusterAdministrator("ClusterAdmin",
 2L));
+  public void testRbacForAMSPropertyProvider() throws Exception {
 
+    SecurityContextHolder.getContext().setAuthentication(null);
+    //Cluster Administrator
+    
SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createClusterAdministrator("ClusterAdmin",
 2L));
     SecurityContextHolder.getContext();
     testPopulateResourcesForSingleHostMetric();
-    testPopulateResourcesForSingleHostMetricPointInTime();
-    testPopulateResourcesForMultipleHostMetricscPointInTime();
-    testPopulateResourcesForMultipleHostMetrics();
-    testPopulateResourcesForRegexpMetrics();
-    testPopulateResourcesForSingleComponentMetric();
-    testPopulateMetricsForEmbeddedHBase();
-    testAggregateFunctionForComponentMetrics();
-    testFilterOutOfBandMetricData();
-    testPopulateResourcesForHostComponentHostMetrics();
-    testPopulateResourcesForHostComponentMetricsForMultipleHosts();
-    testPopulateResourcesHostBatches();
-    testPopulateResourcesForMultipleComponentsMetric();
-  }
-
-  @Test
-  public void testAMSPropertyProviderAsAdministrator() throws Exception {
-    //Setup user with Role 'Administrator'
-    
SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator("Admin"));
-
-    testPopulateResourcesForSingleHostMetric();
-    testPopulateResourcesForSingleHostMetricPointInTime();
-    testPopulateResourcesForMultipleHostMetricscPointInTime();
-    testPopulateResourcesForMultipleHostMetrics();
-    testPopulateResourcesForRegexpMetrics();
-    testPopulateResourcesForSingleComponentMetric();
-    testPopulateMetricsForEmbeddedHBase();
-    testAggregateFunctionForComponentMetrics();
-    testFilterOutOfBandMetricData();
-    testPopulateResourcesForHostComponentHostMetrics();
-    testPopulateResourcesForHostComponentMetricsForMultipleHosts();
-    testPopulateResourcesHostBatches();
-    testPopulateResourcesForMultipleComponentsMetric();
-  }
 
-  @Test
-  public void testAMSPropertyProviderAsServiceAdministrator() throws Exception 
{
+    SecurityContextHolder.getContext().setAuthentication(null);
     //Setup user with 'ServiceAdministrator'
     
SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createServiceAdministrator("ServiceAdmin",
 2L));
-
-    testPopulateResourcesForSingleHostMetric();
+    SecurityContextHolder.getContext();
     testPopulateResourcesForSingleHostMetricPointInTime();
-    testPopulateResourcesForMultipleHostMetricscPointInTime();
-    testPopulateResourcesForMultipleHostMetrics();
-    testPopulateResourcesForRegexpMetrics();
-    testPopulateResourcesForSingleComponentMetric();
-    testPopulateMetricsForEmbeddedHBase();
-    testAggregateFunctionForComponentMetrics();
-    testFilterOutOfBandMetricData();
-    testPopulateResourcesForHostComponentHostMetrics();
-    testPopulateResourcesForHostComponentMetricsForMultipleHosts();
-    testPopulateResourcesHostBatches();
-    testPopulateResourcesForMultipleComponentsMetric();
+
+    SecurityContextHolder.getContext().setAuthentication(null);
+    // Setup user with 'ViewUser'
+    // ViewUser doesn't have the 'CLUSTER_VIEW_METRICS', 'HOST_VIEW_METRICS' 
and 'SERVICE_VIEW_METRICS', thus
+    // can't retrieve the Metrics.    
SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createViewUser("ViewUser",
 2L));
+    SecurityContextHolder.getContext();
+    try {
+      testPopulateResourcesForMultipleHostMetricscPointInTime();
+    } catch (Exception e) {
+      Assert.assertTrue(e instanceof AuthorizationException);
+    }
   }
 
-  @Test(expected = AuthorizationException.class)
+  @Ignore
   public void testAMSPropertyProviderAsViewUser() throws Exception {
     // Setup user with 'ViewUser'
     // ViewUser doesn't have the 'CLUSTER_VIEW_METRICS', 'HOST_VIEW_METRICS' 
and 'SERVICE_VIEW_METRICS', thus
@@ -202,6 +172,7 @@ public class AMSPropertyProviderTest {
     testPopulateResourcesForMultipleComponentsMetric();
   }
 
+  @Test
   public void testPopulateResourcesForSingleHostMetric() throws Exception {
     setUpCommonMocks();
     TestStreamProvider streamProvider = new 
TestStreamProvider(SINGLE_HOST_METRICS_FILE_PATH);
@@ -247,6 +218,7 @@ public class AMSPropertyProviderTest {
     Assert.assertEquals(111, val.length);
   }
 
+  @Test
   public void testPopulateResourcesForSingleHostMetricPointInTime() throws 
Exception {
     setUpCommonMocks();
 
@@ -293,6 +265,7 @@ public class AMSPropertyProviderTest {
     Assert.assertEquals(41.088, val, 0.001);
   }
 
+  @Test
   public void testPopulateResourcesForMultipleHostMetricscPointInTime() throws 
Exception {
     setUpCommonMocks();
     TestStreamProvider streamProvider = new 
TestStreamProvider(MULTIPLE_HOST_METRICS_FILE_PATH);
@@ -348,6 +321,7 @@ public class AMSPropertyProviderTest {
     Assert.assertEquals(2.47025664E8, val2, 0.1);
   }
 
+  @Test
   public void testPopulateResourcesForMultipleHostMetrics() throws Exception {
     setUpCommonMocks();
     TestStreamProvider streamProvider = new 
TestStreamProvider(MULTIPLE_HOST_METRICS_FILE_PATH);
@@ -411,6 +385,7 @@ public class AMSPropertyProviderTest {
     Assert.assertEquals(86, val.length);
   }
 
+  @Test
   public void testPopulateResourcesForRegexpMetrics() throws Exception {
     setUpCommonMocks();
     TestStreamProvider streamProvider = new 
TestStreamProvider(MULTIPLE_COMPONENT_REGEXP_METRICS_FILE_PATH);
@@ -466,6 +441,7 @@ public class AMSPropertyProviderTest {
     Assert.assertEquals(238, val.length);
   }
 
+  @Test
   public void testPopulateResourcesForSingleComponentMetric() throws Exception 
{
     setUpCommonMocks();
     TestStreamProvider streamProvider = new 
TestStreamProvider(SINGLE_COMPONENT_METRICS_FILE_PATH);
@@ -515,6 +491,7 @@ public class AMSPropertyProviderTest {
     Assert.assertEquals(238, val.length);
   }
 
+  @Test
   public void testPopulateResourcesForMultipleComponentsMetric() throws 
Exception {
     setUpCommonMocks();
     TestStreamProvider streamProvider = new 
TestStreamProvider(SINGLE_COMPONENT_METRICS_FILE_PATH);
@@ -567,6 +544,7 @@ public class AMSPropertyProviderTest {
     Assert.assertEquals(2, allSpecs.size());
   }
 
+  @Test
   public void testPopulateMetricsForEmbeddedHBase() throws Exception {
     AmbariManagementController ams = 
createNiceMock(AmbariManagementController.class);
     PowerMock.mockStatic(AmbariServer.class);
@@ -640,6 +618,7 @@ public class AMSPropertyProviderTest {
     Assert.assertEquals(189, val.length);
   }
 
+  @Test
   public void testAggregateFunctionForComponentMetrics() throws Exception {
     AmbariManagementController ams = 
createNiceMock(AmbariManagementController.class);
     PowerMock.mockStatic(AmbariServer.class);
@@ -713,6 +692,7 @@ public class AMSPropertyProviderTest {
     Assert.assertEquals(32, val.length);
   }
 
+  @Test
   public void testFilterOutOfBandMetricData() throws Exception {
     setUpCommonMocks();
     TestStreamProvider streamProvider = new 
TestStreamProvider(SINGLE_HOST_METRICS_FILE_PATH);
@@ -783,6 +763,7 @@ public class AMSPropertyProviderTest {
     }
   }
 
+  @Test
   public void testPopulateResourcesForHostComponentHostMetrics() throws 
Exception {
     setUpCommonMocks();
     TestStreamProviderForHostComponentHostMetricsTest streamProvider =
@@ -888,6 +869,7 @@ public class AMSPropertyProviderTest {
     }
   }
 
+  @Test
   public void testPopulateResourcesHostBatches() throws Exception {
     setUpCommonMocks();
     TestStreamProviderForHostComponentMultipleHostsMetricsTest streamProvider =
@@ -939,6 +921,7 @@ public class AMSPropertyProviderTest {
     Assert.assertEquals(2, allSpecs.size());
   }
 
+  @Test
   public void testPopulateResourcesForHostComponentMetricsForMultipleHosts() 
throws Exception {
     setUpCommonMocks();
     TestStreamProviderForHostComponentMultipleHostsMetricsTest streamProvider =

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b9a2c07/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
index 37a48f0..fd6ce1e 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
@@ -63,7 +63,9 @@ import org.apache.ambari.server.state.host.HostFactory;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.apache.ambari.server.utils.SynchronousThreadPoolExecutor;
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.runners.Enclosed;
 import org.junit.runner.RunWith;
@@ -84,17 +86,17 @@ import junit.framework.Assert;
 public class ConfigHelperTest {
   public static class RunWithInMemoryDefaultTestModule {
     private final static Logger LOG = 
LoggerFactory.getLogger(ConfigHelperTest.class);
-    private Clusters clusters;
-    private Injector injector;
-    private String clusterName;
-    private Cluster cluster;
-    private ConfigGroupFactory configGroupFactory;
-    private ConfigHelper configHelper;
-    private AmbariManagementController managementController;
-    private AmbariMetaInfo metaInfo;
-
-    @Before
-    public void setup() throws Exception {
+    private static Clusters clusters;
+    private static Injector injector;
+    private static String clusterName;
+    private static Cluster cluster;
+    private static ConfigGroupFactory configGroupFactory;
+    private static ConfigHelper configHelper;
+    private static AmbariManagementController managementController;
+    private static AmbariMetaInfo metaInfo;
+
+    @BeforeClass
+    public static void setup() throws Exception {
       // Set the authenticated user
       // TODO: remove this or replace the authenticated user to test 
authorization rules
       
SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator("admin"));
@@ -183,6 +185,57 @@ public class ConfigHelperTest {
         add(clusterRequest3);
       }}, null);
 
+
+      //Another version of core-site & global.
+      // core-site2
+      ConfigurationRequest crr = new ConfigurationRequest();
+      crr.setClusterName(clusterName);
+      crr.setType("core-site2");
+      crr.setVersionTag("version1");
+      crr.setProperties(new HashMap<String, String>() {{
+        put("ipc.client.connect.max.retries", "30");
+        put("fs.trash.interval", "30");
+      }});
+      crr.setPropertiesAttributes(new HashMap<String, Map<String, String>>() {{
+        Map<String, String> attrs = new HashMap<String, String>();
+        attrs.put("ipc.client.connect.max.retries", "1");
+        attrs.put("fs.trash.interval", "2");
+        put("attribute1", attrs);
+      }});
+
+      final ClusterRequest clusterRequestDup =
+        new ClusterRequest(cluster.getClusterId(), clusterName,
+          cluster.getDesiredStackVersion().getStackVersion(), null);
+
+      clusterRequestDup.setDesiredConfig(Collections.singletonList(crr));
+      managementController.updateClusters(new HashSet<ClusterRequest>() {{
+        add(clusterRequestDup);
+      }}, null);
+
+      // global
+      crr.setType("global2");
+      crr.setVersionTag("version1");
+      crr.setProperties(new HashMap<String, String>() {{
+        put("dfs_namenode_name_dir", "/hadoop/hdfs/namenode");
+        put("namenode_heapsize", "1024");
+      }});
+      crr.setPropertiesAttributes(new HashMap<String, Map<String, String>>() {{
+        Map<String, String> attrs = new HashMap<String, String>();
+        attrs.put("dfs_namenode_name_dir", "3");
+        attrs.put("namenode_heapsize", "4");
+        put("attribute2", attrs);
+      }});
+
+      final ClusterRequest clusterRequestGlobalDup =
+        new ClusterRequest(cluster.getClusterId(), clusterName,
+          cluster.getDesiredStackVersion().getStackVersion(), null);
+
+      clusterRequestGlobalDup.setDesiredConfig(Collections.singletonList(crr));
+      managementController.updateClusters(new HashSet<ClusterRequest>() {{
+        add(clusterRequestGlobalDup);
+      }}, null);
+
+
       // oozie-site
       ConfigurationRequest cr4 = new ConfigurationRequest();
       cr4.setClusterName(clusterName);
@@ -202,10 +255,30 @@ public class ConfigHelperTest {
       managementController.updateClusters(new HashSet<ClusterRequest>() {{
         add(clusterRequest4);
       }}, null);
+
+      // ams-site
+      ConfigurationRequest cr5 = new ConfigurationRequest();
+      cr5.setClusterName(clusterName);
+      cr5.setType("ams-site");
+      cr5.setVersionTag("version1");
+      cr5.setProperties(new HashMap<String, String>() {{
+        put("timeline.service.operating.mode", "embedded");
+        put("timeline.service.fifo.enabled", "false");
+      }});
+      cr4.setPropertiesAttributes(null);
+
+      final ClusterRequest clusterRequest5 =
+        new ClusterRequest(cluster.getClusterId(), clusterName,
+          cluster.getDesiredStackVersion().getStackVersion(), null);
+
+      clusterRequest5.setDesiredConfig(Collections.singletonList(cr5));
+      managementController.updateClusters(new HashSet<ClusterRequest>() {{
+        add(clusterRequest5);
+      }}, null);
     }
 
-    @After
-    public void tearDown() {
+    @AfterClass
+    public static void tearDown() {
       injector.getInstance(PersistService.class).stop();
 
       // Clear the authenticated user
@@ -346,7 +419,7 @@ public class ConfigHelperTest {
       properties2.put("namenode_heapsize", "1111");
       config2.setProperties(properties2);
 
-      Long groupId = addConfigGroup("g1", "t1", new ArrayList<String>() {{
+      Long groupId = addConfigGroup("g2", "t1", new ArrayList<String>() {{
         add("h1");
       }}, new ArrayList<Config>() {{
         add(config1);
@@ -373,7 +446,7 @@ public class ConfigHelperTest {
 
     @Test
     public void testEffectivePropertiesAttributesWithOverrides() throws 
Exception {
-      final Config config1 = new ConfigImpl("core-site");
+      final Config config1 = new ConfigImpl("core-site2");
       config1.setTag("version122");
 
       Map<String, String> attributes = new HashMap<String, String>();
@@ -383,7 +456,7 @@ public class ConfigHelperTest {
       config1Attributes.put("attribute1", attributes);
       config1.setPropertiesAttributes(config1Attributes);
 
-      final Config config2 = new ConfigImpl("global");
+      final Config config2 = new ConfigImpl("global2");
       config2.setTag("version122");
       attributes = new HashMap<String, String>();
       attributes.put("namenode_heapsize", "z");
@@ -392,8 +465,8 @@ public class ConfigHelperTest {
       config2Attributes.put("attribute2", attributes);
       config2.setPropertiesAttributes(config2Attributes);
 
-      Long groupId = addConfigGroup("g1", "t1", new ArrayList<String>() {{
-        add("h1");
+      Long groupId = addConfigGroup("g3", "t1", new ArrayList<String>() {{
+        add("h2");
       }}, new ArrayList<Config>() {{
         add(config1);
         add(config2);
@@ -403,13 +476,13 @@ public class ConfigHelperTest {
 
       Map<String, Map<String, Map<String, String>>> effectiveAttributes = 
configHelper
           .getEffectiveConfigAttributes(cluster,
-              configHelper.getEffectiveDesiredTags(cluster, "h1"));
+              configHelper.getEffectiveDesiredTags(cluster, "h2"));
 
       Assert.assertNotNull(effectiveAttributes);
-      Assert.assertEquals(4, effectiveAttributes.size());
+      Assert.assertEquals(7, effectiveAttributes.size());
 
-      Assert.assertTrue(effectiveAttributes.containsKey("global"));
-      Map<String, Map<String, String>> globalAttrs = 
effectiveAttributes.get("global");
+      Assert.assertTrue(effectiveAttributes.containsKey("global2"));
+      Map<String, Map<String, String>> globalAttrs = 
effectiveAttributes.get("global2");
       Assert.assertEquals(1, globalAttrs.size());
       Assert.assertTrue(globalAttrs.containsKey("attribute2"));
       Map<String, String> attribute2Occurances = globalAttrs.get("attribute2");
@@ -421,8 +494,8 @@ public class ConfigHelperTest {
       Assert.assertTrue(attribute2Occurances.containsKey("c"));
       Assert.assertEquals("q", attribute2Occurances.get("c"));
 
-      Assert.assertTrue(effectiveAttributes.containsKey("core-site"));
-      Map<String, Map<String, String>> coreAttrs = 
effectiveAttributes.get("core-site");
+      Assert.assertTrue(effectiveAttributes.containsKey("core-site2"));
+      Map<String, Map<String, String>> coreAttrs = 
effectiveAttributes.get("core-site2");
       Assert.assertEquals(1, coreAttrs.size());
       Assert.assertTrue(coreAttrs.containsKey("attribute1"));
       Map<String, String> attribute1Occurances = coreAttrs.get("attribute1");
@@ -727,28 +800,28 @@ public class ConfigHelperTest {
 
     @Test
     public void testUpdateConfigTypeRemovals() throws Exception {
-      Config currentConfig = cluster.getDesiredConfigByType("oozie-site");
+      Config currentConfig = cluster.getDesiredConfigByType("ams-site");
       Map<String, String> properties = currentConfig.getProperties();
       // Config tag before update
       Assert.assertEquals("version1", currentConfig.getTag());
       // Properties before update
-      Assert.assertEquals("simple", 
properties.get("oozie.authentication.type"));
-      Assert.assertEquals("false", 
properties.get("oozie.service.HadoopAccessorService.kerberos.enabled"));
+      Assert.assertEquals("embedded", 
properties.get("timeline.service.operating.mode"));
+      Assert.assertEquals("false", 
properties.get("timeline.service.fifo.enabled"));
 
       List<String> removals = new ArrayList<String>();
-      removals.add("oozie.authentication.type");
+      removals.add("timeline.service.operating.mode");
 
-      configHelper.updateConfigType(cluster, managementController, 
"oozie-site", null, removals, "admin", "Test note");
+      configHelper.updateConfigType(cluster, managementController, "ams-site", 
null, removals, "admin", "Test note");
 
-      Config updatedConfig = cluster.getDesiredConfigByType("oozie-site");
+      Config updatedConfig = cluster.getDesiredConfigByType("ams-site");
       // Config tag updated
       Assert.assertFalse("version1".equals(updatedConfig.getTag()));
       // Property removed
       properties = updatedConfig.getProperties();
-      Assert.assertFalse(properties.containsKey("oozie.authentication.type"));
+      
Assert.assertFalse(properties.containsKey("timeline.service.operating.mode"));
       // Property unchanged
-      
Assert.assertTrue(properties.containsKey("oozie.service.HadoopAccessorService.kerberos.enabled"));
-      Assert.assertEquals("false", 
properties.get("oozie.service.HadoopAccessorService.kerberos.enabled"));
+      
Assert.assertTrue(properties.containsKey("timeline.service.fifo.enabled"));
+      Assert.assertEquals("false", 
properties.get("timeline.service.fifo.enabled"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/9b9a2c07/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog220Test.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog220Test.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog220Test.java
index 7c1605d..2b3764b 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog220Test.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog220Test.java
@@ -77,8 +77,10 @@ import org.easymock.EasyMock;
 import org.easymock.EasyMockSupport;
 import org.easymock.IMocksControl;
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import javax.persistence.EntityManager;
@@ -114,11 +116,11 @@ import static org.junit.Assert.assertTrue;
  * {@link org.apache.ambari.server.upgrade.UpgradeCatalog220} unit tests.
  */
 public class UpgradeCatalog220Test {
-  private Injector injector;
-  private Provider<EntityManager> entityManagerProvider = 
createStrictMock(Provider.class);
-  private EntityManager entityManager = createNiceMock(EntityManager.class);
-  private UpgradeCatalogHelper upgradeCatalogHelper;
-  private StackEntity desiredStackEntity;
+  private static Injector injector;
+  private static Provider<EntityManager> entityManagerProvider = 
createStrictMock(Provider.class);
+  private static EntityManager entityManager = 
createNiceMock(EntityManager.class);
+  private static UpgradeCatalogHelper upgradeCatalogHelper;
+  private static StackEntity desiredStackEntity;
   private AmbariManagementController amc = 
createNiceMock(AmbariManagementController.class);
   private AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
   private StackDAO stackDAO = createNiceMock(StackDAO.class);
@@ -129,8 +131,8 @@ public class UpgradeCatalog220Test {
 
   private IMocksControl mocksControl = EasyMock.createControl();
 
-  @Before
-  public void init() {
+  @BeforeClass
+  public static void init() {
     reset(entityManagerProvider);
     expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
     replay(entityManagerProvider);
@@ -145,8 +147,8 @@ public class UpgradeCatalog220Test {
     desiredStackEntity = stackDAO.find("HDP", "2.2.0");
   }
 
-  @After
-  public void tearDown() {
+  @AfterClass
+  public static void tearDown() {
     injector.getInstance(PersistService.class).stop();
   }
 

Reply via email to