Skip to content

Commit

Permalink
Merge pull request apache#1377, remove redundant arguments for StatIt…
Browse files Browse the repository at this point in the history
…em.isAllowable()
  • Loading branch information
Ke Li authored and chickenlj committed Feb 22, 2018
1 parent 09d2577 commit 1f96c14
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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());
}
Expand Down

0 comments on commit 1f96c14

Please sign in to comment.