Search in sources :

Example 1 with QueryConditionAnalyzer

use of com.actiontech.dble.statistic.stat.QueryConditionAnalyzer in project dble by actiontech.

the class TestConcurrentSafety method testQueryConditionAnalyzer.

@Test
@Ignore
public void testQueryConditionAnalyzer() throws InterruptedException {
    final QueryResult qr = new QueryResult("zhuam", ServerParse.SELECT, sql, 0, 0, 0, 0, 0, 0);
    final QueryResult qr2 = new QueryResult("zhuam", ServerParse.SELECT, sql2, 0, 0, 0, 0, 0, 0);
    final QueryResult qr3 = new QueryResult("zhuam", ServerParse.SELECT, sql3, 0, 0, 0, 0, 0, 0);
    final QueryConditionAnalyzer analyzer = QueryConditionAnalyzer.getInstance();
    analyzer.setCf("dynamic&fnum");
    Thread[] thread = new Thread[THREAD_COUNT];
    Thread[] thread2 = new Thread[THREAD_COUNT];
    Thread[] thread3 = new Thread[THREAD_COUNT];
    for (int i = 0; i < THREAD_COUNT; i++) {
        thread[i] = new Thread() {

            @Override
            public void run() {
                for (int j = 0; j < LOOP_COUNT; j++) {
                    analyzer.onQueryResult(qr);
                }
            }
        };
        thread2[i] = new Thread() {

            @Override
            public void run() {
                for (int j = 0; j < LOOP_COUNT; j++) {
                    analyzer.onQueryResult(qr2);
                }
            }
        };
        thread3[i] = new Thread() {

            @Override
            public void run() {
                for (int j = 0; j < LOOP_COUNT; j++) {
                    analyzer.onQueryResult(qr3);
                }
            }
        };
    }
    for (int i = 0; i < THREAD_COUNT; i++) {
        thread[i].start();
        thread2[i].start();
        thread3[i].start();
    }
    for (int i = 0; i < THREAD_COUNT; i++) {
        thread[i].join();
        thread2[i].join();
        thread3[i].join();
    }
    List<Map.Entry<Object, AtomicLong>> list = analyzer.getValues();
    Assert.assertTrue((list.get(0).getValue().get() == (long) THREAD_COUNT * LOOP_COUNT));
    Assert.assertTrue((list.get(1).getValue().get() == (long) THREAD_COUNT * LOOP_COUNT));
    Assert.assertTrue((list.get(2).getValue().get() == (long) THREAD_COUNT * LOOP_COUNT));
}
Also used : QueryConditionAnalyzer(com.actiontech.dble.statistic.stat.QueryConditionAnalyzer) QueryResult(com.actiontech.dble.statistic.stat.QueryResult) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

QueryConditionAnalyzer (com.actiontech.dble.statistic.stat.QueryConditionAnalyzer)1 QueryResult (com.actiontech.dble.statistic.stat.QueryResult)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1