Skip to content

Commit

Permalink
Jira Iterator future list tests
Browse files Browse the repository at this point in the history
Signed-off-by: Maxwell Brown <mxwelwbr@amazon.com>
  • Loading branch information
Galactus22625 committed Dec 3, 2024
1 parent 710646e commit 2d09c12
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opensearch.dataprepper.plugins.source.jira;


import com.google.common.annotations.VisibleForTesting;
import lombok.Setter;
import org.opensearch.dataprepper.plugins.source.source_crawler.base.PluginExecutorServiceProvider;
import org.opensearch.dataprepper.plugins.source.source_crawler.model.ItemInfo;
Expand Down Expand Up @@ -100,4 +101,14 @@ public void initialize(Instant jiraChangeLogToken) {
this.firstTime = true;
}

@VisibleForTesting
public List<Future<Boolean>> showFutureList() {
return futureList;
}

@VisibleForTesting
public Queue<ItemInfo> showItemInfoQueue() {
return itemInfoQueue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.NoSuchElementException;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -101,6 +102,38 @@ void testItemInfoQueueNotEmpty() {
assertNotNull(jiraIterator.next());
}

@Test
void testStartCrawlerThreads() {
jiraIterator = createObjectUnderTest();
jiraIterator.initialize(Instant.ofEpochSecond(0));
jiraIterator.hasNext();
jiraIterator.hasNext();
assertTrue(jiraIterator.showFutureList().size() == 1);
}

@Test
void testFuturesCompleted() throws InterruptedException {
jiraIterator = createObjectUnderTest();
List<IssueBean> mockIssues = new ArrayList<>();
IssueBean issue1 = createIssueBean(false);
mockIssues.add(issue1);
IssueBean issue2 = createIssueBean(false);
mockIssues.add(issue2);
IssueBean issue3 = createIssueBean(false);
mockIssues.add(issue3);
when(mockSearchResults.getIssues()).thenReturn(mockIssues);
when(mockSearchResults.getTotal()).thenReturn(0);
doReturn(mockSearchResults).when(jiraRestClient).getAllIssues(any(StringBuilder.class), anyInt(), any(JiraSourceConfig.class));

jiraIterator.initialize(Instant.ofEpochSecond(0));
jiraIterator.setCrawlerQWaitTimeMillis(1);
jiraIterator.hasNext();

Thread.sleep(1);
jiraIterator.showFutureList().forEach(future -> assertTrue(future.isDone()));
assertEquals(jiraIterator.showItemInfoQueue().size(), mockIssues.size());
}

@Test
void testItemInfoQueueEmpty(){
jiraIterator = createObjectUnderTest();
Expand Down

0 comments on commit 2d09c12

Please sign in to comment.