Search in sources :

Example 1 with DalRequestExecutor

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

the class DalRequestExecutorTest method testExecuteNullable.

@Test
public void testExecuteNullable() {
    DalRequestExecutor test = new DalRequestExecutor();
    TestDalRequest request = new TestDalRequest(null, new Integer[] { null });
    DalHints hints = new DalHints();
    try {
        Integer result = test.execute(hints, request, true);
        assertNull(result);
    } catch (Exception e) {
        fail();
    }
    try {
        test.execute(hints, request, false);
        fail();
    } catch (Exception e) {
    }
}
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 2 with DalRequestExecutor

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

the class DalRequestExecutorTest method testExecuteNotCrossShard.

@Test
public void testExecuteNotCrossShard() {
    DalRequestExecutor test = new DalRequestExecutor();
    TestDalRequest request = new TestDalRequest(null, new Integer[] { 1 });
    DalHints hints = new DalHints();
    try {
        Integer result = test.execute(hints, request);
        assertEquals(1, result.intValue());
    } 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 3 with DalRequestExecutor

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

the class DalRequestExecutorTest method testExecuteCrossShard.

@Test
public void testExecuteCrossShard() {
    DalRequestExecutor test = new DalRequestExecutor();
    TestDalRequest request = new TestDalRequest(null, new Integer[] { 1, 2 });
    DalHints hints = new DalHints();
    try {
        Integer result = test.execute(hints, request);
        assertEquals(3, result.intValue());
    } 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 4 with DalRequestExecutor

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

the class DalRequestExecutorTest method testExecuteCallback.

@Test
public void testExecuteCallback() {
    DalRequestExecutor test = new DalRequestExecutor();
    TestDalRequest request = new TestDalRequest(null, new Integer[] { 1 });
    DalHints hints = new DalHints();
    DefaultResultCallback callback = new DefaultResultCallback();
    try {
        Integer result = test.execute(hints.callbackWith(callback), request, true);
        assertNull(result);
        assertEquals(1, ((Integer) hints.getAsyncResult().get()).intValue());
        assertEquals(1, ((Integer) callback.getResult()).intValue());
    } catch (Exception e) {
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalRequestExecutor(com.ctrip.platform.dal.dao.task.DalRequestExecutor) DefaultResultCallback(com.ctrip.platform.dal.dao.helper.DefaultResultCallback) ExecutionException(java.util.concurrent.ExecutionException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 5 with DalRequestExecutor

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

the class DalRequestExecutorTest method testExecuteFailByValidateAsync.

@Test
public void testExecuteFailByValidateAsync() {
    DalRequestExecutor test = new DalRequestExecutor();
    SQLException ex = new SQLException("Test");
    TestDalRequest request = new TestDalRequest(ex, null);
    DalHints hints = new DalHints().asyncExecution();
    try {
        assertNull(test.execute(hints, request));
        Future<?> result = hints.getAsyncResult();
        result.get();
        fail();
    } catch (SQLException | InterruptedException | ExecutionException e) {
        assertEquals(ex, ((ExecutionException) e).getCause());
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalRequestExecutor(com.ctrip.platform.dal.dao.task.DalRequestExecutor) SQLException(java.sql.SQLException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

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