Search in sources :

Example 1 with UserSqlHighStat

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

the class TestConcurrentSafety method testUserSqlHighStat.

@Test
@Ignore
public void testUserSqlHighStat() throws InterruptedException {
    final UserSqlHighStat userSqlHighStat = new UserSqlHighStat();
    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++) {
                    userSqlHighStat.addSql(sql, 10L, 1L, 11L);
                }
            }
        };
        thread2[i] = new Thread() {

            @Override
            public void run() {
                for (int j = 0; j < LOOP_COUNT; j++) {
                    userSqlHighStat.addSql(sql2, 10L, 1L, 11L);
                }
            }
        };
        thread3[i] = new Thread() {

            @Override
            public void run() {
                for (int j = 0; j < LOOP_COUNT; j++) {
                    userSqlHighStat.addSql(sql4, 10L, 1L, 11L);
                }
            }
        };
    }
    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<SqlFrequency> sqlFrequency = userSqlHighStat.getSqlFrequency(true);
    Assert.assertTrue(sqlFrequency.size() == 2);
    Assert.assertTrue(sqlFrequency.get(0).getCount() == 2 * THREAD_COUNT * LOOP_COUNT);
    Assert.assertTrue(sqlFrequency.get(1).getCount() == THREAD_COUNT * LOOP_COUNT);
}
Also used : SqlFrequency(com.actiontech.dble.statistic.stat.SqlFrequency) UserSqlHighStat(com.actiontech.dble.statistic.stat.UserSqlHighStat) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

SqlFrequency (com.actiontech.dble.statistic.stat.SqlFrequency)1 UserSqlHighStat (com.actiontech.dble.statistic.stat.UserSqlHighStat)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1