@@ -175,7 +175,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
175175 }
176176 });
177177 wrr = new WeightedRoundRobinLoadBalancer (helper , fakeClock .getDeadlineTicker (),
178- new FakeRandom ());
178+ new FakeRandom (0 ));
179179 }
180180
181181 @ Test
@@ -919,15 +919,15 @@ public void testAllInvalidWeightsUseOne() {
919919 }
920920
921921 @ Test
922- public void testLacrgestWeightIndexPickedEveryGeneration () {
922+ public void testLargestWeightIndexPickedEveryGeneration () {
923923 float [] weights = {1.0f , 2.0f , 3.0f };
924- int mean = 2 ;
924+ int largestWeightIndex = 2 ;
925925 Random random = new Random ();
926926 StaticStrideScheduler sss = new StaticStrideScheduler (weights , random );
927927 int largestWeightPickCount = 0 ;
928928 int kMaxWeight = 65535 ;
929- for (int i = 0 ; i < mean * kMaxWeight ; i ++) {
930- if (sss .pick () == mean ) {
929+ for (int i = 0 ; i < largestWeightIndex * kMaxWeight ; i ++) {
930+ if (sss .pick () == largestWeightIndex ) {
931931 largestWeightPickCount += 1 ;
932932 }
933933 }
@@ -1022,7 +1022,7 @@ public void testManyComplexWeights() {
10221022 @ Test
10231023 public void testDeterministicPicks () {
10241024 float [] weights = {2.0f , 3.0f , 6.0f };
1025- Random random = new FakeRandom ();
1025+ Random random = new FakeRandom (0 );
10261026 StaticStrideScheduler sss = new StaticStrideScheduler (weights , random );
10271027 assertThat (sss .getSequence ()).isEqualTo (0 );
10281028 assertThat (sss .pick ()).isEqualTo (1 );
@@ -1042,7 +1042,7 @@ public void testDeterministicPicks() {
10421042 @ Test
10431043 public void testImmediateWraparound () {
10441044 float [] weights = {1.0f , 2.0f , 3.0f , 4.0f , 5.0f };
1045- Random random = new FakeRandomWraparound ( );
1045+ Random random = new FakeRandom (- 1 );
10461046 StaticStrideScheduler sss = new StaticStrideScheduler (weights , random );
10471047 double totalWeight = 15 ;
10481048 Map <Integer , Integer > pickCount = new HashMap <>();
@@ -1059,7 +1059,7 @@ public void testImmediateWraparound() {
10591059 @ Test
10601060 public void testWraparound () {
10611061 float [] weights = {1.0f , 2.0f , 3.0f , 4.0f , 5.0f };
1062- Random random = new FakeRandomWraparound2 ( );
1062+ Random random = new FakeRandom (- 500 );
10631063 StaticStrideScheduler sss = new StaticStrideScheduler (weights , random );
10641064 double totalWeight = 15 ;
10651065 Map <Integer , Integer > pickCount = new HashMap <>();
@@ -1076,7 +1076,7 @@ public void testWraparound() {
10761076 @ Test
10771077 public void testDeterministicWraparound () {
10781078 float [] weights = {2.0f , 3.0f , 6.0f };
1079- Random random = new FakeRandomWraparound ( );
1079+ Random random = new FakeRandom (- 1 );
10801080 StaticStrideScheduler sss = new StaticStrideScheduler (weights , random );
10811081 assertThat (sss .getSequence ()).isEqualTo (0xFFFF_FFFFL );
10821082 assertThat (sss .pick ()).isEqualTo (1 );
@@ -1106,25 +1106,17 @@ private static class FakeSocketAddress extends SocketAddress {
11061106 }
11071107
11081108 private static class FakeRandom extends Random {
1109- @ Override
1110- public int nextInt () {
1111- // return constant value to disable init deadline randomization in the scheduler
1112- // sequence will be initialized to 0
1113- return 0 ;
1114- }
1115- }
1109+ private int nextInt ;
11161110
1117- private static class FakeRandomWraparound extends Random {
1118- @ Override
1119- public int nextInt () {
1120- return -1 ;
1111+ public FakeRandom (int nextInt ) {
1112+ this .nextInt = nextInt ;
11211113 }
1122- }
11231114
1124- private static class FakeRandomWraparound2 extends Random {
11251115 @ Override
11261116 public int nextInt () {
1127- return -500 ;
1117+ // return constant value to disable init deadline randomization in the scheduler
1118+ // sequence will be initialized to 0
1119+ return nextInt ;
11281120 }
11291121 }
11301122}
0 commit comments