use of com.netflix.zuul.discovery.DynamicServerResolver in project zuul by Netflix.
the class DefaultClientChannelManagerTest method initializeAndShutdown.
@Test
public void initializeAndShutdown() throws Exception {
final String appName = "app-" + UUID.randomUUID();
final ServerSocket serverSocket = new ServerSocket(0);
final InetSocketAddress serverSocketAddress = (InetSocketAddress) serverSocket.getLocalSocketAddress();
final String serverHostname = serverSocketAddress.getHostName();
final int serverPort = serverSocketAddress.getPort();
final OriginName originName = OriginName.fromVipAndApp("vip", appName);
final DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
Server.defaultOutboundChannelType.set(NioSocketChannel.class);
final InstanceInfo instanceInfo = Builder.newBuilder().setAppName(appName).setHostName(serverHostname).setPort(serverPort).build();
DiscoveryResult discoveryResult = DiscoveryResult.from(instanceInfo, true);
final DynamicServerResolver resolver = mock(DynamicServerResolver.class);
when(resolver.resolve(any())).thenReturn(discoveryResult);
when(resolver.hasServers()).thenReturn(true);
final Registry registry = new DefaultRegistry();
final DefaultClientChannelManager clientChannelManager = new DefaultClientChannelManager(originName, clientConfig, resolver, registry);
final NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(10);
final EventLoop eventLoop = eventLoopGroup.next();
clientChannelManager.init();
Truth.assertThat(clientChannelManager.getConnsInUse()).isEqualTo(0);
final Promise<PooledConnection> promiseConn = clientChannelManager.acquire(eventLoop);
promiseConn.await(200, TimeUnit.MILLISECONDS);
assertTrue(promiseConn.isDone());
assertTrue(promiseConn.isSuccess());
final PooledConnection connection = promiseConn.get();
assertTrue(connection.isActive());
assertFalse(connection.isInPool());
Truth.assertThat(clientChannelManager.getConnsInUse()).isEqualTo(1);
final boolean releaseResult = clientChannelManager.release(connection);
assertTrue(releaseResult);
assertTrue(connection.isInPool());
Truth.assertThat(clientChannelManager.getConnsInUse()).isEqualTo(0);
clientChannelManager.shutdown();
serverSocket.close();
}
use of com.netflix.zuul.discovery.DynamicServerResolver in project zuul by Netflix.
the class DefaultClientChannelManagerTest method updateServerRefOnValidDiscoveryResult.
@Test
public void updateServerRefOnValidDiscoveryResult() {
OriginName originName = OriginName.fromVip("vip", "test");
final DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
final DynamicServerResolver resolver = mock(DynamicServerResolver.class);
final InstanceInfo instanceInfo = Builder.newBuilder().setAppName("server-equality").setHostName("server-equality").setPort(7777).build();
final DiscoveryResult discoveryResult = DiscoveryResult.from(instanceInfo, false);
when(resolver.resolve(any())).thenReturn(discoveryResult);
final DefaultClientChannelManager clientChannelManager = new DefaultClientChannelManager(originName, clientConfig, resolver, new DefaultRegistry());
final AtomicReference<DiscoveryResult> serverRef = new AtomicReference<>();
// TODO(argha-c) capture and assert on the promise once we have a dummy with ServerStats initialized
clientChannelManager.acquire(new DefaultEventLoop(), null, CurrentPassport.create(), serverRef, new AtomicReference<>());
Truth.assertThat(serverRef.get()).isSameInstanceAs(discoveryResult);
}
use of com.netflix.zuul.discovery.DynamicServerResolver in project zuul by Netflix.
the class DefaultClientChannelManagerTest method updateServerRefOnEmptyDiscoveryResult.
@Test
public void updateServerRefOnEmptyDiscoveryResult() {
OriginName originName = OriginName.fromVip("vip", "test");
final DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
final DynamicServerResolver resolver = mock(DynamicServerResolver.class);
when(resolver.resolve(any())).thenReturn(DiscoveryResult.EMPTY);
final DefaultClientChannelManager clientChannelManager = new DefaultClientChannelManager(originName, clientConfig, resolver, new DefaultRegistry());
final AtomicReference<DiscoveryResult> serverRef = new AtomicReference<>();
final Promise<PooledConnection> promise = clientChannelManager.acquire(new DefaultEventLoop(), null, CurrentPassport.create(), serverRef, new AtomicReference<>());
Truth.assertThat(promise.isSuccess()).isFalse();
Truth.assertThat(serverRef.get()).isSameInstanceAs(DiscoveryResult.EMPTY);
}
Aggregations