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);
}
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);
}
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;
}
}
}));
}
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();
}
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());
}
}
Aggregations