@@ -65,12 +65,52 @@ void testIsNotAllowable() {
6565 }
6666
6767 @ Test
68- void testTPSLimiterForMethodLevelConfig () {
68+ void testMethodLevelTpsOverridesServiceLevel () {
6969 Invocation invocation = new MockInvocation ();
7070 URL url = URL .valueOf ("test://test" );
7171 url = url .addParameter (INTERFACE_KEY , "org.apache.dubbo.rpc.file.TpsService" );
7272 url = url .addParameter (TPS_LIMIT_RATE_KEY , TEST_LIMIT_RATE );
7373 int tpsConfigForMethodLevel = 3 ;
74+ url = url .addParameter ("tps" , 1 );
75+ url = url .addParameter ("echo.tps" , tpsConfigForMethodLevel );
76+ url = url .addParameter (TPS_LIMIT_INTERVAL_KEY , 1000 );
77+ for (int i = 1 ; i <= tpsConfigForMethodLevel + 1 ; i ++) {
78+ if (i == tpsConfigForMethodLevel + 1 ) {
79+ Assertions .assertFalse (defaultTPSLimiter .isAllowable (url , invocation ));
80+ } else {
81+ Assertions .assertTrue (defaultTPSLimiter .isAllowable (url , invocation ));
82+ }
83+ }
84+ }
85+
86+ @ Test
87+ void testServiceLevelTpsWhenOtherMethodsHaveTps () {
88+ Invocation invocation = new MockInvocation ();
89+ URL url = URL .valueOf ("test://test" );
90+ url = url .addParameter (INTERFACE_KEY , "org.apache.dubbo.rpc.file.TpsService" );
91+ url = url .addParameter (TPS_LIMIT_RATE_KEY , TEST_LIMIT_RATE );
92+ int tpsConfigForServiceLevel = 3 ;
93+ url = url .addParameter ("tps" , tpsConfigForServiceLevel );
94+ url = url .addParameter ("otherMethod.tps" , 1 );
95+ url = url .addParameter (TPS_LIMIT_INTERVAL_KEY , 1000 );
96+ for (int i = 1 ; i <= tpsConfigForServiceLevel + 1 ; i ++) {
97+ if (i == tpsConfigForServiceLevel + 1 ) {
98+ Assertions .assertFalse (defaultTPSLimiter .isAllowable (url , invocation ));
99+ } else {
100+ Assertions .assertTrue (defaultTPSLimiter .isAllowable (url , invocation ));
101+ }
102+ }
103+ }
104+
105+ @ Test
106+ void testMethodLevelTpsIsolation () {
107+ Invocation invocation = new MockInvocation ();
108+ URL url = URL .valueOf ("test://test" );
109+ url = url .addParameter (INTERFACE_KEY , "org.apache.dubbo.rpc.file.TpsService" );
110+ url = url .addParameter (TPS_LIMIT_RATE_KEY , TEST_LIMIT_RATE );
111+ int tpsConfigForMethodLevel = 3 ;
112+ url = url .addParameter ("tps" , 1 );
113+ url = url .addParameter ("otherMethod.tps" , 2 );
74114 url = url .addParameter ("echo.tps" , tpsConfigForMethodLevel );
75115 url = url .addParameter (TPS_LIMIT_INTERVAL_KEY , 1000 );
76116 for (int i = 1 ; i <= tpsConfigForMethodLevel + 1 ; i ++) {
0 commit comments