-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
127 additions
and
19 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
63 changes: 63 additions & 0 deletions
63
src/test/java/br/unifor/ppgia/resiliencebench/resources/TestDataGenerator.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,63 @@ | ||
package br.unifor.ppgia.resiliencebench.resources; | ||
|
||
import br.unifor.ppgia.resiliencebench.resources.benchmark.*; | ||
import br.unifor.ppgia.resiliencebench.resources.fault.DelayFault; | ||
import br.unifor.ppgia.resiliencebench.resources.workload.Workload; | ||
import br.unifor.ppgia.resiliencebench.resources.workload.WorkloadSpec; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
public class TestDataGenerator { | ||
|
||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
static JsonNode createIntArrayJsonNode(String propertyName, List<Integer> content) { | ||
var jsonNode = objectMapper.createObjectNode(); | ||
var arrayNode = jsonNode.putArray(propertyName); | ||
content.forEach(arrayNode::add); | ||
return jsonNode; | ||
} | ||
|
||
static JsonNode createIntArrayJsonNode(Map<String, List<Integer>> content) { | ||
var jsonNode = objectMapper.createObjectNode(); | ||
for (var entry : content.entrySet()) { | ||
var arrayNode = jsonNode.putArray(entry.getKey()); | ||
entry.getValue().forEach(arrayNode::add); | ||
} | ||
return jsonNode; | ||
} | ||
|
||
public static Benchmark createBenchmark() { | ||
var connections = new ArrayList<Connection>(); | ||
connections.add(createConnection("connection1")); | ||
connections.add(createConnection("connection2")); | ||
var spec = new BenchmarkSpec(5, "workload", connections); | ||
var benchmark = new Benchmark(); | ||
benchmark.setSpec(spec); | ||
return benchmark; | ||
} | ||
|
||
public static Connection createConnection(String connectionName) { | ||
Map<String, JsonNode> patternConfig = Map.of("maxAttempts", objectMapper.valueToTree(List.of(1, 2, 3)), "backoffLimit", objectMapper.valueToTree(List.of(1000, 2000, 3000))); | ||
var source = new Source("api-gateway", patternConfig); | ||
var delay = new DelayFault(1000); | ||
var fault = new BenchmarkFaultTemplate(asList(10), delay); | ||
var target = new Target("vets-service", fault); | ||
return new Connection(connectionName, source, target); | ||
} | ||
|
||
public static Workload createWorkload(List<Integer> users) { | ||
var workload = new Workload(); | ||
workload.setMetadata(new ObjectMetaBuilder().withName("workload").build()); | ||
workload.setSpec(new WorkloadSpec(users, 100, null, null)); | ||
return workload; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/test/java/br/unifor/ppgia/resiliencebench/resources/benchmark/BenchmarkE2ETest.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,42 @@ | ||
package br.unifor.ppgia.resiliencebench.resources.benchmark; | ||
|
||
import br.unifor.ppgia.resiliencebench.BenchmarkReconciler; | ||
import br.unifor.ppgia.resiliencebench.ResilienceServiceReconciler; | ||
import br.unifor.ppgia.resiliencebench.resources.TestDataGenerator; | ||
import br.unifor.ppgia.resiliencebench.resources.scenario.Scenario; | ||
import br.unifor.ppgia.resiliencebench.resources.workload.Workload; | ||
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; | ||
import io.javaoperatorsdk.operator.junit.AbstractOperatorExtension; | ||
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import java.util.List; | ||
|
||
public class BenchmarkE2ETest { | ||
|
||
@RegisterExtension | ||
static AbstractOperatorExtension operator = LocallyRunOperatorExtension.builder() | ||
.waitForNamespaceDeletion(true) | ||
.oneNamespacePerClass(true) | ||
.withReconciler(new ResilienceServiceReconciler()) | ||
.withReconciler(new BenchmarkReconciler()) | ||
.build(); | ||
|
||
@Test | ||
public void creationTest() { | ||
var workload = TestDataGenerator.createWorkload(List.of(10, 20, 30)); | ||
operator.resources(Workload.class).resource(workload).create(); | ||
var benchmark = TestDataGenerator.createBenchmark(); | ||
var newSpec = new BenchmarkSpec(5, workload.getMetadata().getName(), benchmark.getSpec().getConnections()); | ||
benchmark.setSpec(newSpec); | ||
benchmark.setMetadata(new ObjectMetaBuilder().withName("benchmark-test").build()); | ||
var client = operator.resources(Benchmark.class); | ||
var created = client.resource(benchmark).create(); | ||
Assertions.assertNotNull(created); | ||
Assertions.assertEquals(5, created.getSpec().getRounds()); | ||
Assertions.assertEquals("workload", created.getSpec().getWorkload()); | ||
operator.resources(Scenario.class).resources().toList().forEach(System.out::println); | ||
} | ||
} |