From 61993847b68d38b2cc10acad5ce6b3a6f3555769 Mon Sep 17 00:00:00 2001 From: Ke Li Date: Tue, 20 Feb 2018 14:55:25 +0800 Subject: [PATCH] Remove redundant arguments for StatItem#isAllowable --- .../dubbo/rpc/filter/tps/DefaultTPSLimiter.java | 2 +- .../com/alibaba/dubbo/rpc/filter/tps/StatItem.java | 5 +---- .../alibaba/dubbo/rpc/filter/tps/StatItemTest.java | 12 ++---------- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/tps/DefaultTPSLimiter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/tps/DefaultTPSLimiter.java index f374ce3dc8d..ffec670603f 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/tps/DefaultTPSLimiter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/tps/DefaultTPSLimiter.java @@ -40,7 +40,7 @@ public boolean isAllowable(URL url, Invocation invocation) { new StatItem(serviceKey, rate, interval)); statItem = stats.get(serviceKey); } - return statItem.isAllowable(url, invocation); + return statItem.isAllowable(); } else { StatItem statItem = stats.get(serviceKey); if (statItem != null) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/tps/StatItem.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/tps/StatItem.java index 77d7b42f2fd..f1cc91acab3 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/tps/StatItem.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/tps/StatItem.java @@ -16,9 +16,6 @@ */ package com.alibaba.dubbo.rpc.filter.tps; -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.rpc.Invocation; - import java.util.concurrent.atomic.AtomicInteger; class StatItem { @@ -41,7 +38,7 @@ class StatItem { this.token = new AtomicInteger(rate); } - public boolean isAllowable(URL url, Invocation invocation) { + public boolean isAllowable() { long now = System.currentTimeMillis(); if (now > lastResetTime + interval) { token.set(rate); diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/com/alibaba/dubbo/rpc/filter/tps/StatItemTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/com/alibaba/dubbo/rpc/filter/tps/StatItemTest.java index 3f81cad2ec8..d2b5065cff5 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/com/alibaba/dubbo/rpc/filter/tps/StatItemTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/com/alibaba/dubbo/rpc/filter/tps/StatItemTest.java @@ -16,10 +16,6 @@ */ package com.alibaba.dubbo.rpc.filter.tps; -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.rpc.Invocation; -import com.alibaba.dubbo.rpc.RpcInvocation; - import org.junit.After; import org.junit.Test; @@ -30,10 +26,6 @@ public class StatItemTest { private StatItem statItem; - private URL url = URL.valueOf("test://localhost"); - - private Invocation invocation = new RpcInvocation(); - @After public void tearDown() throws Exception { statItem = null; @@ -43,9 +35,9 @@ public void tearDown() throws Exception { public void testIsAllowable() throws Exception { statItem = new StatItem("test", 5, 1000L); long lastResetTime = statItem.getLastResetTime(); - assertEquals(true, statItem.isAllowable(url, invocation)); + assertEquals(true, statItem.isAllowable()); Thread.sleep(1100L); - assertEquals(true, statItem.isAllowable(url, invocation)); + assertEquals(true, statItem.isAllowable()); assertTrue(lastResetTime != statItem.getLastResetTime()); assertEquals(4, statItem.getToken()); }