Search in sources :

Example 1 with CommunicationException

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

the class TestSQLException method testCreateThrowable_02.

/*
	 * Test method for 'com.metamatrix.jdbc.MMSQLException.create(Throwable)'
	 * 
	 * Tests various nested exceptions to see if the expected SQLState is
	 * returend.
	 */
@Test
public void testCreateThrowable_02() {
    testCreateThrowable(new CommunicationException(new ConnectException(// $NON-NLS-1$
    "A test java.net.ConnectException"), // $NON-NLS-1$
    "Test Communication Exception with a ConnectException in it"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new CommunicationException(new SocketException(// $NON-NLS-1$
    "A test java.net.SocketException"), // $NON-NLS-1$
    "Test Communication Exception with a SocketException in it"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(new TeiidException(new SocketTimeoutException(// $NON-NLS-1$
    "A test java.net.SocketTimeoutException"), // $NON-NLS-1$
    "Test MetaMatrixException with a SocketTimeoutException in it"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
}
Also used : SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) CommunicationException(org.teiid.net.CommunicationException) ConnectException(java.net.ConnectException) TeiidException(org.teiid.core.TeiidException) Test(org.junit.Test)

Example 2 with CommunicationException

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

the class TestSQLException method testCreateThrowable_01.

/*
	 * Test method for 'com.metamatrix.jdbc.MMSQLException.create(Throwable)'
	 * 
	 * Tests various simple exceptions to see if the expected SQLState is
	 * returend.
	 */
@Test
public void testCreateThrowable_01() {
    testCreateThrowable(new CommunicationException(// $NON-NLS-1$
    "A test MM Communication Exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new ConnectException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new ConnectionException("A test MM Connection Exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new IOException(// $NON-NLS-1$
    "A test Generic java.io.IOException"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(new MalformedURLException(// $NON-NLS-1$
    "A test java.net.MalformedURLException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new TeiidException("A test Generic MM Core Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(// $NON-NLS-1$
    new TeiidException("A test MM Exception"), SQLStates.DEFAULT);
    testCreateThrowable(new TeiidProcessingException(// $NON-NLS-1$
    "A test Generic MM Query Processing Exception"), SQLStates.USAGE_ERROR);
    testCreateThrowable(new TeiidRuntimeException("A test MM Runtime Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(new TeiidSQLException("A test Generic MM SQL Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(new NoRouteToHostException(// $NON-NLS-1$
    "A test java.net.NoRouteToHostException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new NullPointerException("A test NPE"), SQLStates.DEFAULT);
    testCreateThrowable(new ProcedureErrorInstructionException(// $NON-NLS-1$
    "A test SQL Procedure Error exception"), SQLStates.VIRTUAL_PROCEDURE_ERROR);
    testCreateThrowable(new SocketTimeoutException(// $NON-NLS-1$
    "A test socket timeout exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new UnknownHostException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
}
Also used : MalformedURLException(java.net.MalformedURLException) CommunicationException(org.teiid.net.CommunicationException) UnknownHostException(java.net.UnknownHostException) ProcedureErrorInstructionException(org.teiid.client.ProcedureErrorInstructionException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) NoRouteToHostException(java.net.NoRouteToHostException) TeiidException(org.teiid.core.TeiidException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectionException(org.teiid.net.ConnectionException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 3 with CommunicationException

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

the class SocketServerConnection method getService.

public <T> T getService(Class<T> iface) {
    return iface.cast(Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { iface }, new SocketServerInstanceImpl.RemoteInvocationHandler(iface, PropertiesUtils.getBooleanProperty(connProps, TeiidURL.CONNECTION.ENCRYPT_REQUESTS, false)) {

        @Override
        protected SocketServerInstance getInstance() throws CommunicationException {
            if (failOver && System.currentTimeMillis() - lastPing > pingFailOverInterval) {
                try {
                    ResultsFuture<?> future = selectServerInstance(false).getService(ILogon.class).ping();
                    future.get();
                } catch (SingleInstanceCommunicationException e) {
                    closeServerInstance();
                } catch (CommunicationException e) {
                    throw e;
                } catch (InvalidSessionException e) {
                    disconnect();
                    closeServerInstance();
                } catch (Exception e) {
                    closeServerInstance();
                }
            }
            lastPing = System.currentTimeMillis();
            try {
                return selectServerInstance(false);
            } catch (ConnectionException e) {
                throw new CommunicationException(e);
            }
        }

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            try {
                return super.invoke(proxy, method, args);
            } catch (Exception e) {
                if (ExceptionUtil.getExceptionOfType(e, InvalidSessionException.class) != null) {
                    disconnect();
                }
                throw e;
            }
        }
    }));
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) CommunicationException(org.teiid.net.CommunicationException) Method(java.lang.reflect.Method) ILogon(org.teiid.client.security.ILogon) InvalidSessionException(org.teiid.client.security.InvalidSessionException) TeiidComponentException(org.teiid.core.TeiidComponentException) LogonException(org.teiid.client.security.LogonException) SocketException(java.net.SocketException) CommunicationException(org.teiid.net.CommunicationException) TeiidException(org.teiid.core.TeiidException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ConnectionException(org.teiid.net.ConnectionException) ConnectionException(org.teiid.net.ConnectionException)

Example 4 with CommunicationException

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

the class TestSocketServerConnection method testImmediateFail.

@Test(expected = CommunicationException.class)
public void testImmediateFail() throws Exception {
    SocketServerConnection connection = createConnection(new CommunicationException());
    ILogon logon = connection.getService(ILogon.class);
    logon.ping();
}
Also used : CommunicationException(org.teiid.net.CommunicationException) ILogon(org.teiid.client.security.ILogon) Test(org.junit.Test)

Example 5 with CommunicationException

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

the class TestSocketServerConnection method testLogonFailsWithMultipleHosts.

@Test
public void testLogonFailsWithMultipleHosts() throws Exception {
    Properties p = new Properties();
    SocketServerInstanceFactory instanceFactory = Mockito.mock(SocketServerInstanceFactory.class);
    Mockito.stub(instanceFactory.getServerInstance((HostInfo) Mockito.anyObject())).toThrow(new SingleInstanceCommunicationException());
    // $NON-NLS-1$
    ServerDiscovery discovery = new UrlServerDiscovery(new TeiidURL("mm://host1:1,host2:2"));
    try {
        new SocketServerConnection(instanceFactory, false, discovery, p);
        // $NON-NLS-1$
        fail("exception expected");
    } catch (CommunicationException e) {
        // $NON-NLS-1$
        assertEquals("TEIID20021 No valid host available. Attempted connections to: [host1:1, host2:2]", e.getMessage());
    }
}
Also used : CommunicationException(org.teiid.net.CommunicationException) TeiidURL(org.teiid.net.TeiidURL) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

CommunicationException (org.teiid.net.CommunicationException)20 Test (org.junit.Test)9 ConnectionException (org.teiid.net.ConnectionException)9 IOException (java.io.IOException)7 ILogon (org.teiid.client.security.ILogon)6 LogonException (org.teiid.client.security.LogonException)6 TeiidComponentException (org.teiid.core.TeiidComponentException)6 Properties (java.util.Properties)5 TeiidException (org.teiid.core.TeiidException)5 UnknownHostException (java.net.UnknownHostException)4 InvalidSessionException (org.teiid.client.security.InvalidSessionException)4 SocketException (java.net.SocketException)3 SocketTimeoutException (java.net.SocketTimeoutException)3 CryptoException (org.teiid.core.crypto.CryptoException)3 NullCryptor (org.teiid.core.crypto.NullCryptor)3 TeiidURL (org.teiid.net.TeiidURL)3 SocketServerConnection (org.teiid.net.socket.SocketServerConnection)3 ConnectException (java.net.ConnectException)2 MalformedURLException (java.net.MalformedURLException)2 DQP (org.teiid.client.DQP)2