mirror of https://github.com/tikv/client-java.git
Co-authored-by: Andy Lok <andylokandy@hotmail.com> Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
This commit is contained in:
parent
662d6f3bad
commit
a0e35b50f9
|
@ -83,6 +83,7 @@ public class SlowLogImpl implements SlowLog {
|
|||
|
||||
@Override
|
||||
public void log() {
|
||||
recordTime();
|
||||
if (error != null || timeExceeded()) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
|
||||
logger.warn(
|
||||
|
@ -95,9 +96,12 @@ public class SlowLogImpl implements SlowLog {
|
|||
}
|
||||
}
|
||||
|
||||
boolean timeExceeded() {
|
||||
private void recordTime() {
|
||||
long currentNS = System.nanoTime();
|
||||
durationMS = (currentNS - startNS) / 1_000_000;
|
||||
}
|
||||
|
||||
boolean timeExceeded() {
|
||||
return slowThresholdMS >= 0 && durationMS > slowThresholdMS;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,10 +28,17 @@ public class SlowLogImplTest {
|
|||
public void testThresholdTime() throws InterruptedException {
|
||||
SlowLogImpl slowLog = new SlowLogImpl(1000);
|
||||
Thread.sleep(1100);
|
||||
slowLog.log();
|
||||
Assert.assertTrue(slowLog.timeExceeded());
|
||||
|
||||
slowLog = new SlowLogImpl(1000);
|
||||
Thread.sleep(500);
|
||||
slowLog.log();
|
||||
Assert.assertFalse(slowLog.timeExceeded());
|
||||
|
||||
slowLog = new SlowLogImpl(-1);
|
||||
Thread.sleep(500);
|
||||
slowLog.log();
|
||||
Assert.assertFalse(slowLog.timeExceeded());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue