WatchKeysUtil { public Set<String> assembleAllWatchKeys(String appId, String clusterName, String namespace, String dataCenter) { Multimap<String, String> watchedKeysMap = assembleAllWatchKeys(appId, clusterName, Sets.newHashSet(namespace), dataCenter); return Sets.newHashSet(watchedKeysMap.get(namespace)); } WatchKeysUtil(final AppNamespaceServiceWithCache appNamespaceService); Set<String> assembleAllWatchKeys(String appId, String clusterName, String namespace,
                                          String dataCenter); Multimap<String, String> assembleAllWatchKeys(String appId, String clusterName,
                                                       Set<String> namespaces,
                                                       String dataCenter);  }
@Test public void testAssembleAllWatchKeysWithOneNamespaceAndDefaultCluster() throws Exception { Set<String> watchKeys = watchKeysUtil.assembleAllWatchKeys(someAppId, defaultCluster, someNamespace, null); Set<String> clusters = Sets.newHashSet(defaultCluster); assertEquals(clusters.size(), watchKeys.size()); assertWatchKeys(someAppId, clusters, someNamespace, watchKeys); }
@Test public void testAssembleAllWatchKeysWithOneNamespaceAndSomeDC() throws Exception { Set<String> watchKeys = watchKeysUtil.assembleAllWatchKeys(someAppId, someDC, someNamespace, someDC); Set<String> clusters = Sets.newHashSet(defaultCluster, someDC); assertEquals(clusters.size(), watchKeys.size()); assertWatchKeys(someAppId, clusters, someNamespace, watchKeys); }
@Test public void testAssembleAllWatchKeysWithOneNamespaceAndSomeDCAndSomeCluster() throws Exception { Set<String> watchKeys = watchKeysUtil.assembleAllWatchKeys(someAppId, someCluster, someNamespace, someDC); Set<String> clusters = Sets.newHashSet(defaultCluster, someCluster, someDC); assertEquals(clusters.size(), watchKeys.size()); assertWatchKeys(someAppId, clusters, someNamespace, watchKeys); }
@Test public void testAssembleAllWatchKeysWithMultipleNamespaces() throws Exception { Multimap<String, String> watchKeysMap = watchKeysUtil.assembleAllWatchKeys(someAppId, someCluster, Sets.newHashSet(someNamespace, anotherNamespace), someDC); Set<String> clusters = Sets.newHashSet(defaultCluster, someCluster, someDC); assertEquals(clusters.size() * 2, watchKeysMap.size()); assertWatchKeys(someAppId, clusters, someNamespace, watchKeysMap.get(someNamespace)); assertWatchKeys(someAppId, clusters, anotherNamespace, watchKeysMap.get(anotherNamespace)); }
@Test public void testAssembleAllWatchKeysWithPrivateAndPublicNamespaces() throws Exception { Multimap<String, String> watchKeysMap = watchKeysUtil.assembleAllWatchKeys(someAppId, someCluster, Sets.newHashSet(someNamespace, anotherNamespace, somePublicNamespace), someDC); Set<String> clusters = Sets.newHashSet(defaultCluster, someCluster, someDC); assertEquals(clusters.size() * 4, watchKeysMap.size()); assertWatchKeys(someAppId, clusters, someNamespace, watchKeysMap.get(someNamespace)); assertWatchKeys(someAppId, clusters, anotherNamespace, watchKeysMap.get(anotherNamespace)); assertWatchKeys(someAppId, clusters, somePublicNamespace, watchKeysMap.get(somePublicNamespace)); assertWatchKeys(somePublicAppId, clusters, somePublicNamespace, watchKeysMap.get(somePublicNamespace)); }
@Test public void testAssembleWatchKeysForNoAppIdPlaceHolder() throws Exception { Multimap<String, String> watchKeysMap = watchKeysUtil.assembleAllWatchKeys(ConfigConsts.NO_APPID_PLACEHOLDER, someCluster, Sets.newHashSet(someNamespace, anotherNamespace), someDC); assertTrue(watchKeysMap.isEmpty()); }
@Test public void testAssembleWatchKeysForNoAppIdPlaceHolderAndPublicNamespace() throws Exception { Multimap<String, String> watchKeysMap = watchKeysUtil.assembleAllWatchKeys(ConfigConsts.NO_APPID_PLACEHOLDER, someCluster, Sets.newHashSet(someNamespace, somePublicNamespace), someDC); Set<String> clusters = Sets.newHashSet(defaultCluster, someCluster, someDC); assertEquals(clusters.size(), watchKeysMap.size()); assertWatchKeys(somePublicAppId, clusters, somePublicNamespace, watchKeysMap.get(somePublicNamespace)); }