|
@@ -0,0 +1,189 @@
|
|
|
+/*
|
|
|
+ * Licensed to the Apache Software Foundation (ASF) under one
|
|
|
+ * or more contributor license agreements. See the NOTICE file
|
|
|
+ * distributed with this work for additional information
|
|
|
+ * regarding copyright ownership. The ASF licenses this file
|
|
|
+ * to you under the Apache License, Version 2.0 (the
|
|
|
+ * "License"); you may not use this file except in compliance
|
|
|
+ * with the License. You may obtain a copy of the License at
|
|
|
+ *
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ *
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
+ * limitations under the License.
|
|
|
+ */
|
|
|
+
|
|
|
+package org.apache.ambari.server.upgrade;
|
|
|
+
|
|
|
+import static org.easymock.EasyMock.createMockBuilder;
|
|
|
+import static org.easymock.EasyMock.createNiceMock;
|
|
|
+import static org.easymock.EasyMock.createStrictMock;
|
|
|
+import static org.easymock.EasyMock.expect;
|
|
|
+import static org.easymock.EasyMock.expectLastCall;
|
|
|
+import static org.easymock.EasyMock.replay;
|
|
|
+import static org.easymock.EasyMock.reset;
|
|
|
+import static org.easymock.EasyMock.verify;
|
|
|
+
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.persistence.EntityManager;
|
|
|
+
|
|
|
+import com.google.inject.AbstractModule;
|
|
|
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
|
|
|
+import org.apache.ambari.server.controller.AmbariManagementController;
|
|
|
+import org.apache.ambari.server.orm.DBAccessor;
|
|
|
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
|
|
|
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
|
|
|
+import org.apache.ambari.server.orm.dao.StackDAO;
|
|
|
+import org.apache.ambari.server.orm.entities.StackEntity;
|
|
|
+import org.apache.ambari.server.state.Cluster;
|
|
|
+import org.apache.ambari.server.state.Clusters;
|
|
|
+import org.apache.ambari.server.state.Config;
|
|
|
+import org.apache.ambari.server.state.ConfigHelper;
|
|
|
+import org.apache.ambari.server.state.stack.OsFamily;
|
|
|
+import org.easymock.EasyMockSupport;
|
|
|
+import org.junit.After;
|
|
|
+import org.junit.Assert;
|
|
|
+import org.junit.Before;
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
+import com.google.inject.Binder;
|
|
|
+import com.google.inject.Guice;
|
|
|
+import com.google.inject.Injector;
|
|
|
+import com.google.inject.Module;
|
|
|
+import com.google.inject.Provider;
|
|
|
+import com.google.inject.persist.PersistService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * {@link org.apache.ambari.server.upgrade.UpgradeCatalog213} unit tests.
|
|
|
+ */
|
|
|
+public class UpgradeCatalog213Test {
|
|
|
+ private Injector injector;
|
|
|
+ private Provider<EntityManager> entityManagerProvider = createStrictMock(Provider.class);
|
|
|
+ private EntityManager entityManager = createNiceMock(EntityManager.class);
|
|
|
+ private UpgradeCatalogHelper upgradeCatalogHelper;
|
|
|
+ private StackEntity desiredStackEntity;
|
|
|
+
|
|
|
+ @Before
|
|
|
+ public void init() {
|
|
|
+ reset(entityManagerProvider);
|
|
|
+ expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
|
|
|
+ replay(entityManagerProvider);
|
|
|
+ injector = Guice.createInjector(new InMemoryDefaultTestModule());
|
|
|
+ injector.getInstance(GuiceJpaInitializer.class);
|
|
|
+
|
|
|
+ upgradeCatalogHelper = injector.getInstance(UpgradeCatalogHelper.class);
|
|
|
+ // inject AmbariMetaInfo to ensure that stacks get populated in the DB
|
|
|
+ injector.getInstance(AmbariMetaInfo.class);
|
|
|
+ // load the stack entity
|
|
|
+ StackDAO stackDAO = injector.getInstance(StackDAO.class);
|
|
|
+ desiredStackEntity = stackDAO.find("HDP", "2.2.0");
|
|
|
+ }
|
|
|
+
|
|
|
+ @After
|
|
|
+ public void tearDown() {
|
|
|
+ injector.getInstance(PersistService.class).stop();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testExecuteDMLUpdates() throws Exception {
|
|
|
+ Method addMissingConfigs = UpgradeCatalog213.class.getDeclaredMethod("addMissingConfigs");
|
|
|
+
|
|
|
+ UpgradeCatalog213 upgradeCatalog213 = createMockBuilder(UpgradeCatalog213.class)
|
|
|
+ .addMockedMethod(addMissingConfigs)
|
|
|
+ .createMock();
|
|
|
+
|
|
|
+ upgradeCatalog213.addMissingConfigs();
|
|
|
+ expectLastCall().once();
|
|
|
+
|
|
|
+ replay(upgradeCatalog213);
|
|
|
+
|
|
|
+ upgradeCatalog213.executeDMLUpdates();
|
|
|
+
|
|
|
+ verify(upgradeCatalog213);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testUpdateStormSiteConfigs() throws Exception {
|
|
|
+ EasyMockSupport easyMockSupport = new EasyMockSupport();
|
|
|
+ final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class);
|
|
|
+ final ConfigHelper mockConfigHelper = easyMockSupport.createMock(ConfigHelper.class);
|
|
|
+
|
|
|
+ final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class);
|
|
|
+ final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class);
|
|
|
+ final Map<String, String> propertiesStormSite = new HashMap<String, String>() {
|
|
|
+ {
|
|
|
+ put("nimbus.monitor.freq.secs", "10");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ final Config mockStormSite = easyMockSupport.createNiceMock(Config.class);
|
|
|
+ expect(mockStormSite.getProperties()).andReturn(propertiesStormSite).once();
|
|
|
+
|
|
|
+ final Map<String, String> propertiesExpectedHiveSite = new HashMap<String, String>() {{
|
|
|
+ put("nimbus.monitor.freq.secs", "210");
|
|
|
+ }};
|
|
|
+
|
|
|
+ final Injector mockInjector = Guice.createInjector(new AbstractModule() {
|
|
|
+ @Override
|
|
|
+ protected void configure() {
|
|
|
+ bind(AmbariManagementController.class).toInstance(mockAmbariManagementController);
|
|
|
+ bind(ConfigHelper.class).toInstance(mockConfigHelper);
|
|
|
+ bind(Clusters.class).toInstance(mockClusters);
|
|
|
+
|
|
|
+ bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
|
|
|
+ bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
|
|
|
+ expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
|
|
|
+ put("normal", mockClusterExpected);
|
|
|
+ }}).once();
|
|
|
+
|
|
|
+ expect(mockClusterExpected.getDesiredConfigByType("storm-site")).andReturn(mockStormSite).atLeastOnce();
|
|
|
+ expect(mockStormSite.getProperties()).andReturn(propertiesExpectedHiveSite).atLeastOnce();
|
|
|
+
|
|
|
+ easyMockSupport.replayAll();
|
|
|
+ mockInjector.getInstance(UpgradeCatalog213.class).updateStormConfigs();
|
|
|
+ easyMockSupport.verifyAll();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param dbAccessor
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private AbstractUpgradeCatalog getUpgradeCatalog(final DBAccessor dbAccessor) {
|
|
|
+ Module module = new Module() {
|
|
|
+ @Override
|
|
|
+ public void configure(Binder binder) {
|
|
|
+ binder.bind(DBAccessor.class).toInstance(dbAccessor);
|
|
|
+ binder.bind(EntityManager.class).toInstance(entityManager);
|
|
|
+ binder.bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ Injector injector = Guice.createInjector(module);
|
|
|
+ return injector.getInstance(UpgradeCatalog213.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testGetSourceVersion() {
|
|
|
+ final DBAccessor dbAccessor = createNiceMock(DBAccessor.class);
|
|
|
+ UpgradeCatalog upgradeCatalog = getUpgradeCatalog(dbAccessor);
|
|
|
+ Assert.assertEquals("2.1.2", upgradeCatalog.getSourceVersion());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testGetTargetVersion() throws Exception {
|
|
|
+ final DBAccessor dbAccessor = createNiceMock(DBAccessor.class);
|
|
|
+ UpgradeCatalog upgradeCatalog = getUpgradeCatalog(dbAccessor);
|
|
|
+
|
|
|
+ Assert.assertEquals("2.1.3", upgradeCatalog.getTargetVersion());
|
|
|
+ }
|
|
|
+}
|