Package com.flaptor.hounder.searcher

Examples of com.flaptor.hounder.searcher.TrafficLimitingSearcher


    static int lateDropQueries=0;
    @TestInfo(testType = TestInfo.TestType.UNIT)
    public void testLateDrop() throws InterruptedException {
        WaitingSearcher baseSearcher = new WaitingSearcher(300, false);
        final TrafficLimitingSearcher searcher = new TrafficLimitingSearcher(baseSearcher, 1, 100);
        final int NUM_THREADS=5;
        lateDropQueries=0;
        for (int i =0; i < NUM_THREADS; ++i) {
            try {Thread.sleep(10);} catch (InterruptedException e) {}
            new Thread() {
                public void run() {
//                  long t0 = System.currentTimeMillis();
                    try {
                        searcher.search(null, 0, 1, null, 1, null, null);
                    } catch (Throwable t) {
                        t.printStackTrace();
                        assertTrue(t.getMessage().contains("lateDrop"));
                        lateDropQueries++;
                    } finally {
                        queriesDone++;
                    }
                }
            }.start();
        }
        while (queriesDone < NUM_THREADS) {
            assertTrue(baseSearcher.queriesInProgress <= searcher.getMaxSimultaneousQueries());
            if (baseSearcher.queriesInProgress > searcher.getMaxSimultaneousQueries()){
                fail(baseSearcher.queriesInProgress + " queries, should be <=" + searcher.getMaxSimultaneousQueries());
            }
            Thread.sleep(50);
        }
        assertEquals(NUM_THREADS -1 , lateDropQueries);
    }
View Full Code Here



    private void multithreaded(boolean random) throws InterruptedException {
        int NUM_THREADS = 1000;
        WaitingSearcher baseSearcher = new WaitingSearcher();
        final TrafficLimitingSearcher searcher = new TrafficLimitingSearcher(baseSearcher, 10, 1000);
        baseSearcher.random = random;
        for (int i =0; i < NUM_THREADS; ++i) {
            try {Thread.sleep(10);} catch (InterruptedException e) {}
            new Thread() {
                public void run() {
//                  long t0 = System.currentTimeMillis();
                    try {
                        searcher.search(null, 0, 1, null, 1, null, null);
                    } catch (Throwable t) {
                        assertTrue(t.getMessage().contains("TrafficLimitingSearcher"));
                    } finally {
                        queriesDone++;
                    }
//                  long tf = System.currentTimeMillis();
//                  System.out.println(tf - t0);
                }
            }.start();
        }

        while (queriesDone < NUM_THREADS) {
            assertTrue(baseSearcher.queriesInProgress <= searcher.getMaxSimultaneousQueries());
            if (baseSearcher.queriesInProgress > searcher.getMaxSimultaneousQueries()){
                fail(baseSearcher.queriesInProgress + " queries, should be <=" + searcher.getMaxSimultaneousQueries());
            }
            Thread.sleep(50);
        }
    }
View Full Code Here

    @TestInfo(testType = TestInfo.TestType.UNIT)
    public void testReleaseSemaphoreOnBaseException() {
        // how many simultaneous queries to support
        int slots = 5;
        AlwaysFailSearcher baseSearcher = new AlwaysFailSearcher();
        final TrafficLimitingSearcher searcher = new TrafficLimitingSearcher(baseSearcher,slots,1/*no timeout*/);
        for (int i = 0; i < slots +1 ; i++){
            try {
                searcher.search(null, 0, 1, null, 1, null, null);
                fail(); // should not happen, as AlwaysFailSearcher will throw a SearcherException
            catch (SearcherException se){
                // do nothing ..
            }
        }

        // now, try with another query. If the slots were not released, it should fail with TrafficLimitingSearcher Exception.
        // if it failed with "I always fail", it is ok.
        Thread searchThread  = new Thread() {
            public void run() {
                try {
                    searcher.search(null, 0, 1, null, 1, null, null);
                } catch (Throwable t) {
                    assertFalse(t.getMessage().contains("TrafficLimitingSearcher"));
                    assertTrue(t.getMessage().contains("I always fail"));
                    semaphorePassed = true;
                }
View Full Code Here

TOP

Related Classes of com.flaptor.hounder.searcher.TrafficLimitingSearcher

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.