Skip to content

Commit d32e2b7

Browse files
zeebe-bors-camunda[bot]deepthidevakipihme
authored
merge: #9895 #9897
9895: [Backport stable/8.0] test(qa): wait until message is published before restarting the broker r=deepthidevaki a=backport-action # Description Backport of #9886 to `stable/8.0`. relates to #9813 9897: [Backport stable/8.0] fix(engine): add grace period to detect end of processing r=remcowesterhoud a=backport-action # Description Backport of #9082 to `stable/8.0`. relates to #8738 closes #9641 Co-authored-by: Deepthi Devaki Akkoorath <[email protected]> Co-authored-by: pihme <[email protected]>
3 parents d349d79 + a863a22 + 7a434a5 commit d32e2b7

File tree

2 files changed

+55
-38
lines changed

2 files changed

+55
-38
lines changed

engine/src/test/java/io/camunda/zeebe/engine/processing/streamprocessor/ReplayStateRandomizedPropertyTest.java

+53-37
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.camunda.zeebe.test.util.bpmn.random.TestDataGenerator.TestDataRecord;
2222
import io.camunda.zeebe.test.util.record.RecordingExporter;
2323
import java.util.Collection;
24+
import java.util.Map;
2425
import org.assertj.core.api.SoftAssertions;
2526
import org.awaitility.Awaitility;
2627
import org.junit.Before;
@@ -38,6 +39,9 @@ public class ReplayStateRandomizedPropertyTest {
3839
private static final String PROCESS_COUNT = System.getProperty("processCount", "3");
3940
private static final String EXECUTION_PATH_COUNT =
4041
System.getProperty("replayExecutionCount", "1");
42+
/* Grace period to wait if new records come in after processing has reached end */
43+
private static final long GRACE_PERIOD = 50; // ms
44+
4145
@Parameter public TestDataRecord record;
4246

4347
@Rule
@@ -101,7 +105,12 @@ public void shouldRestoreStateAtEachStepInExecution() {
101105

102106
private void stopAndRestartEngineAndCompareStates() {
103107
// given
104-
waitForProcessingToStop();
108+
Awaitility.await(
109+
"await the last written record to be processed, then wait a GRACE_PERIOD to make sure no new events are added")
110+
.untilAsserted(
111+
() -> {
112+
processingHasStoppedAndNoNewRecordsAreAddedDuringGracePeriod();
113+
});
105114

106115
engineRule.pauseProcessing(1);
107116

@@ -122,51 +131,58 @@ private void stopAndRestartEngineAndCompareStates() {
122131
.untilAsserted(
123132
() -> {
124133
final var replayState = engineRule.collectState();
134+
assertIdenticalStates(processingState, replayState);
135+
});
136+
}
125137

126-
final var softly = new SoftAssertions();
127-
128-
processingState.entrySet().stream()
129-
.filter(entry -> entry.getKey() != ZbColumnFamilies.DEFAULT)
130-
.forEach(
131-
entry -> {
132-
final var column = entry.getKey();
133-
final var processingEntries = entry.getValue();
134-
final var replayEntries = replayState.get(column);
135-
136-
if (processingEntries.isEmpty()) {
137-
softly
138-
.assertThat(replayEntries)
139-
.describedAs(
140-
"The state column '%s' should be empty after replay", column)
141-
.isEmpty();
142-
} else {
143-
softly
144-
.assertThat(replayEntries)
145-
.describedAs(
146-
"The state column '%s' has different entries after replay",
147-
column)
148-
.containsExactlyInAnyOrderEntriesOf(processingEntries);
149-
}
150-
});
151-
152-
softly.assertAll();
138+
private void assertIdenticalStates(
139+
final Map<ZbColumnFamilies, Map<Object, Object>> expectedState,
140+
final Map<ZbColumnFamilies, Map<Object, Object>> actualState) {
141+
final var softly = new SoftAssertions();
142+
expectedState.entrySet().stream()
143+
.filter(entry -> entry.getKey() != ZbColumnFamilies.DEFAULT)
144+
.forEach(
145+
entry -> {
146+
final var column = entry.getKey();
147+
final var expectedEntries = entry.getValue();
148+
final var actualEntries = actualState.get(column);
149+
150+
if (expectedEntries.isEmpty()) {
151+
softly
152+
.assertThat(actualEntries)
153+
.describedAs("The state column '%s' should be empty", column)
154+
.isEmpty();
155+
} else {
156+
softly
157+
.assertThat(actualEntries)
158+
.describedAs("The state column '%s' has different entries", column)
159+
.containsExactlyInAnyOrderEntriesOf(expectedEntries);
160+
}
153161
});
162+
163+
softly.assertAll();
154164
}
155165

156-
private void waitForProcessingToStop() {
157-
Awaitility.await("await the last written record to be processed")
158-
.untilAsserted(
159-
() ->
160-
assertThat(engineRule.hasReachedEnd())
161-
.describedAs("Processing has reached end of the log.")
162-
.isTrue());
166+
private void processingHasStoppedAndNoNewRecordsAreAddedDuringGracePeriod()
167+
throws InterruptedException {
168+
assertThat(engineRule.hasReachedEnd())
169+
.describedAs("Processing has reached end of the log.")
170+
.isTrue();
171+
final var stateBeforeGracePeriod = engineRule.collectState();
172+
Thread.sleep(GRACE_PERIOD);
173+
assertThat(engineRule.hasReachedEnd())
174+
.describedAs("Processing has reached end of the log.")
175+
.isTrue();
176+
final var stateAfterGracePeriod = engineRule.collectState();
177+
178+
assertIdenticalStates(stateBeforeGracePeriod, stateAfterGracePeriod);
163179
}
164180

165181
@Parameters(name = "{0}")
166182
public static Collection<TestDataRecord> getTestRecords() {
167183
// use the following code to rerun a specific test case:
168-
// final var processSeed = 3499044774323385558L;
169-
// final var executionPathSeed = 3627169465144620203L;
184+
// final var processSeed = 6163452194952018956L;
185+
// final var executionPathSeed = 6499103602285813109L;
170186
// return List.of(TestDataGenerator.regenerateTestRecord(processSeed, executionPathSeed));
171187
return TestDataGenerator.generateTestRecords(
172188
Integer.parseInt(PROCESS_COUNT), Integer.parseInt(EXECUTION_PATH_COUNT));

qa/integration-tests/src/test/java/io/camunda/zeebe/it/clustering/CompleteProcessInstanceAfterLeaderChangeTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public static Object[][] actions() {
7676
.newPublishMessageCommand()
7777
.messageName("msg")
7878
.correlationKey("123")
79-
.send(),
79+
.send()
80+
.join(),
8081
(BiConsumer<ClusteringRule, GrpcClientRule>)
8182
(clusteringRule, clientRule) -> {
8283
final var processDefinitionKey =

0 commit comments

Comments
 (0)