Package ru.decipher.proxy.impl

Examples of ru.decipher.proxy.impl.DefaultProxyManager$ProxyUsageInfo


    private static final HttpProxyConfig PROXY4 = new HttpProxyConfig("test4.host", 31337);
    private ProxyManager manager;

    @Before
    public void setUp() throws Exception {
        manager = new DefaultProxyManager(new MockIncrementalGoodHttpProxyNoDelayLoader(), 10, 100, 10, 0);
    }
View Full Code Here


        assertTrue("proxy usage rate fails", time >= 100);
    }

    @Test
    public void testThatUsageRatePerProxyWorksWellInConcurrency() throws Exception {
        final DefaultProxyManager manager =
                new DefaultProxyManager(new Mock3GoodHttpProxyNoDelayLoader(), 0, 1000, 10, 0);
        class Task implements Runnable {
            @Override
            public void run() {
                try {
                    final HttpProxyConfig proxy = manager.take();
                    //do something
                    manager.compliment(proxy);
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
            }
View Full Code Here

        manager.ban(PROXY1);
    }

    @Test
    public void testConcurrentTakeAndBack() throws Exception {
        final DefaultProxyManager manager = new DefaultProxyManager(new MockIncrementalGoodHttpProxyNoDelayLoader(), 10, 100, 10, 0);
        ExecutorService service = Executors.newFixedThreadPool(20);
        Collection<Callable<Object>> tasks = new ArrayList<>();
        final AtomicInteger done = new AtomicInteger(0);
        final Random random = new Random();
        for (int i = 0; i < 100; i++) {
            tasks.add(Executors.callable(new Runnable() {
                @Override
                public void run() {
                    HttpProxyConfig take = manager.take();
                    try {
                        sleep(100);
                    } catch (InterruptedException ignored) {
                    }
                    manager.compliment(take);
                    take = manager.take();
                    try {
                        sleep(100);
                    } catch (InterruptedException ignored) {
                    }
                    if (random.nextBoolean()) {
                        manager.blame(take);
                    } else {
                        manager.ban(take);
                    }
                    done.incrementAndGet();
                }
            }));
        }
View Full Code Here

        assertEquals(100, done.get());
    }

    @Test
    public void testThatManagerDoesNotBlockQueueDuringProxiesUpdate() throws Exception {
        manager = new DefaultProxyManager(new Mock3GoodHttpProxySlowLoader(), 1, 100, 10, 0);
        final HttpProxyConfig firstProxy = manager.take();
        final HttpProxyConfig secondProxy = manager.take();
        manager.ban(secondProxy);
        new Thread(new Runnable() {
            @Override
View Full Code Here

        assertNotNull(actual);
    }

    @Test
    public void testThatCheckedProxiesGoFirst() throws Exception {
        manager = new DefaultProxyManager(new MockIncrementalGoodHttpProxyNoDelayLoader(), 10, 100, 10, 0);
        final HttpProxyConfig firstProxy = manager.take();
        final HttpProxyConfig secondProxy = manager.take();
        final HttpProxyConfig third = manager.take();
        final HttpProxyConfig fourth = manager.take();
View Full Code Here

        assertEquals(expected, actual);
    }

    @Test
    public void testThatUpdateRateLimitWorksWell() throws Exception {
        final DefaultProxyManager manager = new DefaultProxyManager(new LocalhostNoProxyLoader(), 0, 0, 0, 1000);
        final HttpProxyConfig config = manager.take();
        manager.ban(config);
        long time = System.currentTimeMillis();
        manager.take();
        time = System.currentTimeMillis() - time;
        assertTrue("update rate limits failed", time >= 1000);

    }
View Full Code Here

TOP

Related Classes of ru.decipher.proxy.impl.DefaultProxyManager$ProxyUsageInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.