Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pipeline {
}
stage('Ambari Server JTests') {
steps {
sh 'mvn -am test -pl ambari-server -DskipPythonTests -Dmaven.test.failure.ignore -Dmaven.artifact.threads=10 -Drat.skip'
sh 'mvn -am test -pl ambari-server -DskipPythonTests -Dmaven.artifact.threads=10 -Drat.skip'
Comment thread
JiaLiangC marked this conversation as resolved.
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyCollectionOf;
Expand Down Expand Up @@ -426,7 +427,7 @@ public void testActionTimeout() throws Exception {
ServiceComponentHost sch = mock(ServiceComponentHost.class);
UnitOfWork unitOfWork = mock(UnitOfWork.class);
AgentCommandsPublisher agentCommandsPublisher = mock(AgentCommandsPublisher.class);
when(fsm.getCluster(anyString())).thenReturn(oneClusterMock);
when(fsm.getCluster(nullable(String.class))).thenReturn(oneClusterMock);
when(oneClusterMock.getService(anyString())).thenReturn(serviceObj);
when(serviceObj.getServiceComponent(anyString())).thenReturn(scomp);
when(scomp.getServiceComponentHost(anyString())).thenReturn(sch);
Expand Down Expand Up @@ -475,7 +476,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
command.setStatus(HostRoleStatus.TIMEDOUT);
return null;
}
}).when(db).timeoutHostRole(anyString(), anyLong(), anyLong(), anyString(), anyBoolean(), eq(false));
}).when(db).timeoutHostRole(nullable(String.class), anyLong(), anyLong(), anyString(), anyBoolean(), eq(false));


//Small action timeout to test rescheduling
Expand Down Expand Up @@ -526,7 +527,7 @@ public void testActionTimeoutForLostHost() throws Exception {
ServiceComponentHost sch = mock(ServiceComponentHost.class);
UnitOfWork unitOfWork = mock(UnitOfWork.class);
AgentCommandsPublisher agentCommandsPublisher = mock(AgentCommandsPublisher.class);
when(fsm.getCluster(anyString())).thenReturn(oneClusterMock);
when(fsm.getCluster(nullable(String.class))).thenReturn(oneClusterMock);
when(oneClusterMock.getService(anyString())).thenReturn(serviceObj);
when(serviceObj.getServiceComponent(anyString())).thenReturn(scomp);
when(scomp.getServiceComponentHost(anyString())).thenReturn(sch);
Expand Down Expand Up @@ -566,7 +567,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
command.setStatus(HostRoleStatus.ABORTED);
return null;
}
}).when(db).timeoutHostRole(anyString(), anyLong(), anyLong(), anyString(), anyBoolean(), eq(true));
}).when(db).timeoutHostRole(nullable(String.class), anyLong(), anyLong(), anyString(), anyBoolean(), eq(true));

//Small action timeout to test rescheduling
AmbariEventPublisher aep = EasyMock.createNiceMock(AmbariEventPublisher.class);
Expand Down Expand Up @@ -624,7 +625,7 @@ public void testOpFailedEventRaisedForAbortedHostRole() throws Exception {

UnitOfWork unitOfWork = mock(UnitOfWork.class);
AgentCommandsPublisher agentCommandsPublisher = mock(AgentCommandsPublisher.class);
when(fsm.getCluster(anyString())).thenReturn(oneClusterMock);
when(fsm.getCluster(nullable(String.class))).thenReturn(oneClusterMock);
when(oneClusterMock.getService(anyString())).thenReturn(serviceObj);
when(serviceObj.getServiceComponent(anyString())).thenReturn(scomp);
when(serviceObj.getCluster()).thenReturn(oneClusterMock);
Expand Down Expand Up @@ -657,7 +658,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
command.setStatus(HostRoleStatus.ABORTED);
return null;
}
}).when(db).timeoutHostRole(anyString(), anyLong(), anyLong(), anyString(), anyBoolean(), eq(true));
}).when(db).timeoutHostRole(nullable(String.class), anyLong(), anyLong(), anyString(), anyBoolean(), eq(true));

doAnswer(new Answer<Collection<HostRoleCommandEntity>>() {
@Override
Expand Down Expand Up @@ -782,7 +783,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
command.setStatus(HostRoleStatus.valueOf(commandReport.getStatus()));
return null;
}
}).when(db).updateHostRoleState(anyString(), anyLong(), anyLong(), anyString(), any(CommandReport.class));
}).when(db).updateHostRoleState(nullable(String.class), anyLong(), anyLong(), anyString(), any(CommandReport.class));

doAnswer(new Answer<HostRoleCommand>() {
@Override
Expand Down Expand Up @@ -944,7 +945,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
command.setStatus(HostRoleStatus.valueOf(commandReport.getStatus()));
return null;
}
}).when(db).updateHostRoleState(anyString(), anyLong(), anyLong(), anyString(), any(CommandReport.class));
}).when(db).updateHostRoleState(nullable(String.class), anyLong(), anyLong(), anyString(), any(CommandReport.class));

doAnswer(new Answer<HostRoleCommand>() {
@Override
Expand Down Expand Up @@ -1160,7 +1161,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
command.setStatus(HostRoleStatus.valueOf(commandReport.getStatus()));
return null;
}
}).when(db).updateHostRoleState(anyString(), anyLong(), anyLong(), anyString(), any(CommandReport.class));
}).when(db).updateHostRoleState(nullable(String.class), anyLong(), anyLong(), anyString(), any(CommandReport.class));

doAnswer(new Answer<HostRoleCommand>() {
@Override
Expand Down Expand Up @@ -2426,7 +2427,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
command.setStatus(HostRoleStatus.valueOf(commandReport.getStatus()));
return null;
}
}).when(db).updateHostRoleState(anyString(), anyLong(), anyLong(), anyString(), any(CommandReport.class));
}).when(db).updateHostRoleState(nullable(String.class), anyLong(), anyLong(), anyString(), any(CommandReport.class));

doAnswer(new Answer<List<HostRoleCommand>>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@

import com.google.inject.Provider;

import static org.mockito.ArgumentMatchers.nullable;

/**
* Unit tests for HostsRepositoryVersionCheck
*
Expand Down Expand Up @@ -185,7 +187,7 @@ public CheckHelper get() {
Mockito.when(
hostVersionDAO.findByClusterStackVersionAndHost(Mockito.anyString(),
Mockito.any(StackId.class), Mockito.anyString(),
Mockito.anyString())).thenReturn(hostVersion);
nullable(String.class))).thenReturn(hostVersion);

check = hostsRepositoryVersionCheck.perform(request);
Assert.assertEquals(UpgradeCheckStatus.PASS, check.getStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@

import com.google.inject.Provider;

import static org.mockito.ArgumentMatchers.nullable;


/**
* Unit tests for ServicesUpCheck
Expand Down Expand Up @@ -191,7 +193,7 @@ public CheckHelper get() {
Mockito.when(cluster.getService("AMBARI_METRICS")).thenReturn(amsService);

Mockito.when(ambariMetaInfo.getComponent(Mockito.anyString(), Mockito.anyString(),
Mockito.anyString(), Mockito.anyString())).thenAnswer(new Answer<ComponentInfo>() {
nullable(String.class), Mockito.anyString())).thenAnswer(new Answer<ComponentInfo>() {
@Override
public ComponentInfo answer(InvocationOnMock invocation) throws Throwable {
ComponentInfo anyInfo = Mockito.mock(ComponentInfo.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

Expand All @@ -107,6 +108,7 @@
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(AmbariServer.class)
@PowerMockIgnore({"org.apache.logging.log4j.*","org.slf4j.*"})
public class BlueprintConfigurationProcessorTest extends EasyMockSupport {

private static final Configuration EMPTY_CONFIG = new Configuration(emptyMap(), emptyMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.ldap.control.PagedResultsCookie;
Expand All @@ -86,6 +87,7 @@

@RunWith(PowerMockRunner.class)
@PrepareForTest(AmbariLdapUtils.class)
@PowerMockIgnore({"org.apache.logging.log4j.*","org.slf4j.*"})
public class AmbariLdapDataPopulatorTest {
public static class AmbariLdapDataPopulatorTestInstance extends TestAmbariLdapDataPopulator {
public AmbariLdapDataPopulatorTestInstance(Provider<AmbariLdapConfiguration> configurationProvider, Users users) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,13 @@
import org.apache.ambari.spi.upgrade.OrchestrationOptions;
import org.apache.ambari.spi.upgrade.UpgradeType;
import org.apache.commons.io.FileUtils;
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.easymock.EasyMockSupport;
import org.easymock.IAnswer;
import org.easymock.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentMatcher;
import org.springframework.security.core.context.SecurityContextHolder;

import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -2549,7 +2547,6 @@ public void testUpgradeOrchestrationWithRackError() throws Exception {
}
}


/**
* Tests merging configurations between existing and new stack values on
* upgrade.
Expand Down Expand Up @@ -2735,53 +2732,35 @@ public void testMergeConfigurationsWithClusterEnv() throws Exception {
ConfigFactory cf = injector.getInstance(ConfigFactory.class);

Config clusterEnv = cf.createNew(cluster, "cluster-env", "version1",
ImmutableMap.<String, String>builder().put("a", "b").build(),
Collections.emptyMap());
ImmutableMap.<String, String>builder().put("a", "b").build(),
Collections.emptyMap());

Config zooCfg = cf.createNew(cluster, "zoo.cfg", "version1",
ImmutableMap.<String, String>builder().put("c", "d").build(),
Collections.emptyMap());
ImmutableMap.<String, String>builder().put("c", "d").build(),
Collections.emptyMap());

cluster.addDesiredConfig("admin", Sets.newHashSet(clusterEnv, zooCfg));

Map<String, Map<String, String>> stackMap = new HashMap<>();
stackMap.put("cluster-env", new HashMap<>());
stackMap.put("hive-site", new HashMap<>());

final Map<String, String> clusterEnvMap = new HashMap<>();

Capture<Cluster> captureCluster = Capture.newInstance();
Capture<StackId> captureStackId = Capture.newInstance();
Capture<AmbariManagementController> captureAmc = Capture.newInstance();

Capture<Map<String, Map<String, String>>> cap = Capture.newInstance();

/*Capture<Map<String, Map<String, String>>> cap = new Capture<Map<String, Map<String, String>>>() {
@Override
public void setValue(Map<String, Map<String, String>> value) {
if (value.containsKey("cluster-env")) {
clusterEnvMap.putAll(value.get("cluster-env"));
}
}
};*/

Capture<String> captureUsername = Capture.newInstance();
Capture<String> captureNote = Capture.newInstance();
final ClusterEnvWrapper clusterEnvWrapper = new ClusterEnvWrapper();
System.out.println("Initial clusterEnvMap: " + clusterEnvWrapper.getClusterEnvMap()); // Debug print

EasyMock.reset(m_configHelper);
expect(m_configHelper.getDefaultProperties(oldStack, "HIVE")).andReturn(stackMap).atLeastOnce();
expect(m_configHelper.getDefaultProperties(newStack, "HIVE")).andReturn(stackMap).atLeastOnce();
expect(m_configHelper.getDefaultProperties(oldStack, "ZOOKEEPER")).andReturn(stackMap).atLeastOnce();
expect(m_configHelper.getDefaultProperties(newStack, "ZOOKEEPER")).andReturn(stackMap).atLeastOnce();
expect(m_configHelper.createConfigTypes(
EasyMock.capture(captureCluster),
EasyMock.capture(captureStackId),
EasyMock.capture(captureAmc),
EasyMock.capture(cap),

EasyMock.capture(captureUsername),
EasyMock.capture(captureNote))).andReturn(true);

EasyMock.anyObject(Cluster.class),
EasyMock.anyObject(StackId.class),
EasyMock.anyObject(AmbariManagementController.class),
eqClusterEnv(clusterEnvWrapper),
EasyMock.anyString(),
EasyMock.anyString()
)).andReturn(true);
replay(m_configHelper);

RepositoryVersionEntity repoVersionEntity = helper.getOrCreateRepositoryVersion(new StackId("HDP-2.5.0"), "2.5.0-1234");
Expand All @@ -2798,14 +2777,53 @@ public void setValue(Map<String, Map<String, String>> value) {
UpgradeHelper upgradeHelper = injector.getInstance(UpgradeHelper.class);
upgradeHelper.updateDesiredRepositoriesAndConfigs(context);

assertNotNull(clusterEnvMap);
assertTrue(clusterEnvMap.containsKey("a"));
assertEquals("b",clusterEnvWrapper.getClusterEnvMap().get("a"));

assertTrue(clusterEnvWrapper.getClusterEnvMap().containsKey("a"));
// Do stacks cleanup
stackManagerMock.invalidateCurrentPaths();
ambariMetaInfo.init();
}

// Custom matcher for cluster-env map
private static Map<String, Map<String, String>> eqClusterEnv(final ClusterEnvWrapper wrapper) {
EasyMock.reportMatcher(new IArgumentMatcher() {
@Override
public boolean matches(Object argument) {
if (argument instanceof Map) {
Map<String, Map<String, String>> map = (Map<String, Map<String, String>>) argument;
if (map.containsKey("cluster-env")) {
wrapper.updateClusterEnvMap(map.get("cluster-env"));
return true;
}
}
return false;
}

@Override
public void appendTo(StringBuffer buffer) {
buffer.append("eqClusterEnv(");
buffer.append(wrapper);
buffer.append(")");
}
});
return null;
}

// Custom wrapper class to hold and update clusterEnvMap
private static class ClusterEnvWrapper {
private final Map<String, String> clusterEnvMap = new HashMap<>();

public void updateClusterEnvMap(Map<String, String> newMap) {
clusterEnvMap.putAll(newMap);
}

public Map<String, String> getClusterEnvMap() {
return clusterEnvMap;
}
}


@Test
public void testSequentialServiceChecks() throws Exception {
Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
Expand Down