-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: multiple dependents of same type exceptions (#2226)
Signed-off-by: Attila Mészáros <csviri@gmail.com> Signed-off-by: Chris Laprun <claprun@redhat.com> Co-authored-by: Chris Laprun <claprun@redhat.com>
- Loading branch information
Showing
2 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...st/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.javaoperatorsdk.operator.processing.dependent.workflow; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.javaoperatorsdk.operator.AggregatedOperatorException; | ||
import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; | ||
import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class WorkflowResultTest { | ||
|
||
@Test | ||
void throwsExceptionWithoutNumberingIfAllDifferentClass() { | ||
var res = new WorkflowResult(Map.of(new DependentA(), new RuntimeException(), | ||
new DependentB(), new RuntimeException())); | ||
try { | ||
res.throwAggregateExceptionIfErrorsPresent(); | ||
} catch (AggregatedOperatorException e) { | ||
assertThat(e.getAggregatedExceptions()).containsOnlyKeys(DependentA.class.getName(), | ||
DependentB.class.getName()); | ||
} | ||
} | ||
|
||
@Test | ||
void numbersDependentClassNamesIfMoreOfSameType() { | ||
var res = new WorkflowResult(Map.of(new DependentA(), new RuntimeException(), | ||
new DependentA(), new RuntimeException())); | ||
try { | ||
res.throwAggregateExceptionIfErrorsPresent(); | ||
} catch (AggregatedOperatorException e) { | ||
assertThat(e.getAggregatedExceptions()).hasSize(2); | ||
} | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
static class DependentA implements DependentResource { | ||
@Override | ||
public ReconcileResult reconcile(HasMetadata primary, Context context) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Class resourceType() { | ||
return null; | ||
} | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
static class DependentB implements DependentResource { | ||
@Override | ||
public ReconcileResult reconcile(HasMetadata primary, Context context) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Class resourceType() { | ||
return null; | ||
} | ||
} | ||
} |