From 1a2cf17c0d02b34e5acc80865f487bfa2f1a4802 Mon Sep 17 00:00:00 2001 From: Vishal M Yadav Date: Mon, 8 Apr 2024 13:06:54 +0530 Subject: [PATCH 1/4] added test cases for threadUtils class --- .../common/utils/ThreadUtilsTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java new file mode 100644 index 0000000000..16308e006e --- /dev/null +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java @@ -0,0 +1,42 @@ +package org.apache.eventmesh.common.utils; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ThreadUtilsTest { + + @Test + public void testRandomPauseDurationWithinBounds() throws InterruptedException { + long min = 100; + long max = 200; + + long startTime = System.currentTimeMillis(); + + ThreadUtils.randomPause(min, max); + + long endTime = System.currentTimeMillis(); + + long duration = endTime - startTime; + + assertTrue(duration >= min && duration <= max + 10, "The pause duration should be within the specified bounds, allowing a small margin for timing inaccuracies."); + } + + @Test + public void testGetPIDReturnsPositiveValue() { + + long pid = ThreadUtils.getPID(); + + assertTrue(pid > 0, "The PID should be a positive value."); + } + + @Test + public void testGetPIDReturnsConsistentValue() { + + long firstCallPID = ThreadUtils.getPID(); + long secondCallPID = ThreadUtils.getPID(); + + assertEquals(firstCallPID, secondCallPID, "The PID should remain consistent across calls."); + } +} \ No newline at end of file From 219efda433781adf124a5fad2f1a88c4ddc1160d Mon Sep 17 00:00:00 2001 From: Vishal M Yadav Date: Sun, 14 Apr 2024 19:44:09 +0530 Subject: [PATCH 2/4] fixed ci --- .../org/apache/eventmesh/common/utils/ThreadUtilsTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java index 16308e006e..2b94de5bf4 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java @@ -20,7 +20,8 @@ public void testRandomPauseDurationWithinBounds() throws InterruptedException { long duration = endTime - startTime; - assertTrue(duration >= min && duration <= max + 10, "The pause duration should be within the specified bounds, allowing a small margin for timing inaccuracies."); + assertTrue(duration >= min && duration <= max + 10, + "The pause duration should be within the specified bounds, allowing a small margin for timing inaccuracies."); } @Test From 27c16f0101595f97b1d18cbcd248435a59ce36b2 Mon Sep 17 00:00:00 2001 From: Vishal M Yadav Date: Mon, 15 Apr 2024 01:08:00 +0530 Subject: [PATCH 3/4] wip fixed ci --- .../common/utils/ThreadUtilsTest.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java index 2b94de5bf4..6663deb86f 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java @@ -1,10 +1,28 @@ -package org.apache.eventmesh.common.utils; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import org.junit.jupiter.api.Test; + +package org.apache.eventmesh.common.utils; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + public class ThreadUtilsTest { @Test From 3d61048c7c88034e8dbd84c8afb42f2cbfb4c7f2 Mon Sep 17 00:00:00 2001 From: Vishal M Yadav Date: Mon, 15 Apr 2024 12:45:06 +0530 Subject: [PATCH 4/4] wip fixed ci --- .../java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java index 6663deb86f..509f0051fb 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java @@ -38,7 +38,7 @@ public void testRandomPauseDurationWithinBounds() throws InterruptedException { long duration = endTime - startTime; - assertTrue(duration >= min && duration <= max + 10, + assertTrue(duration >= min && duration <= max+20, "The pause duration should be within the specified bounds, allowing a small margin for timing inaccuracies."); }