110110public class TransferShedderTest {
111111 double setupLoadAvg = 0.36400000000000005 ;
112112 double setupLoadStd = 0.3982762860126121 ;
113+ double delta = 1e-5 ;
113114
114115 PulsarService pulsar ;
115116 NamespaceService namespaceService ;
@@ -522,8 +523,8 @@ public void testNoOwnerLoadData() throws IllegalAccessException {
522523 var res = transferShedder .findBundlesForUnloading (ctx , Map .of (), Map .of ());
523524 assertTrue (res .isEmpty ());
524525 assertEquals (counter .getBreakdownCounters ().get (Skip ).get (NoBundles ).get (), 1 );
525- assertEquals (counter .getLoadAvg (), setupLoadAvg );
526- assertEquals (counter .getLoadStd (), setupLoadStd );
526+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
527+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
527528 }
528529
529530 @ Test
@@ -543,8 +544,8 @@ public void testEmptyTopBundlesLoadData() {
543544 var res = transferShedder .findBundlesForUnloading (ctx , Map .of (), Map .of ());
544545 assertTrue (res .isEmpty ());
545546 assertEquals (counter .getBreakdownCounters ().get (Skip ).get (NoLoadData ).get (), 1 );
546- assertEquals (counter .getLoadAvg (), setupLoadAvg );
547- assertEquals (counter .getLoadStd (), setupLoadStd );
547+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
548+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
548549 }
549550
550551 @ Test
@@ -587,8 +588,8 @@ public void testRecentlyUnloadedBrokers() {
587588 expected .add (new UnloadDecision (new Unload ("broker4:8080" , bundleD1 , Optional .of ("broker2:8080" )),
588589 Success , Overloaded ));
589590 assertEquals (res , expected );
590- assertEquals (counter .getLoadAvg (), setupLoadAvg );
591- assertEquals (counter .getLoadStd (), setupLoadStd );
591+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
592+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
592593
593594 var now = System .currentTimeMillis ();
594595 recentlyUnloadedBrokers .put ("broker1:8080" , now );
@@ -616,8 +617,8 @@ public void testRecentlyUnloadedBundles() {
616617 Optional .of ("broker1:8080" )),
617618 Success , Overloaded ));
618619 assertEquals (res , expected );
619- assertEquals (counter .getLoadAvg (), setupLoadAvg );
620- assertEquals (counter .getLoadStd (), setupLoadStd );
620+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
621+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
621622 }
622623
623624 @ Test
@@ -635,8 +636,8 @@ public void testSheddingExcludedNamespaces() {
635636 Optional .of ("broker1:8080" )),
636637 Success , Overloaded ));
637638 assertEquals (res , expected );
638- assertEquals (counter .getLoadAvg (), setupLoadAvg );
639- assertEquals (counter .getLoadStd (), setupLoadStd );
639+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
640+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
640641 }
641642
642643 @ Test
@@ -674,8 +675,8 @@ public void testBundlesWithIsolationPolicies() {
674675 expected .add (new UnloadDecision (new Unload ("broker4:8080" , bundleD1 , Optional .of ("broker1:8080" )),
675676 Success , Overloaded ));
676677 assertEquals (res , expected );
677- assertEquals (counter .getLoadAvg (), setupLoadAvg );
678- assertEquals (counter .getLoadStd (), setupLoadStd );
678+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
679+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
679680
680681 // Test unload a has isolation policies broker.
681682 ctx .brokerConfiguration ().setLoadBalancerTransferEnabled (false );
@@ -685,8 +686,8 @@ public void testBundlesWithIsolationPolicies() {
685686 expected .add (new UnloadDecision (new Unload ("broker4:8080" , bundleD1 , Optional .empty ()),
686687 Success , Overloaded ));
687688 assertEquals (res , expected );
688- assertEquals (counter .getLoadAvg (), setupLoadAvg );
689- assertEquals (counter .getLoadStd (), setupLoadStd );
689+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
690+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
690691
691692
692693 // test setLoadBalancerSheddingBundlesWithPoliciesEnabled=false;
@@ -697,16 +698,16 @@ public void testBundlesWithIsolationPolicies() {
697698 res = transferShedder .findBundlesForUnloading (ctx , Map .of (), Map .of ());
698699 assertTrue (res .isEmpty ());
699700 assertEquals (counter .getBreakdownCounters ().get (Skip ).get (NoBundles ).get (), 1 );
700- assertEquals (counter .getLoadAvg (), setupLoadAvg );
701- assertEquals (counter .getLoadStd (), setupLoadStd );
701+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
702+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
702703
703704 // Test unload a has isolation policies broker.
704705 ctx .brokerConfiguration ().setLoadBalancerTransferEnabled (false );
705706 res = transferShedder .findBundlesForUnloading (ctx , Map .of (), Map .of ());
706707 assertTrue (res .isEmpty ());
707708 assertEquals (counter .getBreakdownCounters ().get (Skip ).get (NoBundles ).get (), 2 );
708- assertEquals (counter .getLoadAvg (), setupLoadAvg );
709- assertEquals (counter .getLoadStd (), setupLoadStd );
709+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
710+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
710711 }
711712
712713 public BrokerLookupData getLookupData () {
@@ -788,8 +789,8 @@ public void testBundlesWithAntiAffinityGroup() throws MetadataStoreException {
788789
789790 assertTrue (res .isEmpty ());
790791 assertEquals (counter .getBreakdownCounters ().get (Skip ).get (NoBundles ).get (), 1 );
791- assertEquals (counter .getLoadAvg (), setupLoadAvg );
792- assertEquals (counter .getLoadStd (), setupLoadStd );
792+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
793+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
793794
794795 doAnswer (invocationOnMock -> {
795796 Map <String , BrokerLookupData > brokers = invocationOnMock .getArgument (0 );
@@ -806,8 +807,8 @@ public void testBundlesWithAntiAffinityGroup() throws MetadataStoreException {
806807 expected2 .add (new UnloadDecision (new Unload ("broker5:8080" , bundleE1 , Optional .of ("broker1:8080" )),
807808 Success , Overloaded ));
808809 assertEquals (res2 , expected2 );
809- assertEquals (counter .getLoadAvg (), setupLoadAvg );
810- assertEquals (counter .getLoadStd (), setupLoadStd );
810+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
811+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
811812 }
812813
813814 @ Test
@@ -837,8 +838,8 @@ public CompletableFuture<Map<String, BrokerLookupData>> filterAsync(Map<String,
837838
838839 assertTrue (res .isEmpty ());
839840 assertEquals (counter .getBreakdownCounters ().get (Skip ).get (NoBundles ).get (), 1 );
840- assertEquals (counter .getLoadAvg (), setupLoadAvg );
841- assertEquals (counter .getLoadStd (), setupLoadStd );
841+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
842+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
842843 }
843844
844845 @ Test
@@ -900,8 +901,8 @@ public void testTargetStd() {
900901
901902 assertTrue (res .isEmpty ());
902903 assertEquals (counter .getBreakdownCounters ().get (Skip ).get (HitCount ).get (), 1 );
903- assertEquals (counter .getLoadAvg (), 0.2000000063578288 );
904- assertEquals (counter .getLoadStd (), 0.08164966587949089 );
904+ assertEquals (counter .getLoadAvg (), 0.2000000063578288 , delta );
905+ assertEquals (counter .getLoadStd (), 0.08164966587949089 , delta );
905906 }
906907
907908 @ Test
@@ -919,8 +920,8 @@ public void testSingleTopBundlesLoadData() {
919920
920921 assertTrue (res .isEmpty ());
921922 assertEquals (counter .getBreakdownCounters ().get (Skip ).get (NoBundles ).get (), 1 );
922- assertEquals (counter .getLoadAvg (), setupLoadAvg );
923- assertEquals (counter .getLoadStd (), setupLoadStd );
923+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
924+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
924925 }
925926
926927 @ Test
@@ -941,8 +942,8 @@ public void testBundleThroughputLargerThanOffloadThreshold() {
941942 Optional .of ("broker1:8080" )),
942943 Success , Overloaded ));
943944 assertEquals (res , expected );
944- assertEquals (counter .getLoadAvg (), setupLoadAvg );
945- assertEquals (counter .getLoadStd (), setupLoadStd );
945+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
946+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
946947 }
947948
948949 @ Test
@@ -961,8 +962,8 @@ public void testZeroBundleThroughput() {
961962 var res = transferShedder .findBundlesForUnloading (ctx , Map .of (), Map .of ());
962963 assertTrue (res .isEmpty ());
963964 assertEquals (counter .getBreakdownCounters ().get (Skip ).get (NoBundles ).get (), 1 );
964- assertEquals (counter .getLoadAvg (), setupLoadAvg );
965- assertEquals (counter .getLoadStd (), setupLoadStd );
965+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
966+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
966967 }
967968
968969
@@ -980,8 +981,8 @@ public void testTargetStdAfterTransfer() {
980981 expected .add (new UnloadDecision (new Unload ("broker5:8080" , bundleE1 , Optional .of ("broker1:8080" )),
981982 Success , Overloaded ));
982983 assertEquals (res , expected );
983- assertEquals (counter .getLoadAvg (), 0.26400000000000007 );
984- assertEquals (counter .getLoadStd (), 0.27644891028904417 );
984+ assertEquals (counter .getLoadAvg (), 0.26400000000000007 , delta );
985+ assertEquals (counter .getLoadStd (), 0.27644891028904417 , delta );
985986 }
986987
987988 @ Test
@@ -1032,12 +1033,12 @@ public void testUnloadBundlesGreaterThanTargetThroughput() throws IllegalAccessE
10321033 expected .add (new UnloadDecision (
10331034 new Unload ("broker1:8080" , "my-tenant/my-namespaceA/0x3FFFFFFF_0x4FFFFFFF" ,
10341035 Optional .of ("broker2:8080" )), Success , Overloaded ));
1035- assertEquals (counter .getLoadAvg (), 5.05 );
1036- assertEquals (counter .getLoadStd (), 4.95 );
1036+ assertEquals (counter .getLoadAvg (), 5.05 , delta );
1037+ assertEquals (counter .getLoadStd (), 4.95 , delta );
10371038 assertEquals (res , expected );
10381039 var stats = (TransferShedder .LoadStats )
10391040 FieldUtils .readDeclaredField (transferShedder , "stats" , true );
1040- assertEquals (stats .std (), 0.050000004900021836 );
1041+ assertEquals (stats .std (), 0.050000004900021836 , delta );
10411042 }
10421043
10431044 @ Test
@@ -1103,12 +1104,12 @@ public void testUnloadBundlesLessThanTargetThroughputAfterSplit() throws Illegal
11031104 new Unload ("broker2:8080" , "my-tenant/my-namespaceB/0x00000000_0x0FFFFFFF" ,
11041105 Optional .of ("broker1:8080" )),
11051106 Success , Overloaded ));
1106- assertEquals (counter .getLoadAvg (), 5.05 );
1107- assertEquals (counter .getLoadStd (), 4.95 );
1107+ assertEquals (counter .getLoadAvg (), 5.05 , delta );
1108+ assertEquals (counter .getLoadStd (), 4.95 , delta );
11081109 assertEquals (res , expected );
11091110 var stats = (TransferShedder .LoadStats )
11101111 FieldUtils .readDeclaredField (transferShedder , "stats" , true );
1111- assertEquals (stats .std (), 0.050000004900021836 );
1112+ assertEquals (stats .std (), 0.050000004900021836 , delta );
11121113
11131114 }
11141115
@@ -1142,19 +1143,19 @@ public void testUnloadBundlesGreaterThanTargetThroughputAfterSplit() throws Ille
11421143 expected .add (new UnloadDecision (
11431144 new Unload ("broker1:8080" ,
11441145 res .stream ().filter (x -> x .getUnload ().sourceBroker ().equals ("broker1:8080" )).findFirst ().get ()
1145- .getUnload ().serviceUnit (), Optional .of ("broker2:8080" )),
1146+ .getUnload ().serviceUnit (), Optional .of ("broker2:8080" )),
11461147 Success , Overloaded ));
11471148 expected .add (new UnloadDecision (
11481149 new Unload ("broker2:8080" ,
11491150 res .stream ().filter (x -> x .getUnload ().sourceBroker ().equals ("broker2:8080" )).findFirst ().get ()
11501151 .getUnload ().serviceUnit (), Optional .of ("broker1:8080" )),
11511152 Success , Overloaded ));
1152- assertEquals (counter .getLoadAvg (), 0.74 );
1153- assertEquals (counter .getLoadStd (), 0.26 );
1153+ assertEquals (counter .getLoadAvg (), 0.74 , delta );
1154+ assertEquals (counter .getLoadStd (), 0.26 , delta );
11541155 assertEquals (res , expected );
11551156 var stats = (TransferShedder .LoadStats )
11561157 FieldUtils .readDeclaredField (transferShedder , "stats" , true );
1157- assertEquals (stats .std (), 2.5809568279517847E-8 );
1158+ assertEquals (stats .std (), 2.5809568279517847E-8 , delta );
11581159 }
11591160
11601161 @ Test
@@ -1180,8 +1181,8 @@ public void testMinBrokerWithLowTraffic() throws IllegalAccessException {
11801181 expected .add (new UnloadDecision (new Unload ("broker4:8080" , bundleD1 , Optional .of ("broker2:8080" )),
11811182 Success , Underloaded ));
11821183 assertEquals (res , expected );
1183- assertEquals (counter .getLoadAvg (), 0.26400000000000007 );
1184- assertEquals (counter .getLoadStd (), 0.27644891028904417 );
1184+ assertEquals (counter .getLoadAvg (), 0.26400000000000007 , delta );
1185+ assertEquals (counter .getLoadStd (), 0.27644891028904417 , delta );
11851186 }
11861187
11871188 @ Test
@@ -1204,8 +1205,8 @@ public void testMinBrokerWithLowerLoadThanAvg() throws IllegalAccessException {
12041205 expected .add (new UnloadDecision (new Unload ("broker4:8080" , bundleD1 , Optional .of ("broker2:8080" )),
12051206 Success , Underloaded ));
12061207 assertEquals (res , expected );
1207- assertEquals (counter .getLoadAvg (), 0.262 );
1208- assertEquals (counter .getLoadStd (), 0.2780935094532054 );
1208+ assertEquals (counter .getLoadAvg (), 0.262 , delta );
1209+ assertEquals (counter .getLoadStd (), 0.2780935094532054 , delta );
12091210 }
12101211
12111212 @ Test
@@ -1222,8 +1223,8 @@ public void testMaxNumberOfTransfersPerShedderCycle() {
12221223 expected .add (new UnloadDecision (new Unload ("broker4:8080" , bundleD1 , Optional .of ("broker2:8080" )),
12231224 Success , Overloaded ));
12241225 assertEquals (res , expected );
1225- assertEquals (counter .getLoadAvg (), setupLoadAvg );
1226- assertEquals (counter .getLoadStd (), setupLoadStd );
1226+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
1227+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
12271228 }
12281229
12291230 @ Test
@@ -1238,8 +1239,8 @@ public void testLoadBalancerSheddingConditionHitCountThreshold() {
12381239 var res = transferShedder .findBundlesForUnloading (ctx , Map .of (), Map .of ());
12391240 assertTrue (res .isEmpty ());
12401241 assertEquals (counter .getBreakdownCounters ().get (Skip ).get (HitCount ).get (), i + 1 );
1241- assertEquals (counter .getLoadAvg (), setupLoadAvg );
1242- assertEquals (counter .getLoadStd (), setupLoadStd );
1242+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
1243+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
12431244 }
12441245 var res = transferShedder .findBundlesForUnloading (ctx , Map .of (), Map .of ());
12451246 var expected = new HashSet <UnloadDecision >();
@@ -1248,8 +1249,8 @@ public void testLoadBalancerSheddingConditionHitCountThreshold() {
12481249 expected .add (new UnloadDecision (new Unload ("broker4:8080" , bundleD1 , Optional .of ("broker2:8080" )),
12491250 Success , Overloaded ));
12501251 assertEquals (res , expected );
1251- assertEquals (counter .getLoadAvg (), setupLoadAvg );
1252- assertEquals (counter .getLoadStd (), setupLoadStd );
1252+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
1253+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
12531254 }
12541255
12551256 @ Test
@@ -1268,8 +1269,8 @@ public void testRemainingTopBundles() {
12681269 expected .add (new UnloadDecision (new Unload ("broker4:8080" , bundleD1 , Optional .of ("broker2:8080" )),
12691270 Success , Overloaded ));
12701271 assertEquals (res , expected );
1271- assertEquals (counter .getLoadAvg (), setupLoadAvg );
1272- assertEquals (counter .getLoadStd (), setupLoadStd );
1272+ assertEquals (counter .getLoadAvg (), setupLoadAvg , delta );
1273+ assertEquals (counter .getLoadStd (), setupLoadStd , delta );
12731274 }
12741275
12751276 @ Test
@@ -1289,14 +1290,14 @@ public void testLoadMoreThan100() throws IllegalAccessException {
12891290 expected .add (new UnloadDecision (new Unload ("broker4:8080" , bundleD1 , Optional .of ("broker2:8080" )),
12901291 Success , Overloaded ));
12911292 assertEquals (res , expected );
1292- assertEquals (counter .getLoadAvg (), 2.4240000000000004 );
1293- assertEquals (counter .getLoadStd (), 3.8633332758124816 );
1293+ assertEquals (counter .getLoadAvg (), 2.4240000000000004 , delta );
1294+ assertEquals (counter .getLoadStd (), 3.8633332758124816 , delta );
12941295
12951296
12961297 var stats = (TransferShedder .LoadStats )
12971298 FieldUtils .readDeclaredField (transferShedder , "stats" , true );
1298- assertEquals (stats .avg (), 2.4240000000000004 );
1299- assertEquals (stats .std (), 2.781643776903451 );
1299+ assertEquals (stats .avg (), 2.4240000000000004 , delta );
1300+ assertEquals (stats .std (), 2.781643776903451 , delta );
13001301 }
13011302
13021303 @ Test
@@ -1328,8 +1329,8 @@ public void testOverloadOutlier() {
13281329 new Unload ("broker99:8080" , "my-tenant/my-namespace99/0x00000000_0x0FFFFFFF" ,
13291330 Optional .of ("broker83:8080" )), Success , Underloaded ))
13301331 );
1331- assertEquals (counter .getLoadAvg (), 0.019900000000000008 , 0.00001 );
1332- assertEquals (counter .getLoadStd (), 0.09850375627355534 , 0.00001 );
1332+ assertEquals (counter .getLoadAvg (), 0.019900000000000008 , delta );
1333+ assertEquals (counter .getLoadStd (), 0.09850375627355534 , delta );
13331334 }
13341335
13351336 @ Test
@@ -1343,8 +1344,8 @@ public void testUnderloadOutlier() {
13431344 new Unload ("broker98:8080" , "my-tenant/my-namespace98/0x00000000_0x0FFFFFFF" ,
13441345 Optional .of ("broker99:8080" )), Success , Underloaded ));
13451346 assertEquals (res , expected );
1346- assertEquals (counter .getLoadAvg (), 0.9704000000000005 , 0.00001 );
1347- assertEquals (counter .getLoadStd (), 0.09652895938523735 , 0.00001 );
1347+ assertEquals (counter .getLoadAvg (), 0.9704000000000005 , delta );
1348+ assertEquals (counter .getLoadStd (), 0.09652895938523735 , delta );
13481349 }
13491350
13501351 @ Test
@@ -1406,8 +1407,8 @@ public void testHighVarianceLoadStats() {
14061407 }
14071408 stats .update (loadStore , availableBrokers , Map .of (), conf );
14081409
1409- assertEquals (stats .avg (), 0.9417647058823528 );
1410- assertEquals (stats .std (), 0.23294117647058868 );
1410+ assertEquals (stats .avg (), 0.9417647058823528 , delta );
1411+ assertEquals (stats .std (), 0.23294117647058868 , delta );
14111412 }
14121413
14131414 @ Test
@@ -1424,7 +1425,7 @@ public void testLowVarianceLoadStats() {
14241425 loadStore .pushAsync ("broker" + i + ":8080" , getCpuLoad (ctx , loads [i ], "broker" + i + ":8080" ));
14251426 }
14261427 stats .update (loadStore , availableBrokers , Map .of (), conf );
1427- assertEquals (stats .avg (), 3.9449999999999994 );
1428- assertEquals (stats .std (), 0.028722813232795824 );
1428+ assertEquals (stats .avg (), 3.9449999999999994 , delta );
1429+ assertEquals (stats .std (), 0.028722813232795824 , delta );
14291430 }
14301431}
0 commit comments