1 16 package scriptella.execution; 17 18 import scriptella.DBTestCase; 19 import scriptella.jdbc.QueryHelper; 20 import scriptella.spi.ParametersCallback; 21 import scriptella.spi.QueryCallback; 22 23 import java.sql.Connection ; 24 import java.sql.SQLException ; 25 26 32 public class CancellationTest extends DBTestCase { 33 private boolean interrupted; 34 35 public void test() throws EtlExecutorException { 36 EtlExecutor etlExecutor = newEtlExecutor(); 37 Connection c = getConnection("cancelTest"); 38 final Thread etlThread = Thread.currentThread(); 39 interrupted = false; 40 new Thread () { 41 public void run() { 42 try { 43 Thread.sleep(200); etlThread.interrupt(); 45 interrupted = true; 46 } catch (InterruptedException e) { 47 Thread.currentThread().interrupt(); 48 } 49 } 50 }.start(); 51 long ti = System.currentTimeMillis(); 52 try { 53 etlExecutor.execute(); 54 } catch (EtlExecutorException e) { 55 assertTrue(e.isCancelled()); 56 } 57 ti = System.currentTimeMillis() - ti; 58 assertTrue(interrupted); 59 assertTrue(ti < 1000); new QueryHelper("select count(*) from t1, t2") { 62 @Override protected void onSQLException(SQLException e) { 63 if (e.getMessage().indexOf("not found")<0) { 64 super.onSQLException(e); 65 } 66 67 } 68 }.execute(c, new QueryCallback() { 69 public void processRow(final ParametersCallback parameters) { 70 assertEquals(0, parameters.getParameter("1")); 71 } 72 }); 73 } 74 } 75 | Popular Tags |