-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathIdempotencyE2ET.java
More file actions
63 lines (51 loc) · 2.23 KB
/
IdempotencyE2ET.java
File metadata and controls
63 lines (51 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package software.amazon.lambda.powertools;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import software.amazon.lambda.powertools.testutils.Infrastructure;
import software.amazon.lambda.powertools.testutils.lambda.InvocationResult;
import java.time.Year;
import java.util.Collections;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import static software.amazon.lambda.powertools.testutils.lambda.LambdaInvoker.invokeFunction;
public class IdempotencyE2ET {
private static Infrastructure infrastructure;
private static String functionName;
@BeforeAll
@Timeout(value = 5, unit = TimeUnit.MINUTES)
public static void setup() {
String random = UUID.randomUUID().toString().substring(0, 6);
infrastructure = Infrastructure.builder()
.testName(IdempotencyE2ET.class.getSimpleName())
.pathToFunction("idempotency")
.idempotencyTable("idempo" + random)
.environmentVariables(Collections.singletonMap("IDEMPOTENCY_TABLE", "idempo" + random))
.build();
functionName = infrastructure.deploy();
}
@AfterAll
public static void tearDown() {
if (infrastructure != null)
infrastructure.destroy();
}
@Test
public void test_ttlNotExpired_sameResult_ttlExpired_differentResult() throws InterruptedException {
// GIVEN
String event = "{\"message\":\"TTL 10sec\"}";
// WHEN
// First invocation
InvocationResult result1 = invokeFunction(functionName, event);
// Second invocation (should get same result)
InvocationResult result2 = invokeFunction(functionName, event);
Thread.sleep(12000);
// Third invocation (should get different result)
InvocationResult result3 = invokeFunction(functionName, event);
// THEN
Assertions.assertThat(result1.getResult()).contains(Year.now().toString());
Assertions.assertThat(result2.getResult()).isEqualTo(result1.getResult());
Assertions.assertThat(result3.getResult()).isNotEqualTo(result2.getResult());
}
}