use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class TestDQPCore method execute.
private ResultsMessage execute(String userName, int sessionid, RequestMessage reqMsg) throws InterruptedException, ExecutionException, TimeoutException, TeiidProcessingException {
DQPWorkContext.getWorkContext().getSession().setSessionId(String.valueOf(sessionid));
DQPWorkContext.getWorkContext().getSession().setUserName(userName);
Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
assertNotNull(core.getClientState(String.valueOf(sessionid), false));
ResultsMessage results = message.get(500000, TimeUnit.MILLISECONDS);
return results;
}
use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class TestPreparedStatement method testBatchedUpdateExecution.
/**
* Verify that the <code>executeBatch()</code> method of <code>
* MMPreparedStatement</code> is resulting in the correct command,
* parameter values for each command of the batch, and the request type
* are being set in the request message that would normally be sent to the
* server.
*
* @throws Exception
*/
@Test
public void testBatchedUpdateExecution() throws Exception {
// Build up a fake connection instance for use with the prepared statement
ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
Mockito.stub(conn.getConnectionProps()).toReturn(new Properties());
DQP dqp = Mockito.mock(DQP.class);
ServerConnection serverConn = Mockito.mock(ServerConnection.class);
LogonResult logonResult = Mockito.mock(LogonResult.class);
// stub methods
Mockito.stub(conn.getServerConnection()).toReturn(serverConn);
Mockito.stub(serverConn.getLogonResult()).toReturn(logonResult);
Mockito.stub(logonResult.getTimeZone()).toReturn(TimeZone.getDefault());
// a dummy result message that is specific to this test case
final ResultsFuture<ResultsMessage> results = new ResultsFuture<ResultsMessage>();
final int[] count = new int[1];
final ResultsMessage rm = new ResultsMessage();
Mockito.stub(dqp.executeRequest(Matchers.anyLong(), (RequestMessage) Matchers.anyObject())).toAnswer(new Answer<ResultsFuture<ResultsMessage>>() {
@Override
public ResultsFuture<ResultsMessage> answer(InvocationOnMock invocation) throws Throwable {
RequestMessage requestMessage = (RequestMessage) invocation.getArguments()[1];
count[0] += requestMessage.getParameterValues().size();
if (count[0] == 100000) {
rm.setException(new TeiidException());
rm.setResults(new List<?>[] { Arrays.asList(Statement.EXECUTE_FAILED) });
} else {
List<?>[] vals = new List<?>[requestMessage.getParameterValues().size()];
Arrays.fill(vals, Arrays.asList(0));
rm.setResults(Arrays.asList(vals));
}
return results;
}
});
rm.setUpdateResult(true);
results.getResultsReceiver().receiveResults(rm);
Mockito.stub(conn.getDQP()).toReturn(dqp);
// some update SQL
// $NON-NLS-1$
String sqlCommand = "delete from table where col=?";
TestableMMPreparedStatement statement = (TestableMMPreparedStatement) getMMPreparedStatement(conn, sqlCommand);
ArrayList<ArrayList<Object>> expectedParameterValues = new ArrayList<ArrayList<Object>>(3);
// Add some batches and their parameter values
expectedParameterValues.add(new ArrayList<Object>(Arrays.asList(new Object[] { new Integer(1) })));
statement.setInt(1, new Integer(1));
statement.addBatch();
expectedParameterValues.add(new ArrayList<Object>(Arrays.asList(new Object[] { new Integer(2) })));
statement.setInt(1, new Integer(2));
statement.addBatch();
expectedParameterValues.add(new ArrayList<Object>(Arrays.asList(new Object[] { new Integer(3) })));
statement.setInt(1, new Integer(3));
statement.addBatch();
// execute the batch and verify that it matches our dummy results
// message set earlier
assertTrue(Arrays.equals(new int[] { 0, 0, 0 }, statement.executeBatch()));
// Now verify the statement's RequestMessage is what we expect
// $NON-NLS-1$
assertEquals("Command does not match", sqlCommand, statement.requestMessage.getCommandString());
// $NON-NLS-1$
assertEquals("Parameter values do not match", expectedParameterValues, statement.requestMessage.getParameterValues());
// $NON-NLS-1$
assertTrue("RequestMessage.isBatchedUpdate should be true", statement.requestMessage.isBatchedUpdate());
// $NON-NLS-1$
assertFalse("RequestMessage.isCallableStatement should be false", statement.requestMessage.isCallableStatement());
// $NON-NLS-1$
assertTrue("RequestMessage.isPreparedStatement should be true", statement.requestMessage.isPreparedStatement());
count[0] = 0;
// large batch handling - should split into 5
for (int i = 0; i < 100000; i++) {
statement.setInt(1, new Integer(1));
statement.addBatch();
}
try {
statement.executeBatch();
fail();
} catch (BatchUpdateException e) {
assertEquals(100000, count[0]);
assertEquals(95309, e.getUpdateCounts().length);
assertEquals(Statement.EXECUTE_FAILED, e.getUpdateCounts()[95308]);
}
}
use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class TestResultSet method testOutputParameter.
@Test
public void testOutputParameter() throws Exception {
StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY);
ResultsMessage resultsMsg = new ResultsMessage();
resultsMsg.setResults(new List<?>[] { Arrays.asList(1, null, null), Arrays.asList(null, 2, 3) });
resultsMsg.setLastRow(2);
resultsMsg.setFirstRow(1);
resultsMsg.setFinalRow(2);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
resultsMsg.setColumnNames(new String[] { "x", "out1", "out2" });
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
resultsMsg.setDataTypes(new String[] { "integer", "integer", "integer" });
ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement, null, 2);
int count = 0;
while (cs.next()) {
cs.getObject(1);
count++;
}
assertEquals(1, count);
assertTrue(cs.isAfterLast());
assertEquals(2, cs.getOutputParamValue(2));
assertEquals(3, cs.getOutputParamValue(3));
}
use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class TestStatement method testBatchExecution.
@Test
public void testBatchExecution() throws Exception {
ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
Mockito.stub(conn.getConnectionProps()).toReturn(new Properties());
DQP dqp = Mockito.mock(DQP.class);
ResultsFuture<ResultsMessage> results = new ResultsFuture<ResultsMessage>();
Mockito.stub(dqp.executeRequest(Mockito.anyLong(), (RequestMessage) Mockito.anyObject())).toReturn(results);
ResultsMessage rm = new ResultsMessage();
rm.setResults(new List<?>[] { Arrays.asList(1), Arrays.asList(2) });
rm.setUpdateResult(true);
results.getResultsReceiver().receiveResults(rm);
Mockito.stub(conn.getDQP()).toReturn(dqp);
StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
// previously caused npe
statement.clearBatch();
// $NON-NLS-1$
statement.addBatch("delete from table");
// $NON-NLS-1$
statement.addBatch("delete from table1");
assertTrue(Arrays.equals(new int[] { 1, 2 }, statement.executeBatch()));
}
use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class TestAllResultsImpl method exampleResultsMsg2a.
/**
* with limited metadata info.
*/
private ResultsMessage exampleResultsMsg2a() {
ResultsMessage resultsMsg = exampleResultsMsg2();
List[] results = exampleResults2();
resultsMsg.setDataTypes(dataTypes());
resultsMsg.setColumnNames(columnNames());
resultsMsg.setResults(results);
resultsMsg.setFinalRow(results.length);
resultsMsg.setLastRow(results.length);
resultsMsg.setFirstRow(1);
return resultsMsg;
}
Aggregations