This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new f5075e006ea [#22941] Add test cases for TimeRecorder (#23253)
f5075e006ea is described below
commit f5075e006ea680b7696806e66d735eeb34bdd2bf
Author: Rahul Nag <[email protected]>
AuthorDate: Mon Jan 2 15:41:17 2023 +0530
[#22941] Add test cases for TimeRecorder (#23253)
* [#22941] Add test cases for TimeRecorder
* Review changes
* License added
* Remove blank line
Co-authored-by: Rahul <[email protected]>
---
.../agent/plugin/core/util/TimeRecorderTest.java | 39 ++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git
a/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/util/TimeRecorderTest.java
b/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/util/TimeRecorderTest.java
new file mode 100644
index 00000000000..c27992786f2
--- /dev/null
+++
b/agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/util/TimeRecorderTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.agent.plugin.core.util;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+
+public final class TimeRecorderTest {
+
+ @Test
+ public void
assertRecordedElapsedTimeIsCorrectWhenCurrentRecorderIsPresent() throws
InterruptedException {
+ TimeRecorder.INSTANCE.record();
+ Thread.sleep(5);
+ assertTrue(TimeRecorder.INSTANCE.getElapsedTime() >= 5);
+ }
+
+ @Test
+ public void
assertElapsedTimeThrowsNullPointerExceptionWhenCurrentRecorderIsNotPresent() {
+ TimeRecorder.INSTANCE.clean();
+ assertThrows(NullPointerException.class,
TimeRecorder.INSTANCE::getElapsedTime);
+ }
+}
\ No newline at end of file