Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant arguments for StatItem#isAllowable #1377

Merged
merged 1 commit into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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