Skip to content

Commit

Permalink
Changed s3 event index lambda to default index yesterday and today to…
Browse files Browse the repository at this point in the history
… match eventbridge rule change

Signed-off-by: Brandon Shien <[email protected]>
  • Loading branch information
bshien committed Nov 13, 2024
1 parent 259544c commit 9304e37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Void handleRequest(Map<String, String> input, Context context) {
}
LocalDate collectionCurrentDate = collectionStartDate;
LocalDate today = LocalDate.now(ZoneOffset.UTC);
while (collectionCurrentDate.isBefore(today)) {
while (!collectionCurrentDate.isAfter(today)) {
Map<String, String> finalEventData = new HashMap<>();
for (GithubEvents eventToIndex : eventsToIndex) {
String prefix = eventToIndex.getEventName() + "/" + collectionCurrentDate + "/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ public void testHandleRequestYesterday() {

Map<String,String> input = new HashMap<>();
LocalDate yesterday = LocalDate.now(ZoneOffset.UTC).minus(1, ChronoUnit.DAYS);
LocalDate today = LocalDate.now(ZoneOffset.UTC);
input.put("collectionStartDate", yesterday.toString());

// Act
githubEventsLambda.handleRequest(input, mock(Context.class));

// Assert
String indexName = "github-user-activity-events-" + yesterday.format(DateTimeFormatter.ofPattern("MM-yyyy"));
verify(openSearchUtil).createIndexIfNotExists(indexName);
verify(openSearchUtil).bulkIndex(eq(indexName), any(Map.class));
String indexNameYesterday = "github-user-activity-events-" + yesterday.format(DateTimeFormatter.ofPattern("MM-yyyy"));
String indexNameToday = "github-user-activity-events-" + today.format(DateTimeFormatter.ofPattern("MM-yyyy"));
verify(openSearchUtil, atLeastOnce()).createIndexIfNotExists(indexNameYesterday);
verify(openSearchUtil, atLeastOnce()).createIndexIfNotExists(indexNameToday);
verify(openSearchUtil, atLeastOnce()).bulkIndex(eq(indexNameYesterday), any(Map.class));
verify(openSearchUtil, atLeastOnce()).bulkIndex(eq(indexNameToday), any(Map.class));
}

@Test
Expand All @@ -88,8 +92,8 @@ public void testHandleRequestMonthAgo() {
when(s3Util.getObjectInputStream(anyString())).thenReturn(new ResponseInputStream<>(getObjectResponse, new ByteArrayInputStream(eventJson.getBytes())));

Map<String,String> input = new HashMap<>();
LocalDate yesterday = LocalDate.now(ZoneOffset.UTC).minus(1, ChronoUnit.DAYS);
LocalDate lastMonth = yesterday.minus(1, ChronoUnit.MONTHS);
LocalDate today = LocalDate.now(ZoneOffset.UTC);
LocalDate lastMonth = today.minus(1, ChronoUnit.MONTHS);
input.put("collectionStartDate", lastMonth.toString());

// Act
Expand All @@ -100,7 +104,7 @@ public void testHandleRequestMonthAgo() {
verify(openSearchUtil, atLeastOnce()).createIndexIfNotExists(indexNameLastMonth);
verify(openSearchUtil, atLeastOnce()).bulkIndex(eq(indexNameLastMonth), any(Map.class));

String indexNameThisMonth = "github-user-activity-events-" + yesterday.format(DateTimeFormatter.ofPattern("MM-yyyy"));
String indexNameThisMonth = "github-user-activity-events-" + today.format(DateTimeFormatter.ofPattern("MM-yyyy"));
verify(openSearchUtil, atLeastOnce()).createIndexIfNotExists(indexNameThisMonth);
verify(openSearchUtil, atLeastOnce()).bulkIndex(eq(indexNameThisMonth), any(Map.class));
}
Expand All @@ -119,14 +123,18 @@ public void testHandleRequestDefault() {

Map<String,String> input = new HashMap<>();
LocalDate yesterday = LocalDate.now(ZoneOffset.UTC).minus(1, ChronoUnit.DAYS);
LocalDate today = LocalDate.now(ZoneOffset.UTC);

// Act
githubEventsLambda.handleRequest(input, mock(Context.class));

// Assert
String indexName = "github-user-activity-events-" + yesterday.format(DateTimeFormatter.ofPattern("MM-yyyy"));
verify(openSearchUtil).createIndexIfNotExists(indexName);
verify(openSearchUtil).bulkIndex(eq(indexName), any(Map.class));
String indexNameYesterday = "github-user-activity-events-" + yesterday.format(DateTimeFormatter.ofPattern("MM-yyyy"));
String indexNameToday = "github-user-activity-events-" + today.format(DateTimeFormatter.ofPattern("MM-yyyy"));
verify(openSearchUtil, atLeastOnce()).createIndexIfNotExists(indexNameYesterday);
verify(openSearchUtil, atLeastOnce()).createIndexIfNotExists(indexNameToday);
verify(openSearchUtil, atLeastOnce()).bulkIndex(eq(indexNameYesterday), any(Map.class));
verify(openSearchUtil, atLeastOnce()).bulkIndex(eq(indexNameToday), any(Map.class));
}

@Test
Expand Down

0 comments on commit 9304e37

Please sign in to comment.