-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for AgentHealth monitoring
- Loading branch information
Showing
13 changed files
with
547 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...c/test/java/rocks/inspectit/ocelot/core/selfmonitoring/AgentHealthIncidentBufferTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package rocks.inspectit.ocelot.core.selfmonitoring; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Answers; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.context.ApplicationContext; | ||
import rocks.inspectit.ocelot.commons.models.health.AgentHealth; | ||
import rocks.inspectit.ocelot.commons.models.health.AgentHealthIncident; | ||
import rocks.inspectit.ocelot.core.SpringTestBase; | ||
import rocks.inspectit.ocelot.core.config.InspectitEnvironment; | ||
import rocks.inspectit.ocelot.core.selfmonitoring.event.models.AgentHealthIncidentAddedEvent; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class AgentHealthIncidentBufferTest { | ||
|
||
@InjectMocks | ||
private AgentHealthIncidentBuffer incidentBuffer; | ||
@Mock | ||
private ApplicationContext ctx; | ||
@Mock(answer = Answers.RETURNS_DEEP_STUBS) | ||
private InspectitEnvironment env; | ||
|
||
private AgentHealthIncident incident; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
when(env.getCurrentConfig().getSelfMonitoring().getAgentHealth().getIncidentBufferSize()).thenReturn(2); | ||
incident = new AgentHealthIncident("2001-01-01", AgentHealth.WARNING, this.getClass().getCanonicalName(), "Mock message", true); | ||
} | ||
@Test | ||
void verifyBufferSize() { | ||
incidentBuffer.put(incident); | ||
incidentBuffer.put(incident); | ||
incidentBuffer.put(incident); | ||
|
||
verify(ctx, times(3)).publishEvent(any(AgentHealthIncidentAddedEvent.class)); | ||
} | ||
|
||
@Test | ||
void verifyEventPublisher() { | ||
incidentBuffer.put(incident); | ||
incidentBuffer.put(incident); | ||
incidentBuffer.put(incident); | ||
|
||
verify(ctx, times(3)).publishEvent(any(AgentHealthIncidentAddedEvent.class)); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
...e/src/test/java/rocks/inspectit/ocelot/core/selfmonitoring/AgentHealthManagerIntTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package rocks.inspectit.ocelot.core.selfmonitoring; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import rocks.inspectit.ocelot.commons.models.health.AgentHealth; | ||
import rocks.inspectit.ocelot.core.SpringTestBase; | ||
import rocks.inspectit.ocelot.core.config.propertysources.http.HttpConfigurationPoller; | ||
|
||
import java.time.Duration; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* Integration tests {@link AgentHealthManager} | ||
*/ | ||
public class AgentHealthManagerIntTest extends SpringTestBase { | ||
|
||
@Autowired | ||
private AgentHealthManager healthManager; | ||
@Autowired | ||
private HttpConfigurationPoller configurationPoller; | ||
@Autowired | ||
private AgentHealthIncidentBuffer incidentBuffer; | ||
|
||
@BeforeEach | ||
void clearBuffer() { | ||
incidentBuffer.clear(); | ||
} | ||
|
||
@Nested | ||
class InvalidatableHealth { | ||
|
||
@Test | ||
void verifyAgentHealthUpdating() { | ||
AgentHealth currentHealth = configurationPoller.getCurrentAgentHealthState().getHealth(); | ||
int bufferSize = healthManager.getIncidentHistory().size(); | ||
assertEquals(currentHealth, AgentHealth.OK); | ||
assertEquals(bufferSize, 0); | ||
|
||
healthManager.notifyAgentHealth(AgentHealth.WARNING, this.getClass(), this.getClass().getName(), "Mock message"); | ||
|
||
currentHealth = configurationPoller.getCurrentAgentHealthState().getHealth(); | ||
bufferSize = healthManager.getIncidentHistory().size(); | ||
assertEquals(currentHealth, AgentHealth.WARNING); | ||
assertEquals(bufferSize, 1); | ||
|
||
healthManager.notifyAgentHealth(AgentHealth.ERROR, this.getClass(), this.getClass().getName(), "Mock message"); | ||
|
||
currentHealth = configurationPoller.getCurrentAgentHealthState().getHealth(); | ||
bufferSize = healthManager.getIncidentHistory().size(); | ||
assertEquals(currentHealth, AgentHealth.ERROR); | ||
assertEquals(bufferSize, 2); | ||
} | ||
|
||
@Test | ||
void verifyAgentHealthInvalidation() { | ||
AgentHealth currentHealth = configurationPoller.getCurrentAgentHealthState().getHealth(); | ||
int bufferSize = healthManager.getIncidentHistory().size(); | ||
assertEquals(currentHealth, AgentHealth.OK); | ||
assertEquals(bufferSize, 0); | ||
|
||
healthManager.notifyAgentHealth(AgentHealth.ERROR, this.getClass(), this.getClass().getName(), "Mock message"); | ||
|
||
currentHealth = configurationPoller.getCurrentAgentHealthState().getHealth(); | ||
bufferSize = healthManager.getIncidentHistory().size(); | ||
assertEquals(currentHealth, AgentHealth.ERROR); | ||
assertEquals(bufferSize, 1); | ||
|
||
healthManager.invalidateIncident(this.getClass(), "Mock invalidation"); | ||
|
||
currentHealth = configurationPoller.getCurrentAgentHealthState().getHealth(); | ||
bufferSize = healthManager.getIncidentHistory().size(); | ||
assertEquals(currentHealth, AgentHealth.OK); | ||
assertEquals(bufferSize, 2); | ||
} | ||
} | ||
|
||
@Nested | ||
class TimeoutHealth { | ||
|
||
@Test | ||
void verifyAgentHealthUpdating() throws InterruptedException { | ||
AgentHealth currentHealth = configurationPoller.getCurrentAgentHealthState().getHealth(); | ||
int bufferSize = healthManager.getIncidentHistory().size(); | ||
assertEquals(currentHealth, AgentHealth.OK); | ||
assertEquals(bufferSize, 0); | ||
|
||
// Use custom method for testing, to reduce the validityPeriod | ||
// This method should not be used outside of tests! | ||
healthManager.handleTimeoutHealthTesting(AgentHealth.WARNING, this.getClass().getName(), | ||
"Mock message", Duration.ofSeconds(10)); | ||
|
||
currentHealth = configurationPoller.getCurrentAgentHealthState().getHealth(); | ||
bufferSize = healthManager.getIncidentHistory().size(); | ||
assertEquals(currentHealth, AgentHealth.WARNING); | ||
assertEquals(bufferSize, 1); | ||
|
||
// wait 61s for time out (which has to be at least 60s) | ||
Thread.sleep(61000); | ||
|
||
currentHealth = configurationPoller.getCurrentAgentHealthState().getHealth(); | ||
bufferSize = healthManager.getIncidentHistory().size(); | ||
assertEquals(currentHealth, AgentHealth.OK); | ||
assertEquals(bufferSize, 3); | ||
} | ||
} | ||
} |
Oops, something went wrong.