@@ -0,0 +1,2391 @@
+package com.ctrip.xpipe.redis.meta.server;%0A%0Aimport com.ctrip.xpipe.simpleserver.Server;%0Aimport com.ctrip.xpipe.spring.RestTemplateFactory;%0Aimport org.junit.After;%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.springframework.web.client.RestOperations;%0A%0Aimport java.util.concurrent.Callable;%0Aimport java.util.concurrent.CountDownLatch;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.stream.IntStream;%0A%0Apublic class RestConnPerRouteTest extends AbstractMetaServerTest %7B%0A%0A    private int PORT = randomPort();%0A%0A    private static final int serverDelay = 1000;%0A%0A    private Server server;%0A%0A    @Before%0A    public void setUpRestConnPerRouteTest() throws Exception %7B%0A        server = startServer(PORT, new Callable%3CString%3E() %7B%0A            @Override%0A            public String call() throws Exception %7B%0A                sleep(serverDelay);%0A                return %22HTTP/1.1 200 OK%5Cr%5Cn%22%0A                        + %22Content-type:text/plain%5Cr%5Cn%22%0A                        + %22Content-length:4%5Cr%5Cn%22 +%0A                        %22%5Cr%5Cn%22%0A                        + %22OK%5Cr%5Cn%22;%0A            %7D%0A        %7D);%0A    %7D%0A%0A    @After%0A    public void afterRestConnPerRouteTest() throws Exception %7B%0A        server.stop();%0A    %7D%0A%0A    @Test%0A    public void testForSingleConn() throws Exception %7B%0A        RestOperations restTemplate = RestTemplateFactory.createCommonsHttpRestTemplate(1, 10, 5000, 5000);%0A        long startAt = System.currentTimeMillis();%0A%0A        Assert.assertTrue(concurrentRequest(restTemplate, 2, 4 * serverDelay));%0A        Assert.assertTrue(System.currentTimeMillis() - startAt %3E 2 * serverDelay);%0A    %7D%0A%0A    @Test%0A    public void testFroMultiConn() throws Exception %7B%0A        RestOperations restTemplate = RestTemplateFactory.createCommonsHttpRestTemplate(5, 10, 5000, 5000);%0A        Assert.assertTrue(concurrentRequest(restTemplate, 5, 2 * serverDelay));%0A    %7D%0A%0A    private boolean concurrentRequest(RestOperations restTemplate, int threadCnt, int timeoutMillSecond) throws Exception %7B%0A        CountDownLatch latch = new CountDownLatch(threadCnt);%0A        IntStream.range(0, threadCnt).forEach(i -%3E %7B%0A            new Thread(() -%3E %7B%0A                restTemplate.getForEntity(%22http://127.0.0.1:%22 + PORT, String.class);%0A                latch.countDown();%0A            %7D).start();%0A        %7D);%0A        return latch.await(timeoutMillSecond, TimeUnit.MILLISECONDS);%0A    %7D%0A%0A%7D%0A

test for HttpClient ConnPerRoute (#323)