NamespaceUnlockAspect { boolean isModified(Namespace namespace) { Release release = releaseService.findLatestActiveRelease(namespace); List<Item> items = itemService.findItemsWithoutOrdered(namespace.getId()); if (release == null) { return hasNormalItems(items); } Map<String, String> releasedConfiguration = GSON.fromJson(release.getConfigurations(), GsonType.CONFIG); Map<String, String> configurationFromItems = generateConfigurationFromItems(namespace, items); MapDifference<String, String> difference = Maps.difference(releasedConfiguration, configurationFromItems); return !difference.areEqual(); } NamespaceUnlockAspect(
      final NamespaceLockService namespaceLockService,
      final NamespaceService namespaceService,
      final ItemService itemService,
      final ReleaseService releaseService,
      final BizConfig bizConfig); @After("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, item, ..)") void requireLockAdvice(String appId, String clusterName, String namespaceName,
                                ItemDTO item); @After("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, itemId, item, ..)") void requireLockAdvice(String appId, String clusterName, String namespaceName, long itemId,
                                ItemDTO item); @After("@annotation(PreAcquireNamespaceLock) && args(appId, clusterName, namespaceName, changeSet, ..)") void requireLockAdvice(String appId, String clusterName, String namespaceName,
                                ItemChangeSets changeSet); @After("@annotation(PreAcquireNamespaceLock) && args(itemId, operator, ..)") void requireLockAdvice(long itemId, String operator);  }
@Test public void testNamespaceHasNoNormalItemsAndRelease() { long namespaceId = 1; Namespace namespace = createNamespace(namespaceId); when(releaseService.findLatestActiveRelease(namespace)).thenReturn(null); when(itemService.findItemsWithoutOrdered(namespaceId)).thenReturn(Collections.singletonList(createItem("", ""))); boolean isModified = namespaceUnlockAspect.isModified(namespace); Assert.assertFalse(isModified); }
@Test public void testNamespaceAddItem() { long namespaceId = 1; Namespace namespace = createNamespace(namespaceId); Release release = createRelease("{\"k1\":\"v1\"}"); List<Item> items = Arrays.asList(createItem("k1", "v1"), createItem("k2", "v2")); when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release); when(itemService.findItemsWithoutOrdered(namespaceId)).thenReturn(items); when(namespaceService.findParentNamespace(namespace)).thenReturn(null); boolean isModified = namespaceUnlockAspect.isModified(namespace); Assert.assertTrue(isModified); }
@Test public void testNamespaceModifyItem() { long namespaceId = 1; Namespace namespace = createNamespace(namespaceId); Release release = createRelease("{\"k1\":\"v1\"}"); List<Item> items = Collections.singletonList(createItem("k1", "v2")); when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release); when(itemService.findItemsWithoutOrdered(namespaceId)).thenReturn(items); when(namespaceService.findParentNamespace(namespace)).thenReturn(null); boolean isModified = namespaceUnlockAspect.isModified(namespace); Assert.assertTrue(isModified); }
@Test public void testNamespaceDeleteItem() { long namespaceId = 1; Namespace namespace = createNamespace(namespaceId); Release release = createRelease("{\"k1\":\"v1\"}"); List<Item> items = Collections.singletonList(createItem("k2", "v2")); when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release); when(itemService.findItemsWithoutOrdered(namespaceId)).thenReturn(items); when(namespaceService.findParentNamespace(namespace)).thenReturn(null); boolean isModified = namespaceUnlockAspect.isModified(namespace); Assert.assertTrue(isModified); }
@Test public void testChildNamespaceModified() { long childNamespaceId = 1, parentNamespaceId = 2; Namespace childNamespace = createNamespace(childNamespaceId); Namespace parentNamespace = createNamespace(parentNamespaceId); Release childRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}"); List<Item> childItems = Collections.singletonList(createItem("k1", "v3")); Release parentRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}"); when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease); when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(parentRelease); when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems); when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace); boolean isModified = namespaceUnlockAspect.isModified(childNamespace); Assert.assertTrue(isModified); }
@Test public void testChildNamespaceNotModified() { long childNamespaceId = 1, parentNamespaceId = 2; Namespace childNamespace = createNamespace(childNamespaceId); Namespace parentNamespace = createNamespace(parentNamespaceId); Release childRelease = createRelease("{\"k1\":\"v3\", \"k2\":\"v2\"}"); List<Item> childItems = Collections.singletonList(createItem("k1", "v3")); Release parentRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}"); when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease); when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(parentRelease); when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems); when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace); boolean isModified = namespaceUnlockAspect.isModified(childNamespace); Assert.assertFalse(isModified); }
@Test public void testParentNamespaceNotReleased() { long childNamespaceId = 1, parentNamespaceId = 2; Namespace childNamespace = createNamespace(childNamespaceId); Namespace parentNamespace = createNamespace(parentNamespaceId); Release childRelease = createRelease("{\"k1\":\"v3\", \"k2\":\"v2\"}"); List<Item> childItems = Arrays.asList(createItem("k1", "v2"), createItem("k2", "v2")); when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease); when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(null); when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems); when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace); boolean isModified = namespaceUnlockAspect.isModified(childNamespace); Assert.assertTrue(isModified); }