@@ -24,6 +24,9 @@ package org.bitlap.tools
2424import org .scalatest .flatspec .AnyFlatSpec
2525import org .scalatest .matchers .should .Matchers
2626
27+ import scala .concurrent .Await
28+ import scala .concurrent .duration .Duration
29+
2730import scala .concurrent .Future
2831
2932/** @author
@@ -37,22 +40,22 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
3740 // Duration and TimeUnit must Full class name
3841 """
3942 | class A {
40- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.INFO)
43+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.INFO)
4144 | def i = ???
4245 | }
4346 |
4447 | class B {
45- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.WARN)
48+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.WARN)
4649 | def j = ???
4750 | }
4851 |
4952 | class C {
50- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.DEBUG)
53+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.DEBUG)
5154 | def j = ???
5255 | }
5356 |
5457 | class D {
55- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.INFO)
58+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.INFO)
5659 | def i:String = ???
5760 | }
5861 | val a = new A()
@@ -66,13 +69,13 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
6669 // Duration and TimeUnit must Full class name
6770 """
6871 |class A {
69- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.NANOSECONDS) , logLevel = org.bitlap.tools.LogLevel.INFO)
72+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.INFO)
7073 | def helloWorld: String = {
7174 | println("hello world")
7275 | "hello"
7376 | }
7477 |
75- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.INFO)
78+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.INFO)
7679 | def helloScala: String = {
7780 | Thread.sleep(2000)
7881 | println("hello world")
@@ -89,18 +92,18 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
8992 // Duration and TimeUnit must Full class name
9093 """
9194 | class A {
92- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.NANOSECONDS) , logLevel = org.bitlap.tools.LogLevel.INFO)
95+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.INFO)
9396 | def helloWorld: String = {
9497 | println("") ; println(""); ""
9598 | }
9699 |
97- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.INFO)
100+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.INFO)
98101 | def helloScala1: String = { println("") ; println(""); ""}
99102 |
100- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.INFO)
103+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.INFO)
101104 | def helloScala2: String = { println("") ; println(""); "" }
102105 |
103- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.INFO)
106+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.INFO)
104107 | def helloScala3: String = {
105108 | val s = "hello"
106109 | val x = "world"
@@ -115,7 +118,7 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
115118 // Duration and TimeUnit must Full class name
116119 """
117120 | class A {
118- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.INFO)
121+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.INFO)
119122 | def helloScala1: String = {
120123 | val s = "hello"
121124 | if (s == "hello") {
@@ -130,7 +133,7 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
130133 | a.helloScala1
131134 |
132135 | class B {
133- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.INFO)
136+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.INFO)
134137 | def helloScala11: String = {
135138 | val s = "hello"
136139 | if (s == "hello") {
@@ -151,7 +154,7 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
151154 private final val log3 : org.slf4j.Logger = org.slf4j.LoggerFactory .getLogger(classOf [A ])
152155
153156 @ elapsed(
154- limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ) ,
157+ limit = 1 ,
155158 logLevel = org.bitlap.tools.LogLevel .INFO
156159 )
157160 def helloScala1 : Future [String ] = {
@@ -160,7 +163,7 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
160163 }
161164
162165 @ elapsed(
163- limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ) ,
166+ limit = 1 ,
164167 logLevel = org.bitlap.tools.LogLevel .DEBUG
165168 )
166169 def helloScala2 : Future [String ] = {
@@ -171,7 +174,7 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
171174 }
172175
173176 @ elapsed(
174- limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ) ,
177+ limit = 1 ,
175178 logLevel = org.bitlap.tools.LogLevel .WARN
176179 )
177180 def helloScala3 : Future [String ] = Future {
@@ -182,25 +185,21 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
182185
183186 " elapsed6" should " failed, not support when only has one expr" in {
184187 class B {
185-
186- import scala .concurrent .Await
187- import scala .concurrent .duration .Duration
188-
189188 @ elapsed(
190- limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ) ,
189+ limit = 1 ,
191190 logLevel = org.bitlap.tools.LogLevel .WARN
192191 )
193192 def helloScala (t : String ): Future [String ] =
194193 Future (t)(scala.concurrent.ExecutionContext .Implicits .global)
195194
196195 @ elapsed(
197- limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ) ,
196+ limit = 1 ,
198197 logLevel = org.bitlap.tools.LogLevel .WARN
199198 )
200199 def helloScala11 (t : String ): Future [String ] = Future (t)(scala.concurrent.ExecutionContext .Implicits .global)
201200
202201 @ elapsed(
203- limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ) ,
202+ limit = 1 ,
204203 logLevel = org.bitlap.tools.LogLevel .INFO
205204 )
206205 def helloScala2 : String = {
@@ -215,21 +214,21 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
215214 | object A {
216215 | private final val log1: org.slf4j.Logger = org.slf4j.LoggerFactory.getLogger(A.getClass)
217216 |
218- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.INFO)
217+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.INFO)
219218 | def helloScala1: Future[String] = {
220219 | Thread.sleep(1000)
221220 | Future.successful("hello world")
222221 | }
223222 |
224- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.DEBUG)
223+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.DEBUG)
225224 | def helloScala2: Future[String] = {
226225 | Thread.sleep(2000)
227226 | Future {
228227 | "hello world"
229228 | }(scala.concurrent.ExecutionContext.Implicits.global)
230229 | }
231230 |
232- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.WARN)
231+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.WARN)
233232 | def helloScala3: Future[String] = Future {
234233 | "hello world"
235234 | }(scala.concurrent.ExecutionContext.Implicits.global)
@@ -239,35 +238,38 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
239238
240239 " elapsed8" should " ok at input args" in {
241240 @ elapsed(
242- limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ) ,
241+ limit = 1 ,
243242 logLevel = LogLevel .WARN
244243 )
245244 def helloScala1 : String = {
246245 println(" " )
247246 println(" " )
248247 " hello"
249248 }
250- @ elapsed(limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ), logLevel = WARN )
249+ @ elapsed(limit = 1 , logLevel = LogLevel . INFO )
251250 def helloScala2 : String = {
252251 println(" " )
253252 println(" " )
254253 " hello"
255254 }
256255
257256 @ elapsed(
258- limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ) ,
257+ limit = 1 ,
259258 logLevel = org.bitlap.tools.LogLevel .WARN
260259 )
261260 def helloScala3 : String = {
262261 println(" " )
263- println( " " )
262+ Thread .sleep( 10 )
264263 " hello"
265264 }
265+
266+ helloScala3
267+
266268 }
267269
268270 " elapsed9" should " failed at input args" in {
269271 """
270- |@elapsed(logLevel = org.bitlap.tools.LogLevel.WARN, limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) )
272+ |@elapsed(logLevel = org.bitlap.tools.LogLevel.WARN, limit = 1 )
271273 | def helloScala1: String = {
272274 | println("")
273275 | println("")
@@ -279,7 +281,7 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
279281 class A {
280282
281283 @ elapsed(
282- limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ) ,
284+ limit = 1 ,
283285 logLevel = org.bitlap.tools.LogLevel .INFO
284286 )
285287 def j : Int = {
@@ -302,7 +304,7 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
302304 }
303305
304306 @ elapsed(
305- limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ) ,
307+ limit = 1 ,
306308 logLevel = org.bitlap.tools.LogLevel .INFO
307309 )
308310 def k : Unit = {
@@ -337,7 +339,7 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
337339 }
338340
339341 @ elapsed(
340- limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ) ,
342+ limit = 1 ,
341343 logLevel = org.bitlap.tools.LogLevel .INFO
342344 )
343345 def l : Int = {
@@ -350,7 +352,7 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
350352 }
351353
352354 @ elapsed(
353- limit = scala.concurrent.duration. Duration ( 1 , java.util.concurrent. TimeUnit . SECONDS ) ,
355+ limit = 1 ,
354356 logLevel = org.bitlap.tools.LogLevel .INFO
355357 )
356358 def m : Int = {
@@ -366,7 +368,6 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
366368 val u = 0
367369 return 0
368370 }
369-
370371 1
371372 }
372373
@@ -376,7 +377,7 @@ class ElapsedTest extends AnyFlatSpec with Matchers {
376377 " elapsed11" should " failed at abstract method" in {
377378 """
378379 |abstract class A {
379- | @elapsed(limit = scala.concurrent.duration.Duration(1, java.util.concurrent.TimeUnit.SECONDS) , logLevel = org.bitlap.tools.LogLevel.WARN)
380+ | @elapsed(limit = 1 , logLevel = org.bitlap.tools.LogLevel.WARN)
380381 | def hello:String
381382 | }
382383 |""" .stripMargin shouldNot compile
0 commit comments