一起写RPC框架(二十六)RPC测试篇三---限流的测试

本小节测试一下限流的功能,首先我们先定义一个简单的类,配置一下它单位时间最大的调用次数

package org.laopopo.example.generic.test_5;

import org.laopopo.client.annotation.RPCService;
import org.laopopo.example.demo.service.HelloSerivce;

public class HelloServiceFlowControllerImpl implements HelloSerivce {

	@Override
	@RPCService(responsibilityName="xiaoy",serviceName="LAOPOPO.TEST.SAYHELLO",maxCallCountInMinute = 40)
	public String sayHello(String str) {
		return "hello "+ str;
	}

}


服务提供者的代码基本上不用动:

package org.laopopo.example.generic.test_5;

import org.laopopo.client.provider.DefaultProvider;
import org.laopopo.common.exception.remoting.RemotingException;

/**
 * 
 * @author BazingaLyn
 * @description 测试单位时间的限流
 * @time 2016年9月14日
 * @modifytime
 */
public class ProviderTest {
	
public static void main(String[] args) throws InterruptedException, RemotingException {
		
		DefaultProvider defaultProvider = new DefaultProvider();
		
		defaultProvider.serviceListenPort(8899) //暴露服务的地址
					   .publishService(new HelloServiceFlowControllerImpl()) //暴露的服务
					   .start(); //启动服务
		
	}

}

消费者的代码基本上也不用改变:

package org.laopopo.example.generic.test_5;

import org.laopopo.client.consumer.ConsumerClient;
import org.laopopo.client.consumer.proxy.ProxyFactory;
import org.laopopo.common.utils.UnresolvedAddress;

/**
 * 
 * @author BazingaLyn
 * @description 测试
 * @time
 * @modifytime
 */
public class ConsumerTest {
	
	public static void main(String[] args) throws Exception {
		
		ConsumerClient client = new ConsumerClient();

		client.start();
		
		UnresolvedAddress addresses = new UnresolvedAddress("127.0.0.1", 8899);
		
		HelloService helloService = ProxyFactory.factory(HelloService.class).consumer(client).addProviderAddress(addresses).timeoutMillis(3000l).newProxyInstance();
		
		for(int index = 1;index < 45;index++){
			
			String str = helloService.sayHello("Lyncc");
			System.out.println("当前调用的次数是:" + index);
			System.out.println(str);
			
		}
		
	}

}


先运行服务提供者之后,再运行服务消费者:



基本上是没有问题的~

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值