-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Santhosh Gandhe <[email protected]>
- Loading branch information
Showing
5 changed files
with
47 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
.../opensearch/dataprepper/plugins/source/source_crawler/util/CustomInstantDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.opensearch.dataprepper.plugins.source.source_crawler.util; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
|
||
public class CustomInstantDeserializer extends JsonDeserializer<Instant> { | ||
@Override | ||
public Instant deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
long millis = p.getLongValue(); | ||
return Instant.ofEpochMilli(millis); | ||
} | ||
} |
36 changes: 23 additions & 13 deletions
36
...prepper/plugins/source/source_crawler/coordination/state/SaasWorkerProgressStateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,44 @@ | ||
package org.opensearch.dataprepper.plugins.source.source_crawler.coordination.state; | ||
|
||
import com.fasterxml.jackson.core.JsonFactory; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.Instant; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class SaasWorkerProgressStateTest { | ||
|
||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
private static final ObjectMapper objectMapper = new ObjectMapper(new JsonFactory()) | ||
.registerModule(new JavaTimeModule()); | ||
|
||
@Test | ||
void testDefaultValues() throws JsonProcessingException { | ||
String state = "{}"; | ||
SaasWorkerProgressState workderProgressState = objectMapper.readValue(state, SaasWorkerProgressState.class); | ||
assert workderProgressState.getTotalItems() == 0; | ||
assert workderProgressState.getLoadedItems() == 0; | ||
assert workderProgressState.getKeyAttributes() != null; | ||
assert workderProgressState.getKeyAttributes().isEmpty(); | ||
assert workderProgressState.getExportStartTime() == 0; | ||
assert workderProgressState.getItemIds() == null; | ||
assertEquals(0, workderProgressState.getTotalItems()); | ||
assertEquals(0, workderProgressState.getLoadedItems()); | ||
assertNotNull(workderProgressState.getKeyAttributes()); | ||
assertTrue(workderProgressState.getKeyAttributes().isEmpty()); | ||
assertNull(workderProgressState.getExportStartTime()); | ||
assertNull(workderProgressState.getItemIds()); | ||
} | ||
|
||
@Test | ||
void testInitializedValues() throws JsonProcessingException { | ||
String state = "{\"keyAttributes\":{\"project\":\"project-1\"},\"totalItems\":10,\"loadedItems\":20,\"exportStartTime\":1729391235717,\"itemIds\":[\"GTMS-25\",\"GTMS-24\"]}"; | ||
SaasWorkerProgressState workderProgressState = objectMapper.readValue(state, SaasWorkerProgressState.class); | ||
assert workderProgressState.getTotalItems() == 10; | ||
assert workderProgressState.getLoadedItems() == 20; | ||
assert workderProgressState.getKeyAttributes() != null; | ||
assert workderProgressState.getExportStartTime() == 1729391235717L; | ||
assert workderProgressState.getItemIds() != null; | ||
assert workderProgressState.getItemIds().size() == 2; | ||
assertEquals(10, workderProgressState.getTotalItems()); | ||
assertEquals(20, workderProgressState.getLoadedItems()); | ||
assertNotNull(workderProgressState.getKeyAttributes()); | ||
assertEquals(workderProgressState.getExportStartTime(), Instant.ofEpochMilli(1729391235717L)); | ||
assertNotNull(workderProgressState.getItemIds()); | ||
assertEquals(2,workderProgressState.getItemIds().size()); | ||
} | ||
} |