filter groups with too long group descriptor id [r=sergey.vasiliev]
authorNikolay Matveev <Nikolay.Matveev@jetbrains.com>
Thu, 29 Dec 2011 16:38:03 +0000 (20:38 +0400)
committerNikolay Matveev <Nikolay.Matveev@jetbrains.com>
Thu, 29 Dec 2011 16:38:03 +0000 (20:38 +0400)
platform/platform-impl/src/com/intellij/internal/statistic/beans/ConvertUsagesUtil.java
platform/platform-impl/src/com/intellij/internal/statistic/beans/GroupDescriptor.java
platform/platform-tests/testSrc/com/intellij/usagesStatistics/StatisticsUploadAssistantTest.java

index 5f9d75957849fa82bb619ef5052bcb4648217f8a..2cfeae08456d2fd2a50ffbeb1afc0383cb24dc88 100644 (file)
 package com.intellij.internal.statistic.beans;
 
 
-import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.containers.hash.HashMap;
 import org.jetbrains.annotations.NotNull;
 
 import java.util.*;
-import java.util.regex.Pattern;
 
 public class ConvertUsagesUtil {
   private static final char GROUP_SEPARATOR = ':';
@@ -83,7 +81,11 @@ public class ConvertUsagesUtil {
       if (!isEmptyOrSpaces(groupStr)) {
         final StringPair group = getPair(groupStr, Character.toString(GROUP_SEPARATOR));
         if (group != null) {
-          descriptors.putAll(convertValueString(GroupDescriptor.create(group.first), group.second));
+          final String groupId = group.first;
+          assert groupId != null;
+          if (groupId.length() < GroupDescriptor.MAX_ID_LENGTH) {
+            descriptors.putAll(convertValueString(GroupDescriptor.create(groupId), group.second));
+          }
         }
       }
     }
index f67236f3bbe869717158734361b90dfcfb4b7db5..39ed8725ea50afda455373bfaf7e8a4d04402888 100644 (file)
@@ -20,7 +20,9 @@ public class GroupDescriptor implements Comparable<GroupDescriptor> {
     public static final double HIGHER_PRIORITY = 100.0;
     public static final double LOWER_PRIORITY = -100.0;
 
-    private final String myId;
+  public static final int MAX_ID_LENGTH = 30;
+
+  private final String myId;
     private double myPriority;
 
     public static GroupDescriptor create(String id) {
index 899f2a0e37d0a3748800ea9cf16b412c4a486a0a..e12cd30e9901503ae6931b8466165cd6a9064e9e 100644 (file)
@@ -91,7 +91,7 @@ public class StatisticsUploadAssistantTest extends TestCase {
     public void testConvertUsages() {
         final Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = StatisticsUploadAssistant
                 .getPatchedUsages(createDescriptors("g:a1:-1", "g2:a2:-2", "g2:a3:-3", "g:a2:-2", "g2:a1:-1", "g3:a1:13"),
-                        new HashMap<GroupDescriptor, Set<UsageDescriptor>>());
+                                  new HashMap<GroupDescriptor, Set<UsageDescriptor>>());
 
         final String result = ConvertUsagesUtil.convertUsages(patchedUsages);
         final Map<GroupDescriptor, Set<UsageDescriptor>> convertedUsages = ConvertUsagesUtil.convertString(result);
@@ -112,7 +112,7 @@ public class StatisticsUploadAssistantTest extends TestCase {
 
 
         assertEquals(ConvertUsagesUtil.convertUsages(patchedUsages),
-                "high:h=1,h2=1;default_1:d11=1,d12=1;default_2:d21=1;low:l1=1,l2=1;");
+                     "high:h=1,h2=1;default_1:d11=1,d12=1;default_2:d21=1;low:l1=1,l2=1;");
     }
 
     public void testConvertUsagesWithEqualPriority() {
@@ -151,6 +151,15 @@ public class StatisticsUploadAssistantTest extends TestCase {
         assertEquals(ConvertUsagesUtil.convertString("asdfa:sd=ds2,f=f,sad=;").size(), 0);
     }
 
+    public void testConvertWithTooLongGroupDescriptorId() {
+      final Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = new HashMap<GroupDescriptor, Set<PatchedUsage>>();
+      createPatchDescriptor(patchedUsages, "g1", GroupDescriptor.HIGHER_PRIORITY, "k1", 1);
+      createPatchDescriptor(patchedUsages, "g1", GroupDescriptor.HIGHER_PRIORITY, "k2", 2);
+
+      final String veryLongGroupId = StringUtil.repeat("g", GroupDescriptor.MAX_ID_LENGTH);
+      assertMapEquals(patchedUsages, ConvertUsagesUtil.convertString(veryLongGroupId + ":k1=1;g1:k1=1,k2=2;"));
+    }
+
     public void testPersistSentPatchWithRestrictedSize() {
         int size = 15;
         final Map<GroupDescriptor, Set<UsageDescriptor>> allUsages = createDescriptors("g:a1:-1", "g2:a2:-2", "g2:a3:-3", "g:a2:-2", "g3:a1:-1", "g3:a2:13");