27
27
import org .junit .ClassRule ;
28
28
import org .junit .Test ;
29
29
30
+ import org .apache .geode .management .api .ClusterManagementGetResult ;
30
31
import org .apache .geode .management .api .ClusterManagementListResult ;
32
+ import org .apache .geode .management .api .ClusterManagementResult ;
31
33
import org .apache .geode .management .api .ClusterManagementService ;
34
+ import org .apache .geode .management .api .ConfigurationInfo ;
32
35
import org .apache .geode .management .client .ClusterManagementServiceBuilder ;
33
36
import org .apache .geode .management .configuration .AbstractConfiguration ;
34
37
import org .apache .geode .management .configuration .Region ;
40
43
41
44
public class ListRegionManagementDunitTest {
42
45
46
+ public static final String REGION_WITH_MULTIPLE_TYPES = "region-with-multiple-types" ;
47
+ public static final String REGION_IN_MULTIPLE_GROUPS = "region-in-multiple-groups" ;
48
+ public static final String REGION_IN_CLUSTER = "region-in-cluster" ;
49
+ public static final String REGION_IN_SINGLE_GROUP = "region-in-single-group" ;
43
50
@ ClassRule
44
51
public static ClusterStartupRule cluster = new ClusterStartupRule ();
45
52
@@ -66,41 +73,41 @@ public static void beforeClass() throws Exception {
66
73
67
74
// create regions
68
75
Region regionConfig = new Region ();
69
- regionConfig .setName ("customers1" );
76
+ regionConfig .setName (REGION_IN_SINGLE_GROUP );
70
77
regionConfig .setGroup ("group1" );
71
78
regionConfig .setType (RegionType .PARTITION );
72
79
client .create (regionConfig );
73
- locator .waitUntilRegionIsReadyOnExactlyThisManyServers ("/customers1" , 1 );
80
+ locator .waitUntilRegionIsReadyOnExactlyThisManyServers ("/" + REGION_IN_SINGLE_GROUP , 1 );
74
81
75
82
// create a region that has different type on different group
76
83
regionConfig = new Region ();
77
- regionConfig .setName ("customers2" );
84
+ regionConfig .setName (REGION_WITH_MULTIPLE_TYPES );
78
85
regionConfig .setGroup ("group1" );
79
86
regionConfig .setType (RegionType .PARTITION_PROXY );
80
87
client .create (regionConfig );
81
88
82
89
regionConfig = new Region ();
83
- regionConfig .setName ("customers2" );
90
+ regionConfig .setName (REGION_WITH_MULTIPLE_TYPES );
84
91
regionConfig .setGroup ("group2" );
85
92
regionConfig .setType (RegionType .PARTITION );
86
93
client .create (regionConfig );
87
- locator .waitUntilRegionIsReadyOnExactlyThisManyServers ("/customers2" , 2 );
94
+ locator .waitUntilRegionIsReadyOnExactlyThisManyServers ("/" + REGION_WITH_MULTIPLE_TYPES , 2 );
88
95
89
96
regionConfig = new Region ();
90
- regionConfig .setName ("customers" );
97
+ regionConfig .setName (REGION_IN_CLUSTER );
91
98
regionConfig .setType (RegionType .PARTITION );
92
99
client .create (regionConfig );
93
- locator .waitUntilRegionIsReadyOnExactlyThisManyServers ("/customers" , 2 );
100
+ locator .waitUntilRegionIsReadyOnExactlyThisManyServers ("/" + REGION_IN_CLUSTER , 2 );
94
101
95
102
// create a region that belongs to multiple groups
96
103
regionConfig = new Region ();
97
- regionConfig .setName ("customers3" );
104
+ regionConfig .setName (REGION_IN_MULTIPLE_GROUPS );
98
105
regionConfig .setGroup ("group1" );
99
106
regionConfig .setType (RegionType .PARTITION );
100
107
client .create (regionConfig );
101
108
regionConfig .setGroup ("group2" );
102
109
client .create (regionConfig );
103
- locator .waitUntilRegionIsReadyOnExactlyThisManyServers ("/customers3" , 2 );
110
+ locator .waitUntilRegionIsReadyOnExactlyThisManyServers ("/" + REGION_IN_MULTIPLE_GROUPS , 2 );
104
111
}
105
112
106
113
@ Before
@@ -113,55 +120,77 @@ public void listAll() {
113
120
// list all
114
121
List <Region > regions = client .list (filter ).getConfigResult ();
115
122
assertThat (regions ).hasSize (6 );
116
- Region element = find (regions , "customers" );
123
+ Region element = find (regions , REGION_IN_CLUSTER );
117
124
assertThat (element .getGroup ()).isNull ();
118
125
119
- element = find (regions , "customers1" );
126
+ element = find (regions , REGION_IN_SINGLE_GROUP );
120
127
assertThat (element .getGroup ()).isEqualTo ("group1" );
121
128
122
- assertThat (regions .stream ().filter (x -> x .getId ().equals ("customers2" )).map (Region ::getGroup )
129
+ assertThat (regions .stream ().filter (x -> x .getId ().equals (REGION_WITH_MULTIPLE_TYPES ))
130
+ .map (Region ::getGroup )
123
131
.collect (Collectors .toList ())).containsExactlyInAnyOrder ("group1" , "group2" );
124
132
125
- assertThat (regions .stream ().filter (x -> x .getId ().equals ("customers2" )).map (Region ::getType )
133
+ assertThat (regions .stream ().filter (x -> x .getId ().equals (REGION_WITH_MULTIPLE_TYPES ))
134
+ .map (Region ::getType )
126
135
.collect (Collectors .toList ())).containsExactlyInAnyOrder (RegionType .PARTITION ,
127
136
RegionType .PARTITION_PROXY );
128
137
129
- assertThat (regions .stream ().filter (x -> x .getId ().equals ("customers3" )).map (Region ::getGroup )
138
+ assertThat (regions .stream ().filter (x -> x .getId ().equals (REGION_IN_MULTIPLE_GROUPS ))
139
+ .map (Region ::getGroup )
130
140
.collect (Collectors .toList ())).containsExactlyInAnyOrder ("group1" , "group2" );
131
141
}
132
142
143
+ @ Test
144
+ public void getRegionInMultipleGroups () throws Exception {
145
+ Region region = new Region ();
146
+ // customers2 belongs to multiple groups
147
+ region .setName (REGION_WITH_MULTIPLE_TYPES );
148
+ ClusterManagementGetResult <Region , RuntimeRegionInfo > result =
149
+ client .get (region );
150
+ assertThat (result .getStatusCode ()).isEqualTo (ClusterManagementResult .StatusCode .OK );
151
+ ConfigurationInfo <Region , RuntimeRegionInfo > configInfo = result .getResult ();
152
+ assertThat (configInfo .getId ()).isEqualTo (REGION_WITH_MULTIPLE_TYPES );
153
+ assertThat (configInfo .getConfigurations ()).extracting (Region ::getName )
154
+ .containsExactlyInAnyOrder (
155
+ REGION_WITH_MULTIPLE_TYPES , REGION_WITH_MULTIPLE_TYPES );
156
+ assertThat (configInfo .getConfigurations ()).extracting (Region ::getType )
157
+ .containsExactlyInAnyOrder (RegionType .PARTITION , RegionType .PARTITION_PROXY );
158
+ assertThat (configInfo .getConfigurations ()).extracting (Region ::getGroup )
159
+ .containsExactlyInAnyOrder ("group1" , "group2" );
160
+ }
161
+
133
162
@ Test
134
163
public void listClusterLevel () {
135
164
// list cluster level only
136
165
filter .setGroup ("cluster" );
137
166
List <Region > regions = client .list (filter ).getConfigResult ();
138
167
assertThat (regions ).hasSize (1 );
139
- assertThat (regions .get (0 ).getId ()).isEqualTo ("customers" );
168
+ assertThat (regions .get (0 ).getId ()).isEqualTo (REGION_IN_CLUSTER );
140
169
assertThat (regions .get (0 ).getGroup ()).isNull ();
141
170
}
142
171
143
172
@ Test
144
173
public void testEntryCount () {
145
174
server1 .invoke (() -> {
146
175
org .apache .geode .cache .Region <String , String > region =
147
- ClusterStartupRule .getCache ().getRegion ("/customers" );
176
+ ClusterStartupRule .getCache ().getRegion ("/" + REGION_IN_CLUSTER );
148
177
region .put ("k1" , "v1" );
149
178
region .put ("k2" , "v2" );
150
179
});
151
180
152
181
// wait till entry size are correctly gathered by the mbean
153
182
locator .invoke (() -> {
154
183
await ().untilAsserted (
155
- () -> assertThat (ClusterStartupRule .memberStarter .getRegionMBean ("/customers" )
184
+ () -> assertThat (ClusterStartupRule .memberStarter .getRegionMBean ("/" + REGION_IN_CLUSTER )
156
185
.getSystemRegionEntryCount ()).isEqualTo (2 ));
157
186
});
158
187
159
- filter .setName ("customers" );
188
+ filter .setName (REGION_IN_CLUSTER );
160
189
ClusterManagementListResult <Region , RuntimeRegionInfo > result = client .list (filter );
161
190
List <Region > regions = result .getConfigResult ();
162
191
assertThat (regions ).hasSize (1 );
163
192
Region regionConfig = regions .get (0 );
164
- assertThat (regionConfig .getName ()).isEqualTo ("customers" );
193
+ assertThat (regionConfig .getName ()).isEqualTo (REGION_IN_CLUSTER );
165
194
166
195
List <RuntimeRegionInfo > runtimeRegionInfos = result .getRuntimeResult ();
167
196
assertThat (runtimeRegionInfos ).hasSize (1 );
@@ -175,13 +204,13 @@ public void listGroup1() {
175
204
List <Region > regions = client .list (filter ).getConfigResult ();
176
205
assertThat (regions ).hasSize (3 );
177
206
// when filtering by group, the returned list should not have group info
178
- Region region = find (regions , "customers1" );
207
+ Region region = find (regions , REGION_IN_SINGLE_GROUP );
179
208
assertThat (region .getGroup ()).isEqualTo ("group1" );
180
209
181
- region = find (regions , "customers2" );
210
+ region = find (regions , REGION_WITH_MULTIPLE_TYPES );
182
211
assertThat (region .getGroup ()).isEqualTo ("group1" );
183
212
184
- region = find (regions , "customers3" );
213
+ region = find (regions , REGION_IN_MULTIPLE_GROUPS );
185
214
assertThat (region .getGroup ()).isEqualTo ("group1" );
186
215
}
187
216
@@ -192,10 +221,10 @@ public void listGroup2() {
192
221
List <Region > regions = client .list (filter ).getConfigResult ();
193
222
assertThat (regions ).hasSize (2 );
194
223
195
- Region region = find (regions , "customers2" );
224
+ Region region = find (regions , REGION_WITH_MULTIPLE_TYPES );
196
225
assertThat (region .getGroup ()).isEqualTo ("group2" );
197
226
198
- region = find (regions , "customers3" );
227
+ region = find (regions , REGION_IN_MULTIPLE_GROUPS );
199
228
assertThat (region .getGroup ()).isEqualTo ("group2" );
200
229
}
201
230
@@ -209,25 +238,25 @@ public void listNonExistentGroup() {
209
238
210
239
@ Test
211
240
public void listRegionByName () {
212
- filter .setName ("customers" );
241
+ filter .setName (REGION_IN_CLUSTER );
213
242
List <Region > regions = client .list (filter ).getConfigResult ();
214
243
assertThat (regions ).hasSize (1 );
215
- assertThat (regions .get (0 ).getId ()).isEqualTo ("customers" );
244
+ assertThat (regions .get (0 ).getId ()).isEqualTo (REGION_IN_CLUSTER );
216
245
assertThat (regions .get (0 ).getGroup ()).isNull ();
217
246
}
218
247
219
248
@ Test
220
249
public void listRegionByName1 () {
221
- filter .setName ("customers1" );
250
+ filter .setName (REGION_IN_SINGLE_GROUP );
222
251
List <Region > regions = client .list (filter ).getConfigResult ();
223
252
assertThat (regions ).hasSize (1 );
224
- assertThat (regions .get (0 ).getId ()).isEqualTo ("customers1" );
253
+ assertThat (regions .get (0 ).getId ()).isEqualTo (REGION_IN_SINGLE_GROUP );
225
254
assertThat (regions .get (0 ).getGroup ()).isEqualTo ("group1" );
226
255
}
227
256
228
257
@ Test
229
258
public void listRegionByName2 () {
230
- filter .setName ("customers2" );
259
+ filter .setName (REGION_WITH_MULTIPLE_TYPES );
231
260
List <Region > regions = client .list (filter ).getConfigResult ();
232
261
assertThat (regions ).hasSize (2 );
233
262
assertThat (
@@ -241,7 +270,7 @@ public void listRegionByName2() {
241
270
242
271
@ Test
243
272
public void listRegionByName3 () {
244
- filter .setName ("customers3" );
273
+ filter .setName (REGION_IN_MULTIPLE_GROUPS );
245
274
List <Region > regions = client .list (filter ).getConfigResult ();
246
275
assertThat (regions ).hasSize (2 );
247
276
assertThat (regions ).extracting (Region ::getGroup ).containsExactlyInAnyOrder ("group1" , "group2" );
@@ -250,7 +279,7 @@ public void listRegionByName3() {
250
279
@ Test
251
280
public void listNonExistentRegion () {
252
281
// list non-existent region
253
- filter .setName ("customer4 " );
282
+ filter .setName ("non-existent-region " );
254
283
List <Region > regions = client .list (filter ).getConfigResult ();
255
284
assertThat (regions ).hasSize (0 );
256
285
}
0 commit comments