-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add batch size field for jira source #5348
Changes from 4 commits
5095cf1
4e01478
f36a799
0ef2cc7
e4572fd
65e1c46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ | |
public interface CrawlerSourceConfig { | ||
|
||
int DEFAULT_NUMBER_OF_WORKERS = 1; | ||
|
||
int getBatchSize(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
import org.opensearch.dataprepper.plugins.source.source_crawler.model.ItemInfo; | ||
import org.opensearch.dataprepper.plugins.source.source_crawler.model.TestItemInfo; | ||
|
||
import java.lang.reflect.Field; | ||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
@@ -68,20 +67,21 @@ public void executePartitionTest() { | |
void testCrawlWithEmptyList() { | ||
Instant lastPollTime = Instant.ofEpochMilli(0); | ||
when(client.listItems()).thenReturn(Collections.emptyIterator()); | ||
crawler.crawl(lastPollTime, coordinator); | ||
int maxItemsPerPage = 50; | ||
crawler.crawl(lastPollTime, coordinator, maxItemsPerPage); | ||
verify(coordinator, never()).createPartition(any(SaasSourcePartition.class)); | ||
} | ||
|
||
@Test | ||
void testCrawlWithNonEmptyList() throws NoSuchFieldException, IllegalAccessException { | ||
Instant lastPollTime = Instant.ofEpochMilli(0); | ||
List<ItemInfo> itemInfoList = new ArrayList<>(); | ||
int maxItemsPerPage = getMaxItemsPerPage(); | ||
int maxItemsPerPage = 50; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be moved out of the test and directly reference the default from the class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
for (int i = 0; i < maxItemsPerPage; i++) { | ||
itemInfoList.add(new TestItemInfo("itemId")); | ||
} | ||
when(client.listItems()).thenReturn(itemInfoList.iterator()); | ||
crawler.crawl(lastPollTime, coordinator); | ||
crawler.crawl(lastPollTime, coordinator, maxItemsPerPage); | ||
verify(coordinator, times(1)).createPartition(any(SaasSourcePartition.class)); | ||
|
||
} | ||
|
@@ -90,27 +90,50 @@ void testCrawlWithNonEmptyList() throws NoSuchFieldException, IllegalAccessExcep | |
void testCrawlWithMultiplePartitions() throws NoSuchFieldException, IllegalAccessException { | ||
Instant lastPollTime = Instant.ofEpochMilli(0); | ||
List<ItemInfo> itemInfoList = new ArrayList<>(); | ||
int maxItemsPerPage = getMaxItemsPerPage(); | ||
int maxItemsPerPage = 50; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be moved out of the test and directly reference the default from the class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
for (int i = 0; i < maxItemsPerPage + 1; i++) { | ||
itemInfoList.add(new TestItemInfo("testId")); | ||
} | ||
when(client.listItems()).thenReturn(itemInfoList.iterator()); | ||
crawler.crawl(lastPollTime, coordinator); | ||
crawler.crawl(lastPollTime, coordinator, maxItemsPerPage); | ||
verify(coordinator, times(2)).createPartition(any(SaasSourcePartition.class)); | ||
} | ||
|
||
@Test | ||
void testBatchSize() { | ||
Instant lastPollTime = Instant.ofEpochMilli(0); | ||
List<ItemInfo> itemInfoList = new ArrayList<>(); | ||
int maxItemsPerPage = 50; | ||
for (int i = 0; i < maxItemsPerPage; i++) { | ||
itemInfoList.add(new TestItemInfo("testId")); | ||
} | ||
when(client.listItems()).thenReturn(itemInfoList.iterator()); | ||
crawler.crawl(lastPollTime, coordinator, maxItemsPerPage); | ||
int expectedNumberOfInvocations = 1; | ||
verify(coordinator, times(expectedNumberOfInvocations)).createPartition(any(SaasSourcePartition.class)); | ||
|
||
List<ItemInfo> itemInfoList2 = new ArrayList<>(); | ||
int maxItemsPerPage2 = 25; | ||
for (int i = 0; i < maxItemsPerPage; i++) { | ||
itemInfoList2.add(new TestItemInfo("testId")); | ||
} | ||
when(client.listItems()).thenReturn(itemInfoList.iterator()); | ||
crawler.crawl(lastPollTime, coordinator, maxItemsPerPage2); | ||
expectedNumberOfInvocations += 2; | ||
verify(coordinator, times(expectedNumberOfInvocations)).createPartition(any(SaasSourcePartition.class)); | ||
} | ||
|
||
@Test | ||
void testCrawlWithNullItemsInList() throws NoSuchFieldException, IllegalAccessException { | ||
Instant lastPollTime = Instant.ofEpochMilli(0); | ||
List<ItemInfo> itemInfoList = new ArrayList<>(); | ||
int maxItemsPerPage = getMaxItemsPerPage(); | ||
int maxItemsPerPage = 50; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be moved out of the test and directly reference the default from the class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
itemInfoList.add(null); | ||
for (int i = 0; i < maxItemsPerPage - 1; i++) { | ||
itemInfoList.add(new TestItemInfo("testId")); | ||
} | ||
when(client.listItems()).thenReturn(itemInfoList.iterator()); | ||
crawler.crawl(lastPollTime, coordinator); | ||
crawler.crawl(lastPollTime, coordinator, maxItemsPerPage); | ||
verify(coordinator, times(1)).createPartition(any(SaasSourcePartition.class)); | ||
} | ||
|
||
|
@@ -121,7 +144,8 @@ void testUpdatingPollTimeNullMetaData() { | |
ItemInfo testItem = createTestItemInfo("1"); | ||
itemInfoList.add(testItem); | ||
when(client.listItems()).thenReturn(itemInfoList.iterator()); | ||
Instant updatedPollTime = crawler.crawl(lastPollTime, coordinator); | ||
int maxItemsPerPage = 50; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be moved out of the test and directly reference the default from the class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
Instant updatedPollTime = crawler.crawl(lastPollTime, coordinator, maxItemsPerPage); | ||
assertNotEquals(Instant.ofEpochMilli(0), updatedPollTime); | ||
} | ||
|
||
|
@@ -132,17 +156,11 @@ void testUpdatedPollTimeNiCreatedLarger() { | |
ItemInfo testItem = createTestItemInfo("1"); | ||
itemInfoList.add(testItem); | ||
when(client.listItems()).thenReturn(itemInfoList.iterator()); | ||
Instant updatedPollTime = crawler.crawl(lastPollTime, coordinator); | ||
int maxItemsPerPage = 50; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be moved out of the test and directly reference the default from the class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
Instant updatedPollTime = crawler.crawl(lastPollTime, coordinator, maxItemsPerPage); | ||
assertNotEquals(lastPollTime, updatedPollTime); | ||
} | ||
|
||
|
||
private int getMaxItemsPerPage() throws NoSuchFieldException, IllegalAccessException { | ||
Field maxItemsPerPageField = Crawler.class.getDeclaredField("maxItemsPerPage"); | ||
maxItemsPerPageField.setAccessible(true); | ||
return (int) maxItemsPerPageField.get(null); | ||
} | ||
|
||
private ItemInfo createTestItemInfo(String id) { | ||
return new TestItemInfo(id, new HashMap<>(), Instant.now()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest you add a private static final variable at the top of the class and set it there. Assign that variable here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok