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