Search in sources :

Example 1 with SocketServerConnectionFactory

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

the class TestCommSockets method helpEstablishConnection.

private SocketServerConnection helpEstablishConnection(boolean clientSecure, SSLConfiguration config, Properties socketConfig) throws CommunicationException, ConnectionException {
    if (listener == null) {
        ClientServiceRegistryImpl server = new ClientServiceRegistryImpl() {

            @Override
            public ClassLoader getCallerClassloader() {
                return getClass().getClassLoader();
            }
        };
        service = new SessionServiceImpl();
        server.registerClientService(ILogon.class, new LogonImpl(service, "fakeCluster"), null);
        server.registerClientService(FakeService.class, new TestSocketRemoting.FakeServiceImpl(), null);
        storageManager = new MemoryStorageManager();
        listener = new SocketListener(addr, 0, 0, 2, config, server, storageManager);
        SocketListenerStats stats = listener.getStats();
        assertEquals(0, stats.maxSockets);
        assertEquals(0, stats.objectsRead);
        assertEquals(0, stats.objectsWritten);
        assertEquals(0, stats.sockets);
    }
    Properties p = new Properties(socketConfig);
    String url = new TeiidURL(addr.getHostName(), listener.getPort(), clientSecure).getAppServerURL();
    p.setProperty(TeiidURL.CONNECTION.SERVER_URL, url);
    p.setProperty(TeiidURL.CONNECTION.APP_NAME, "test");
    p.setProperty(TeiidURL.CONNECTION.DISCOVERY_STRATEGY, UrlServerDiscovery.class.getName());
    if (sscf == null) {
        sscf = new SocketServerConnectionFactory();
        sscf.initialize(socketConfig);
    }
    return sscf.getConnection(p);
}
Also used : SocketServerConnectionFactory(org.teiid.net.socket.SocketServerConnectionFactory) SessionServiceImpl(org.teiid.services.SessionServiceImpl) TeiidURL(org.teiid.net.TeiidURL) Properties(java.util.Properties) UrlServerDiscovery(org.teiid.net.socket.UrlServerDiscovery) MemoryStorageManager(org.teiid.common.buffer.impl.MemoryStorageManager)

Example 2 with SocketServerConnectionFactory

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

the class TestFailover method helpEstablishConnection.

private SocketServerConnection helpEstablishConnection(boolean clientSecure, SSLConfiguration config, Properties socketConfig) throws CommunicationException, ConnectionException {
    listener = createListener(addr, config);
    listener1 = createListener(addr, config);
    listener1.stop();
    Properties p = new Properties();
    TeiidURL teiidUrl = new TeiidURL(addr.getHostName(), listener.getPort(), clientSecure);
    teiidUrl.getHostInfo().add(new HostInfo(addr.getHostName(), listener1.getPort()));
    String url = teiidUrl.getAppServerURL();
    p.setProperty(TeiidURL.CONNECTION.SERVER_URL, url);
    p.setProperty(TeiidURL.CONNECTION.DISCOVERY_STRATEGY, UrlServerDiscovery.class.getName());
    p.setProperty(TeiidURL.CONNECTION.AUTO_FAILOVER, Boolean.TRUE.toString());
    if (sscf == null) {
        sscf = new SocketServerConnectionFactory();
        sscf.initialize(socketConfig);
    }
    return sscf.getConnection(p);
}
Also used : SocketServerConnectionFactory(org.teiid.net.socket.SocketServerConnectionFactory) TeiidURL(org.teiid.net.TeiidURL) UrlServerDiscovery(org.teiid.net.socket.UrlServerDiscovery) Properties(java.util.Properties) HostInfo(org.teiid.net.HostInfo)

Example 3 with SocketServerConnectionFactory

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

the class TestJDBCSocketTransport method testSyncTimeout.

/**
 * Tests to ensure that a SynchronousTtl/synchTimeout does
 * not cause a cancel.
 * TODO: had to increase the values since the test would fail on slow machine runs
 * @throws Exception
 */
@Test
public void testSyncTimeout() throws Exception {
    TeiidDriver td = new TeiidDriver();
    td.setSocketProfile(new ConnectionProfile() {

        @Override
        public ConnectionImpl connect(String url, Properties info) throws TeiidSQLException {
            SocketServerConnectionFactory sscf = new SocketServerConnectionFactory();
            sscf.initialize(info);
            try {
                return new ConnectionImpl(sscf.getConnection(info), info, url);
            } catch (CommunicationException e) {
                throw TeiidSQLException.create(e);
            } catch (ConnectionException e) {
                throw TeiidSQLException.create(e);
            }
        }
    });
    Properties p = new Properties();
    p.setProperty("user", "testuser");
    p.setProperty("password", "testpassword");
    ConnectorManagerRepository cmr = server.getConnectorManagerRepository();
    AutoGenDataService agds = new AutoGenDataService() {

        @Override
        public Object getConnectionFactory() throws TranslatorException {
            return null;
        }
    };
    // wait longer than the synch ttl/soTimeout, we should still succeed
    agds.setSleep(2000);
    cmr.addConnectorManager("source", agds);
    try {
        conn = td.connect("jdbc:teiid:parts@mm://" + addr.getHostName() + ":" + jdbcTransport.getPort(), p);
        Statement s = conn.createStatement();
        assertTrue(s.execute("select * from parts"));
    } finally {
        server.setConnectorManagerRepository(cmr);
    }
}
Also used : SocketServerConnectionFactory(org.teiid.net.socket.SocketServerConnectionFactory) CommunicationException(org.teiid.net.CommunicationException) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ConnectionProfile(org.teiid.jdbc.ConnectionProfile) ConnectionImpl(org.teiid.jdbc.ConnectionImpl) Properties(java.util.Properties) TeiidDriver(org.teiid.jdbc.TeiidDriver) AutoGenDataService(org.teiid.dqp.service.AutoGenDataService) ConnectionException(org.teiid.net.ConnectionException) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)3 SocketServerConnectionFactory (org.teiid.net.socket.SocketServerConnectionFactory)3 TeiidURL (org.teiid.net.TeiidURL)2 UrlServerDiscovery (org.teiid.net.socket.UrlServerDiscovery)2 PreparedStatement (java.sql.PreparedStatement)1 Statement (java.sql.Statement)1 Test (org.junit.Test)1 MemoryStorageManager (org.teiid.common.buffer.impl.MemoryStorageManager)1 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)1 AutoGenDataService (org.teiid.dqp.service.AutoGenDataService)1 ConnectionImpl (org.teiid.jdbc.ConnectionImpl)1 ConnectionProfile (org.teiid.jdbc.ConnectionProfile)1 TeiidDriver (org.teiid.jdbc.TeiidDriver)1 TeiidSQLException (org.teiid.jdbc.TeiidSQLException)1 CommunicationException (org.teiid.net.CommunicationException)1 ConnectionException (org.teiid.net.ConnectionException)1 HostInfo (org.teiid.net.HostInfo)1 SessionServiceImpl (org.teiid.services.SessionServiceImpl)1