-
Notifications
You must be signed in to change notification settings - Fork 556
/
StreamProcessorHealthTest.java
95 lines (79 loc) · 3.59 KB
/
StreamProcessorHealthTest.java
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
* one or more contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright ownership.
* Licensed under the Zeebe Community License 1.1. You may not use this file
* except in compliance with the Zeebe Community License 1.1.
*/
package io.camunda.zeebe.engine.processing.streamprocessor;
import static io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent.ACTIVATE_ELEMENT;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import io.camunda.zeebe.engine.api.EmptyProcessingResult;
import io.camunda.zeebe.engine.util.RecordToWrite;
import io.camunda.zeebe.engine.util.Records;
import io.camunda.zeebe.engine.util.StreamPlatform;
import io.camunda.zeebe.engine.util.StreamPlatformExtension;
import io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord;
import io.camunda.zeebe.streamprocessor.StreamProcessor;
import java.util.concurrent.atomic.AtomicBoolean;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ExtendWith(StreamPlatformExtension.class)
public class StreamProcessorHealthTest {
private static final ProcessInstanceRecord PROCESS_INSTANCE_RECORD = Records.processInstance(1);
@SuppressWarnings("unused") // injected by the extension
private StreamPlatform streamPlatform;
private StreamProcessor streamProcessor;
@Test
void shouldBeHealthyOnStart() {
// when
streamProcessor = streamPlatform.startStreamProcessor();
// then
Awaitility.await("wait to become healthy again")
.until(() -> streamProcessor.getHealthReport().isHealthy());
}
@Test
void shouldMarkUnhealthyWhenLoopInErrorHandling() {
// given
streamProcessor = streamPlatform.startStreamProcessor();
final var mockProcessor = streamPlatform.getDefaultMockedRecordProcessor();
when(mockProcessor.process(any(), any())).thenThrow(new RuntimeException("expected"));
when(mockProcessor.onProcessingError(any(), any(), any()))
.thenThrow(new RuntimeException("expected"));
// when
// since processing fails we will write error event
// we want to fail error even transaction
streamPlatform.writeBatch(
RecordToWrite.command().processInstance(ACTIVATE_ELEMENT, PROCESS_INSTANCE_RECORD));
// then
Awaitility.await("wait to become unhealthy")
.until(() -> streamProcessor.getHealthReport().isUnhealthy());
}
@Test
void shouldBecomeHealthyWhenErrorIsResolved() {
// given
streamProcessor = streamPlatform.startStreamProcessor();
final var shouldFail = new AtomicBoolean(true);
final var mockProcessor = streamPlatform.getDefaultMockedRecordProcessor();
when(mockProcessor.process(any(), any())).thenThrow(new RuntimeException("expected"));
when(mockProcessor.onProcessingError(any(), any(), any()))
.thenAnswer(
invocationOnMock -> {
if (shouldFail.get()) {
throw new RuntimeException("expected");
}
return EmptyProcessingResult.INSTANCE;
});
streamPlatform.writeBatch(
RecordToWrite.command().processInstance(ACTIVATE_ELEMENT, PROCESS_INSTANCE_RECORD));
Awaitility.await("wait to become unhealthy")
.until(() -> streamProcessor.getHealthReport().isUnhealthy());
// when
shouldFail.set(false);
// then
Awaitility.await("wait to become healthy again")
.until(() -> streamProcessor.getHealthReport().isHealthy());
}
}