-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Attila Mészáros <[email protected]>
- Loading branch information
Showing
7 changed files
with
576 additions
and
618 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
352 changes: 164 additions & 188 deletions
352
src/test/java/io/csviri/operator/resourceglue/GlueOperatorTest.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 |
---|---|---|
@@ -1,199 +1,175 @@ | ||
package io.csviri.operator.resourceglue; | ||
|
||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.stream.IntStream; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.csviri.operator.resourceglue.customresource.TestCustomResource; | ||
import io.csviri.operator.resourceglue.customresource.TestCustomResource2; | ||
import io.csviri.operator.resourceglue.customresource.TestCustomResourceSpec; | ||
import io.csviri.operator.resourceglue.customresource.glue.DependentResourceSpec; | ||
import io.csviri.operator.resourceglue.customresource.operator.GlueOperator; | ||
import io.csviri.operator.resourceglue.customresource.operator.Parent; | ||
import io.csviri.operator.resourceglue.customresource.operator.ResourceGlueOperatorSpec; | ||
import io.csviri.operator.resourceglue.reconciler.glue.GlueReconciler; | ||
import io.csviri.operator.resourceglue.reconciler.operator.GlueOperatorReconciler; | ||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; | ||
|
||
import static io.csviri.operator.resourceglue.customresource.TestCustomResource.CR_GROUP; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
class GlueOperatorTest { | ||
|
||
public static final String TEST_RESOURCE_VALUE = "val"; | ||
public static final String TEST_RESOURCE_PREFIX = "testcr"; | ||
public static final String TEST_RESOURCE2_PREFIX = "testcr2"; | ||
|
||
|
||
@RegisterExtension | ||
LocallyRunOperatorExtension extension = | ||
LocallyRunOperatorExtension.builder() | ||
.withReconciler(new GlueReconciler()) | ||
.withReconciler(new GlueOperatorReconciler()) | ||
.withAdditionalCustomResourceDefinition(TestCustomResource.class) | ||
.withAdditionalCustomResourceDefinition(TestCustomResource2.class) | ||
.build(); | ||
|
||
@Test | ||
void smokeTestResourceGlueOperator() { | ||
extension.create(testWorkflowOperator()); | ||
var cr = extension.create(testCustomResource()); | ||
|
||
await().untilAsserted(() -> { | ||
var cm1 = extension.get(ConfigMap.class, "test1"); | ||
assertThat(cm1).isNotNull(); | ||
}); | ||
|
||
extension.delete(cr); | ||
|
||
await().timeout(Duration.ofSeconds(10)).untilAsserted(() -> { | ||
var cm1 = extension.get(ConfigMap.class, "test1"); | ||
var actualCR = extension.get(TestCustomResource.class, cr.getMetadata().getName()); | ||
assertThat(cm1).isNull(); | ||
assertThat(actualCR).isNull(); | ||
}); | ||
} | ||
|
||
@Test | ||
void templating() { | ||
var wo = TestUtils | ||
.loadResourceFlowOperator("/resourceglueoperator/Templating.yaml"); | ||
extension.create(wo); | ||
var cr = extension.create(testCustomResource()); | ||
String initialValue = cr.getSpec().getValue(); | ||
String name = cr.getMetadata().getName(); | ||
|
||
await().untilAsserted(() -> { | ||
var cm1 = extension.get(ConfigMap.class, name); | ||
assertThat(cm1).isNotNull(); | ||
assertThat(cm1.getData()).containsEntry("key", initialValue); | ||
}); | ||
|
||
var changedValue = "changed-value"; | ||
cr.getSpec().setValue(changedValue); | ||
cr = extension.replace(cr); | ||
|
||
await().untilAsserted(() -> { | ||
var cm1 = extension.get(ConfigMap.class, name); | ||
assertThat(cm1.getData()).containsEntry("key", changedValue); | ||
}); | ||
|
||
extension.delete(cr); | ||
|
||
await().untilAsserted(() -> { | ||
var cm1 = extension.get(ConfigMap.class, name); | ||
var actualCR = extension.get(TestCustomResource.class, name); | ||
assertThat(cm1).isNull(); | ||
assertThat(actualCR).isNull(); | ||
}); | ||
} | ||
|
||
@Test | ||
void simpleConcurrencyTest() { | ||
int num = 10; | ||
extension.create(TestUtils | ||
.loadResourceFlowOperator("/resourceglueoperator/Concurrency.yaml")); | ||
|
||
var resources = | ||
IntStream.range(0, num).mapToObj(n -> extension.create(testCustomResource(n))).toList(); | ||
|
||
await() | ||
.untilAsserted(() -> IntStream.range(0, num).forEach(n -> { | ||
var cm = extension.get(ConfigMap.class, TEST_RESOURCE_PREFIX + n); | ||
assertThat(cm).isNotNull(); | ||
assertThat(cm.getData()).containsEntry("key", TEST_RESOURCE_VALUE + n); | ||
})); | ||
|
||
resources.forEach(r -> extension.delete(r)); | ||
|
||
await() | ||
.untilAsserted(() -> IntStream.range(0, num).forEach(n -> { | ||
var cm = extension.get(ConfigMap.class, TEST_RESOURCE_PREFIX + n); | ||
assertThat(cm).isNull(); | ||
})); | ||
} | ||
|
||
@Test | ||
void simpleConcurrencyForMultipleOperatorTest() { | ||
int num = 10; | ||
extension.create(TestUtils | ||
.loadResourceFlowOperator("/resourceglueoperator/Concurrency.yaml")); | ||
extension.create(TestUtils | ||
.loadResourceFlowOperator("/resourceglueoperator/Concurrency2.yaml")); | ||
|
||
var crs = | ||
IntStream.range(0, num).mapToObj(n -> extension.create(testCustomResource(n))).toList(); | ||
var cr2s = | ||
IntStream.range(0, num).mapToObj(n -> extension.create(testCustomResource2(n))).toList(); | ||
|
||
await().untilAsserted(() -> IntStream.range(0, num).forEach(n -> { | ||
var cm = extension.get(ConfigMap.class, TEST_RESOURCE_PREFIX + n); | ||
assertThat(cm).isNotNull(); | ||
assertThat(cm.getData()).containsEntry("key", TEST_RESOURCE_VALUE + n); | ||
|
||
var cm2 = extension.get(ConfigMap.class, TEST_RESOURCE2_PREFIX + n); | ||
assertThat(cm2).isNotNull(); | ||
assertThat(cm2.getData()).containsEntry("key", TEST_RESOURCE_VALUE + n); | ||
})); | ||
|
||
crs.forEach(r -> extension.delete(r)); | ||
cr2s.forEach(r -> extension.delete(r)); | ||
|
||
await().untilAsserted(() -> { | ||
IntStream.range(0, num).forEach(n -> { | ||
var cm = extension.get(ConfigMap.class, TEST_RESOURCE_PREFIX + n); | ||
assertThat(cm).isNull(); | ||
var cm2 = extension.get(ConfigMap.class, TEST_RESOURCE2_PREFIX + n); | ||
assertThat(cm2).isNull(); | ||
}); | ||
}); | ||
} | ||
|
||
TestCustomResource testCustomResource() { | ||
return testCustomResource(1); | ||
} | ||
|
||
TestCustomResource testCustomResource(int index) { | ||
var res = new TestCustomResource(); | ||
res.setMetadata(new ObjectMetaBuilder() | ||
.withName(TEST_RESOURCE_PREFIX + index) | ||
.build()); | ||
res.setSpec(new TestCustomResourceSpec()); | ||
res.getSpec().setValue(TEST_RESOURCE_VALUE + index); | ||
return res; | ||
} | ||
|
||
TestCustomResource2 testCustomResource2(int index) { | ||
var res = new TestCustomResource2(); | ||
res.setMetadata(new ObjectMetaBuilder() | ||
.withName(TEST_RESOURCE2_PREFIX + index) | ||
.build()); | ||
res.setSpec(new TestCustomResourceSpec()); | ||
res.getSpec().setValue(TEST_RESOURCE_VALUE + index); | ||
return res; | ||
} | ||
|
||
GlueOperator testWorkflowOperator() { | ||
var wo = new GlueOperator(); | ||
wo.setMetadata(new ObjectMetaBuilder() | ||
.withName("wo1") | ||
.build()); | ||
var spec = new ResourceGlueOperatorSpec(); | ||
wo.setSpec(spec); | ||
spec.setParent(new Parent(CR_GROUP + "/v1", TestCustomResource.class.getSimpleName())); | ||
|
||
spec.setResources(new ArrayList<>()); | ||
DependentResourceSpec drs = new DependentResourceSpec(); | ||
spec.getResources().add(drs); | ||
drs.setResource(TestUtils.load("/ConfigMap.yaml")); | ||
drs.setName("configMap1"); | ||
return wo; | ||
} | ||
// @RegisterExtension | ||
// LocallyRunOperatorExtension extension = | ||
// LocallyRunOperatorExtension.builder() | ||
// .withReconciler(new GlueReconciler()) | ||
// .withReconciler(new GlueOperatorReconciler()) | ||
// .withAdditionalCustomResourceDefinition(TestCustomResource.class) | ||
// .withAdditionalCustomResourceDefinition(TestCustomResource2.class) | ||
// .build(); | ||
// | ||
// @Test | ||
// void smokeTestResourceGlueOperator() { | ||
// extension.create(testWorkflowOperator()); | ||
// var cr = extension.create(testCustomResource()); | ||
// | ||
// await().untilAsserted(() -> { | ||
// var cm1 = extension.get(ConfigMap.class, "test1"); | ||
// assertThat(cm1).isNotNull(); | ||
// }); | ||
// | ||
// extension.delete(cr); | ||
// | ||
// await().timeout(Duration.ofSeconds(10)).untilAsserted(() -> { | ||
// var cm1 = extension.get(ConfigMap.class, "test1"); | ||
// var actualCR = extension.get(TestCustomResource.class, cr.getMetadata().getName()); | ||
// assertThat(cm1).isNull(); | ||
// assertThat(actualCR).isNull(); | ||
// }); | ||
// } | ||
// | ||
// @Test | ||
// void templating() { | ||
// var wo = TestUtils | ||
// .loadResourceFlowOperator("/resourceglueoperator/Templating.yaml"); | ||
// extension.create(wo); | ||
// var cr = extension.create(testCustomResource()); | ||
// String initialValue = cr.getSpec().getValue(); | ||
// String name = cr.getMetadata().getName(); | ||
// | ||
// await().untilAsserted(() -> { | ||
// var cm1 = extension.get(ConfigMap.class, name); | ||
// assertThat(cm1).isNotNull(); | ||
// assertThat(cm1.getData()).containsEntry("key", initialValue); | ||
// }); | ||
// | ||
// var changedValue = "changed-value"; | ||
// cr.getSpec().setValue(changedValue); | ||
// cr = extension.replace(cr); | ||
// | ||
// await().untilAsserted(() -> { | ||
// var cm1 = extension.get(ConfigMap.class, name); | ||
// assertThat(cm1.getData()).containsEntry("key", changedValue); | ||
// }); | ||
// | ||
// extension.delete(cr); | ||
// | ||
// await().untilAsserted(() -> { | ||
// var cm1 = extension.get(ConfigMap.class, name); | ||
// var actualCR = extension.get(TestCustomResource.class, name); | ||
// assertThat(cm1).isNull(); | ||
// assertThat(actualCR).isNull(); | ||
// }); | ||
// } | ||
// | ||
// @Test | ||
// void simpleConcurrencyTest() { | ||
// int num = 10; | ||
// extension.create(TestUtils | ||
// .loadResourceFlowOperator("/resourceglueoperator/Concurrency.yaml")); | ||
// | ||
// var resources = | ||
// IntStream.range(0, num).mapToObj(n -> extension.create(testCustomResource(n))).toList(); | ||
// | ||
// await() | ||
// .untilAsserted(() -> IntStream.range(0, num).forEach(n -> { | ||
// var cm = extension.get(ConfigMap.class, TEST_RESOURCE_PREFIX + n); | ||
// assertThat(cm).isNotNull(); | ||
// assertThat(cm.getData()).containsEntry("key", TEST_RESOURCE_VALUE + n); | ||
// })); | ||
// | ||
// resources.forEach(r -> extension.delete(r)); | ||
// | ||
// await() | ||
// .untilAsserted(() -> IntStream.range(0, num).forEach(n -> { | ||
// var cm = extension.get(ConfigMap.class, TEST_RESOURCE_PREFIX + n); | ||
// assertThat(cm).isNull(); | ||
// })); | ||
// } | ||
// | ||
// @Test | ||
// void simpleConcurrencyForMultipleOperatorTest() { | ||
// int num = 10; | ||
// extension.create(TestUtils | ||
// .loadResourceFlowOperator("/resourceglueoperator/Concurrency.yaml")); | ||
// extension.create(TestUtils | ||
// .loadResourceFlowOperator("/resourceglueoperator/Concurrency2.yaml")); | ||
// | ||
// var crs = | ||
// IntStream.range(0, num).mapToObj(n -> extension.create(testCustomResource(n))).toList(); | ||
// var cr2s = | ||
// IntStream.range(0, num).mapToObj(n -> extension.create(testCustomResource2(n))).toList(); | ||
// | ||
// await().untilAsserted(() -> IntStream.range(0, num).forEach(n -> { | ||
// var cm = extension.get(ConfigMap.class, TEST_RESOURCE_PREFIX + n); | ||
// assertThat(cm).isNotNull(); | ||
// assertThat(cm.getData()).containsEntry("key", TEST_RESOURCE_VALUE + n); | ||
// | ||
// var cm2 = extension.get(ConfigMap.class, TEST_RESOURCE2_PREFIX + n); | ||
// assertThat(cm2).isNotNull(); | ||
// assertThat(cm2.getData()).containsEntry("key", TEST_RESOURCE_VALUE + n); | ||
// })); | ||
// | ||
// crs.forEach(r -> extension.delete(r)); | ||
// cr2s.forEach(r -> extension.delete(r)); | ||
// | ||
// await().untilAsserted(() -> { | ||
// IntStream.range(0, num).forEach(n -> { | ||
// var cm = extension.get(ConfigMap.class, TEST_RESOURCE_PREFIX + n); | ||
// assertThat(cm).isNull(); | ||
// var cm2 = extension.get(ConfigMap.class, TEST_RESOURCE2_PREFIX + n); | ||
// assertThat(cm2).isNull(); | ||
// }); | ||
// }); | ||
// } | ||
// | ||
// TestCustomResource testCustomResource() { | ||
// return testCustomResource(1); | ||
// } | ||
// | ||
// TestCustomResource testCustomResource(int index) { | ||
// var res = new TestCustomResource(); | ||
// res.setMetadata(new ObjectMetaBuilder() | ||
// .withName(TEST_RESOURCE_PREFIX + index) | ||
// .build()); | ||
// res.setSpec(new TestCustomResourceSpec()); | ||
// res.getSpec().setValue(TEST_RESOURCE_VALUE + index); | ||
// return res; | ||
// } | ||
// | ||
// TestCustomResource2 testCustomResource2(int index) { | ||
// var res = new TestCustomResource2(); | ||
// res.setMetadata(new ObjectMetaBuilder() | ||
// .withName(TEST_RESOURCE2_PREFIX + index) | ||
// .build()); | ||
// res.setSpec(new TestCustomResourceSpec()); | ||
// res.getSpec().setValue(TEST_RESOURCE_VALUE + index); | ||
// return res; | ||
// } | ||
// | ||
// GlueOperator testWorkflowOperator() { | ||
// var wo = new GlueOperator(); | ||
// wo.setMetadata(new ObjectMetaBuilder() | ||
// .withName("wo1") | ||
// .build()); | ||
// var spec = new ResourceGlueOperatorSpec(); | ||
// wo.setSpec(spec); | ||
// spec.setParent(new Parent(CR_GROUP + "/v1", TestCustomResource.class.getSimpleName())); | ||
// | ||
// spec.setResources(new ArrayList<>()); | ||
// DependentResourceSpec drs = new DependentResourceSpec(); | ||
// spec.getResources().add(drs); | ||
// drs.setResource(TestUtils.load("/ConfigMap.yaml")); | ||
// drs.setName("configMap1"); | ||
// return wo; | ||
// } | ||
|
||
} |
Oops, something went wrong.