Skip to content

Commit

Permalink
test: add test to verify health reports
Browse files Browse the repository at this point in the history
Test verify that initial state is unhealthy
Test verify that on no disk space it is unhealthy
Test verify that on disk space free after empty it is healthy again

Related to #6232

(cherry picked from commit a8006f7)
  • Loading branch information
Zelldon authored and github-actions[bot] committed Jul 3, 2023
1 parent 2863648 commit 08d8133
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;

public class ZeebePartitionTest {
Expand Down Expand Up @@ -351,6 +352,69 @@ public void shouldCloseZeebePartitionWhileOngoingTransition() {
Awaitility.await().until(closeFuture::isDone);
}

@Test
public void shouldReportUnhealthyPerDefault() {
// given
final var captor = ArgumentCaptor.forClass(ZeebePartitionHealth.class);
schedulerRule.submitActor(partition);
partition.onNewRole(Role.LEADER, 1);
schedulerRule.workUntilDone();

// when
schedulerRule.workUntilDone();

// then
verify(healthMonitor).registerComponent(any(), captor.capture());

final var zeebePartitionHealth = captor.getValue();
final HealthReport healthReport = zeebePartitionHealth.getHealthReport();
assertThat(healthReport.getStatus()).isEqualTo(HealthStatus.UNHEALTHY);
assertThat(healthReport.getIssue().message()).contains("Initial state");
}

@Test
public void shouldReportUnhealthyWhenNoDiskAvailable() {
// given
final var captor = ArgumentCaptor.forClass(ZeebePartitionHealth.class);
schedulerRule.submitActor(partition);
partition.onNewRole(Role.LEADER, 1);
schedulerRule.workUntilDone();

// when
partition.onDiskSpaceNotAvailable();
schedulerRule.workUntilDone();

// then
verify(healthMonitor).registerComponent(any(), captor.capture());

final var zeebePartitionHealth = captor.getValue();
final HealthReport healthReport = zeebePartitionHealth.getHealthReport();
assertThat(healthReport.getStatus()).isEqualTo(HealthStatus.UNHEALTHY);
assertThat(healthReport.getIssue().message()).contains("Not enough disk space available");
}

@Test
public void shouldReportHealthyWhenDiskIsAvailableAgain() {
// given
final var captor = ArgumentCaptor.forClass(ZeebePartitionHealth.class);
schedulerRule.submitActor(partition);
partition.onNewRole(Role.LEADER, 1);
partition.onDiskSpaceNotAvailable();
schedulerRule.workUntilDone();

// when
partition.onDiskSpaceAvailable();
schedulerRule.workUntilDone();

// then
verify(healthMonitor).registerComponent(any(), captor.capture());

final var zeebePartitionHealth = captor.getValue();
final HealthReport healthReport = zeebePartitionHealth.getHealthReport();
assertThat(healthReport.getStatus()).isEqualTo(HealthStatus.HEALTHY);
assertThat(healthReport.getIssue()).isNull();
}

private static class NoopStartupStep implements PartitionStartupStep {

@Override
Expand Down

0 comments on commit 08d8133

Please sign in to comment.