Skip to content

Commit

Permalink
add helper method for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC committed Dec 13, 2024
1 parent 29ee5aa commit d948839
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ protected boolean doEnable(InspectitConfig configuration) {
@Override
protected boolean doDisable() {
log.info("Stopping agent command polling service.");
if (timeoutExecutor != null) {
timeoutExecutor.cancelTimeout();
}
cancelTimeout();
if (handlerFuture != null) {
handlerFuture.cancel(true);
}
Expand All @@ -112,7 +110,7 @@ public void run() {
try {
commandHandler.nextCommand();
// After the command was fetched, the task should no longer timeout
timeoutExecutor.cancelTimeout();
cancelTimeout();
} catch (Exception exception) {
log.error("Error while fetching agent command.", exception);
}
Expand Down Expand Up @@ -151,4 +149,11 @@ URI getCommandUri(InspectitConfig configuration) throws URISyntaxException {
return settings.getUrl().toURI();
}
}

@VisibleForTesting
void cancelTimeout() {
if (timeoutExecutor != null) {
timeoutExecutor.cancelTimeout();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rocks.inspectit.ocelot.core.config.propertysources.http;

import com.google.common.annotations.VisibleForTesting;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -79,9 +80,7 @@ protected boolean doEnable(InspectitConfig configuration) {
@Override
protected boolean doDisable() {
log.info("Stopping HTTP configuration polling service.");
if (timeoutExecutor != null) {
timeoutExecutor.cancelTimeout();
}
cancelTimeout();
if (pollerFuture != null) {
pollerFuture.cancel(true);
}
Expand All @@ -98,7 +97,7 @@ public void run() {
// Fetch configuration
boolean wasUpdated = currentState.update(false);
// After the configuration was fetched, the task should no longer timeout
timeoutExecutor.cancelTimeout();
cancelTimeout();
if (wasUpdated) {
env.updatePropertySources(propertySources -> {
if (propertySources.contains(InspectitEnvironment.HTTP_BASED_CONFIGURATION)) {
Expand Down Expand Up @@ -129,4 +128,11 @@ public AgentHealthState getCurrentAgentHealthState() {
if(currentState == null) return null;
return currentState.getAgentHealth();
}

@VisibleForTesting
void cancelTimeout() {
if (timeoutExecutor != null) {
timeoutExecutor.cancelTimeout();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void scheduleCancelling(Future<?> task, String taskName, Runnable restart
}

/**
* Cancel the timeout executor
* Cancel the timeout executor, if started
*/
public void cancelTimeout() {
if(timeoutExecutor != null) timeoutExecutor.cancel(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ public void verifyPrioritization() throws Exception {
public class TaskTimeout {

@AfterEach
void disableTimeout() {
// Stop restarting the task after timeout
service.doDisable();
void cancelTimeout() {
service.cancelTimeout();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ public void stateUpdated() {
public class TaskTimeout {

@AfterEach
void disableTimeout() {
// Stop restarting the task after timeout
poller.doDisable();
void cancelTimeout() {
poller.cancelTimeout();
}

@Test
Expand Down

0 comments on commit d948839

Please sign in to comment.