Search in sources :

Example 21 with ResultsFuture

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();
}
Also used : ResultsFuture(org.teiid.client.util.ResultsFuture) ResultsMessage(org.teiid.client.ResultsMessage) Test(org.junit.Test)

Example 22 with ResultsFuture

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);
                }
            }
        }
    });
}
Also used : TeiidSQLException(org.teiid.jdbc.TeiidSQLException) SQLException(java.sql.SQLException) ResultsFuture(org.teiid.client.util.ResultsFuture) PreparedStatementImpl(org.teiid.jdbc.PreparedStatementImpl) StatementImpl(org.teiid.jdbc.StatementImpl) List(java.util.List) ArrayList(java.util.ArrayList)

Example 23 with ResultsFuture

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);
}
Also used : ResultsFuture(org.teiid.client.util.ResultsFuture) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) CompletionListener(org.teiid.client.util.ResultsFuture.CompletionListener) FakeService(org.teiid.transport.TestSocketRemoting.FakeService) Properties(java.util.Properties) SocketServerConnection(org.teiid.net.socket.SocketServerConnection) SessionServiceException(org.teiid.dqp.service.SessionServiceException) CommunicationException(org.teiid.net.CommunicationException) ConnectionException(org.teiid.net.ConnectionException) Test(org.junit.Test)

Example 24 with ResultsFuture

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());
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) SessionToken(org.teiid.client.security.SessionToken) InetSocketAddress(java.net.InetSocketAddress) LogonResult(org.teiid.client.security.LogonResult) Properties(java.util.Properties) ResultsFuture(org.teiid.client.util.ResultsFuture) SessionService(org.teiid.dqp.service.SessionService) LogonException(org.teiid.client.security.LogonException) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 25 with ResultsFuture

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);
    }
}
Also used : Message(org.teiid.net.socket.Message) ClientService(org.teiid.transport.ClientServiceRegistryImpl.ClientService) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) ResultsFuture(org.teiid.client.util.ResultsFuture) ExecutionException(java.util.concurrent.ExecutionException) ServiceInvocationStruct(org.teiid.net.socket.ServiceInvocationStruct)

Aggregations

ResultsFuture (org.teiid.client.util.ResultsFuture)34 Test (org.junit.Test)21 SQLException (java.sql.SQLException)17 ResultsMessage (org.teiid.client.ResultsMessage)13 TranslatorException (org.teiid.translator.TranslatorException)11 ResultSet (java.sql.ResultSet)10 Statement (java.sql.Statement)10 RequestOptions (org.teiid.jdbc.RequestOptions)10 TeiidStatement (org.teiid.jdbc.TeiidStatement)10 AsynchPositioningException (org.teiid.jdbc.AsynchPositioningException)9 ContinuousStatementCallback (org.teiid.jdbc.ContinuousStatementCallback)9 TeiidResultSet (org.teiid.jdbc.TeiidResultSet)9 Properties (java.util.Properties)8 ExecutionException (java.util.concurrent.ExecutionException)8 StatementCallback (org.teiid.jdbc.StatementCallback)8 DQP (org.teiid.client.DQP)7 RequestMessage (org.teiid.client.RequestMessage)5 TeiidComponentException (org.teiid.core.TeiidComponentException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4