Skip to content

Commit

Permalink
test: add method to check attr InstanceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-Montes committed Jan 23, 2025
1 parent 997fbd4 commit 3dc8d19
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;

Expand All @@ -36,6 +37,7 @@
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.common.HttpStatus;
import com.linecorp.armeria.common.MediaType;
import com.linecorp.armeria.common.eureka.InstanceInfo;
import com.linecorp.armeria.internal.testing.GenerateNativeImageTrace;
import com.linecorp.armeria.server.ServerBuilder;
import com.linecorp.armeria.testing.junit5.server.ServerExtension;
Expand Down Expand Up @@ -77,4 +79,25 @@ void upStatusInstancesAreChosen() {
// Created 6 instances but 1 is down, so 5 instances.
assertThat(endpointsCaptor.join()).hasSize(5);
}

@Test
void shouldRetrieveInstanceInfoFromEndpointInEurekaEndpointGroup() {

final EurekaEndpointGroup eurekaEndpointGroup = EurekaEndpointGroup.builder(eurekaServer.httpUri())
.build();
final CompletableFuture<List<Endpoint>> endpointsCaptor = new CompletableFuture<>();
eurekaEndpointGroup.addListener(endpointsCaptor::complete);

final Optional<Endpoint> optEndpoint = endpointsCaptor.join().stream().findFirst();
assertThat(optEndpoint.isPresent()).isTrue();
final Endpoint endpoint = optEndpoint.get();
final InstanceInfo instanceInfoRetrieved = InstanceInfo.instanceInfo(endpoint);

assertThat(instanceInfoRetrieved).isNotNull();
assertThat(instanceInfoRetrieved.getHostName()).isEqualTo(endpoint.host());
assertThat(instanceInfoRetrieved.getIpAddr()).isEqualTo(endpoint.ipAddr());
assertThat(instanceInfoRetrieved.getInstanceId()).isEqualTo("i-00000000");
assertThat(instanceInfoRetrieved.getAppName()).isEqualTo("APPLICATION0");
assertThat(instanceInfoRetrieved.getAppGroupName()).isEqualTo("APPLICATION0GROUP");
}
}

0 comments on commit 3dc8d19

Please sign in to comment.