use of org.teiid.client.util.ResultsFuture in project teiid by teiid.
the class TestAllResultsImpl method testResultsMessageException.
@Test(expected = TeiidSQLException.class)
public void testResultsMessageException() throws Exception {
// $NON-NLS-1$
ResultsMessage resultsMsg = exampleMessage(exampleResults1(1), new String[] { "IntNum" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
resultsMsg.setFinalRow(-1);
ResultsMessage next = new ResultsMessage();
next.setException(new Throwable());
ResultsFuture<ResultsMessage> rf = new ResultsFuture<ResultsMessage>();
rf.getResultsReceiver().receiveResults(next);
Mockito.stub(statement.getDQP().processCursorRequest(0, 2, 0)).toReturn(rf);
ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement, null, 2);
cs.next();
cs.next();
}
use of org.teiid.client.util.ResultsFuture in project teiid by teiid.
the class ODBCServerRemoteImpl method sqlExecute.
private void sqlExecute(final String sql, final ResultsFuture<Integer> completion) throws SQLException {
String modfiedSQL = fixSQL(sql);
final StatementImpl stmt = connection.createStatement();
executionFuture = stmt.submitExecute(modfiedSQL, null);
completion.addCompletionListener(new ResultsFuture.CompletionListener<Integer>() {
public void onCompletion(ResultsFuture<Integer> future) {
try {
stmt.close();
} catch (SQLException e) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_ODBC, e, "Error closing statement");
}
}
});
executionFuture.addCompletionListener(new ResultsFuture.CompletionListener<Boolean>() {
@Override
public void onCompletion(ResultsFuture<Boolean> future) {
executionFuture = null;
try {
if (future.get()) {
List<PgColInfo> cols = getPgColInfo(stmt.getResultSet().getMetaData());
String tag = PgBackendProtocol.getCompletionTag(sql, null);
// $NON-NLS-1$ //$NON-NLS-2$
client.sendResults(sql, stmt.getResultSet(), cols, completion, CursorDirection.FORWARD, -1, tag.equals("SELECT") || tag.equals("SHOW"), null);
} else {
client.sendUpdateCount(sql, stmt.getUpdateCount());
updateSessionProperties();
completion.getResultsReceiver().receiveResults(1);
}
} catch (Throwable e) {
if (!completion.isDone()) {
completion.getResultsReceiver().exceptionOccurred(e);
}
}
}
});
}
use of org.teiid.client.util.ResultsFuture in project teiid by teiid.
the class TestCommSockets method testAutoFailoverPing.
@Test
public void testAutoFailoverPing() throws Exception {
Properties p = new Properties();
p.setProperty(TeiidURL.CONNECTION.AUTO_FAILOVER, "true");
p.setProperty("org.teiid.sockets.synchronousttl", "20000");
SocketServerConnection conn = helpEstablishConnection(false, new SSLConfiguration(), p);
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
Future<?> future = exec.submit(new Runnable() {
@Override
public void run() {
final FakeService fs = conn.getService(FakeService.class);
ResultsFuture<Integer> f = fs.delayedAsynchResult();
f.addCompletionListener(new CompletionListener<Integer>() {
@Override
public void onCompletion(ResultsFuture<Integer> future) {
// potentially recurrent;
fs.asynchResult();
}
});
try {
f.get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
future.get(19, TimeUnit.SECONDS);
}
use of org.teiid.client.util.ResultsFuture in project teiid by teiid.
the class TestFailover method createListener.
private SocketListener createListener(InetSocketAddress address, SSLConfiguration config) {
ClientServiceRegistryImpl server = new ClientServiceRegistryImpl() {
@Override
public ClassLoader getCallerClassloader() {
return getClass().getClassLoader();
}
};
SessionService ss = mock(SessionService.class);
server.registerClientService(ILogon.class, new // $NON-NLS-1$
LogonImpl(// $NON-NLS-1$
ss, // $NON-NLS-1$
"fakeCluster") {
@Override
public LogonResult logon(Properties connProps) throws LogonException {
logonAttempts++;
return new LogonResult(new SessionToken("dummy"), "x", "z");
}
@Override
public ResultsFuture<?> ping() throws InvalidSessionException, TeiidComponentException {
return ResultsFuture.NULL_FUTURE;
}
@Override
public void assertIdentity(SessionToken checkSession) throws InvalidSessionException, TeiidComponentException {
throw new InvalidSessionException();
}
}, null);
server.registerClientService(FakeService.class, new TestSocketRemoting.FakeServiceImpl(), null);
return new SocketListener(new InetSocketAddress(address.getAddress().getHostAddress(), address.getPort()), 0, 0, 2, config, server, BufferManagerFactory.getStandaloneBufferManager());
}
use of org.teiid.client.util.ResultsFuture in project teiid by teiid.
the class ServerWorkItem method run.
/**
* main entry point for remote method calls.
*/
public void run() {
Message result = null;
String loggingContext = null;
final boolean encrypt = !(message.getContents() instanceof ServiceInvocationStruct);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
try {
Thread.currentThread().setContextClassLoader(this.csr.getCallerClassloader());
} catch (Throwable t) {
// ignore
}
message.setContents(this.socketClientInstance.getCryptor().unsealObject(message.getContents()));
if (!(message.getContents() instanceof ServiceInvocationStruct)) {
// $NON-NLS-1$
throw new AssertionError("unknown message contents");
}
final ServiceInvocationStruct serviceStruct = (ServiceInvocationStruct) message.getContents();
final ClientService clientService = this.csr.getClientService(serviceStruct.targetClass.getName());
loggingContext = clientService.getLoggingContext();
Method m = clientService.getReflectionHelper().findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args);
Object methodResult;
try {
methodResult = m.invoke(clientService.getInstance(), serviceStruct.args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
if (ResultsFuture.class.isAssignableFrom(m.getReturnType()) && methodResult != null) {
ResultsFuture<Object> future = (ResultsFuture<Object>) methodResult;
future.addCompletionListener(new ResultsFuture.CompletionListener<Object>() {
public void onCompletion(ResultsFuture<Object> completedFuture) {
Message asynchResult = new Message();
try {
asynchResult.setContents(completedFuture.get());
} catch (InterruptedException e) {
asynchResult.setContents(processException(e, clientService.getLoggingContext()));
} catch (ExecutionException e) {
asynchResult.setContents(processException(e.getCause(), clientService.getLoggingContext()));
}
sendResult(asynchResult, encrypt);
}
});
} else {
// synch call
Message resultHolder = new Message();
resultHolder.setContents(methodResult);
result = resultHolder;
}
} catch (Throwable t) {
Message holder = new Message();
holder.setContents(processException(t, loggingContext));
result = holder;
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
if (result != null) {
sendResult(result, encrypt);
}
}
Aggregations