From f148f526fb2deed95c562ef00d7758176789021a Mon Sep 17 00:00:00 2001 From: HenryL27 Date: Mon, 9 Oct 2023 16:47:36 -0700 Subject: [PATCH] Add OpenSearhMemoryHandler unit tests for singular get Signed-off-by: HenryL27 --- .../memory/index/InteractionsIndexTests.java | 3 --- ...earchConversationalMemoryHandlerTests.java | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/memory/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexTests.java b/memory/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexTests.java index 54ec44df77..2d4184eec3 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexTests.java @@ -63,9 +63,6 @@ import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.SendRequestTransportException; -import lombok.extern.log4j.Log4j2; - -@Log4j2 public class InteractionsIndexTests extends OpenSearchTestCase { @Mock Client client; diff --git a/memory/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java b/memory/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java index 175949b0ef..c8df948bcb 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import java.time.Instant; import java.util.List; import org.junit.Before; @@ -268,4 +269,26 @@ public void testSearchInteractions_Future() { ActionFuture result = cmHandler.searchInteractions(cid, request); assert (result.actionGet().equals(response)); } + + public void testGetAConversation_Future() { + ConversationMeta response = new ConversationMeta("cid", Instant.now(), "boring name", null); + doAnswer(invocation -> { + ActionListener listener = invocation.getArgument(1); + listener.onResponse(response); + return null; + }).when(conversationMetaIndex).getConversation(any(), any()); + ActionFuture result = cmHandler.getConversation("cid"); + assert (result.actionGet().equals(response)); + } + + public void testGetAnInteraction_Future() { + Interaction interaction = new Interaction("iid", Instant.now(), "cid", "inp", "pt", "rsp", "ogn", "extra"); + doAnswer(invocation -> { + ActionListener listener = invocation.getArgument(2); + listener.onResponse(interaction); + return null; + }).when(interactionsIndex).getInteraction(any(), any(), any()); + ActionFuture result = cmHandler.getInteraction("cid", "iid"); + assert (result.actionGet().equals(interaction)); + } }