org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent Java Examples

The following examples show how to use org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent. 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: AdminApplicationDiscoveryTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
private URI registerInstance() {
    //We register the instance by setting static values for the SimpleDiscoveryClient and issuing a
    //InstanceRegisteredEvent that makes sure the instance gets registered.
    SimpleDiscoveryProperties.SimpleServiceInstance serviceInstance = new SimpleDiscoveryProperties.SimpleServiceInstance();
    serviceInstance.setServiceId("Test-Instance");
    serviceInstance.setUri(URI.create("http://localhost:" + port));
    serviceInstance.getMetadata().put("management.context-path", "/mgmt");
    simpleDiscovery.getInstances().put("Test-Application", singletonList(serviceInstance));

    instance.publishEvent(new InstanceRegisteredEvent<>(new Object(), null));

    //To get the location of the registered instances we fetch the instance with the name.
    List<JSONObject> applications = webClient.get()
                                             .uri("/instances?name=Test-Instance")
                                             .accept(MediaType.APPLICATION_JSON)
                                             .exchange()
                                             .expectStatus()
                                             .isOk()
                                             .returnResult(JSONObject.class)
                                             .getResponseBody()
                                             .collectList()
                                             .block();
    assertThat(applications).hasSize(1);
    return URI.create("http://localhost:" + port + "/instances/" + applications.get(0).optString("id"));
}
 
Example #2
Source File: AlphaConsulAutoConfiguration.java    From servicecomb-pack with Apache License 2.0 6 votes vote down vote up
/**
 * Update grpc port of consul tags after Conusl Registered
 * */
@EventListener
public void listenInstanceRegisteredEvent(InstanceRegisteredEvent instanceRegisteredEvent){
  if(alphaServerPort == 0){
    if(instanceRegisteredEvent.getConfig() instanceof ConsulDiscoveryProperties){
      ConsulDiscoveryProperties properties = (ConsulDiscoveryProperties)instanceRegisteredEvent.getConfig();
      this.consuleInstanceId = formatConsulInstanceId(properties.getInstanceId());
      Response<List<CatalogService>> services = consulClient.getCatalogService(serviceName,null);
      if(services.getValue() != null){
        services.getValue().stream().filter(service ->
            service.getServiceId().equalsIgnoreCase(this.consuleInstanceId)).forEach(service -> {

          NewService newservice =  new NewService();
          newservice.setName(service.getServiceName());
          newservice.setId(service.getServiceId());
          newservice.setAddress(service.getAddress());
          newservice.setPort(service.getServicePort());
          List<String> tags = service.getServiceTags();
          tags.remove("alpha-server-port=0");
          tags.add("alpha-server-port="+actualAlphaServerPort);
          newservice.setTags(tags);
          consulClient.agentServiceRegister(newservice);
        });
      }
    }
  }
}
 
Example #3
Source File: InstanceDiscoveryListenerTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_not_register_instances_when_instanceMetadata_matches_wanted_metadata_and_ignored_metadata() {
	when(this.discovery.getServices()).thenReturn(asList("service", "service-1"));
	when(this.discovery.getInstances("service")).thenReturn(singletonList(
			new DefaultServiceInstance("test-1", "service", "localhost", 80, false, new HashMap<String, String>() {
				{
					put("monitoring", "true");
					put("management", "true");
				}
			})));
	when(this.discovery.getInstances("service-1")).thenReturn(singletonList(new DefaultServiceInstance("test-1",
			"service-1", "localhost", 80, false, new HashMap<String, String>() {
				{
					put("monitoring", "true");
					put("management", "false");
				}
			})));

	this.listener.setInstancesMetadata(Collections.singletonMap("monitoring", "true"));
	this.listener.setIgnoredInstancesMetadata(Collections.singletonMap("management", "true"));
	this.listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

	StepVerifier.create(this.registry.getInstances())
			.assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("service-1")).verifyComplete();
}
 
Example #4
Source File: InstanceDiscoveryListenerTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_register_instance_when_new_service_instance_is_discovered() {
	when(this.discovery.getServices()).thenReturn(singletonList("service"));
	when(this.discovery.getInstances("service"))
			.thenReturn(singletonList(new DefaultServiceInstance("test-1", "service", "localhost", 80, false)));

	this.listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

	StepVerifier.create(this.registry.getInstances()).assertNext((application) -> {
		Registration registration = application.getRegistration();
		assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:80/actuator/health");
		assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/actuator");
		assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80");
		assertThat(registration.getName()).isEqualTo("service");
	}).verifyComplete();
}
 
Example #5
Source File: InstanceDiscoveryListenerTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_not_register_instance_when_instanceMetadata_matches_ignored_metadata() {
	when(this.discovery.getServices()).thenReturn(asList("service", "rabbit-1", "rabbit-2"));
	when(this.discovery.getInstances("service")).thenReturn(singletonList(new DefaultServiceInstance("test-1",
			"service", "localhost", 80, false, Collections.singletonMap("monitoring", "true"))));
	when(this.discovery.getInstances("rabbit-1"))
			.thenReturn(singletonList(new DefaultServiceInstance("rabbit-test-1", "rabbit-1", "localhost", 80,
					false, Collections.singletonMap("monitoring", "false"))));
	when(this.discovery.getInstances("rabbit-2"))
			.thenReturn(singletonList(new DefaultServiceInstance("rabbit-test-1", "rabbit-2", "localhost", 80,
					false, Collections.singletonMap("monitoring", "false"))));

	this.listener.setIgnoredInstancesMetadata(Collections.singletonMap("monitoring", "false"));
	this.listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

	StepVerifier.create(this.registry.getInstances())
			.assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("service")).verifyComplete();
}
 
Example #6
Source File: InstanceDiscoveryListenerTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_not_throw_error_when_conversion_fails_and_proceed_with_next_instance() {
	when(this.discovery.getServices()).thenReturn(singletonList("service"));
	when(this.discovery.getInstances("service"))
			.thenReturn(asList(new DefaultServiceInstance("test-1", "service", "localhost", 80, false),
					new DefaultServiceInstance("error-1", "error", "localhost", 80, false)));
	this.listener.setConverter((instance) -> {
		if (instance.getServiceId().equals("error")) {
			throw new IllegalStateException("Test-Error");
		}
		else {
			return new DefaultServiceInstanceConverter().convert(instance);
		}
	});

	this.listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

	StepVerifier.create(this.registry.getInstances())
			.assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("service")).verifyComplete();
}
 
Example #7
Source File: ReactiveDiscoveryClientHealthIndicatorTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnUpStatusWithServices() {
	when(discoveryClient.getServices()).thenReturn(Flux.just("service"));
	when(properties.isIncludeDescription()).thenReturn(true);
	when(discoveryClient.description()).thenReturn("Mocked Service Discovery Client");
	Health expectedHealth = Health
			.status(new Status(Status.UP.getCode(),
					"Mocked Service Discovery Client"))
			.withDetail("services", singletonList("service")).build();

	indicator.onApplicationEvent(new InstanceRegisteredEvent<>(this, null));
	Mono<Health> health = indicator.health();

	assertThat(indicator.getName()).isEqualTo("Mocked Service Discovery Client");
	StepVerifier.create(health).expectNext(expectedHealth).expectComplete().verify();
}
 
Example #8
Source File: AbstractAutoServiceRegistration.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
public void start() {
	if (!isEnabled()) {
		if (logger.isDebugEnabled()) {
			logger.debug("Discovery Lifecycle disabled. Not starting");
		}
		return;
	}

	// only initialize if nonSecurePort is greater than 0 and it isn't already running
	// because of containerPortInitializer below
	if (!this.running.get()) {
		this.context.publishEvent(
				new InstancePreRegisteredEvent(this, getRegistration()));
		register();
		if (shouldRegisterManagement()) {
			registerManagement();
		}
		this.context.publishEvent(
				new InstanceRegisteredEvent<>(this, getConfiguration()));
		this.running.compareAndSet(false, true);
	}

}
 
Example #9
Source File: AdminApplicationDiscoveryTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
private URI registerInstance() {
	// We register the instance by setting static values for the SimpleDiscoveryClient
	// and issuing a
	// InstanceRegisteredEvent that makes sure the instance gets registered.
	SimpleDiscoveryProperties.SimpleServiceInstance serviceInstance = new SimpleDiscoveryProperties.SimpleServiceInstance();
	serviceInstance.setServiceId("Test-Instance");
	serviceInstance.setUri(URI.create("http://localhost:" + this.port));
	serviceInstance.getMetadata().put("management.context-path", "/mgmt");
	this.simpleDiscovery.getInstances().put("Test-Application", singletonList(serviceInstance));

	this.instance.publishEvent(new InstanceRegisteredEvent<>(new Object(), null));

	// To get the location of the registered instances we fetch the instance with the
	// name.
	List<JSONObject> applications = this.webClient.get().uri("/instances?name=Test-Instance")
			.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().returnResult(JSONObject.class)
			.getResponseBody().collectList().block();
	assertThat(applications).hasSize(1);
	return URI.create("http://localhost:" + this.port + "/instances/" + applications.get(0).optString("id"));
}
 
Example #10
Source File: InstanceDiscoveryListenerTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void should_not_throw_error_when_conversion_fails_and_proceed_with_next_instance() {
    when(discovery.getServices()).thenReturn(singletonList("service"));
    when(discovery.getInstances("service")).thenReturn(asList(new DefaultServiceInstance("test-1", "service",
        "localhost",
        80,
        false
    ), new DefaultServiceInstance("error-1", "error", "localhost", 80, false)));
    listener.setConverter(instance -> {
        if (instance.getServiceId().equals("error")) {
            throw new IllegalStateException("Test-Error");
        } else {
            return new DefaultServiceInstanceConverter().convert(instance);
        }
    });

    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

    StepVerifier.create(registry.getInstances())
                .assertNext(a -> assertThat(a.getRegistration().getName()).isEqualTo("service"))
                .verifyComplete();
}
 
Example #11
Source File: InstanceDiscoveryListenerTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void should_register_instance_when_new_service_instance_is_discovered() {
    when(discovery.getServices()).thenReturn(singletonList("service"));
    when(discovery.getInstances("service")).thenReturn(singletonList(new DefaultServiceInstance("test-1", "service",
        "localhost",
        80,
        false
    )));

    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

    StepVerifier.create(registry.getInstances()).assertNext(application -> {
        Registration registration = application.getRegistration();
        assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:80/actuator/health");
        assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/actuator");
        assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80/");
        assertThat(registration.getName()).isEqualTo("service");
    }).verifyComplete();


}
 
Example #12
Source File: InstanceDiscoveryListenerTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void should_register_instances_when_serviceId_matches_wanted_pattern_and_igonred_pattern() {
    when(discovery.getServices()).thenReturn(asList("service-1", "service", "rabbit-1", "rabbit-2"));
    when(discovery.getInstances("service")).thenReturn(singletonList(new DefaultServiceInstance("test-1", "service",
        "localhost",
        80,
        false
    )));
    when(discovery.getInstances("service-1")).thenReturn(singletonList(new DefaultServiceInstance("test-1",
        "service-1",
        "localhost",
        80,
        false
    )));

    listener.setServices(singleton("ser*"));
    listener.setIgnoredServices(singleton("service-*"));
    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

    StepVerifier.create(registry.getInstances())
                .assertNext(a -> assertThat(a.getRegistration().getName()).isEqualTo("service"))
                .verifyComplete();
}
 
Example #13
Source File: InstanceDiscoveryListenerTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void should_register_instances_when_serviceId_matches_wanted_pattern() {
    when(discovery.getServices()).thenReturn(asList("service", "rabbit-1", "rabbit-2"));
    when(discovery.getInstances("service")).thenReturn(singletonList(new DefaultServiceInstance("test-1", "service",
        "localhost",
        80,
        false
    )));

    listener.setServices(singleton("ser*"));
    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

    StepVerifier.create(registry.getInstances())
                .assertNext(a -> assertThat(a.getRegistration().getName()).isEqualTo("service"))
                .verifyComplete();
}
 
Example #14
Source File: InstanceDiscoveryListenerTest.java    From Moss with Apache License 2.0 6 votes vote down vote up
@Test
public void should_not_register_instance_when_serviceId_matches_ignored_pattern() {
    when(discovery.getServices()).thenReturn(asList("service", "rabbit-1", "rabbit-2"));
    when(discovery.getInstances("service")).thenReturn(singletonList(new DefaultServiceInstance("test-1", "service",
        "localhost",
        80,
        false
    )));

    listener.setIgnoredServices(singleton("rabbit-*"));
    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

    StepVerifier.create(registry.getInstances())
                .assertNext(a -> assertThat(a.getRegistration().getName()).isEqualTo("service"))
                .verifyComplete();
}
 
Example #15
Source File: EurekaAutoServiceRegistration.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Override
public void start() {
	// only set the port if the nonSecurePort or securePort is 0 and this.port != 0
	if (this.port.get() != 0) {
		if (this.registration.getNonSecurePort() == 0) {
			this.registration.setNonSecurePort(this.port.get());
		}

		if (this.registration.getSecurePort() == 0 && this.registration.isSecure()) {
			this.registration.setSecurePort(this.port.get());
		}
	}

	// only initialize if nonSecurePort is greater than 0 and it isn't already running
	// because of containerPortInitializer below
	if (!this.running.get() && this.registration.getNonSecurePort() > 0) {

		this.serviceRegistry.register(this.registration);

		this.context.publishEvent(new InstanceRegisteredEvent<>(this,
				this.registration.getInstanceConfig()));
		this.running.set(true);
	}
}
 
Example #16
Source File: InstanceDiscoveryListenerTest.java    From spring-boot-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void should_register_instances_when_instanceMetadata_matches_wanted_metadata() {
	when(this.discovery.getServices()).thenReturn(asList("service", "rabbit-1", "rabbit-2"));
	when(this.discovery.getInstances("service")).thenReturn(singletonList(new DefaultServiceInstance("test-1",
			"service", "localhost", 80, false, Collections.singletonMap("monitoring", "true"))));
	when(this.discovery.getInstances("rabbit-1"))
			.thenReturn(singletonList(new DefaultServiceInstance("rabbit-test-1", "rabbit-1", "localhost", 80,
					false, Collections.singletonMap("monitoring", "false"))));
	when(this.discovery.getInstances("rabbit-2"))
			.thenReturn(singletonList(new DefaultServiceInstance("rabbit-test-1", "rabbit-2", "localhost", 80,
					false, Collections.singletonMap("monitoring", "false"))));

	this.listener.setInstancesMetadata(Collections.singletonMap("monitoring", "true"));
	this.listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

	StepVerifier.create(this.registry.getInstances())
			.assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("service")).verifyComplete();
}
 
Example #17
Source File: InstanceDiscoveryListenerTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_register_instance_when_instanceMetadata_is_not_ignored() {
	when(this.discovery.getServices()).thenReturn(singletonList("service"));
	when(this.discovery.getInstances("service")).thenReturn(singletonList(new DefaultServiceInstance("test-1",
			"service", "localhost", 80, false, Collections.singletonMap("monitoring", "true"))));

	this.listener.setInstancesMetadata(Collections.singletonMap("monitoring", "false"));
	this.listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

	StepVerifier.create(this.registry.getInstances()).verifyComplete();
}
 
Example #18
Source File: ZookeeperServiceWatch.java    From spring-cloud-zookeeper with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(InstanceRegisteredEvent<?> event) {
	this.cache = TreeCache.newBuilder(this.curator, this.properties.getRoot())
			.build();
	this.cache.getListenable().addListener(this);
	try {
		this.cache.start();
	}
	catch (Exception e) {
		ReflectionUtils.rethrowRuntimeException(e);
	}
}
 
Example #19
Source File: InstanceDiscoveryListenerTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_not_register_instance_when_serviceId_matches_ignored_pattern() {
	when(this.discovery.getServices()).thenReturn(asList("service", "rabbit-1", "rabbit-2"));
	when(this.discovery.getInstances("service"))
			.thenReturn(singletonList(new DefaultServiceInstance("test-1", "service", "localhost", 80, false)));

	this.listener.setIgnoredServices(singleton("rabbit-*"));
	this.listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

	StepVerifier.create(this.registry.getInstances())
			.assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("service")).verifyComplete();
}
 
Example #20
Source File: DocumentController.java    From sc-generator with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void upload(MultipartFile file, HttpServletResponse response) throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copy(file.getInputStream(), out);
    Swagger swagger = new SwaggerParser()
            .parse(out.toString("utf-8"));
    out.close();
    String content = objectMapper.writeValueAsString(swagger);
    documentService.save(new Document()
            .setContent(content)
            .setTitle(file.getOriginalFilename()));
    applicationEventPublisher.publishEvent(new InstanceRegisteredEvent<>(SwaggerDocDiscovery.class, swagger));
    response.sendRedirect("/#/document.html");
}
 
Example #21
Source File: InstanceDiscoveryListenerTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_register_instance_when_serviceId_is_not_ignored() {
	when(this.discovery.getServices()).thenReturn(singletonList("service"));
	when(this.discovery.getInstances("service"))
			.thenReturn(singletonList(new DefaultServiceInstance("test-1", "service", "localhost", 80, false)));

	this.listener.setServices(singleton("notService2"));
	this.listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

	StepVerifier.create(this.registry.getInstances()).verifyComplete();
}
 
Example #22
Source File: DiscoveryClientHealthIndicatorTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testHealthIndicatorDescriptionDisabled() {
	then(this.healthContributor).as("healthIndicator was null").isNotNull();
	assertHealth(getHealth("testDiscoveryHealthIndicator"), Status.UNKNOWN);
	assertHealth(getHealth("discoveryClient"), Status.UNKNOWN);

	this.clientHealthIndicator
			.onApplicationEvent(new InstanceRegisteredEvent<>(this, null));

	assertHealth(getHealth("testDiscoveryHealthIndicator"), Status.UNKNOWN);
	Status status = assertHealth(getHealth("discoveryClient"), Status.UP);
	then(status.getDescription()).as("status description was wrong")
			.isEqualTo("TestDiscoveryClient");
}
 
Example #23
Source File: ReactiveDiscoveryClientHealthIndicatorTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnUpStatusWithoutServices() {
	when(discoveryClient.description()).thenReturn("Mocked Service Discovery Client");
	when(discoveryClient.getServices()).thenReturn(Flux.empty());
	Health expectedHealth = Health.status(new Status(Status.UP.getCode(), ""))
			.withDetail("services", emptyList()).build();

	indicator.onApplicationEvent(new InstanceRegisteredEvent<>(this, null));
	Mono<Health> health = indicator.health();

	assertThat(indicator.getName()).isEqualTo("Mocked Service Discovery Client");
	StepVerifier.create(health).expectNext(expectedHealth).expectComplete().verify();
}
 
Example #24
Source File: ReactiveDiscoveryClientHealthIndicatorTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnDownStatusWhenServicesCouldNotBeRetrieved() {
	RuntimeException ex = new RuntimeException("something went wrong");
	Health expectedHealth = Health.down(ex).build();
	when(discoveryClient.getServices()).thenReturn(Flux.error(ex));

	indicator.onApplicationEvent(new InstanceRegisteredEvent<>(this, null));
	Mono<Health> health = indicator.health();

	StepVerifier.create(health).expectNext(expectedHealth).expectComplete()
			.verifyThenAssertThat();
}
 
Example #25
Source File: InstanceDiscoveryListenerTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_not_register_instance_when_instanceMetadata_is_ignored() {
	when(this.discovery.getServices()).thenReturn(singletonList("service"));
	when(this.discovery.getInstances("service")).thenReturn(singletonList(new DefaultServiceInstance("test-1",
			"service", "localhost", 80, false, Collections.singletonMap("monitoring", "false"))));

	this.listener.setIgnoredInstancesMetadata(Collections.singletonMap("monitoring", "false"));
	this.listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

	StepVerifier.create(this.registry.getInstances()).verifyComplete();
}
 
Example #26
Source File: InstanceDiscoveryListenerTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_not_register_instance_when_serviceId_is_ignored() {
	when(this.discovery.getServices()).thenReturn(singletonList("service"));
	when(this.discovery.getInstances("service"))
			.thenReturn(singletonList(new DefaultServiceInstance("test-1", "service", "localhost", 80, false)));

	this.listener.setIgnoredServices(singleton("service"));
	this.listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

	StepVerifier.create(this.registry.getInstances()).verifyComplete();
}
 
Example #27
Source File: InstanceDiscoveryListenerTest.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void should_register_instances_when_serviceId_matches_wanted_pattern() {
	when(this.discovery.getServices()).thenReturn(asList("service", "rabbit-1", "rabbit-2"));
	when(this.discovery.getInstances("service"))
			.thenReturn(singletonList(new DefaultServiceInstance("test-1", "service", "localhost", 80, false)));

	this.listener.setServices(singleton("ser*"));
	this.listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

	StepVerifier.create(this.registry.getInstances())
			.assertNext((a) -> assertThat(a.getRegistration().getName()).isEqualTo("service")).verifyComplete();
}
 
Example #28
Source File: KubernetesDiscoveryLifecycle.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
    if (!isEnabled()) {
        return;
    }
    if (running.compareAndSet(false, true)) {
        register();
        getContext().publishEvent(new InstanceRegisteredEvent<>(this,
                getConfiguration()));
    }
}
 
Example #29
Source File: RouteRefreshListenerTests.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Test
public void onInstanceRegisteredEvent() {
	ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
	RouteRefreshListener listener = new RouteRefreshListener(publisher);

	listener.onApplicationEvent(new InstanceRegisteredEvent<>(this, new Object()));

	verify(publisher).publishEvent(any(RefreshRoutesEvent.class));
}
 
Example #30
Source File: KubernetesAutoServiceRegistration.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
	this.serviceRegistry.register(this.registration);

	this.context.publishEvent(
			new InstanceRegisteredEvent<>(this, this.registration.getProperties()));
	this.running.set(true);
}