Skip to content

Commit d327f07

Browse files
authored
Merge pull request apolloconfig#565 from lepdou/lock
bugfix: still lock branch when master modified
2 parents 573b118 + c08abef commit d327f07

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/aop/NamespaceUnlockAspect.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ private Map<String, String> generateConfigurationFromItems(Namespace namespace,
133133
if (parentNamespace == null) {
134134
generateMapFromItems(namespaceItems, configurationFromItems);
135135
} else {//child namespace
136-
List<Item> parentItems = itemService.findItems(parentNamespace.getId());
137-
138-
generateMapFromItems(parentItems, configurationFromItems);
136+
Release parentRelease = releaseService.findLatestActiveRelease(parentNamespace);
137+
if (parentRelease != null) {
138+
configurationFromItems = gson.fromJson(parentRelease.getConfigurations(), GsonType.CONFIG);
139+
}
139140
generateMapFromItems(namespaceItems, configurationFromItems);
140141
}
141142

apollo-adminservice/src/test/java/com/ctrip/framework/apollo/adminservice/aop/NamespaceUnlockAspectTest.java

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,18 @@ public void testNamespaceDeleteItem() {
103103
public void testChildNamespaceModified() {
104104
long childNamespaceId = 1, parentNamespaceId = 2;
105105
Namespace childNamespace = createNamespace(childNamespaceId);
106-
Namespace parentNamespace = createNamespace(childNamespaceId);
106+
Namespace parentNamespace = createNamespace(parentNamespaceId);
107107

108108
Release childRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
109109
List<Item> childItems = Arrays.asList(createItem("k1", "v3"));
110-
List<Item> parentItems = Arrays.asList(createItem("k1", "v1"), createItem("k2", "v2"));
110+
Release parentRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
111111

112112
when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
113+
when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(parentRelease);
113114
when(itemService.findItems(childNamespaceId)).thenReturn(childItems);
114-
when(itemService.findItems(parentNamespaceId)).thenReturn(parentItems);
115-
when(namespaceService.findParentNamespace(parentNamespace)).thenReturn(parentNamespace);
115+
when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
116116

117-
boolean isModified = namespaceUnlockAspect.isModified(parentNamespace);
117+
boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
118118

119119
Assert.assertTrue(isModified);
120120
}
@@ -123,18 +123,37 @@ public void testChildNamespaceModified() {
123123
public void testChildNamespaceNotModified() {
124124
long childNamespaceId = 1, parentNamespaceId = 2;
125125
Namespace childNamespace = createNamespace(childNamespaceId);
126-
Namespace parentNamespace = createNamespace(childNamespaceId);
126+
Namespace parentNamespace = createNamespace(parentNamespaceId);
127127

128-
Release childRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
129-
List<Item> childItems = Arrays.asList(createItem("k1", "v1"));
130-
List<Item> parentItems = Arrays.asList(createItem("k2", "v2"));
128+
Release childRelease = createRelease("{\"k1\":\"v3\", \"k2\":\"v2\"}");
129+
List<Item> childItems = Arrays.asList(createItem("k1", "v3"));
130+
Release parentRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
131+
132+
when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
133+
when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(parentRelease);
134+
when(itemService.findItems(childNamespaceId)).thenReturn(childItems);
135+
when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
136+
137+
boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
138+
139+
Assert.assertFalse(isModified);
140+
}
141+
142+
@Test
143+
public void testParentNamespaceNotReleased() {
144+
long childNamespaceId = 1, parentNamespaceId = 2;
145+
Namespace childNamespace = createNamespace(childNamespaceId);
146+
Namespace parentNamespace = createNamespace(parentNamespaceId);
147+
148+
Release childRelease = createRelease("{\"k1\":\"v3\", \"k2\":\"v2\"}");
149+
List<Item> childItems = Arrays.asList(createItem("k1", "v2"), createItem("k2", "v2"));
131150

132151
when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
152+
when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(null);
133153
when(itemService.findItems(childNamespaceId)).thenReturn(childItems);
134-
when(itemService.findItems(parentNamespaceId)).thenReturn(parentItems);
135-
when(namespaceService.findParentNamespace(parentNamespace)).thenReturn(parentNamespace);
154+
when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
136155

137-
boolean isModified = namespaceUnlockAspect.isModified(parentNamespace);
156+
boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
138157

139158
Assert.assertTrue(isModified);
140159
}

0 commit comments

Comments
 (0)