Reset probe in testing

This commit is contained in:
alandavis
2022-08-01 08:39:59 +01:00
parent 5883065d1b
commit 478c689902
3 changed files with 12 additions and 4 deletions

View File

@@ -249,7 +249,7 @@ public abstract class ProbeTestTransform
{ {
throw new TransformException(TOO_MANY_REQUESTS, throw new TransformException(TOO_MANY_REQUESTS,
getMessagePrefix(isLiveProbe) + "Transformer requested to die. A transform took " + getMessagePrefix(isLiveProbe) + "Transformer requested to die. A transform took " +
"longer than " + (maxTransformTime * 1000) + " seconds"); "longer than " + (maxTransformTime / 1000) + " seconds");
} }
if (maxTransformCount > 0 && transformCount.get() > maxTransformCount) if (maxTransformCount > 0 && transformCount.get() > maxTransformCount)

View File

@@ -242,7 +242,7 @@ public class ProbeTransform
{ {
throw new TransformException(TOO_MANY_REQUESTS, throw new TransformException(TOO_MANY_REQUESTS,
getMessagePrefix(isLiveProbe) + "Transformer requested to die. A transform took " + getMessagePrefix(isLiveProbe) + "Transformer requested to die. A transform took " +
"longer than " + (maxTransformTime * 1000) + " seconds"); "longer than " + (maxTransformTime / 1000) + " seconds");
} }
if (maxTransformCount > 0 && transformCount.get() > maxTransformCount) if (maxTransformCount > 0 && transformCount.get() > maxTransformCount)
@@ -302,8 +302,7 @@ public class ProbeTransform
true)) || transCount > AVERAGE_OVER_TRANSFORMS) true)) || transCount > AVERAGE_OVER_TRANSFORMS)
{ {
nextTransformTime = System.currentTimeMillis() + livenessTransformPeriod; nextTransformTime = System.currentTimeMillis() + livenessTransformPeriod;
logger.trace("{} - {}ms+{}%={}ms", message, normalTime, livenessPercent, logger.trace("{} - {}ms+{}%={}ms", message, normalTime, livenessPercent, maxTime);
maxTime);
} }
} }
else if (!isLiveProbe && !readySent.getAndSet(true)) else if (!isLiveProbe && !readySent.getAndSet(true))
@@ -356,4 +355,10 @@ public class ProbeTransform
{ {
return normalTime; return normalTime;
} }
public void resetForTesting()
{
die.set(false);
transformCount.set(0);
}
} }

View File

@@ -129,6 +129,7 @@ public class TransformControllerTest
public File tempDir; public File tempDir;
@MockBean @MockBean
protected AlfrescoSharedFileStoreClient fakeSfsClient; protected AlfrescoSharedFileStoreClient fakeSfsClient;
@BeforeEach @BeforeEach
public void fakeSfsClient() public void fakeSfsClient()
{ {
@@ -229,6 +230,7 @@ public class TransformControllerTest
@Test @Test
public void testReadyEndpointReturnsSuccessful() throws Exception public void testReadyEndpointReturnsSuccessful() throws Exception
{ {
transformController.probeTransform.resetForTesting();
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_READY)) mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_READY))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().string(containsString("Success - "))); .andExpect(content().string(containsString("Success - ")));
@@ -237,6 +239,7 @@ public class TransformControllerTest
@Test @Test
public void testLiveEndpointReturnsSuccessful() throws Exception public void testLiveEndpointReturnsSuccessful() throws Exception
{ {
transformController.probeTransform.resetForTesting();
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_LIVE)) mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_LIVE))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().string(containsString("Success - "))); .andExpect(content().string(containsString("Success - ")));