private void test_comparator_date_0(boolean desc) throws Exception {
    long now = System.currentTimeMillis();
    MapComparator<String, Date> comparator = new MapComparator<String, Date>(orderByKey, desc);

    Map<String, Date> map1 = new HashMap<String, Date>();
    Map<String, Date> map2 = new HashMap<String, Date>();

    map1.put(orderByKey, new Date(now));
    map2.put(orderByKey, new Date(now - 1));
    Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);

    map2.put(orderByKey, new Date(now));
    Assert.assertEquals(true, comparator.compare(map1, map2) == 0);

    map2.put(orderByKey, new Date(now + 1));
    Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);

    map2.put(orderByKey, null);
    Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);

    map1.put(orderByKey, null);
    map2.put(orderByKey, new Date(now));
    Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);

    map1.put(orderByKey, null);
    map2.put(orderByKey, null);
    Assert.assertEquals(true, comparator.compare(map1, map2) == 0);
  }
  private void test_comparator_number_0(boolean desc) throws Exception {
    MapComparator<String, Double> comparator = new MapComparator<String, Double>(orderByKey, desc);
    double baseNumber = 100.123;

    Map<String, Double> map1 = new HashMap<String, Double>();
    Map<String, Double> map2 = new HashMap<String, Double>();

    map1.put(orderByKey, baseNumber);
    map2.put(orderByKey, baseNumber - 1);
    Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);

    map2.put(orderByKey, baseNumber);
    Assert.assertEquals(true, comparator.compare(map1, map2) == 0);

    map2.put(orderByKey, baseNumber + 1);
    Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);

    map2.put(orderByKey, null);
    Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);

    map1.put(orderByKey, null);
    map2.put(orderByKey, baseNumber);
    Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);

    map1.put(orderByKey, null);
    map2.put(orderByKey, null);
    Assert.assertEquals(true, comparator.compare(map1, map2) == 0);
  }
  private void test_comparator_array_0(boolean desc) throws Exception {
    String orderByKey = "orderby";
    long now = System.currentTimeMillis();
    MapComparator<String, Date[]> comparator =
        new MapComparator<String, Date[]>(orderByKey + "[0]", desc);

    Map<String, Date[]> map1 = new HashMap<String, Date[]>();
    Map<String, Date[]> map2 = new HashMap<String, Date[]>();

    map1.put(orderByKey, new Date[] {new Date(now)});
    map2.put(orderByKey, new Date[] {new Date(now - 1)});
    Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);

    map2.put(orderByKey, new Date[] {new Date(now)});
    Assert.assertEquals(true, comparator.compare(map1, map2) == 0);

    map2.put(orderByKey, new Date[] {new Date(now + 1)});
    Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);

    map2.put(orderByKey, null);
    Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);

    map1.put(orderByKey, null);
    map2.put(orderByKey, new Date[] {new Date(now)});
    Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);

    map1.put(orderByKey, null);
    map2.put(orderByKey, null);
    Assert.assertEquals(true, comparator.compare(map1, map2) == 0);
  }
  private void test_comparator_string_0(boolean desc) throws Exception {
    MapComparator<String, String> comparator = new MapComparator<String, String>(orderByKey, desc);

    Map<String, String> map1 = new HashMap<String, String>();
    Map<String, String> map2 = new HashMap<String, String>();

    map1.put(orderByKey, "opq");
    map2.put(orderByKey, "xyz");
    Assert.assertEquals(desc, comparator.compare(map1, map2) > 0);

    map2.put(orderByKey, "opq");
    Assert.assertEquals(true, comparator.compare(map1, map2) == 0);

    map2.put(orderByKey, "abc");
    Assert.assertEquals(desc, comparator.compare(map1, map2) < 0);

    map2.put(orderByKey, null);
    Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);

    map1.put(orderByKey, null);
    map2.put(orderByKey, "opq");
    Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);

    map1.put(orderByKey, null);
    map2.put(orderByKey, null);
    Assert.assertEquals(true, comparator.compare(map1, map2) == 0);
  }
  @Override
  public void onAlertPublishSpecChange(PublishSpec pubSpec, Map<String, StreamDefinition> sds) {
    if (pubSpec == null) {
      return;
    }

    List<Publishment> newPublishments = pubSpec.getPublishments();
    if (newPublishments == null) {
      LOG.info("no publishments with PublishSpec {} for this topology", pubSpec);
      return;
    }

    Map<String, Publishment> newPublishmentsMap = new HashMap<>();
    newPublishments.forEach(p -> newPublishmentsMap.put(p.getName(), p));
    MapComparator<String, Publishment> comparator =
        new MapComparator<>(newPublishmentsMap, cachedPublishments);
    comparator.compare();

    List<Publishment> beforeModified = new ArrayList<>();
    comparator.getModified().forEach(p -> beforeModified.add(cachedPublishments.get(p.getName())));
    alertPublisher.onPublishChange(
        comparator.getAdded(), comparator.getRemoved(), comparator.getModified(), beforeModified);

    // switch
    cachedPublishments = newPublishmentsMap;
    specVersion = pubSpec.getVersion();
  }