Skip to content

Commit

Permalink
Merge branch 'master' into restclient
Browse files Browse the repository at this point in the history
  • Loading branch information
szczygiel-m committed Apr 5, 2024
2 parents 3617163 + 82996cf commit e428be1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand All @@ -32,7 +33,9 @@ public void setReady(DatacenterReadiness datacenterReadiness) {
toSave.put(datacenter, current.get(datacenter));
}
toSave.put(datacenterReadiness.getDatacenter(), datacenterReadiness);
List<DatacenterReadiness> readiness = toSave.values().stream().toList();
List<DatacenterReadiness> readiness = toSave.values().stream()
.filter(Objects::nonNull)
.toList();
commandExecutor.execute(new SetReadinessCommand(readiness));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ public WebTestClient.ResponseSpec setReadiness(String dc, boolean state) {
}

public WebTestClient.ResponseSpec getReadiness() {
return managementTestClient.getReadiness();
}

public WebTestClient.ResponseSpec getFrontendReadiness() {
return frontendTestClient.getStatusReady();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class ManagementTestClient {

private static final String SET_READINESS = "/readiness/datacenters/{dc}";

private static final String GET_READINESS = "/readiness/datacenters";

private static final String TOPIC_SCHEMA = "/topics/{topicName}/schema";

private static final String ALL_TOPIC_CLIENTS = "/topics/{topicName}/clients";
Expand Down Expand Up @@ -337,6 +339,14 @@ public WebTestClient.ResponseSpec setReadiness(String dc, boolean state) {
.exchange();
}

public WebTestClient.ResponseSpec getReadiness() {
return webTestClient.get().uri(UriBuilder
.fromUri(managementContainerUrl)
.path(GET_READINESS)
.build())
.exchange();
}

public WebTestClient.ResponseSpec saveSchema(String qualifiedTopicName, boolean validate, String schema) {
return webTestClient.post().uri(UriBuilder
.fromUri(managementContainerUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void shouldRespectReadinessStatusSetByAdmin() {
// then
waitAtMost(Duration.FIVE_SECONDS).until(() ->
hermes.api()
.getReadiness()
.getFrontendReadiness()
.expectStatus().is5xxServerError()
.expectBody(String.class).isEqualTo("NOT_READY")
);
Expand All @@ -32,7 +32,7 @@ public void shouldRespectReadinessStatusSetByAdmin() {
// then
waitAtMost(Duration.FIVE_SECONDS).until(() ->
hermes.api()
.getReadiness()
.getFrontendReadiness()
.expectStatus().isOk()
.expectBody(String.class).isEqualTo("READY")
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package pl.allegro.tech.hermes.integrationtests.management;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import pl.allegro.tech.hermes.api.DatacenterReadiness;
import pl.allegro.tech.hermes.integrationtests.setup.HermesExtension;

import static pl.allegro.tech.hermes.api.DatacenterReadiness.ReadinessStatus.READY;
import static pl.allegro.tech.hermes.infrastructure.dc.DefaultDatacenterNameProvider.DEFAULT_DC_NAME;

public class ReadinessManagementTest {

@RegisterExtension
public static final HermesExtension hermes = new HermesExtension();

@Test
public void shouldNotFailWhileSettingReadinessStatusForTheFirstTime() {
//when
hermes.api().setReadiness("unhealthy-dc", false);

//then
hermes.api().getReadiness()
.expectStatus()
.isOk()
.expectBodyList(DatacenterReadiness.class)
// 'unhealthy-dc' should not be returned here, since it doesn't exist in management configuration
// In this test, we are just verifying if setting readiness status for the first time doesn't break anything.
.hasSize(1)
.contains(new DatacenterReadiness(DEFAULT_DC_NAME, READY));
}
}

0 comments on commit e428be1

Please sign in to comment.