From 2d6930058dcae53e34e74e09a7cd4c8aea747c65 Mon Sep 17 00:00:00 2001 From: Poison Date: Wed, 20 Sep 2023 15:12:45 +0800 Subject: [PATCH] Adjust time display accuracy to milliseconds (#2663) --- .../arthas/core/command/model/StackModel.java | 8 ++-- .../arthas/core/command/model/ThreadNode.java | 12 +++--- .../core/command/model/TimeFragmentVO.java | 8 ++-- .../arthas/core/command/model/WatchModel.java | 8 ++-- .../monitor200/MonitorAdviceListener.java | 3 +- .../core/command/monitor200/MonitorData.java | 10 ++--- .../monitor200/StackAdviceListener.java | 4 +- .../core/command/monitor200/TimeFragment.java | 8 ++-- .../monitor200/TimeTunnelAdviceListener.java | 4 +- .../command/monitor200/TimeTunnelCommand.java | 3 +- .../command/monitor200/TimeTunnelTable.java | 3 +- .../monitor200/WatchAdviceListener.java | 4 +- .../arthas/core/command/view/MonitorView.java | 3 +- .../arthas/core/command/view/StackView.java | 2 +- .../arthas/core/command/view/TraceView.java | 2 +- .../arthas/core/command/view/WatchView.java | 2 +- .../term/impl/http/api/HttpApiHandler.java | 6 +-- .../taobao/arthas/core/util/ArthasBanner.java | 2 +- .../taobao/arthas/core/util/DateUtils.java | 24 ++++++------ .../arthas/core/util/DateUtilsTest.java | 38 +++++++++---------- 20 files changed, 76 insertions(+), 78 deletions(-) diff --git a/core/src/main/java/com/taobao/arthas/core/command/model/StackModel.java b/core/src/main/java/com/taobao/arthas/core/command/model/StackModel.java index a2c0ae3647..b635620527 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/model/StackModel.java +++ b/core/src/main/java/com/taobao/arthas/core/command/model/StackModel.java @@ -1,6 +1,6 @@ package com.taobao.arthas.core.command.model; -import java.util.Date; +import java.time.LocalDateTime; /** * StackCommand result model @@ -8,7 +8,7 @@ */ public class StackModel extends ResultModel { - private Date ts; + private LocalDateTime ts; private double cost; private String traceId; private String rpcId; @@ -25,11 +25,11 @@ public String getType() { return "stack"; } - public Date getTs() { + public LocalDateTime getTs() { return ts; } - public void setTs(Date ts) { + public void setTs(LocalDateTime ts) { this.ts = ts; } diff --git a/core/src/main/java/com/taobao/arthas/core/command/model/ThreadNode.java b/core/src/main/java/com/taobao/arthas/core/command/model/ThreadNode.java index 070e89e219..45a4e4bfd5 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/model/ThreadNode.java +++ b/core/src/main/java/com/taobao/arthas/core/command/model/ThreadNode.java @@ -1,6 +1,6 @@ package com.taobao.arthas.core.command.model; -import java.util.Date; +import java.time.LocalDateTime; /** * Thread root node of TraceCommand @@ -13,14 +13,14 @@ public class ThreadNode extends TraceNode { private boolean daemon; private int priority; private String classloader; - private Date timestamp; + private LocalDateTime timestamp; private String traceId; private String rpcId; public ThreadNode() { super("thread"); - timestamp = new Date(); + timestamp = LocalDateTime.now(); } public ThreadNode(String threadName, long threadId, boolean daemon, int priority, String classloader) { @@ -30,7 +30,7 @@ public ThreadNode(String threadName, long threadId, boolean daemon, int priority this.daemon = daemon; this.priority = priority; this.classloader = classloader; - timestamp = new Date(); + timestamp = LocalDateTime.now(); } public String getThreadName() { @@ -73,11 +73,11 @@ public void setClassloader(String classloader) { this.classloader = classloader; } - public Date getTimestamp() { + public LocalDateTime getTimestamp() { return timestamp; } - public void setTimestamp(Date timestamp) { + public void setTimestamp(LocalDateTime timestamp) { this.timestamp = timestamp; } diff --git a/core/src/main/java/com/taobao/arthas/core/command/model/TimeFragmentVO.java b/core/src/main/java/com/taobao/arthas/core/command/model/TimeFragmentVO.java index d6bd3a47b4..3ae7007cb8 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/model/TimeFragmentVO.java +++ b/core/src/main/java/com/taobao/arthas/core/command/model/TimeFragmentVO.java @@ -1,6 +1,6 @@ package com.taobao.arthas.core.command.model; -import java.util.Date; +import java.time.LocalDateTime; /** * VO for TimeFragment @@ -8,7 +8,7 @@ */ public class TimeFragmentVO { private Integer index; - private Date timestamp; + private LocalDateTime timestamp; private double cost; private boolean isReturn; private boolean isThrow; @@ -31,11 +31,11 @@ public TimeFragmentVO setIndex(Integer index) { return this; } - public Date getTimestamp() { + public LocalDateTime getTimestamp() { return timestamp; } - public TimeFragmentVO setTimestamp(Date timestamp) { + public TimeFragmentVO setTimestamp(LocalDateTime timestamp) { this.timestamp = timestamp; return this; } diff --git a/core/src/main/java/com/taobao/arthas/core/command/model/WatchModel.java b/core/src/main/java/com/taobao/arthas/core/command/model/WatchModel.java index e05c090c75..a6b6bfb4cf 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/model/WatchModel.java +++ b/core/src/main/java/com/taobao/arthas/core/command/model/WatchModel.java @@ -1,6 +1,6 @@ package com.taobao.arthas.core.command.model; -import java.util.Date; +import java.time.LocalDateTime; /** * Watch command result model @@ -9,7 +9,7 @@ */ public class WatchModel extends ResultModel { - private Date ts; + private LocalDateTime ts; private double cost; private ObjectVO value; @@ -26,11 +26,11 @@ public String getType() { return "watch"; } - public Date getTs() { + public LocalDateTime getTs() { return ts; } - public void setTs(Date ts) { + public void setTs(LocalDateTime ts) { this.ts = ts; } diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/MonitorAdviceListener.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/MonitorAdviceListener.java index 1870fa69f8..77b41b7730 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/MonitorAdviceListener.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/MonitorAdviceListener.java @@ -11,6 +11,7 @@ import com.taobao.arthas.core.util.StringUtils; import com.taobao.arthas.core.util.ThreadLocalWatch; +import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicReference; @@ -160,7 +161,7 @@ private void finishing(Class clazz, ArthasMethod method, boolean isThrowing, MonitorData oData = value.get(); MonitorData nData = new MonitorData(); nData.setCost(oData.getCost() + cost); - nData.setTimestamp(new Date()); + nData.setTimestamp(LocalDateTime.now()); if (isThrowing) { nData.setFailed(oData.getFailed() + 1); nData.setSuccess(oData.getSuccess()); diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/MonitorData.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/MonitorData.java index d060cd4533..0e47aff46e 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/MonitorData.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/MonitorData.java @@ -1,6 +1,6 @@ package com.taobao.arthas.core.command.monitor200; -import java.util.Date; +import java.time.LocalDateTime; /** * 数据监控用的value for MonitorCommand @@ -14,7 +14,7 @@ public class MonitorData { private int success; private int failed; private double cost; - private Date timestamp; + private LocalDateTime timestamp; public String getClassName() { return className; @@ -64,14 +64,14 @@ public void setCost(double cost) { this.cost = cost; } - public Date getTimestamp() { + public LocalDateTime getTimestamp() { if (timestamp == null) { - timestamp = new Date(); + timestamp = LocalDateTime.now(); } return timestamp; } - public void setTimestamp(Date timestamp) { + public void setTimestamp(LocalDateTime timestamp) { this.timestamp = timestamp; } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/StackAdviceListener.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/StackAdviceListener.java index a983770d4c..5e58bdb277 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/StackAdviceListener.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/StackAdviceListener.java @@ -11,7 +11,7 @@ import com.taobao.arthas.core.util.ThreadLocalWatch; import com.taobao.arthas.core.util.ThreadUtil; -import java.util.Date; +import java.time.LocalDateTime; /** * @author beiwei30 on 29/11/2016. @@ -61,7 +61,7 @@ private void finishing(Advice advice) { if (conditionResult) { // TODO: concurrency issues for process.write StackModel stackModel = ThreadUtil.getThreadStackModel(advice.getLoader(), Thread.currentThread()); - stackModel.setTs(new Date()); + stackModel.setTs(LocalDateTime.now()); process.appendResult(stackModel); process.times().incrementAndGet(); if (isLimitExceeded(command.getNumberOfLimit(), process.times().get())) { diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeFragment.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeFragment.java index 85da00c59b..72b47b3ccd 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeFragment.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeFragment.java @@ -2,28 +2,28 @@ import com.taobao.arthas.core.advisor.Advice; -import java.util.Date; +import java.time.LocalDateTime; /** * 时间碎片 */ class TimeFragment { - public TimeFragment(Advice advice, Date gmtCreate, double cost) { + public TimeFragment(Advice advice, LocalDateTime gmtCreate, double cost) { this.advice = advice; this.gmtCreate = gmtCreate; this.cost = cost; } private final Advice advice; - private final Date gmtCreate; + private final LocalDateTime gmtCreate; private final double cost; public Advice getAdvice() { return advice; } - public Date getGmtCreate() { + public LocalDateTime getGmtCreate() { return gmtCreate; } diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelAdviceListener.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelAdviceListener.java index a422dbbf14..6c9faf7084 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelAdviceListener.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelAdviceListener.java @@ -12,8 +12,8 @@ import com.taobao.arthas.core.util.LogUtil; import com.taobao.arthas.core.util.ThreadLocalWatch; +import java.time.LocalDateTime; import java.util.Collections; -import java.util.Date; /** * @author beiwei30 on 30/11/2016. @@ -68,7 +68,7 @@ public void afterThrowing(ClassLoader loader, Class clazz, ArthasMethod metho private void afterFinishing(Advice advice) { double cost = threadLocalWatch.costInMillis(); - TimeFragment timeTunnel = new TimeFragment(advice, new Date(), cost); + TimeFragment timeTunnel = new TimeFragment(advice, LocalDateTime.now(), cost); boolean match = false; try { diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelCommand.java index ce120ec58b..9c4f301c8e 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelCommand.java @@ -28,6 +28,7 @@ import com.taobao.middleware.cli.annotations.Summary; import com.taobao.middleware.cli.annotations.Argument; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Date; import java.util.LinkedHashMap; @@ -513,7 +514,7 @@ private void processPlay(CommandProcess process) { //copy from tt record TimeFragmentVO replayResult = createTimeFragmentVO(index, tf, expand); - replayResult.setTimestamp(new Date()) + replayResult.setTimestamp(LocalDateTime.now()) .setCost(0) .setReturn(false) .setReturnObj(null) diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelTable.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelTable.java index 348daa5ac7..22d238279c 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelTable.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/TimeTunnelTable.java @@ -2,6 +2,7 @@ import com.taobao.arthas.core.command.model.ObjectVO; import com.taobao.arthas.core.command.model.TimeFragmentVO; +import com.taobao.arthas.core.util.DateUtils; import com.taobao.arthas.core.util.StringUtils; import com.taobao.arthas.core.view.ObjectView; import com.taobao.text.Decoration; @@ -81,7 +82,7 @@ public static Element drawTimeTunnelTable(List timeFragmentList, static TableElement fillTableRow(TableElement table, TimeFragmentVO tf) { return table.row( "" + tf.getIndex(), - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tf.getTimestamp()), + DateUtils.formatDateTime(tf.getTimestamp()), "" + tf.getCost(), "" + tf.isReturn(), "" + tf.isThrow(), diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/WatchAdviceListener.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/WatchAdviceListener.java index 7d9175f986..6d186d34de 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/WatchAdviceListener.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/WatchAdviceListener.java @@ -12,7 +12,7 @@ import com.taobao.arthas.core.util.LogUtil; import com.taobao.arthas.core.util.ThreadLocalWatch; -import java.util.Date; +import java.time.LocalDateTime; /** * @author beiwei30 on 29/11/2016. @@ -87,7 +87,7 @@ private void watching(Advice advice) { Object value = getExpressionResult(command.getExpress(), advice, cost); WatchModel model = new WatchModel(); - model.setTs(new Date()); + model.setTs(LocalDateTime.now()); model.setCost(cost); model.setValue(new ObjectVO(value, command.getExpand())); model.setSizeLimit(command.getSizeLimit()); diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/MonitorView.java b/core/src/main/java/com/taobao/arthas/core/command/view/MonitorView.java index 0907abf423..78be134a20 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/view/MonitorView.java +++ b/core/src/main/java/com/taobao/arthas/core/command/view/MonitorView.java @@ -3,6 +3,7 @@ import com.taobao.arthas.core.command.model.MonitorModel; import com.taobao.arthas.core.command.monitor200.MonitorData; import com.taobao.arthas.core.shell.command.CommandProcess; +import com.taobao.arthas.core.util.DateUtils; import com.taobao.text.Decoration; import com.taobao.text.ui.TableElement; import com.taobao.text.util.RenderUtil; @@ -33,7 +34,7 @@ public void draw(CommandProcess process, MonitorModel result) { for (MonitorData data : result.getMonitorDataList()) { table.row( - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(data.getTimestamp()), + DateUtils.formatDateTime(data.getTimestamp()), data.getClassName(), data.getMethodName(), "" + data.getTotal(), diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/StackView.java b/core/src/main/java/com/taobao/arthas/core/command/view/StackView.java index 2ec5a7d3db..a4bc88ae75 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/view/StackView.java +++ b/core/src/main/java/com/taobao/arthas/core/command/view/StackView.java @@ -35,7 +35,7 @@ public void draw(CommandProcess process, StackModel result) { .append(ste.getLineNumber()) .append(")\n"); } - process.write("ts=" + DateUtils.formatDate(result.getTs()) + ";" + sb.toString() + "\n"); + process.write("ts=" + DateUtils.formatDateTime(result.getTs()) + ";" + sb.toString() + "\n"); } } diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/TraceView.java b/core/src/main/java/com/taobao/arthas/core/command/view/TraceView.java index 89fa45a524..5893aafd17 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/view/TraceView.java +++ b/core/src/main/java/com/taobao/arthas/core/command/view/TraceView.java @@ -90,7 +90,7 @@ private void renderNode(StringBuilder sb, TraceNode node, Ansi highlighted) { ThreadNode threadNode = (ThreadNode) node; //ts=2020-04-29 10:34:00;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2 sb.append(format("ts=%s;thread_name=%s;id=%d;is_daemon=%s;priority=%d;TCCL=%s", - DateUtils.formatDate(threadNode.getTimestamp()), + DateUtils.formatDateTime(threadNode.getTimestamp()), threadNode.getThreadName(), threadNode.getThreadId(), threadNode.isDaemon(), diff --git a/core/src/main/java/com/taobao/arthas/core/command/view/WatchView.java b/core/src/main/java/com/taobao/arthas/core/command/view/WatchView.java index c8e4eece3f..4a99c6989f 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/view/WatchView.java +++ b/core/src/main/java/com/taobao/arthas/core/command/view/WatchView.java @@ -20,6 +20,6 @@ public void draw(CommandProcess process, WatchModel model) { String result = StringUtils.objectToString( objectVO.needExpand() ? new ObjectView(model.getSizeLimit(), objectVO).draw() : objectVO.getObject()); process.write("method=" + model.getClassName() + "." + model.getMethodName() + " location=" + model.getAccessPoint() + "\n"); - process.write("ts=" + DateUtils.formatDate(model.getTs()) + "; [cost=" + model.getCost() + "ms] result=" + result + "\n"); + process.write("ts=" + DateUtils.formatDateTime(model.getTs()) + "; [cost=" + model.getCost() + "ms] result=" + result + "\n"); } } diff --git a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java index 998259dddc..1db6035e71 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/api/HttpApiHandler.java @@ -33,19 +33,15 @@ import com.taobao.arthas.core.util.DateUtils; import com.taobao.arthas.core.util.StringUtils; import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufOutputStream; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.*; import io.netty.util.CharsetUtil; import io.termd.core.function.Function; -import java.io.IOException; import java.util.List; import java.util.Map; import java.util.TreeMap; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.TimeUnit; /** @@ -230,7 +226,7 @@ private ApiResponse processInitSessionRequest(ApiRequest apiRequest) throws ApiE welcomeModel.setTutorials(ArthasBanner.tutorials()); welcomeModel.setMainClass(PidUtils.mainClass()); welcomeModel.setPid(PidUtils.currentPid()); - welcomeModel.setTime(DateUtils.getCurrentDate()); + welcomeModel.setTime(DateUtils.getCurrentDateTime()); resultDistributor.appendResult(welcomeModel); //allow input diff --git a/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java b/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java index dca33b96a6..e03db910c3 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java +++ b/core/src/main/java/com/taobao/arthas/core/util/ArthasBanner.java @@ -118,7 +118,7 @@ public static String welcome(Map infos) { .row("version", version()) .row("main_class", PidUtils.mainClass()) .row("pid", PidUtils.currentPid()) - .row("time", DateUtils.getCurrentDate()); + .row("time", DateUtils.getCurrentDateTime()); for (Entry entry : infos.entrySet()) { table.row(entry.getKey(), entry.getValue()); } diff --git a/core/src/main/java/com/taobao/arthas/core/util/DateUtils.java b/core/src/main/java/com/taobao/arthas/core/util/DateUtils.java index 9c07b4f28d..50bb357f8d 100644 --- a/core/src/main/java/com/taobao/arthas/core/util/DateUtils.java +++ b/core/src/main/java/com/taobao/arthas/core/util/DateUtils.java @@ -1,26 +1,24 @@ package com.taobao.arthas.core.util; -import java.text.SimpleDateFormat; -import java.util.Date; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; /** * @author diecui1202 on 2017/10/25. */ -public class DateUtils { +public final class DateUtils { - private static final ThreadLocal dataFormat = new ThreadLocal() { + private DateUtils() { + throw new AssertionError(); + } - @Override - protected SimpleDateFormat initialValue() { - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - } - }; + public static DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); - public static String getCurrentDate() { - return dataFormat.get().format(new Date()); + public static String getCurrentDateTime() { + return DATE_TIME_FORMATTER.format(LocalDateTime.now()); } - public static String formatDate(Date date) { - return dataFormat.get().format(date); + public static String formatDateTime(LocalDateTime dateTime) { + return DATE_TIME_FORMATTER.format(dateTime); } } diff --git a/core/src/test/java/com/taobao/arthas/core/util/DateUtilsTest.java b/core/src/test/java/com/taobao/arthas/core/util/DateUtilsTest.java index d109222653..ef4b276461 100644 --- a/core/src/test/java/com/taobao/arthas/core/util/DateUtilsTest.java +++ b/core/src/test/java/com/taobao/arthas/core/util/DateUtilsTest.java @@ -1,30 +1,30 @@ package com.taobao.arthas.core.util; - import java.text.SimpleDateFormat; -import java.util.Date; + import org.junit.Assert; import org.junit.Test; - /** - * + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * * @author brijeshprasad89 * */ public class DateUtilsTest { - - @Test - public void testGetCurrentDateWithCorrectFormat() { - - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // supported date format - Date date = new Date(); - Assert.assertEquals(DateUtils.formatDate(date), dateFormat.format(date)); - } - @Test - public void testGetCurrentDateWithInCorrectFormat() { - - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); // Not supported Date format - Date date = new Date(); - Assert.assertNotEquals(DateUtils.formatDate(date), dateFormat.format(date)); + public void testFormatDateTimeWithCorrectFormat() { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); // supported date format + LocalDateTime dateTime = LocalDateTime.now(); + Assert.assertEquals(DateUtils.formatDateTime(dateTime), dateTimeFormatter.format(dateTime)); + } + @Test + public void testFormatDateTimeWithInCorrectFormat() { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); // Not supported Date format + LocalDateTime dateTime = LocalDateTime.now(); + Assert.assertNotEquals(DateUtils.formatDateTime(dateTime), dateTimeFormatter.format(dateTime)); } - } \ No newline at end of file + +} \ No newline at end of file