Search in sources :

Example 11 with DiscoveryClient

use of com.netflix.discovery.DiscoveryClient in project eureka by Netflix.

the class Jersey2EurekaModuleTest method testDI.

@SuppressWarnings("deprecation")
@Test
public void testDI() {
    InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
    Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
    EurekaClient eurekaClient = injector.getInstance(EurekaClient.class);
    DiscoveryClient discoveryClient = injector.getInstance(DiscoveryClient.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClient(), eurekaClient);
    Assert.assertEquals(DiscoveryManager.getInstance().getDiscoveryClient(), discoveryClient);
    Assert.assertEquals(eurekaClient, discoveryClient);
    EurekaClientConfig eurekaClientConfig = injector.getInstance(EurekaClientConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClientConfig(), eurekaClientConfig);
    EurekaInstanceConfig eurekaInstanceConfig = injector.getInstance(EurekaInstanceConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaInstanceConfig(), eurekaInstanceConfig);
    Binding<TransportClientFactories> binding = injector.getExistingBinding(Key.get(TransportClientFactories.class));
    // has a binding for jersey2
    Assert.assertNotNull(binding);
    TransportClientFactories transportClientFactories = injector.getInstance(TransportClientFactories.class);
    Assert.assertTrue(transportClientFactories instanceof Jersey2TransportClientFactories);
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) Jersey2TransportClientFactories(com.netflix.discovery.shared.transport.jersey2.Jersey2TransportClientFactories) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient) Jersey2TransportClientFactories(com.netflix.discovery.shared.transport.jersey2.Jersey2TransportClientFactories) TransportClientFactories(com.netflix.discovery.shared.transport.jersey.TransportClientFactories) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 12 with DiscoveryClient

use of com.netflix.discovery.DiscoveryClient in project eureka by Netflix.

the class AbstractTester method setUp.

@Before
public void setUp() throws Exception {
    ConfigurationManager.getConfigInstance().clearProperty("eureka.remoteRegion.global.appWhiteList");
    ConfigurationManager.getConfigInstance().setProperty("eureka.responseCacheAutoExpirationInSeconds", "10");
    ConfigurationManager.getConfigInstance().clearProperty("eureka.remoteRegion." + REMOTE_REGION_NAME + ".appWhiteList");
    ConfigurationManager.getConfigInstance().setProperty("eureka.deltaRetentionTimerIntervalInMs", "600000");
    ConfigurationManager.getConfigInstance().setProperty("eureka.remoteRegion.registryFetchIntervalInSeconds", "5");
    populateRemoteRegistryAtStartup();
    mockRemoteEurekaServer = newMockRemoteServer();
    mockRemoteEurekaServer.start();
    ConfigurationManager.getConfigInstance().setProperty("eureka.remoteRegionUrlsWithName", REMOTE_REGION_NAME + ";http://localhost:" + mockRemoteEurekaServer.getPort() + MockRemoteEurekaServer.EUREKA_API_BASE_PATH);
    serverConfig = spy(new DefaultEurekaServerConfig());
    InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder();
    builder.setIPAddr("10.10.101.00");
    builder.setHostName("Hosttt");
    builder.setAppName("EurekaTestApp-" + UUID.randomUUID());
    builder.setLeaseInfo(LeaseInfo.Builder.newBuilder().build());
    builder.setDataCenterInfo(getDataCenterInfo());
    ConfigurationManager.getConfigInstance().setProperty("eureka.serviceUrl.default", "http://localhost:" + mockRemoteEurekaServer.getPort() + MockRemoteEurekaServer.EUREKA_API_BASE_PATH);
    DefaultEurekaClientConfig clientConfig = new DefaultEurekaClientConfig();
    // setup config in advance, used in initialize converter
    ApplicationInfoManager applicationInfoManager = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), builder.build());
    client = new DiscoveryClient(applicationInfoManager, clientConfig);
    ServerCodecs serverCodecs = new DefaultServerCodecs(serverConfig);
    registry = makePeerAwareInstanceRegistry(serverConfig, clientConfig, serverCodecs, client);
    serverContext = new DefaultEurekaServerContext(serverConfig, serverCodecs, registry, mock(PeerEurekaNodes.class), applicationInfoManager);
    serverContext.initialize();
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) DiscoveryClient(com.netflix.discovery.DiscoveryClient) DefaultServerCodecs(com.netflix.eureka.resources.DefaultServerCodecs) InstanceInfo(com.netflix.appinfo.InstanceInfo) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) DefaultServerCodecs(com.netflix.eureka.resources.DefaultServerCodecs) ServerCodecs(com.netflix.eureka.resources.ServerCodecs) Before(org.junit.Before)

Example 13 with DiscoveryClient

use of com.netflix.discovery.DiscoveryClient in project ribbon by Netflix.

the class DiscoveryEnabledLoadBalancerSupportsUseIpAddrTest method setupMock.

@Before
public void setupMock() {
    List<InstanceInfo> servers = DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.getDummyInstanceInfo("dummy", HOST1, IP1, 8080);
    List<InstanceInfo> servers2 = DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.getDummyInstanceInfo("dummy", HOST2, IP2, 8080);
    servers.addAll(servers2);
    PowerMock.mockStatic(DiscoveryManager.class);
    PowerMock.mockStatic(DiscoveryClient.class);
    DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class);
    DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class);
    expect(DiscoveryClient.getZone((InstanceInfo) EasyMock.anyObject())).andReturn("dummyZone").anyTimes();
    expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes();
    expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes();
    expect(mockedDiscoveryClient.getInstancesByVipAddress("dummy", false, "region")).andReturn(servers).anyTimes();
    replay(DiscoveryManager.class);
    replay(DiscoveryClient.class);
    replay(mockedDiscoveryManager);
    replay(mockedDiscoveryClient);
}
Also used : DiscoveryManager(com.netflix.discovery.DiscoveryManager) DiscoveryClient(com.netflix.discovery.DiscoveryClient) InstanceInfo(com.netflix.appinfo.InstanceInfo) Before(org.junit.Before)

Example 14 with DiscoveryClient

use of com.netflix.discovery.DiscoveryClient in project ribbon by Netflix.

the class LBBuilderTest method setupMock.

@Before
public void setupMock() {
    List<InstanceInfo> instances = getDummyInstanceInfo("dummy", expected.getHost(), expected.getPort());
    PowerMock.mockStatic(DiscoveryManager.class);
    PowerMock.mockStatic(DiscoveryClient.class);
    DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class);
    DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class);
    expect(DiscoveryClient.getZone((InstanceInfo) EasyMock.anyObject())).andReturn("dummyZone").anyTimes();
    expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes();
    expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes();
    expect(mockedDiscoveryClient.getInstancesByVipAddress("dummy:7001", false, null)).andReturn(instances).anyTimes();
    replay(DiscoveryManager.class);
    replay(DiscoveryClient.class);
    replay(mockedDiscoveryManager);
    replay(mockedDiscoveryClient);
}
Also used : DiscoveryManager(com.netflix.discovery.DiscoveryManager) DiscoveryClient(com.netflix.discovery.DiscoveryClient) InstanceInfo(com.netflix.appinfo.InstanceInfo) Before(org.junit.Before)

Example 15 with DiscoveryClient

use of com.netflix.discovery.DiscoveryClient in project ribbon by Netflix.

the class MockedDiscoveryServerListTest method setupMock.

@Before
public void setupMock() {
    List<InstanceInfo> instances = getDummyInstanceInfo("dummy", getMockServerList());
    PowerMock.mockStatic(DiscoveryManager.class);
    PowerMock.mockStatic(DiscoveryClient.class);
    DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class);
    DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class);
    expect(DiscoveryClient.getZone((InstanceInfo) EasyMock.anyObject())).andReturn("dummyZone").anyTimes();
    expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes();
    expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes();
    expect(mockedDiscoveryClient.getInstancesByVipAddress(getVipAddress(), false, null)).andReturn(instances).anyTimes();
    replay(DiscoveryManager.class);
    replay(DiscoveryClient.class);
    replay(mockedDiscoveryManager);
    replay(mockedDiscoveryClient);
}
Also used : DiscoveryManager(com.netflix.discovery.DiscoveryManager) DiscoveryClient(com.netflix.discovery.DiscoveryClient) InstanceInfo(com.netflix.appinfo.InstanceInfo) Before(org.junit.Before)

Aggregations

DiscoveryClient (com.netflix.discovery.DiscoveryClient)15 InstanceInfo (com.netflix.appinfo.InstanceInfo)10 EurekaClient (com.netflix.discovery.EurekaClient)6 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)6 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)5 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)5 DefaultEurekaClientConfig (com.netflix.discovery.DefaultEurekaClientConfig)5 Before (org.junit.Before)5 Test (org.junit.Test)5 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)4 DiscoveryManager (com.netflix.discovery.DiscoveryManager)4 Archaius2VipAddressResolver (com.netflix.appinfo.providers.Archaius2VipAddressResolver)2 VipAddressResolver (com.netflix.appinfo.providers.VipAddressResolver)2 TransportClientFactories (com.netflix.discovery.shared.transport.jersey.TransportClientFactories)2 DefaultServerCodecs (com.netflix.eureka.resources.DefaultServerCodecs)2 ServerCodecs (com.netflix.eureka.resources.ServerCodecs)2 Injector (com.google.inject.Injector)1 AmazonInfo (com.netflix.appinfo.AmazonInfo)1 CloudInstanceConfig (com.netflix.appinfo.CloudInstanceConfig)1 Ec2EurekaArchaius2InstanceConfig (com.netflix.appinfo.Ec2EurekaArchaius2InstanceConfig)1