Search in sources :

Example 6 with SocketServerConnection

use of org.teiid.net.socket.SocketServerConnection in project teiid by teiid.

the class TestSocketRemoting method testMethodInvocation.

@Test
public void testMethodInvocation() throws Exception {
    ClientServiceRegistryImpl csr = new ClientServiceRegistryImpl() {

        @Override
        public ClassLoader getCallerClassloader() {
            return getClass().getClassLoader();
        }
    };
    csr.registerClientService(ILogon.class, new ILogon() {

        public ResultsFuture<?> logoff() throws InvalidSessionException {
            ResultsFuture<?> result = new ResultsFuture<Void>();
            // $NON-NLS-1$
            result.getResultsReceiver().exceptionOccurred(new TeiidComponentException("some exception"));
            return result;
        }

        public LogonResult logon(Properties connectionProperties) throws LogonException, TeiidComponentException {
            return new LogonResult();
        }

        // tests asynch where we don't care about the result
        public ResultsFuture<?> ping() throws InvalidSessionException, TeiidComponentException {
            return null;
        }

        @Override
        public ResultsFuture<?> ping(Collection<String> sessions) throws TeiidComponentException, CommunicationException {
            return null;
        }

        @Override
        public void assertIdentity(SessionToken sessionId) throws InvalidSessionException, TeiidComponentException {
        }

        @Override
        public LogonResult neogitiateGssLogin(Properties connectionProperties, byte[] serviceToken, boolean createSession) throws LogonException {
            return null;
        }
    }, // $NON-NLS-1$
    "foo");
    // $NON-NLS-1$
    csr.registerClientService(FakeService.class, new FakeServiceImpl(), "foo");
    final FakeClientServerInstance serverInstance = new FakeClientServerInstance(csr);
    SocketServerConnection connection = createFakeConnection(serverInstance);
    ILogon logon = connection.getService(ILogon.class);
    Future<?> result = logon.ping();
    assertNull(result.get(0, TimeUnit.MILLISECONDS));
    result = logon.logoff();
    try {
        result.get(0, TimeUnit.MICROSECONDS);
        // $NON-NLS-1$
        fail("exception expected");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof TeiidComponentException);
    }
    FakeService service = connection.getService(FakeService.class);
    Future<Integer> asynchInteger = service.asynchResult();
    assertEquals(new Integer(5), asynchInteger.get(0, TimeUnit.MILLISECONDS));
    try {
        service.exceptionMethod();
        // $NON-NLS-1$
        fail("exception expected");
    } catch (TeiidProcessingException e) {
    }
    DQP dqp = connection.getService(DQP.class);
    try {
        ResultsFuture<?> future = dqp.begin();
        future.get();
        // $NON-NLS-1$
        fail("exception expected");
    } catch (Exception e) {
        // $NON-NLS-1$
        assertTrue(e.getMessage().indexOf("Component not found:") != -1);
    }
}
Also used : LogonResult(org.teiid.client.security.LogonResult) Properties(java.util.Properties) TeiidProcessingException(org.teiid.core.TeiidProcessingException) LogonException(org.teiid.client.security.LogonException) ExecutionException(java.util.concurrent.ExecutionException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) DQP(org.teiid.client.DQP) CommunicationException(org.teiid.net.CommunicationException) SessionToken(org.teiid.client.security.SessionToken) ILogon(org.teiid.client.security.ILogon) InvalidSessionException(org.teiid.client.security.InvalidSessionException) TeiidComponentException(org.teiid.core.TeiidComponentException) LogonException(org.teiid.client.security.LogonException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) CommunicationException(org.teiid.net.CommunicationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ConnectionException(org.teiid.net.ConnectionException) ResultsFuture(org.teiid.client.util.ResultsFuture) TeiidComponentException(org.teiid.core.TeiidComponentException) SocketServerConnection(org.teiid.net.socket.SocketServerConnection) Test(org.junit.Test)

Example 7 with SocketServerConnection

use of org.teiid.net.socket.SocketServerConnection in project teiid by teiid.

the class SocketProfile method connect.

/**
 * This method tries to make a connection to the given URL. This class
 * will return a null if this is not the right driver to connect to the given URL.
 * @param The URL used to establish a connection.
 * @return Connection object created
 * @throws SQLException if it is unable to establish a connection to the server.
 */
public ConnectionImpl connect(String url, Properties info) throws TeiidSQLException {
    int loginTimeoutSeconds = 0;
    SocketServerConnection serverConn;
    try {
        String timeout = info.getProperty(TeiidURL.CONNECTION.LOGIN_TIMEOUT);
        if (timeout != null) {
            loginTimeoutSeconds = Integer.parseInt(timeout);
        }
        if (loginTimeoutSeconds > 0) {
            OioOjbectChannelFactory.TIMEOUTS.set(System.currentTimeMillis() + loginTimeoutSeconds * 1000);
        }
        serverConn = SocketServerConnectionFactory.getInstance().getConnection(info);
    } catch (TeiidException e) {
        throw TeiidSQLException.create(e);
    } finally {
        if (loginTimeoutSeconds > 0) {
            OioOjbectChannelFactory.TIMEOUTS.set(null);
        }
    }
    // construct a MMConnection object.
    ConnectionImpl connection = new ConnectionImpl(serverConn, info, url);
    return connection;
}
Also used : SocketServerConnection(org.teiid.net.socket.SocketServerConnection) TeiidException(org.teiid.core.TeiidException)

Example 8 with SocketServerConnection

use of org.teiid.net.socket.SocketServerConnection in project teiid by teiid.

the class TestCommSockets method testConnectWithPooling.

@Test
public void testConnectWithPooling() throws Exception {
    SocketServerConnection conn = helpEstablishConnection(false);
    SocketListenerStats stats = listener.getStats();
    // handshake response, logon
    assertEquals(2, stats.objectsRead);
    assertEquals(1, stats.sockets);
    conn.close();
    stats = listener.getStats();
    assertEquals(1, stats.maxSockets);
    // handshake response, logon, logoff
    assertEquals(3, stats.objectsRead);
    stats = listener.getStats();
    assertEquals(1, stats.sockets);
    conn = helpEstablishConnection(false);
    conn.close();
    stats = listener.getStats();
    assertEquals(1, stats.sockets);
    assertEquals(1, stats.maxSockets);
}
Also used : SocketServerConnection(org.teiid.net.socket.SocketServerConnection) Test(org.junit.Test)

Example 9 with SocketServerConnection

use of org.teiid.net.socket.SocketServerConnection in project teiid by teiid.

the class TestCommSockets method testAnonSSLConnect.

@Test
public void testAnonSSLConnect() throws Exception {
    SSLContext context = SSLContext.getDefault();
    String[] ciphers = context.getServerSocketFactory().getSupportedCipherSuites();
    if (!Arrays.asList(ciphers).contains(SocketUtil.ANON_CIPHER_SUITE)) {
        // Cannot test anon if no cipher suite is available
        return;
    }
    SSLConfiguration config = new SSLConfiguration();
    config.setMode(SSLConfiguration.ENABLED);
    // ensure that this cipher suite is not used
    config.setEnabledCipherSuites("x");
    config.setAuthenticationMode(SSLConfiguration.ANONYMOUS);
    Properties p = new Properties();
    helpEstablishConnection(true, config, p);
    SocketServerConnection conn = helpEstablishConnection(true, config, p);
    conn.close();
    try {
        helpEstablishConnection(false, config, p);
        fail();
    } catch (CommunicationException e) {
    }
}
Also used : CommunicationException(org.teiid.net.CommunicationException) SSLContext(javax.net.ssl.SSLContext) Properties(java.util.Properties) SocketServerConnection(org.teiid.net.socket.SocketServerConnection) Test(org.junit.Test)

Example 10 with SocketServerConnection

use of org.teiid.net.socket.SocketServerConnection 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)

Aggregations

SocketServerConnection (org.teiid.net.socket.SocketServerConnection)12 Test (org.junit.Test)10 Properties (java.util.Properties)6 CommunicationException (org.teiid.net.CommunicationException)4 FakeService (org.teiid.transport.TestSocketRemoting.FakeService)3 ResultsFuture (org.teiid.client.util.ResultsFuture)2 ConnectionException (org.teiid.net.ConnectionException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 StringReader (java.io.StringReader)1 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 SSLContext (javax.net.ssl.SSLContext)1 DQP (org.teiid.client.DQP)1 ILogon (org.teiid.client.security.ILogon)1 InvalidSessionException (org.teiid.client.security.InvalidSessionException)1 LogonException (org.teiid.client.security.LogonException)1