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