-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathAppendConsistencyViolationException.java
More file actions
37 lines (32 loc) · 1.37 KB
/
AppendConsistencyViolationException.java
File metadata and controls
37 lines (32 loc) · 1.37 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
package io.kurrent.dbclient;
import java.util.List;
import java.util.stream.Collectors;
/**
* Exception thrown when one or more consistency checks fail during an AppendRecords operation.
* The entire transaction is aborted and no records are written.
*/
public class AppendConsistencyViolationException extends RuntimeException {
private final List<ConsistencyViolation> violations;
/**
* Creates a new AppendConsistencyViolationException.
*
* @param violations the consistency violations that caused the transaction to be aborted.
*/
public AppendConsistencyViolationException(List<ConsistencyViolation> violations) {
super(formatMessage(violations));
this.violations = violations;
}
/**
* Returns the consistency violations that caused the transaction to be aborted.
*/
public List<ConsistencyViolation> getViolations() {
return violations;
}
private static String formatMessage(List<ConsistencyViolation> violations) {
String details = violations.stream()
.map(v -> String.format("[Check %d: Stream '%s' expected state %s, actual state %s]",
v.getCheckIndex(), v.getStream(), v.getExpectedState(), v.getActualState()))
.collect(Collectors.joining(", "));
return "Append failed due to consistency violation(s): " + details;
}
}