4040import org .apache .bookkeeper .proto .BookieAddressResolver ;
4141import org .apache .bookkeeper .test .TestStatsProvider ;
4242import org .apache .bookkeeper .util .StaticDNSResolver ;
43+ import org .apache .commons .lang3 .reflect .FieldUtils ;
4344import org .junit .Before ;
4445import org .junit .Test ;
4546
@@ -54,7 +55,7 @@ public class RackawareEnsemblePlacementPolicyImplTest {
5455 String defaultRack = "/default-rack" ;
5556
5657 @ Before
57- public void setUp () {
58+ public void setUp () throws IllegalAccessException {
5859 TestStatsProvider provider = new TestStatsProvider ();
5960 policy = new RackawareEnsemblePlacementPolicyImpl ();
6061 ClientConfiguration clientConfiguration = mock (ClientConfiguration .class );
@@ -77,7 +78,7 @@ public void setUp() {
7778 .thenReturn (Collections .emptySet ());
7879
7980 // Use reflection to inject the mock topology into the policy
80- TestUtils . setField ( TopologyAwareEnsemblePlacementPolicy . class , policy , "topology" , topology );
81+ FieldUtils . writeField ( policy , "topology" , topology , true );
8182 }
8283
8384 @ Test
@@ -139,17 +140,4 @@ public void testEmptyDefaultRackBookies() {
139140 // Verify: should return the original exclusion set
140141 assertSame (excludeBookies , result );
141142 }
142- }
143-
144- // Utility class for setting private fields
145- class TestUtils {
146- public static void setField (Class <?> tclass , Object target , String fieldName , Object value ) {
147- try {
148- java .lang .reflect .Field field = tclass .getDeclaredField (fieldName );
149- field .setAccessible (true );
150- field .set (target , value );
151- } catch (Exception e ) {
152- throw new RuntimeException (e );
153- }
154- }
155- }
143+ }
0 commit comments