lhotari commented on code in PR #23811:
URL: https://github.com/apache/pulsar/pull/23811#discussion_r1905803095
##########
pulsar-functions/instance/src/test/java/org/apache/pulsar/functions/instance/JavaInstanceTest.java:
##########
@@ -309,4 +314,22 @@ public void testAsyncFunctionMaxPendingVoidResult() throws
Exception {
log.info("start:{} end:{} during:{}", startTime, endTime, endTime -
startTime);
instance.close();
}
+
+ @Test
+ public void testAsyncFunctionTime() {
+ JavaInstance instance = new JavaInstance(
+ mock(ContextImpl.class),
+ (Function<String, String>) (input, context) -> {
+ Thread.sleep(500);
+ return input;
+ },
+ new InstanceConfig());
+ String testString = "ABC123";
+ JavaExecutionResult result =
instance.handleMessage(mock(Record.class), testString);
+ LongSupplier timeSupplier = () -> System.nanoTime() - 500_000_000L;
+ assertNotNull(result.getResult());
+ long beforeTime = timeSupplier.getAsLong();
+ assertTrue(Math.abs(beforeTime - result.getStartTime()) <= 20_000_000);
Review Comment:
the usage of `LongSupplier timeSupplier` doesn't make much sense in this
way. just get rid of it for now. What I was trying to explain earlier was that
a common pattern for testing time is to have a mock clock that gets injected
also in the production code. Instead of calling `System.nanoTime()` in
production code, the "clock" interface (`LongSupplier` for example) would be
used. Let's forget that for now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]