Skip to content

Commit e3fc48d

Browse files
authored
Pull out createTimer logic (#1419)
* pull out logical changes from @salaboy's PR to release it Signed-off-by: Cassandra Coyle <[email protected]> * add missing import Signed-off-by: Cassandra Coyle <[email protected]> --------- Signed-off-by: Cassandra Coyle <[email protected]>
1 parent 981b3b4 commit e3fc48d

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

sdk-workflows/src/main/java/io/dapr/workflows/WorkflowContext.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,7 @@ default Task<Task<?>> anyOf(Task<?>... tasks) {
347347
* @param zonedDateTime timestamp with specific zone when the timer should expire
348348
* @return a new {@code Task} that completes after the specified delay
349349
*/
350-
default Task<Void> createTimer(ZonedDateTime zonedDateTime) {
351-
throw new UnsupportedOperationException("This method is not implemented.");
352-
}
353-
350+
Task<Void> createTimer(ZonedDateTime zonedDateTime);
354351

355352
/**
356353
* Gets the deserialized input of the current task orchestration.

sdk-workflows/src/main/java/io/dapr/workflows/runtime/DefaultWorkflowContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import java.time.Duration;
3535
import java.time.Instant;
36+
import java.time.ZonedDateTime;
3637
import java.util.List;
3738
import java.util.UUID;
3839

@@ -189,6 +190,11 @@ public Task<Void> createTimer(Duration duration) {
189190
return this.innerContext.createTimer(duration);
190191
}
191192

193+
@Override
194+
public Task<Void> createTimer(ZonedDateTime zonedDateTime) {
195+
return this.innerContext.createTimer(zonedDateTime);
196+
}
197+
192198
/**
193199
* {@inheritDoc}
194200
*/

sdk-workflows/src/test/java/io/dapr/workflows/DefaultWorkflowContextTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,10 @@
3939

4040
import static org.junit.jupiter.api.Assertions.assertEquals;
4141
import static org.junit.jupiter.api.Assertions.assertNull;
42+
import static org.junit.jupiter.api.Assertions.assertThrows;
4243
import static org.mockito.ArgumentMatchers.any;
4344
import static org.mockito.ArgumentMatchers.eq;
44-
import static org.mockito.Mockito.mock;
45-
import static org.mockito.Mockito.spy;
46-
import static org.mockito.Mockito.times;
47-
import static org.mockito.Mockito.verify;
48-
import static org.mockito.Mockito.when;
49-
import static org.junit.jupiter.api.Assertions.assertThrows;
45+
import static org.mockito.Mockito.*;
5046

5147
public class DefaultWorkflowContextTest {
5248
private DefaultWorkflowContext context;
@@ -124,6 +120,11 @@ public Task<Void> createTimer(Duration duration) {
124120
return null;
125121
}
126122

123+
@Override
124+
public Task<Void> createTimer(ZonedDateTime zonedDateTime) {
125+
return null;
126+
}
127+
127128
@Override
128129
public <V> V getInput(Class<V> targetType) {
129130
return null;
@@ -269,8 +270,10 @@ public void createTimerTest() {
269270
}
270271

271272
@Test
272-
public void createTimerWithZonedDateTimeThrowsTest() {
273-
assertThrows(UnsupportedOperationException.class, () -> context.createTimer(ZonedDateTime.now()));
273+
public void createTimerWithZonedDateTimeTest() {
274+
ZonedDateTime now = ZonedDateTime.now();
275+
context.createTimer(now);
276+
verify(mockInnerContext, times(1)).createTimer(now);
274277
}
275278

276279
@Test

0 commit comments

Comments
 (0)