com.netflix.discovery.EurekaClient Java Examples

The following examples show how to use com.netflix.discovery.EurekaClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EurekaDynamicServerListLoadBalancerTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
private EurekaClient setUpEurekaClientMock(List<InstanceInfo> servers) {
    final EurekaClient eurekaClientMock = PowerMock.createMock(EurekaClient.class);

    EasyMock.expect(eurekaClientMock.getEurekaClientConfig()).andReturn(new DefaultEurekaClientConfig()).anyTimes();

    EasyMock
            .expect(eurekaClientMock.getInstancesByVipAddress(EasyMock.anyString(), EasyMock.anyBoolean(), EasyMock.anyString()))
            .andReturn(servers.subList(0, initialServerListSize)).times(1)
            .andReturn(servers.subList(initialServerListSize, servers.size())).anyTimes();

    EasyMock
            .expectLastCall();

    EasyMock
            .expect(eurekaClientMock.unregisterEventListener(EasyMock.isA(EurekaEventListener.class)))
            .andReturn(true).anyTimes();

    return eurekaClientMock;
}
 
Example #2
Source File: EurekaDynamicServerListLoadBalancerTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    PowerMock.mockStatic(DiscoveryClient.class);

    EasyMock
            .expect(DiscoveryClient.getZone(EasyMock.isA(InstanceInfo.class)))
            .andReturn("zone")
            .anyTimes();

    eurekaClientMock = setUpEurekaClientMock(servers);
    eurekaClientProvider = new Provider<EurekaClient>() {
        @Override
        public EurekaClient get() {
            return eurekaClientMock;
        }
    };

    config = DefaultClientConfigImpl.getClientConfigWithDefaultValues();
    config.set(CommonClientConfigKey.DeploymentContextBasedVipAddresses, vipAddress);
    config.set(CommonClientConfigKey.ServerListUpdaterClassName, EurekaNotificationServerListUpdater.class.getName());
}
 
Example #3
Source File: EurekaContainerHealthService.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Inject
public EurekaContainerHealthService(ReadOnlyJobOperations jobOperations, EurekaClient eurekaClient, TitusRuntime titusRuntime) {
    this.jobOperations = jobOperations;
    this.eurekaClient = eurekaClient;
    this.titusRuntime = titusRuntime;

    Flux<EurekaEvent> eurekaCallbacks = ReactorExt.fromListener(
            EurekaEventListener.class,
            eurekaClient::registerEventListener,
            eurekaClient::unregisterEventListener
    );

    this.healthStatuses = Flux.defer(() -> {
        ConcurrentMap<String, ContainerHealthEvent> current = new ConcurrentHashMap<>();
        return Flux.merge(eurekaCallbacks, ReactorExt.toFlux(jobOperations.observeJobs()))
                .flatMap(event -> handleJobManagerOrEurekaStatusUpdate(event, current));
    }).share().compose(ReactorExt.badSubscriberHandler(logger));

}
 
Example #4
Source File: BaseServerStartup.java    From zuul with Apache License 2.0 6 votes vote down vote up
@Inject
public BaseServerStartup(ServerStatusManager serverStatusManager, FilterLoader filterLoader,
                         SessionContextDecorator sessionCtxDecorator, FilterUsageNotifier usageNotifier,
                         RequestCompleteHandler reqCompleteHandler, Registry registry,
                         DirectMemoryMonitor directMemoryMonitor, EventLoopGroupMetrics eventLoopGroupMetrics,
                         EurekaClient discoveryClient, ApplicationInfoManager applicationInfoManager,
                         AccessLogPublisher accessLogPublisher)
{
    this.serverStatusManager = serverStatusManager;
    this.registry = registry;
    this.directMemoryMonitor = directMemoryMonitor;
    this.eventLoopGroupMetrics = eventLoopGroupMetrics;
    this.discoveryClient = discoveryClient;
    this.applicationInfoManager = applicationInfoManager;
    this.accessLogPublisher = accessLogPublisher;
    this.sessionCtxDecorator = sessionCtxDecorator;
    this.reqCompleteHandler = reqCompleteHandler;
    this.filterLoader = filterLoader;
    this.usageNotifier = usageNotifier;
}
 
Example #5
Source File: ClientConnectionsShutdown.java    From zuul with Apache License 2.0 6 votes vote down vote up
public ClientConnectionsShutdown(ChannelGroup channels, EventExecutor executor, EurekaClient discoveryClient)
    {
        this.channels = channels;
        this.executor = executor;
        this.discoveryClient = discoveryClient;

        if (discoveryClient != null) {
            initDiscoveryListener();
        }

        // Only uncomment this for local testing!
        // Allow a fast property to invoke connection shutdown for testing purposes.
//        DynamicBooleanProperty DEBUG_SHUTDOWN = new DynamicBooleanProperty("server.outofservice.connections.shutdown.debug", false);
//        DEBUG_SHUTDOWN.addCallback(() -> {
//            if (DEBUG_SHUTDOWN.get()) {
//                gracefullyShutdownClientChannels();
//            }
//        });
    }
 
Example #6
Source File: EurekaNotificationServerListUpdaterTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testFailIfDiscoveryIsNotAvailable() {
    EurekaNotificationServerListUpdater serverListUpdater = new EurekaNotificationServerListUpdater(
            new Provider<EurekaClient>() {
                @Override
                public EurekaClient get() {
                    return null;
                }
            },
            testExecutor
    );

    serverListUpdater.start(new ServerListUpdater.UpdateAction() {
        @Override
        public void doUpdate() {
            Assert.fail("Should not reach here");
        }
    });
}
 
Example #7
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean(value = EurekaClient.class,
		search = SearchStrategy.CURRENT)
public EurekaClient eurekaClient(ApplicationInfoManager manager,
		EurekaClientConfig config, ApplicationContext context) {
	return new CloudEurekaClient(manager, config, null, context) {
		@Override
		public synchronized void shutdown() {
			CountDownLatch latch = countDownLatch();
			if (latch.getCount() == 1) {
				latch.countDown();
			}
			super.shutdown();
		}
	};
}
 
Example #8
Source File: DynoJedisUtils.java    From dyno with Apache License 2.0 6 votes vote down vote up
public static void updateConnectionPoolConfig(ConnectionPoolConfigurationImpl cpConfig,
                                              HostSupplier hostSupplier, TokenMapSupplier tokenMapSupplier,
                                              EurekaClient discoveryClient, String clusterName) {
    if (hostSupplier == null) {
        if (discoveryClient == null) {
            throw new DynoConnectException("HostSupplier not provided. Cannot initialize EurekaHostsSupplier "
                    + "which requires a DiscoveryClient");
        } else {
            hostSupplier = new EurekaHostsSupplier(clusterName, discoveryClient);
        }
    }
    cpConfig.withHostSupplier(hostSupplier);
    if (tokenMapSupplier != null)
        cpConfig.withTokenSupplier(tokenMapSupplier);
    setLoadBalancingStrategy(cpConfig);
    setHashtagConnectionPool(hostSupplier, cpConfig);
}
 
Example #9
Source File: SampleServerStartup.java    From zuul with Apache License 2.0 5 votes vote down vote up
@Inject
public SampleServerStartup(ServerStatusManager serverStatusManager, FilterLoader filterLoader,
                           SessionContextDecorator sessionCtxDecorator, FilterUsageNotifier usageNotifier,
                           RequestCompleteHandler reqCompleteHandler, Registry registry,
                           DirectMemoryMonitor directMemoryMonitor, EventLoopGroupMetrics eventLoopGroupMetrics,
                           EurekaClient discoveryClient, ApplicationInfoManager applicationInfoManager,
                           AccessLogPublisher accessLogPublisher, PushConnectionRegistry pushConnectionRegistry,
                           SamplePushMessageSenderInitializer pushSenderInitializer) {
    super(serverStatusManager, filterLoader, sessionCtxDecorator, usageNotifier, reqCompleteHandler, registry,
            directMemoryMonitor, eventLoopGroupMetrics, discoveryClient, applicationInfoManager,
            accessLogPublisher);
    this.pushConnectionRegistry = pushConnectionRegistry;
    this.pushSenderInitializer = pushSenderInitializer;
}
 
Example #10
Source File: MultRegisterCenterServerMgmtConfig.java    From Moss with Apache License 2.0 5 votes vote down vote up
public EurekaRegistration eurekaRegistration(EurekaClient eurekaClient,
                                             CloudEurekaInstanceConfig instanceConfig,
                                             ApplicationInfoManager applicationInfoManager,
                                             @Autowired(required = false) ObjectProvider<HealthCheckHandler> healthCheckHandler) {
    return EurekaRegistration.builder(instanceConfig)
            .with(applicationInfoManager)
            .with(eurekaClient)
            .with(healthCheckHandler)
            .build();
}
 
Example #11
Source File: MultRegisterCenterServerMgmtConfig.java    From Moss with Apache License 2.0 5 votes vote down vote up
/**
 * 动态添加一个注册中心
 *
 * @param registerCenterCode
 * @param registerCenterUrl
 */
public void addEureka(String registerCenterCode, String registerCenterUrl) {

    ManagementMetadataProvider managementMetadataProvider = serviceManagementMetadataProvider();
    EurekaClientConfigBean configBean = eurekaClientConfigBean(env);
    configBean.getServiceUrl().clear();
    configBean.getServiceUrl().put(EurekaClientConfigBean.DEFAULT_ZONE, registerCenterUrl);
    EurekaInstanceConfigBean instanceConfigBean = eurekaInstanceConfigBean(inetUtils, env, managementMetadataProvider);
    instanceConfigBean.setEnvironment(env);
    instanceConfigBean.setAppname(instanceConfigBean.getAppname());
    ApplicationInfoManager manager = eurekaApplicationInfoManager(instanceConfigBean);


    /**
     * 添加EurekaClient,如果有就先删除,再添加
     */
    Map<String, EurekaClient> multEurekaMap = multRegisterCenter.getMultEurekaMap();
    revomeEurekaClientByCode(registerCenterCode);
    EurekaClient eurekaClient = eurekaClient(manager, configBean);
    multEurekaMap.put(registerCenterCode, eurekaClient);
    multRegisterCenter.getMultEurekaCodeMap().put(eurekaClient, registerCenterCode);

    /**
     * 添加autoServiceRegistration,如果有就先删除,再添加
     */
    Map<String, MossEurekaAutoServiceRegistration> multRegistrationMap = multRegisterCenter.getMultRegistrationMap();
    revomeServiceRegistration(registerCenterCode);
    EurekaRegistration registration = eurekaRegistration(eurekaClient, instanceConfigBean, manager, healthCheckHandler);
    MossEurekaAutoServiceRegistration autoServiceRegistration = eurekaAutoServiceRegistration(context, eurekaServiceRegistry(), registration, registration);
    autoServiceRegistration.start();
    multRegistrationMap.put(registerCenterCode, autoServiceRegistration);

    /**
     * 添加 HeartbeatMonitor
     */
    Map<EurekaClient, HeartbeatMonitor> multHeartbeatMonitorMap = multRegisterCenter.getMultHeartbeatMonitorMap();
    multHeartbeatMonitorMap.remove(registerCenterCode);
    multHeartbeatMonitorMap.put(eurekaClient, new HeartbeatMonitor());

}
 
Example #12
Source File: EurekaClientAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
@ConditionalOnProperty(
		value = "spring.cloud.service-registry.auto-registration.enabled",
		matchIfMissing = true)
public EurekaRegistration eurekaRegistration(EurekaClient eurekaClient,
		CloudEurekaInstanceConfig instanceConfig,
		ApplicationInfoManager applicationInfoManager, @Autowired(
				required = false) ObjectProvider<HealthCheckHandler> healthCheckHandler) {
	return EurekaRegistration.builder(instanceConfig).with(applicationInfoManager)
			.with(eurekaClient).with(healthCheckHandler).build();
}
 
Example #13
Source File: EurekaNotificationServerListUpdaterTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testEurekaClientUnregister() {
    ThreadPoolExecutor executorMock = EasyMock.createMock(ThreadPoolExecutor.class);
    EasyMock.expect(executorMock.isShutdown()).andReturn(Boolean.TRUE);

    EurekaNotificationServerListUpdater serverListUpdater = new EurekaNotificationServerListUpdater(
            new Provider<EurekaClient>() {
                @Override
                public EurekaClient get() {
                    return eurekaClientMock;
                }
            },
            executorMock
    );

    try {
        Capture<EurekaEventListener> registeredListener = new Capture<EurekaEventListener>();
        eurekaClientMock.registerEventListener(EasyMock.capture(registeredListener));

        EasyMock.replay(eurekaClientMock);
        EasyMock.replay(executorMock);

        serverListUpdater.start(new ServerListUpdater.UpdateAction() {
            @Override
            public void doUpdate() {
                Assert.fail("should not reach here");
            }
        });

        registeredListener.getValue().onEvent(new CacheRefreshedEvent());
        
    } finally {
        EasyMock.verify(executorMock);
        EasyMock.verify(eurekaClientMock);
    }

}
 
Example #14
Source File: EurekaClientAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledHealthIndicator("eureka")
public EurekaHealthIndicator eurekaHealthIndicator(EurekaClient eurekaClient,
		EurekaInstanceConfig instanceConfig, EurekaClientConfig clientConfig) {
	return new EurekaHealthIndicator(eurekaClient, instanceConfig, clientConfig);
}
 
Example #15
Source File: SingleServiceLoadBalancer.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public SingleServiceLoadBalancer(EurekaClient eurekaClient,
                                 String vipAddress,
                                 boolean secure,
                                 TitusRuntime titusRuntime) {
    this.clock = titusRuntime.getClock();
    this.eurekaClient = eurekaClient;
    this.vipAddress = vipAddress;
    this.secure = secure;
    eurekaClient.registerEventListener(this);
    refresh();
}
 
Example #16
Source File: EurekaLoadBalancer.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public EurekaLoadBalancer(EurekaClient eurekaClient,
                          Function<URI, String> vipExtractor,
                          TitusRuntime titusRuntime) {
    this.eurekaClient = eurekaClient;
    this.vipExtractor = vipExtractor;
    this.titusRuntime = titusRuntime;
}
 
Example #17
Source File: EurekaHealthStatusBridgeModuleTest.java    From runtime-health with Apache License 2.0 5 votes vote down vote up
@Test
public void testHealthCheckHandlerRegistered() {
    InjectorBuilder.fromModules(new EurekaHealthStatusBridgeModule(), new AbstractModule() {
        @Override
        protected void configure() {
            bind(ApplicationInfoManager.class).toInstance(infoManager);
            bind(EurekaClient.class).toInstance(eurekaClient);
            bind(HealthCheckAggregator.class).toInstance(healthCheckAggregator);
        }
    }).createInjector();
    Mockito.verify(eurekaClient, Mockito.times(1)).registerHealthCheck(Mockito.any(HealthCheckHandler.class));
}
 
Example #18
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReregisterHealthCheckHandlerAfterRefresh() throws Exception {
	TestPropertyValues.of("eureka.client.healthcheck.enabled=true")
			.applyTo(this.context);
	setupContext(RefreshAutoConfiguration.class,
			AutoServiceRegistrationConfiguration.class);

	EurekaClient oldEurekaClient = getLazyInitEurekaClient();

	HealthCheckHandler healthCheckHandler = this.context
			.getBean("eurekaHealthCheckHandler", HealthCheckHandler.class);

	assertThat(healthCheckHandler).isInstanceOf(EurekaHealthCheckHandler.class);
	assertThat(oldEurekaClient.getHealthCheckHandler()).isSameAs(healthCheckHandler);

	ContextRefresher refresher = this.context.getBean("contextRefresher",
			ContextRefresher.class);
	refresher.refresh();

	EurekaClient newEurekaClient = getLazyInitEurekaClient();
	HealthCheckHandler newHealthCheckHandler = this.context
			.getBean("eurekaHealthCheckHandler", HealthCheckHandler.class);

	assertThat(healthCheckHandler).isSameAs(newHealthCheckHandler);
	assertThat(oldEurekaClient).isNotSameAs(newEurekaClient);
	assertThat(newEurekaClient.getHealthCheckHandler()).isSameAs(healthCheckHandler);
}
 
Example #19
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void eurekaConfigNotLoadedWhenDiscoveryClientDisabled() {
	TestPropertyValues.of("spring.cloud.discovery.enabled=false")
			.applyTo(this.context);
	setupContext(TestConfiguration.class);
	assertBeanNotPresent(EurekaClientConfigBean.class);
	assertBeanNotPresent(EurekaInstanceConfigBean.class);
	assertBeanNotPresent(DiscoveryClient.class);
	assertBeanNotPresent(EurekaServiceRegistry.class);
	assertBeanNotPresent(EurekaClient.class);
	assertBeanNotPresent(EurekaDiscoveryClientConfiguration.Marker.class);
}
 
Example #20
Source File: MultRegisterCenter.java    From Moss with Apache License 2.0 5 votes vote down vote up
public MultRegisterCenter(Map<String, EurekaClient> multEurekaMap, Map<String, MossEurekaAutoServiceRegistration> multRegistrationMap,
                          Map<EurekaClient, HeartbeatMonitor> multHeartbeatMonitorMap) {
    this.multEurekaMap = multEurekaMap;
    this.multRegistrationMap = multRegistrationMap;
    this.multEurekaCodeMap = multEurekaMap.entrySet().stream().collect(Collectors.toMap(e -> e.getValue(), e -> e.getKey()));
    this.multHeartbeatMonitorMap=multHeartbeatMonitorMap;
}
 
Example #21
Source File: EurekaClientAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean(value = EurekaClient.class,
		search = SearchStrategy.CURRENT)
public EurekaClient eurekaClient(ApplicationInfoManager manager,
		EurekaClientConfig config) {
	return new CloudEurekaClient(manager, config, this.optionalArgs,
			this.context);
}
 
Example #22
Source File: EurekaRegisterHandler.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public EurekaRegisterHandler(EurekaClient client, TarsEurekaInstance instanceConfig,
                             HealthCheckHandler healthCheckHandler, ApplicationInfoManager applicationInfoManager) {
    this.client = client;
    this.instanceConfig = instanceConfig;
    this.healthCheckHandler = healthCheckHandler;
    this.applicationInfoManager = applicationInfoManager;
}
 
Example #23
Source File: ApiMediationClientImpl.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create and initialize EurekaClient instance.
 *
 * @param applicationInfoManager
 * @param clientConfig
 * @param config
 * @return Initialized {@link DiscoveryClient} instance - an implementation of {@link EurekaClient}
 */
private EurekaClient initializeEurekaClient(
    ApplicationInfoManager applicationInfoManager, EurekaClientConfig clientConfig, ApiMediationServiceConfig config) {

    Ssl sslConfig = config.getSsl();

    HttpsConfig.HttpsConfigBuilder builder = HttpsConfig.builder();
    if (sslConfig != null) {
        builder.protocol(sslConfig.getProtocol());
        if (Boolean.TRUE.equals(sslConfig.getEnabled())) {
            builder.keyAlias(sslConfig.getKeyAlias())
                .keyStore(sslConfig.getKeyStore())
                .keyPassword(sslConfig.getKeyPassword())
                .keyStorePassword(sslConfig.getKeyStorePassword())
                .keyStoreType(sslConfig.getKeyStoreType());
        }

        builder.verifySslCertificatesOfServices(Boolean.TRUE.equals(sslConfig.getVerifySslCertificatesOfServices()));
        if (Boolean.TRUE.equals(sslConfig.getVerifySslCertificatesOfServices())) {
            builder.trustStore(sslConfig.getTrustStore())
                .trustStoreType(sslConfig.getTrustStoreType())
                .trustStorePassword(sslConfig.getTrustStorePassword());
        }
    }
    HttpsConfig httpsConfig = builder.build();

    HttpsFactory factory = new HttpsFactory(httpsConfig);
    EurekaJerseyClient eurekaJerseyClient = factory.createEurekaJerseyClientBuilder(
        config.getDiscoveryServiceUrls().get(0), config.getServiceId()).build();

    AbstractDiscoveryClientOptionalArgs args = new DiscoveryClient.DiscoveryClientOptionalArgs();
    args.setEurekaJerseyClient(eurekaJerseyClient);
    applicationInfoManager.setInstanceStatus(InstanceInfo.InstanceStatus.UP);
    return this.eurekaClientProvider.client(applicationInfoManager, clientConfig, args);
}
 
Example #24
Source File: SecurityServiceConfiguration.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Bean
public GatewayInstanceInitializer gatewayInstanceInitializer(
    @Qualifier("eurekaClient") EurekaClient eurekaClient,
    ApplicationEventPublisher applicationEventPublisher,
    GatewayClient gatewayClient) {


    return new GatewayInstanceInitializer(
        new InstanceLookupExecutor(eurekaClient),
        applicationEventPublisher,
        gatewayClient);
}
 
Example #25
Source File: RegistrationEventInstanceRegistry.java    From eureka-consul-adapter with MIT License 5 votes vote down vote up
public RegistrationEventInstanceRegistry(EurekaServerConfig serverConfig, EurekaClientConfig clientConfig,
                                         ServerCodecs serverCodecs, EurekaClient eurekaClient,
                                         int expectedNumberOfRenewsPerMin, int defaultOpenForTrafficCount,
                                         ServiceChangeDetector serviceChangeDetector) {
    super(serverConfig, clientConfig, serverCodecs, eurekaClient, expectedNumberOfRenewsPerMin,
            defaultOpenForTrafficCount);
    this.serviceChangeDetector = serviceChangeDetector;
}
 
Example #26
Source File: EurekaHealthIndicator.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
public EurekaHealthIndicator(EurekaClient eurekaClient,
		EurekaInstanceConfig instanceConfig, EurekaClientConfig clientConfig) {
	super();
	this.eurekaClient = eurekaClient;
	this.instanceConfig = instanceConfig;
	this.clientConfig = clientConfig;
}
 
Example #27
Source File: EurekaEventsRegistryTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Test
void givenApplicationReadyEvent_whenEurekaRegisterEvent_thenCallRegisterEventListener() {
    EurekaClient eurekaClient = mock(EurekaClient.class);
    EurekaEventsRegistry eventRegister = new EurekaEventsRegistry(eurekaClient,
        Collections.singletonList(mock(RibbonMetadataProcessor.class)));

    eventRegister.onApplicationEvent(mock(ApplicationReadyEvent.class));

    verify(eurekaClient, times(1)).registerEventListener(any());
}
 
Example #28
Source File: ApimlInstanceRegistry.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
public ApimlInstanceRegistry(
    EurekaServerConfig serverConfig,
    EurekaClientConfig clientConfig,
    ServerCodecs serverCodecs,
    EurekaClient eurekaClient,
    InstanceRegistryProperties instanceRegistryProperties,
    ApplicationContext appCntx
) {
    super(serverConfig, clientConfig, serverCodecs, eurekaClient,
        instanceRegistryProperties.getExpectedNumberOfClientsSendingRenews(),
        instanceRegistryProperties.getDefaultOpenForTrafficCount()
    );
    this.appCntx = appCntx;
    init();
}
 
Example #29
Source File: LegacyEurekaClientProvider.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized EurekaClient get() {
    if (eurekaClient == null) {
        eurekaClient = DiscoveryManager.getInstance().getDiscoveryClient();
    }

    return eurekaClient;
}
 
Example #30
Source File: EurekaNotificationServerListUpdaterTest.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Test
public void testTaskAlreadyQueued() throws Exception {
    EurekaNotificationServerListUpdater serverListUpdater = new EurekaNotificationServerListUpdater(
            new Provider<EurekaClient>() {
                @Override
                public EurekaClient get() {
                    return eurekaClientMock;
                }
            },
            testExecutor
    );

    try {
        Capture<EurekaEventListener> eventListenerCapture = new Capture<EurekaEventListener>();
        eurekaClientMock.registerEventListener(EasyMock.capture(eventListenerCapture));

        EasyMock.replay(eurekaClientMock);

        final CountDownLatch countDownLatch = new CountDownLatch(1);
        serverListUpdater.start(new ServerListUpdater.UpdateAction() {
            @Override
            public void doUpdate() {
                if (countDownLatch.getCount() == 0) {
                    Assert.fail("should only countdown once");
                }
                countDownLatch.countDown();
            }
        });

        eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
        eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());

        Assert.assertTrue(countDownLatch.await(2, TimeUnit.SECONDS));
        Thread.sleep(100);  // sleep a bit more

        Assert.assertFalse(serverListUpdater.updateQueued.get());
    } finally {
        serverListUpdater.stop();

        EasyMock.verify(eurekaClientMock);
    }
}