From 294ecf55f5e535eea8bf01cb9ca57f0481d74fc0 Mon Sep 17 00:00:00 2001 From: carlosdelest Date: Thu, 6 Jun 2024 14:13:32 +0200 Subject: [PATCH] add tests --- .../SynonymsManagementAPIServiceIT.java | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/synonyms/SynonymsManagementAPIServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/synonyms/SynonymsManagementAPIServiceIT.java index d53a057634e51..8e0f07ea09473 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/synonyms/SynonymsManagementAPIServiceIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/synonyms/SynonymsManagementAPIServiceIT.java @@ -38,17 +38,19 @@ public void setUp() throws Exception { } public void testCreateManySynonyms() throws InterruptedException { - CountDownLatch latch = new CountDownLatch(1); + CountDownLatch putLatch = new CountDownLatch(1); + String synonymSetId = randomIdentifier(); + int rulesNumber = randomIntBetween( + SynonymsManagementAPIService.MAX_SYNONYMS_SETS / 2, + SynonymsManagementAPIService.MAX_SYNONYMS_SETS + ); synonymsManagementAPIService.putSynonymsSet( - randomIdentifier(), - randomSynonymsSet( - randomIntBetween(SynonymsManagementAPIService.MAX_SYNONYMS_SETS / 2, SynonymsManagementAPIService.MAX_SYNONYMS_SETS), - SynonymsManagementAPIService.MAX_SYNONYMS_SETS - ), + synonymSetId, + randomSynonymsSet(rulesNumber, rulesNumber), new ActionListener() { @Override public void onResponse(SynonymsManagementAPIService.SynonymsReloadResult synonymsReloadResult) { - latch.countDown(); + putLatch.countDown(); } @Override @@ -58,7 +60,30 @@ public void onFailure(Exception e) { } ); - latch.await(5, TimeUnit.SECONDS); + putLatch.await(5, TimeUnit.SECONDS); + + CountDownLatch getLatch = new CountDownLatch(1); + // Also retrieve them + synonymsManagementAPIService.getSynonymSetRules( + synonymSetId, + 0, + SynonymsManagementAPIService.MAX_SYNONYMS_SETS, + new ActionListener>() { + @Override + public void onResponse(PagedResult synonymRulePagedResult) { + assertEquals(rulesNumber, synonymRulePagedResult.totalResults()); + assertEquals(rulesNumber, synonymRulePagedResult.pageResults().length); + getLatch.countDown(); + } + + @Override + public void onFailure(Exception e) { + fail(e); + } + } + ); + + getLatch.await(5, TimeUnit.SECONDS); } public void testCreateTooManySynonymsAtOnce() throws InterruptedException {