Skip to content

Commit 06dc6eb

Browse files
committed
fix: tests
1 parent d63f308 commit 06dc6eb

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowReconcileExecutor.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ private synchronized void handleReconcileOrDelete(
7777

7878
if (onlyReconcileForPossibleDelete) {
7979
reconcileConditionOrParentsConditionNotMet.add(dependentResourceNode);
80-
} else if (dependentResourceNode.getReconcileCondition().isPresent()) {
81-
handleReconcileCondition(dependentResourceNode);
80+
} else {
81+
dependentResourceNode.getReconcileCondition()
82+
.ifPresent(reconcileCondition -> handleReconcileCondition(dependentResourceNode,
83+
reconcileCondition));
8284
}
8385

8486
Future<?> nodeFuture =
@@ -107,8 +109,7 @@ private boolean ownOrParentsReconcileConditionNotMet(
107109
DependentResourceNode<?, ?> dependentResourceNode) {
108110
return reconcileConditionOrParentsConditionNotMet.contains(dependentResourceNode) ||
109111
dependentResourceNode.getDependsOn().stream()
110-
.anyMatch(dependsOnRelation -> reconcileConditionOrParentsConditionNotMet
111-
.contains(dependsOnRelation.getDependsOn()));
112+
.anyMatch(reconcileConditionOrParentsConditionNotMet::contains);
112113
}
113114

114115
private class NodeExecutor implements Runnable {
@@ -170,9 +171,8 @@ private boolean alreadyReconciled(
170171
}
171172

172173

173-
private void handleReconcileCondition(DependentResourceNode<?, ?> dependentResourceNode) {
174-
ReconcileCondition<P> reconcileCondition =
175-
(ReconcileCondition<P>) dependentResourceNode.getReconcileCondition().get();
174+
private void handleReconcileCondition(DependentResourceNode<?, ?> dependentResourceNode,
175+
ReconcileCondition reconcileCondition) {
176176
boolean conditionMet =
177177
reconcileCondition.isMet(dependentResourceNode.getDependentResource(), primary, context);
178178
if (!conditionMet) {
@@ -191,6 +191,6 @@ private boolean hasErroredDependOn(
191191
DependentResourceNode<?, ?> dependentResourceNode) {
192192
return !dependentResourceNode.getDependsOn().isEmpty()
193193
&& dependentResourceNode.getDependsOn().stream()
194-
.anyMatch(dependsOnRelation -> errored.contains(dependsOnRelation.getDependsOn()));
194+
.anyMatch(errored::contains);
195195
}
196196
}

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/ExecutionAssert.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public ExecutionAssert reconciledInOrder(DependentResource<?, ?>... dependentRes
7474
}
7575

7676
public ExecutionAssert notReconciled(DependentResource<?, ?>... dependentResources) {
77-
for (int i = 0; i < dependentResources.length - 1; i++) {
78-
if (!getActualDependentResources().contains(dependentResources[i])) {
77+
for (int i = 0; i < dependentResources.length; i++) {
78+
if (getActualDependentResources().contains(dependentResources[i])) {
7979
failWithMessage("Resource was reconciled: %s with index %d", dependentResources, i);
8080
}
8181
}

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowTest.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void exceptionHandlingSimpleCases() {
101101
.build();
102102
assertThrows(AggregatedOperatorException.class,
103103
() -> workflow.reconcile(new TestCustomResource(), null));
104-
assertThat(executionHistory).notReconciled(drError);
104+
assertThat(executionHistory).reconciled(drError);
105105
}
106106

107107
@Test
@@ -114,7 +114,25 @@ void dependentsOnErroredResourceNotReconciled() {
114114
assertThrows(AggregatedOperatorException.class,
115115
() -> workflow.reconcile(new TestCustomResource(), null));
116116

117-
assertThat(executionHistory).reconciled(dr1).notReconciled(drError, dr2);
117+
assertThat(executionHistory).reconciled(dr1, drError).notReconciled(dr2);
118+
}
119+
120+
@Test
121+
void oneBranchErrorsOtherCompletes() {
122+
TestDependent dr3 = new TestDependent("DR_3");
123+
124+
var workflow = new WorkflowBuilder<TestCustomResource>()
125+
.addDependent(dr1).build()
126+
.addDependent(drError).dependsOn(dr1).build()
127+
.addDependent(dr2).dependsOn(dr1).build()
128+
.addDependent(dr3).dependsOn(dr2).build()
129+
.build();
130+
131+
assertThrows(AggregatedOperatorException.class,
132+
() -> workflow.reconcile(new TestCustomResource(), null));
133+
134+
assertThat(executionHistory).reconciledInOrder(dr1, dr2, dr3);
135+
assertThat(executionHistory).reconciledInOrder(dr1, drError);
118136
}
119137

120138
@Test
@@ -145,6 +163,21 @@ void simpleReconcileCondition() {
145163
assertThat(executionHistory).deleted(drDeleter);
146164
}
147165

166+
@Test
167+
void triangleOnceConditionNotMet() {
168+
var workflow = new WorkflowBuilder<TestCustomResource>()
169+
.addDependent(dr1).build()
170+
.addDependent(dr2).dependsOn(dr1).build()
171+
.addDependent(drDeleter).withReconcileCondition(not_met_reconcile_condition).dependsOn(dr1)
172+
.build()
173+
.build();
174+
175+
workflow.reconcile(new TestCustomResource(), null);
176+
177+
assertThat(executionHistory).reconciledInOrder(dr1, dr2);
178+
assertThat(executionHistory).deleted(drDeleter);
179+
}
180+
148181
@Test
149182
void reconcileConditionTransitiveDelete() {
150183
TestDeleterDependent drDeleter2 = new TestDeleterDependent("DR_DELETER_2");

0 commit comments

Comments
 (0)