ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oleew...@apache.org
Subject ambari git commit: AMBARI-17004. Unit tests failing because of the order of hash sets/maps (Miklos Gergely via oleewere)
Date Wed, 08 Jun 2016 10:37:26 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 210238c4f -> 32890b554


AMBARI-17004. Unit tests failing because of the order of hash sets/maps (Miklos Gergely via
oleewere)


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

Branch: refs/heads/trunk
Commit: 32890b5542dee84de30d127896fe2426af1926ee
Parents: 210238c
Author: Miklos Gergely <mgergely@hortonworks.com>
Authored: Wed Jun 8 12:18:16 2016 +0200
Committer: oleewere <oleewere@gmail.com>
Committed: Wed Jun 8 12:32:28 2016 +0200

----------------------------------------------------------------------
 .../ChangeRepositoryVersionRequestAuditEvent.java        |  5 +++--
 .../request/ClusterPrivilegeChangeRequestAuditEvent.java |  4 +++-
 .../eventcreator/RepositoryVersionEventCreator.java      | 10 ++++++----
 .../eventcreator/RequestAuditEventCreatorHelper.java     |  5 +++--
 .../audit/request/creator/PrivilegeEventCreatorTest.java |  6 +++---
 .../request/creator/ViewPrivilegeEventCreatorTest.java   |  6 +++---
 .../internal/ComponentResourceProviderTest.java          |  9 ++++++---
 .../security/ldap/AmbariLdapDataPopulatorTest.java       | 11 ++++++-----
 8 files changed, 33 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/32890b55/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ChangeRepositoryVersionRequestAuditEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ChangeRepositoryVersionRequestAuditEvent.java
b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ChangeRepositoryVersionRequestAuditEvent.java
index 74e7267..702cd6f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ChangeRepositoryVersionRequestAuditEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ChangeRepositoryVersionRequestAuditEvent.java
@@ -20,6 +20,7 @@ package org.apache.ambari.server.audit.event.request;
 
 import java.util.List;
 import java.util.Map;
+import java.util.SortedMap;
 
 import javax.annotation.concurrent.Immutable;
 
@@ -57,7 +58,7 @@ public class ChangeRepositoryVersionRequestAuditEvent extends RequestAuditEvent
      * Details of the repositories
      * os type -> list of repositories, where a repository is a key-value map of the properties
(repo_id, repo_name, base_url)
      */
-    private Map<String, List<Map<String, String>>> repos;
+    private SortedMap<String, List<Map<String, String>>> repos;
 
     public ChangeRepositoryVersionAuditEventBuilder() {
       super.withOperation("Repository version change");
@@ -125,7 +126,7 @@ public class ChangeRepositoryVersionRequestAuditEvent extends RequestAuditEvent
       return this;
     }
 
-    public ChangeRepositoryVersionAuditEventBuilder withRepos(Map<String, List<Map<String,
String>>> repos) {
+    public ChangeRepositoryVersionAuditEventBuilder withRepos(SortedMap<String, List<Map<String,
String>>> repos) {
       this.repos = repos;
       return this;
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/32890b55/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ClusterPrivilegeChangeRequestAuditEvent.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ClusterPrivilegeChangeRequestAuditEvent.java
b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ClusterPrivilegeChangeRequestAuditEvent.java
index cc59038..b28bb2a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ClusterPrivilegeChangeRequestAuditEvent.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/event/request/ClusterPrivilegeChangeRequestAuditEvent.java
@@ -23,6 +23,8 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 import javax.annotation.concurrent.Immutable;
 
@@ -67,7 +69,7 @@ public class ClusterPrivilegeChangeRequestAuditEvent extends RequestAuditEvent
{
     protected void buildAuditMessage(StringBuilder builder) {
       super.buildAuditMessage(builder);
 
-      Set<String> roleSet = new HashSet<String>();
+      SortedSet<String> roleSet = new TreeSet<String>();
       roleSet.addAll(users.keySet());
       roleSet.addAll(groups.keySet());
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/32890b55/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RepositoryVersionEventCreator.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RepositoryVersionEventCreator.java
b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RepositoryVersionEventCreator.java
index 2f09b74..bfe3226 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RepositoryVersionEventCreator.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RepositoryVersionEventCreator.java
@@ -23,6 +23,8 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
 
 import org.apache.ambari.server.api.services.Request;
 import org.apache.ambari.server.api.services.Result;
@@ -135,9 +137,9 @@ public class RepositoryVersionEventCreator implements RequestAuditEventCreator
{
    * @param request
    * @return a map of repositories
    */
-  private Map<String, List<Map<String, String>>> getRepos(Request request)
{
+  private SortedMap<String, List<Map<String, String>>> getRepos(Request
request) {
 
-    Map<String, List<Map<String, String>>> result = new HashMap<String,
List<Map<String, String>>>();
+    SortedMap<String, List<Map<String, String>>> result = new TreeMap<String,
List<Map<String, String>>>();
 
     Map<String, Object> first = Iterables.getFirst(request.getBody().getPropertySets(),
null);
 
@@ -153,8 +155,8 @@ public class RepositoryVersionEventCreator implements RequestAuditEventCreator
{
    * @param set
    * @return
    */
-  private Map<String, List<Map<String, String>>> createResultForOperationSystems(Set<Object>
set) {
-    Map<String, List<Map<String, String>>> result = new HashMap<String,
List<Map<String, String>>>();
+  private SortedMap<String, List<Map<String, String>>> createResultForOperationSystems(Set<Object>
set) {
+    SortedMap<String, List<Map<String, String>>> result = new TreeMap<String,
List<Map<String, String>>>();
     for (Object entry : set) {
       if (entry instanceof Map) {
         Map<String, Object> map = (Map<String, Object>) entry;

http://git-wip-us.apache.org/repos/asf/ambari/blob/32890b55/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestAuditEventCreatorHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestAuditEventCreatorHelper.java
b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestAuditEventCreatorHelper.java
index f7a6e36..398b275 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestAuditEventCreatorHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/audit/request/eventcreator/RequestAuditEventCreatorHelper.java
@@ -85,8 +85,9 @@ public class RequestAuditEventCreatorHelper {
   public static List<String> getPropertyList(Request request, String propertyName)
{
     List<String> list = new LinkedList<String>();
     for (Map<String, Object> propertyMap : request.getBody().getPropertySets()) {
-      String userName = String.valueOf(propertyMap.get(propertyName));
-      list.add(userName);
+      if (propertyMap.containsKey(propertyName)) {
+        list.add(String.valueOf(propertyMap.get(propertyName)));
+      }
     }
     return list;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/32890b55/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/PrivilegeEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/PrivilegeEventCreatorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/PrivilegeEventCreatorTest.java
index ff4abd6..5a805fc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/PrivilegeEventCreatorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/PrivilegeEventCreatorTest.java
@@ -97,11 +97,11 @@ public class PrivilegeEventCreatorTest extends AuditEventCreatorTestBase{
 
     String actual = event.getAuditMessage();
     String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Role change),
RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Roles(\n"
+
-      "Permission2: \n" +
-      "  Users: " + userName + "2\n" +
       "Permission1: \n" +
       "  Users: " + userName + "\n" +
-      "  Groups: testgroup)";
+      "  Groups: testgroup\n" +
+      "Permission2: \n" +
+      "  Users: " + userName + "2)";
 
     Assert.assertTrue("Class mismatch", event instanceof ClusterPrivilegeChangeRequestAuditEvent);
     Assert.assertEquals(expected, actual);

http://git-wip-us.apache.org/repos/asf/ambari/blob/32890b55/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java
index ab2b068..4685b72 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java
@@ -75,11 +75,11 @@ public class ViewPrivilegeEventCreatorTest extends AuditEventCreatorTestBase{
 
     String actual = event.getAuditMessage();
     String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(View permission
change), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK),
Type(MyView), Version(MyView), Name(MyView), Permissions(\n" +
-      "Permission2: \n" +
-      "  Users: testuser2\n" +
       "Permission1: \n" +
       "  Users: testuser\n" +
-      "  Groups: testgroup)";
+      "  Groups: testgroup\n" +
+      "Permission2: \n" +
+      "  Users: testuser2)";
 
     Assert.assertTrue("Class mismatch", event instanceof ViewPrivilegeChangeRequestAuditEvent);
     Assert.assertEquals(expected, actual);

http://git-wip-us.apache.org/repos/asf/ambari/blob/32890b55/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
index d299fad..cbf3044 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
@@ -226,6 +226,9 @@ public class ComponentResourceProviderTest {
     expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo);
     expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
     expect(cluster.getDesiredStackVersion()).andReturn(stackId);
+    expect(serviceComponent1.getName()).andReturn("Component100");
+    expect(serviceComponent2.getName()).andReturn("Component101");
+    expect(serviceComponent3.getName()).andReturn("Component102");
 
     expect(cluster.getServices()).andReturn(Collections.singletonMap("Service100", service)).anyTimes();
 
@@ -241,9 +244,9 @@ public class ComponentResourceProviderTest {
       new ServiceComponentResponse(100L, "Cluster100", "Service100", "Component102", null,
"", 1, 1, 0,
               true /* recovery enabled */, "Component102 Client"));
 
-    expect(ambariMetaInfo.getComponent((String) anyObject(),
-        (String) anyObject(), (String) anyObject(), (String) anyObject()))
-        .andReturn(componentInfo1).times(2).andReturn(componentInfo2);
+    expect(ambariMetaInfo.getComponent(null, null, null, "Component100")).andReturn(componentInfo1);
+    expect(ambariMetaInfo.getComponent(null, null, null, "Component101")).andReturn(componentInfo2);
+    expect(ambariMetaInfo.getComponent(null, null, null, "Component102")).andReturn(componentInfo1);
 
     expect(componentInfo1.getCategory()).andReturn("MASTER").anyTimes();
     expect(componentInfo2.getCategory()).andReturn("SLAVE").anyTimes();

http://git-wip-us.apache.org/repos/asf/ambari/blob/32890b55/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java
index fbe233d..2265eec 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/ldap/AmbariLdapDataPopulatorTest.java
@@ -303,16 +303,17 @@ public class AmbariLdapDataPopulatorTest {
     expect(users.getAllUsers()).andReturn(Collections.EMPTY_LIST);
     expect(configuration.getLdapServerProperties()).andReturn(new LdapServerProperties()).anyTimes();
 
-    Set<LdapGroupDto> groupDtos = Sets.newHashSet();
     LdapGroupDto group1Dto = new LdapGroupDto();
     group1Dto.setGroupName("group1");
     group1Dto.setMemberAttributes(Sets.newHashSet("group2"));
+    Set<LdapGroupDto> groupDtos1 = Sets.newHashSet();
+    groupDtos1.add(group1Dto);
 
     LdapGroupDto group2Dto = new LdapGroupDto();
     group2Dto.setGroupName("group2");
     group2Dto.setMemberAttributes(Collections.EMPTY_SET);
-    groupDtos.add(group1Dto);
-    groupDtos.add(group2Dto);
+    Set<LdapGroupDto> groupDtos2 = Sets.newHashSet();
+    groupDtos2.add(group2Dto);
 
     LdapBatchDto batchInfo = new LdapBatchDto();
     replay(configuration, users, group1, group2);
@@ -325,8 +326,8 @@ public class AmbariLdapDataPopulatorTest {
 
     expect(dataPopulator.getLdapUserByMemberAttr(anyString())).andReturn(null).anyTimes();
     expect(dataPopulator.getLdapGroupByMemberAttr("group2")).andReturn(group2Dto);
-    expect(dataPopulator.getLdapGroups("group1")).andReturn(groupDtos).anyTimes();
-    expect(dataPopulator.getLdapGroups("group2")).andReturn(groupDtos).anyTimes();
+    expect(dataPopulator.getLdapGroups("group1")).andReturn(groupDtos1).anyTimes();
+    expect(dataPopulator.getLdapGroups("group2")).andReturn(groupDtos2).anyTimes();
 
     replay(dataPopulator);
     // WHEN


Mime
View raw message