Example #1
0
 @SuppressWarnings("unchecked")
 @Test
 public void testTransactionStatementsAsynch() throws Exception {
   ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
   Mockito.stub(conn.submitSetAutoCommitTrue(Mockito.anyBoolean()))
       .toReturn((ResultsFuture) ResultsFuture.NULL_FUTURE);
   Properties p = new Properties();
   Mockito.stub(conn.getExecutionProperties()).toReturn(p);
   StatementImpl statement =
       new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
   statement.submitExecute("start transaction", null); // $NON-NLS-1$
   Mockito.verify(conn).setAutoCommit(false);
   statement.submitExecute("commit", null); // $NON-NLS-1$
   Mockito.verify(conn).submitSetAutoCommitTrue(true);
   statement.submitExecute("start transaction", null); // $NON-NLS-1$
   statement.submitExecute("rollback", null); // $NON-NLS-1$
   Mockito.verify(conn).submitSetAutoCommitTrue(false);
 }
Example #2
0
 @Test
 public void testAsynchTimeout() throws Exception {
   ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
   final StatementImpl statement =
       new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
   statement.setQueryTimeoutMS(1);
   DQP dqp = Mockito.mock(DQP.class);
   Mockito.stub(statement.getDQP()).toReturn(dqp);
   final AtomicInteger counter = new AtomicInteger();
   Mockito.stub(dqp.cancelRequest(0))
       .toAnswer(
           new Answer<Boolean>() {
             @Override
             public Boolean answer(InvocationOnMock invocation) throws Throwable {
               synchronized (statement) {
                 counter.incrementAndGet();
                 statement.notifyAll();
               }
               return true;
             }
           });
   ResultsFuture<ResultsMessage> future = new ResultsFuture<ResultsMessage>();
   Mockito.stub(dqp.executeRequest(Mockito.anyLong(), (RequestMessage) Mockito.anyObject()))
       .toReturn(future);
   statement.submitExecute("select 'hello world'", null);
   synchronized (statement) {
     while (counter.get() != 1) {
       statement.wait();
     }
   }
   statement.setQueryTimeoutMS(1);
   statement.submitExecute("select 'hello world'", null);
   synchronized (statement) {
     while (counter.get() != 2) {
       statement.wait();
     }
   }
 }