From b721f1eb0f2460bfb7524d8067bddc7905d64876 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 13 Aug 2022 23:21:48 +0800 Subject: Add HistoricMessageRecorder. --- .../history/HistoricMessageRecorderTest.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/test/java/com/keuin/crosslink/messaging/history/HistoricMessageRecorderTest.java (limited to 'src/test') diff --git a/src/test/java/com/keuin/crosslink/messaging/history/HistoricMessageRecorderTest.java b/src/test/java/com/keuin/crosslink/messaging/history/HistoricMessageRecorderTest.java new file mode 100644 index 0000000..4dfdfd4 --- /dev/null +++ b/src/test/java/com/keuin/crosslink/messaging/history/HistoricMessageRecorderTest.java @@ -0,0 +1,31 @@ +package com.keuin.crosslink.messaging.history; + +import com.keuin.crosslink.messaging.endpoint.IEndpoint; +import com.keuin.crosslink.messaging.message.IMessage; +import com.keuin.crosslink.messaging.sender.ISender; +import com.keuin.crosslink.testable.FakeEndpoint; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; + +class HistoricMessageRecorderTest { + + @Test + void testTTL() throws InterruptedException { + var recorder = new HistoricMessageRecorder(1000); + var ep0 = new FakeEndpoint("z"); + var sender = ISender.create("sender", UUID.randomUUID()); + var msg = IMessage.create(ep0, sender, "MSG,,,"); + recorder.addMessage(msg); + Thread.sleep(500); + var list = recorder.getMessages(); + assertEquals(1, list.size()); + assertEquals(msg, list.get(0)); + Thread.sleep(510); + list = recorder.getMessages(); + assertEquals(0, list.size()); + } +} \ No newline at end of file -- cgit v1.2.3