Skip to content

Commit

Permalink
add test for search conversation
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am committed Jul 26, 2024
1 parent 8c2d61e commit a82db1e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.Stack;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -671,4 +672,47 @@ public void testCanCreateConversationWithAdditionalInfo() {
log.error(e);
}
}

public void testCanQueryOverConversationsByAdditionalInfo() {
CountDownLatch cdl = new CountDownLatch(1);
StepListener<String> convo1 = new StepListener<>();
index.createConversation("Conversation1", "app", Map.of("k1", "v1"), convo1);

StepListener<String> convo2 = new StepListener<>();
convo1.whenComplete(cid -> { index.createConversation("Mehul Conversation", convo2); }, e -> {
cdl.countDown();
log.error(e);
assert (false);
});

StepListener<SearchResponse> search = new StepListener<>();
convo2.whenComplete(cid -> {
SearchRequest request = new SearchRequest();
request.source(new SearchSourceBuilder());
request.source().query(QueryBuilders.matchQuery(ConversationalIndexConstants.META_ADDITIONAL_INFO_FIELD + ".k1", "v1"));
index.searchConversations(request, search);
}, e -> {
cdl.countDown();
log.error(e);
assert (false);
});

search.whenComplete(response -> {
log.info("SEARCH RESPONSE");
log.info(response.toString());
cdl.countDown();
assert (response.getHits().getAt(0).getId().equals(convo1.result()));
Assert.assertEquals(1L, Objects.requireNonNull(response.getHits().getTotalHits()).value);
}, e -> {
cdl.countDown();
log.error(e);
assert (false);
});

try {
cdl.await();
} catch (InterruptedException e) {
log.error(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import org.junit.Before;
import org.mockito.ArgumentCaptor;
Expand Down

0 comments on commit a82db1e

Please sign in to comment.