Search in sources :

Example 6 with TeiidURL

use of org.teiid.net.TeiidURL in project teiid by teiid.

the class TestSocketServerConnection method createConnection.

private SocketServerConnection createConnection(final Throwable t, final HostInfo hostInfo, Properties p) throws CommunicationException, ConnectionException {
    ServerDiscovery discovery = new UrlServerDiscovery(new TeiidURL(hostInfo.getHostName(), hostInfo.getPortNumber(), false));
    SocketServerInstanceFactory instanceFactory = new SocketServerInstanceFactory() {

        FakeILogon logon = new FakeILogon(t);

        @Override
        public SocketServerInstance getServerInstance(HostInfo info) throws CommunicationException, IOException {
            SocketServerInstance instance = Mockito.mock(SocketServerInstance.class);
            Mockito.stub(instance.getCryptor()).toReturn(new NullCryptor());
            Mockito.stub(instance.getHostInfo()).toReturn(hostInfo);
            Mockito.stub(instance.getService(ILogon.class)).toReturn(logon);
            Mockito.stub(instance.getServerVersion()).toReturn("07.03");
            if (t != null) {
                try {
                    Mockito.doAnswer(new Answer<Void>() {

                        @Override
                        public Void answer(InvocationOnMock invocation) throws Throwable {
                            if (logon.t == null) {
                                return null;
                            }
                            throw logon.t;
                        }
                    }).when(instance).send((Message) Mockito.anyObject(), (ResultsReceiver<Object>) Mockito.anyObject(), (Serializable) Mockito.anyObject());
                } catch (Exception e) {
                }
            }
            Mockito.stub(instance.isOpen()).toReturn(true);
            return instance;
        }

        @Override
        public void connected(SocketServerInstance instance, SessionToken session) {
        }

        @Override
        public void disconnected(SocketServerInstance instance, SessionToken session) {
        }
    };
    SocketServerConnection connection = new SocketServerConnection(instanceFactory, false, discovery, p);
    return connection;
}
Also used : SessionToken(org.teiid.client.security.SessionToken) TeiidURL(org.teiid.net.TeiidURL) NullCryptor(org.teiid.core.crypto.NullCryptor) InvalidSessionException(org.teiid.client.security.InvalidSessionException) TeiidComponentException(org.teiid.core.TeiidComponentException) CommunicationException(org.teiid.net.CommunicationException) IOException(java.io.IOException) LogonException(org.teiid.client.security.LogonException) ConnectionException(org.teiid.net.ConnectionException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HostInfo(org.teiid.net.HostInfo)

Example 7 with TeiidURL

use of org.teiid.net.TeiidURL 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 8 with TeiidURL

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

Aggregations

TeiidURL (org.teiid.net.TeiidURL)8 Properties (java.util.Properties)4 CommunicationException (org.teiid.net.CommunicationException)3 MalformedURLException (java.net.MalformedURLException)2 Test (org.junit.Test)2 LogonException (org.teiid.client.security.LogonException)2 TeiidComponentException (org.teiid.core.TeiidComponentException)2 ConnectionException (org.teiid.net.ConnectionException)2 HostInfo (org.teiid.net.HostInfo)2 SocketServerConnectionFactory (org.teiid.net.socket.SocketServerConnectionFactory)2 UrlServerDiscovery (org.teiid.net.socket.UrlServerDiscovery)2 IOException (java.io.IOException)1 PrivilegedAction (java.security.PrivilegedAction)1 Subject (javax.security.auth.Subject)1 LoginContext (javax.security.auth.login.LoginContext)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 InvalidSessionException (org.teiid.client.security.InvalidSessionException)1 LogonResult (org.teiid.client.security.LogonResult)1 SessionToken (org.teiid.client.security.SessionToken)1 MemoryStorageManager (org.teiid.common.buffer.impl.MemoryStorageManager)1