@@ -2142,6 +2142,55 @@ public void testShuffleWithMask() {
2142
2142
assertTrue (shuffleOccurred );
2143
2143
}
2144
2144
2145
+ @ Test
2146
+ public void testUpdateTopologyWithRackChange () throws Exception {
2147
+ String defaultRackForThisTest = NetworkTopology .DEFAULT_REGION_AND_RACK ;
2148
+ repp .uninitalize ();
2149
+ updateMyRack (defaultRackForThisTest );
2150
+
2151
+ // Update cluster
2152
+ BookieSocketAddress newAddr1 = new BookieSocketAddress ("127.0.0.100" , 3181 );
2153
+ BookieSocketAddress newAddr2 = new BookieSocketAddress ("127.0.0.101" , 3181 );
2154
+ BookieSocketAddress newAddr3 = new BookieSocketAddress ("127.0.0.102" , 3181 );
2155
+ BookieSocketAddress newAddr4 = new BookieSocketAddress ("127.0.0.103" , 3181 );
2156
+
2157
+ // update dns mapping
2158
+ StaticDNSResolver .addNodeToRack (newAddr1 .getHostName (), defaultRackForThisTest );
2159
+ StaticDNSResolver .addNodeToRack (newAddr2 .getHostName (), defaultRackForThisTest );
2160
+ StaticDNSResolver .addNodeToRack (newAddr3 .getHostName (), defaultRackForThisTest );
2161
+ StaticDNSResolver .addNodeToRack (newAddr4 .getHostName (), defaultRackForThisTest );
2162
+
2163
+ TestStatsProvider statsProvider = new TestStatsProvider ();
2164
+ TestStatsLogger statsLogger = statsProvider .getStatsLogger ("" );
2165
+
2166
+ repp = new RackawareEnsemblePlacementPolicy ();
2167
+ repp .initialize (conf , Optional .<DNSToSwitchMapping > empty (), timer ,
2168
+ DISABLE_ALL , statsLogger , BookieSocketAddress .LEGACY_BOOKIEID_RESOLVER );
2169
+ repp .withDefaultRack (defaultRackForThisTest );
2170
+
2171
+ Gauge <? extends Number > numBookiesInDefaultRackGauge = statsLogger
2172
+ .getGauge (BookKeeperClientStats .NUM_WRITABLE_BOOKIES_IN_DEFAULT_RACK );
2173
+
2174
+ Set <BookieId > writeableBookies = new HashSet <>();
2175
+ Set <BookieId > readOnlyBookies = new HashSet <>();
2176
+ writeableBookies .add (newAddr1 .toBookieId ());
2177
+ writeableBookies .add (newAddr2 .toBookieId ());
2178
+ writeableBookies .add (newAddr3 .toBookieId ());
2179
+ writeableBookies .add (newAddr4 .toBookieId ());
2180
+ repp .onClusterChanged (writeableBookies , readOnlyBookies );
2181
+ // only writable bookie - newAddr1 in default rack
2182
+ assertEquals ("NUM_WRITABLE_BOOKIES_IN_DEFAULT_RACK guage value" , 4 , numBookiesInDefaultRackGauge .getSample ());
2183
+
2184
+ // newAddr4 rack is changed and it is not in default anymore
2185
+ StaticDNSResolver
2186
+ .changeRack (Collections .singletonList (newAddr3 ), Collections .singletonList ("/default-region/r4" ));
2187
+ assertEquals ("NUM_WRITABLE_BOOKIES_IN_DEFAULT_RACK guage value" , 3 , numBookiesInDefaultRackGauge .getSample ());
2188
+
2189
+ StaticDNSResolver
2190
+ .changeRack (Collections .singletonList (newAddr1 ), Collections .singletonList (defaultRackForThisTest ));
2191
+ assertEquals ("NUM_WRITABLE_BOOKIES_IN_DEFAULT_RACK guage value" , 3 , numBookiesInDefaultRackGauge .getSample ());
2192
+ }
2193
+
2145
2194
@ Test
2146
2195
public void testNumBookiesInDefaultRackGauge () throws Exception {
2147
2196
String defaultRackForThisTest = NetworkTopology .DEFAULT_REGION_AND_RACK ;
0 commit comments