Skip to content

Commit

Permalink
default batch size comments
Browse files Browse the repository at this point in the history
Signed-off-by: Maxwell Brown <[email protected]>
  • Loading branch information
Galactus22625 committed Jan 23, 2025
1 parent e4572fd commit 65e1c46
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
import org.opensearch.dataprepper.plugins.source.jira.configuration.FilterConfig;
import org.opensearch.dataprepper.plugins.source.source_crawler.base.CrawlerSourceConfig;

import java.time.Duration;
import java.util.List;

@Getter
public class JiraSourceConfig implements CrawlerSourceConfig {

private static final Duration DEFAULT_BACKOFF_MILLIS = Duration.ofMinutes(2);
private static final int DEFAULT_BATCH_SIZE = 50;

/**
* Jira account url
Expand All @@ -42,7 +41,7 @@ public class JiraSourceConfig implements CrawlerSourceConfig {
* Batch size for fetching tickets
*/
@JsonProperty("batch_size")
private int batchSize = 50;
private int batchSize = DEFAULT_BATCH_SIZE;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class CrawlerTest {

private Crawler crawler;

private static final int DEFAULT_BATCH_SIZE = 50;

@BeforeEach
public void setup() {
crawler = new Crawler(client);
Expand All @@ -68,35 +70,32 @@ public void executePartitionTest() {
void testCrawlWithEmptyList() {
Instant lastPollTime = Instant.ofEpochMilli(0);
when(client.listItems()).thenReturn(Collections.emptyIterator());
int maxItemsPerPage = 50;
crawler.crawl(lastPollTime, coordinator, maxItemsPerPage);
crawler.crawl(lastPollTime, coordinator, DEFAULT_BATCH_SIZE);
verify(coordinator, never()).createPartition(any(SaasSourcePartition.class));
}

@Test
void testCrawlWithNonEmptyList() throws NoSuchFieldException, IllegalAccessException {
void testCrawlWithNonEmptyList(){
Instant lastPollTime = Instant.ofEpochMilli(0);
List<ItemInfo> itemInfoList = new ArrayList<>();
int maxItemsPerPage = 50;
for (int i = 0; i < maxItemsPerPage; i++) {
for (int i = 0; i < DEFAULT_BATCH_SIZE; i++) {
itemInfoList.add(new TestItemInfo("itemId"));
}
when(client.listItems()).thenReturn(itemInfoList.iterator());
crawler.crawl(lastPollTime, coordinator, maxItemsPerPage);
crawler.crawl(lastPollTime, coordinator, DEFAULT_BATCH_SIZE);
verify(coordinator, times(1)).createPartition(any(SaasSourcePartition.class));

}

@Test
void testCrawlWithMultiplePartitions() throws NoSuchFieldException, IllegalAccessException {
void testCrawlWithMultiplePartitions(){
Instant lastPollTime = Instant.ofEpochMilli(0);
List<ItemInfo> itemInfoList = new ArrayList<>();
int maxItemsPerPage = 50;
for (int i = 0; i < maxItemsPerPage + 1; i++) {
for (int i = 0; i < DEFAULT_BATCH_SIZE + 1; i++) {
itemInfoList.add(new TestItemInfo("testId"));
}
when(client.listItems()).thenReturn(itemInfoList.iterator());
crawler.crawl(lastPollTime, coordinator, maxItemsPerPage);
crawler.crawl(lastPollTime, coordinator, DEFAULT_BATCH_SIZE);
verify(coordinator, times(2)).createPartition(any(SaasSourcePartition.class));
}

Expand Down Expand Up @@ -128,13 +127,12 @@ void testBatchSize() {
void testCrawlWithNullItemsInList() throws NoSuchFieldException, IllegalAccessException {
Instant lastPollTime = Instant.ofEpochMilli(0);
List<ItemInfo> itemInfoList = new ArrayList<>();
int maxItemsPerPage = 50;
itemInfoList.add(null);
for (int i = 0; i < maxItemsPerPage - 1; i++) {
for (int i = 0; i < DEFAULT_BATCH_SIZE - 1; i++) {
itemInfoList.add(new TestItemInfo("testId"));
}
when(client.listItems()).thenReturn(itemInfoList.iterator());
crawler.crawl(lastPollTime, coordinator, maxItemsPerPage);
crawler.crawl(lastPollTime, coordinator, DEFAULT_BATCH_SIZE);
verify(coordinator, times(1)).createPartition(any(SaasSourcePartition.class));
}

Expand All @@ -145,8 +143,7 @@ void testUpdatingPollTimeNullMetaData() {
ItemInfo testItem = createTestItemInfo("1");
itemInfoList.add(testItem);
when(client.listItems()).thenReturn(itemInfoList.iterator());
int maxItemsPerPage = 50;
Instant updatedPollTime = crawler.crawl(lastPollTime, coordinator, maxItemsPerPage);
Instant updatedPollTime = crawler.crawl(lastPollTime, coordinator, DEFAULT_BATCH_SIZE);
assertNotEquals(Instant.ofEpochMilli(0), updatedPollTime);
}

Expand All @@ -157,8 +154,7 @@ void testUpdatedPollTimeNiCreatedLarger() {
ItemInfo testItem = createTestItemInfo("1");
itemInfoList.add(testItem);
when(client.listItems()).thenReturn(itemInfoList.iterator());
int maxItemsPerPage = 50;
Instant updatedPollTime = crawler.crawl(lastPollTime, coordinator, maxItemsPerPage);
Instant updatedPollTime = crawler.crawl(lastPollTime, coordinator, DEFAULT_BATCH_SIZE);
assertNotEquals(lastPollTime, updatedPollTime);
}

Expand Down

0 comments on commit 65e1c46

Please sign in to comment.