From 70b5006590d1b3da18292d771b9e3e3478d49ee8 Mon Sep 17 00:00:00 2001 From: Sabby Anandan Date: Mon, 17 Aug 2020 13:15:38 -0700 Subject: [PATCH] Simulate variable blocking behavior --- .../thumbinator/ThumbinatorApplication.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/thumbinator/src/main/java/com/springone/thumbinator/ThumbinatorApplication.java b/thumbinator/src/main/java/com/springone/thumbinator/ThumbinatorApplication.java index 8a46147..b3368bb 100644 --- a/thumbinator/src/main/java/com/springone/thumbinator/ThumbinatorApplication.java +++ b/thumbinator/src/main/java/com/springone/thumbinator/ThumbinatorApplication.java @@ -19,6 +19,8 @@ import javax.imageio.ImageIO; import java.io.File; import java.net.URL; +import java.util.Arrays; +import java.util.List; import java.util.Random; @EnableTask @@ -32,6 +34,9 @@ public class ThumbinatorApplication { String READY_THUMBNAIL_IMG = "/tmp/ready/dataflow-icon-thumb-ready.png"; + static List SLEEP_TIMERS = Arrays + .asList(1000, 20000, 5000, 7000, 8000, 10000, 10000, 12000, 9900); + Random random = new Random(); @Autowired @@ -89,7 +94,8 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon .println("##### THUMBNAIL DRAFT is: [" + draftThumbnail.length() + "] bytes #####"); - Thread.sleep(random.nextInt(10000)); + // simulate variable wait timer, so metrics can be captured in Prometheus + Thread.sleep(SLEEP_TIMERS.get(random.nextInt(SLEEP_TIMERS.size()))); System.out.println("Job-1 + Step-2 FINISHED"); return RepeatStatus.FINISHED; @@ -117,7 +123,8 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon thumbnailFrom.renameTo(thumbnailTo); - Thread.sleep(random.nextInt(10000)); + // simulate variable wait timer, so metrics can be captured in Prometheus + Thread.sleep(SLEEP_TIMERS.get(random.nextInt(SLEEP_TIMERS.size()))); System.out.println( "##### THUMBNAIL DRAFT is: [" + thumbnailFromSize @@ -142,7 +149,8 @@ public Job statusImage() { public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { - Thread.sleep(random.nextInt(10000)); + // simulate variable wait timer, so metrics can be captured in Prometheus + Thread.sleep(SLEEP_TIMERS.get(random.nextInt(SLEEP_TIMERS.size()))); System.out.println( "##### ORIGINAL is: [" + new File(ORIGINAL_IMG).length()