Java Code Examples for org.springframework.cloud.client.discovery.ReactiveDiscoveryClient#getInstances()

The following examples show how to use org.springframework.cloud.client.discovery.ReactiveDiscoveryClient#getInstances() . 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: KubernetesReactiveDiscoveryClientTests.java    From spring-cloud-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnEmptyFluxWhenServiceHasNoSubsets(
		@Client KubernetesClient kubernetesClient,
		@Server KubernetesServer kubernetesServer) {
	kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
			.andReturn(200,
					new ServiceListBuilder().addNewItem().withNewMetadata()
							.withName("existing-service")
							.withLabels(new HashMap<String, String>() {
								{
									put("label", "value");
								}
							}).endMetadata().endItem().build())
			.once();

	KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties();
	ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(
			kubernetesClient, properties, KubernetesClient::services);
	Flux<ServiceInstance> instances = client.getInstances("existing-service");
	StepVerifier.create(instances).expectNextCount(0).expectComplete().verify();
}
 
Example 2
Source File: KubernetesReactiveDiscoveryClientTests.java    From spring-cloud-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnEmptyFluxForNonExistingService(
		@Client KubernetesClient kubernetesClient) {
	KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties();
	ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(
			kubernetesClient, properties, KubernetesClient::services);
	Flux<ServiceInstance> instances = client.getInstances("nonexistent-service");
	StepVerifier.create(instances).expectNextCount(0).expectComplete().verify();
}
 
Example 3
Source File: KubernetesReactiveDiscoveryClientTests.java    From spring-cloud-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldReturnFlux(@Client KubernetesClient kubernetesClient,
		@Server KubernetesServer kubernetesServer) {
	kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
			.andReturn(200,
					new ServiceListBuilder().addNewItem().withNewMetadata()
							.withName("existing-service")
							.withLabels(new HashMap<String, String>() {
								{
									put("label", "value");
								}
							}).endMetadata().endItem().build())
			.once();

	Endpoints endPoints = new EndpointsBuilder().withNewMetadata()
			.withName("endpoint").withNamespace("test").endMetadata().addNewSubset()
			.addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1")
			.endTargetRef().endAddress().addNewPort("http", 80, "TCP").endSubset()
			.build();

	kubernetesServer.expect().get()
			.withPath("/api/v1/namespaces/test/endpoints/existing-service")
			.andReturn(200, endPoints).once();

	kubernetesServer.expect().get()
			.withPath("/api/v1/namespaces/test/services/existing-service")
			.andReturn(200,
					new ServiceBuilder().withNewMetadata()
							.withName("existing-service")
							.withLabels(new HashMap<String, String>() {
								{
									put("label", "value");
								}
							}).endMetadata().build())
			.once();

	KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties();
	ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(
			kubernetesClient, properties, KubernetesClient::services);
	Flux<ServiceInstance> instances = client.getInstances("existing-service");
	StepVerifier.create(instances).expectNextCount(1).expectComplete().verify();
}
 
Example 4
Source File: KubernetesReactiveDiscoveryClientTests.java    From spring-cloud-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldReturnFluxWithPrefixedMetadata(
		@Client KubernetesClient kubernetesClient,
		@Server KubernetesServer kubernetesServer) {
	kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
			.andReturn(200,
					new ServiceListBuilder().addNewItem().withNewMetadata()
							.withName("existing-service")
							.withLabels(new HashMap<String, String>() {
								{
									put("label", "value");
								}
							}).endMetadata().endItem().build())
			.once();

	Endpoints endPoints = new EndpointsBuilder().withNewMetadata()
			.withName("endpoint").withNamespace("test").endMetadata().addNewSubset()
			.addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1")
			.endTargetRef().endAddress().addNewPort("http", 80, "TCP").endSubset()
			.build();

	kubernetesServer.expect().get()
			.withPath("/api/v1/namespaces/test/endpoints/existing-service")
			.andReturn(200, endPoints).once();

	kubernetesServer.expect().get()
			.withPath("/api/v1/namespaces/test/services/existing-service")
			.andReturn(200,
					new ServiceBuilder().withNewMetadata()
							.withName("existing-service")
							.withLabels(new HashMap<String, String>() {
								{
									put("label", "value");
								}
							}).endMetadata().build())
			.once();

	KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties();
	properties.getMetadata().setAnnotationsPrefix("annotation.");
	properties.getMetadata().setLabelsPrefix("label.");
	properties.getMetadata().setPortsPrefix("port.");
	ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(
			kubernetesClient, properties, KubernetesClient::services);
	Flux<ServiceInstance> instances = client.getInstances("existing-service");
	StepVerifier.create(instances).expectNextCount(1).expectComplete().verify();
}
 
Example 5
Source File: KubernetesReactiveDiscoveryClientTests.java    From spring-cloud-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldReturnFluxWhenServiceHasMultiplePortsAndPrimaryPortNameIsSet(
		@Client KubernetesClient kubernetesClient,
		@Server KubernetesServer kubernetesServer) {
	kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
			.andReturn(200,
					new ServiceListBuilder().addNewItem().withNewMetadata()
							.withName("existing-service")
							.withLabels(new HashMap<String, String>() {
								{
									put("label", "value");
								}
							}).endMetadata().endItem().build())
			.once();

	Endpoints endPoints = new EndpointsBuilder().withNewMetadata()
			.withName("endpoint").withNamespace("test").endMetadata().addNewSubset()
			.addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1")
			.endTargetRef().endAddress().addNewPort("http", 80, "TCP")
			.addNewPort("https", 443, "TCP").endSubset().build();

	kubernetesServer.expect().get()
			.withPath("/api/v1/namespaces/test/endpoints/existing-service")
			.andReturn(200, endPoints).once();

	kubernetesServer.expect().get()
			.withPath("/api/v1/namespaces/test/services/existing-service")
			.andReturn(200,
					new ServiceBuilder().withNewMetadata()
							.withName("existing-service")
							.withLabels(new HashMap<String, String>() {
								{
									put("label", "value");
								}
							}).endMetadata().build())
			.once();

	KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties();
	properties.setPrimaryPortName("https");
	ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(
			kubernetesClient, properties, KubernetesClient::services);
	Flux<ServiceInstance> instances = client.getInstances("existing-service");
	StepVerifier.create(instances).expectNextCount(1).expectComplete().verify();
}
 
Example 6
Source File: KubernetesReactiveDiscoveryClientTests.java    From spring-cloud-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldReturnFluxOfServicesAcrossAllNamespaces(
		@Client KubernetesClient kubernetesClient,
		@Server KubernetesServer kubernetesServer) {
	kubernetesServer.expect().get().withPath("/api/v1/namespaces/test/services")
			.andReturn(200,
					new ServiceListBuilder().addNewItem().withNewMetadata()
							.withName("existing-service")
							.withLabels(new HashMap<String, String>() {
								{
									put("label", "value");
								}
							}).endMetadata().endItem().build())
			.once();

	Endpoints endpoints = new EndpointsBuilder().withNewMetadata()
			.withName("endpoint").withNamespace("test").endMetadata().addNewSubset()
			.addNewAddress().withIp("ip1").withNewTargetRef().withUid("uid1")
			.endTargetRef().endAddress().addNewPort("http", 80, "TCP")
			.addNewPort("https", 443, "TCP").endSubset().build();

	EndpointsList endpointsList = new EndpointsList();
	endpointsList.setItems(singletonList(endpoints));

	kubernetesServer.expect().get().withPath(
			"/api/v1/endpoints?fieldSelector=metadata.name%3Dexisting-service")
			.andReturn(200, endpointsList).once();

	kubernetesServer.expect().get()
			.withPath("/api/v1/namespaces/test/services/existing-service")
			.andReturn(200,
					new ServiceBuilder().withNewMetadata()
							.withName("existing-service")
							.withLabels(new HashMap<String, String>() {
								{
									put("label", "value");
								}
							}).endMetadata().build())
			.once();

	KubernetesDiscoveryProperties properties = new KubernetesDiscoveryProperties();
	properties.setAllNamespaces(true);
	ReactiveDiscoveryClient client = new KubernetesReactiveDiscoveryClient(
			kubernetesClient, properties, KubernetesClient::services);
	Flux<ServiceInstance> instances = client.getInstances("existing-service");
	StepVerifier.create(instances).expectNextCount(1).expectComplete().verify();
}