Search in sources :

Example 6 with DalRequestExecutor

use of com.ctrip.platform.dal.dao.task.DalRequestExecutor in project dal by ctripcorp.

the class DalRequestExecutorTest method testThreadPoolFeatureMax.

@Test
public void testThreadPoolFeatureMax() {
    DalRequestExecutor.shutdown();
    DalRequestExecutor.init("1000", "10");
    DalRequestExecutor test = new DalRequestExecutor();
    System.out.println(test.getPoolSize());
    TestDalRequest request = new TestThreadPoolDalRequest(20000);
    DalHints hints = new DalHints();
    try {
        all.clear();
        System.out.println("Start");
        long start = System.currentTimeMillis();
        test.execute(hints, request, true);
        start = System.currentTimeMillis() - start;
        System.out.println(start + "ms");
        assertEquals(1000, all.keySet().size());
        assertEquals(1000, test.getPoolSize());
    } catch (Exception e) {
        fail();
    }
    try {
        Thread.sleep(9 * 1000);
        System.out.println("after 9s: " + test.getPoolSize());
        Thread.sleep(1 * 1000);
        System.out.println("after 10s: " + test.getPoolSize());
        request = new TestThreadPoolDalRequest(5);
        test.execute(hints, request, true);
        System.out.println(test.getPoolSize());
        assertTrue(test.getPoolSize() < 1000);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalRequestExecutor(com.ctrip.platform.dal.dao.task.DalRequestExecutor) ExecutionException(java.util.concurrent.ExecutionException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 7 with DalRequestExecutor

use of com.ctrip.platform.dal.dao.task.DalRequestExecutor in project dal by ctripcorp.

the class DalRequestExecutorTest method testThreadPoolFeature.

@Test
public void testThreadPoolFeature() {
    DalRequestExecutor.shutdown();
    DalRequestExecutor.init("10", null);
    DalRequestExecutor test = new DalRequestExecutor();
    TestDalRequest request = new TestThreadPoolDalRequest(50);
    DalHints hints = new DalHints();
    try {
        all.clear();
        test.execute(hints, request, true);
        assertEquals(10, all.keySet().size());
    } catch (Exception e) {
        fail();
    }
    all.clear();
    DalRequestExecutor.shutdown();
    DalRequestExecutor.init("200", null);
    test = new DalRequestExecutor();
    request = new TestThreadPoolDalRequest(1000);
    hints = new DalHints();
    try {
        test.execute(hints, request, true);
        assertEquals(200, all.keySet().size());
    } catch (Exception e) {
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalRequestExecutor(com.ctrip.platform.dal.dao.task.DalRequestExecutor) ExecutionException(java.util.concurrent.ExecutionException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 8 with DalRequestExecutor

use of com.ctrip.platform.dal.dao.task.DalRequestExecutor in project dal by ctripcorp.

the class DalRequestExecutorTest method testThreadPoolFeatureCooldown.

@Test
public void testThreadPoolFeatureCooldown() {
    DalRequestExecutor.shutdown();
    DalRequestExecutor.init("10", "10");
    DalRequestExecutor test = new DalRequestExecutor();
    System.out.println(test.getPoolSize());
    TestDalRequest request = new TestThreadPoolDalRequest(50);
    DalHints hints = new DalHints();
    try {
        all.clear();
        test.execute(hints, request, true);
        assertEquals(10, test.getPoolSize());
        assertEquals(10, all.keySet().size());
        assertEquals(10, test.getPoolSize());
    } catch (Exception e) {
        fail();
    }
    try {
        Thread.sleep(9 * 1000);
        System.out.println(test.getPoolSize());
        Thread.sleep(1 * 1000);
        System.out.println(test.getPoolSize());
        request = new TestThreadPoolDalRequest(5);
        test.execute(hints, request, true);
        Thread.sleep(10 * 1000);
        System.out.println(test.getPoolSize());
        assertTrue(test.getPoolSize() < 10);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalRequestExecutor(com.ctrip.platform.dal.dao.task.DalRequestExecutor) ExecutionException(java.util.concurrent.ExecutionException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 9 with DalRequestExecutor

use of com.ctrip.platform.dal.dao.task.DalRequestExecutor in project dal by ctripcorp.

the class DalRequestExecutorTest method testExecuteFailByValidate.

@Test
public void testExecuteFailByValidate() {
    DalRequestExecutor test = new DalRequestExecutor();
    SQLException ex = new SQLException("Test");
    TestDalRequest request = new TestDalRequest(ex, null);
    DalHints hints = new DalHints();
    try {
        test.execute(hints, request);
        fail();
    } catch (SQLException e) {
        assertEquals(ex, e);
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalRequestExecutor(com.ctrip.platform.dal.dao.task.DalRequestExecutor) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 10 with DalRequestExecutor

use of com.ctrip.platform.dal.dao.task.DalRequestExecutor in project dal by ctripcorp.

the class DalRequestExecutorTest method testThreadPoolCheckCapacity.

@Test
public void testThreadPoolCheckCapacity() {
    DalRequestExecutor.shutdown();
    DalRequestExecutor.init("1000", "1");
    DalRequestExecutor test = new DalRequestExecutor();
    testCapacity(test, 100, 1000);
    testCapacity(test, 200, 1000);
    testCapacity(test, 300, 1000);
    testCapacity(test, 500, 1000);
    testCapacity(test, 1000, 1000);
    testCapacity(test, 1500, 2000);
    testCapacity(test, 2000, 2000);
    testCapacity(test, 10000, 10000);
}
Also used : DalRequestExecutor(com.ctrip.platform.dal.dao.task.DalRequestExecutor) Test(org.junit.Test)

Aggregations

DalRequestExecutor (com.ctrip.platform.dal.dao.task.DalRequestExecutor)10 Test (org.junit.Test)10 DalHints (com.ctrip.platform.dal.dao.DalHints)9 SQLException (java.sql.SQLException)9 ExecutionException (java.util.concurrent.ExecutionException)8 DefaultResultCallback (com.ctrip.platform.dal.dao.helper.DefaultResultCallback)1