X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=enrichment-coordinator-service%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fenrichment%2FApplicationTest.java;h=b62a9653432e81f61f049020ef4a5f41be6f17b7;hb=1da5c887797ae8cb715ad0b16b388aae18cda948;hp=9ef2590f7baf288b280f066f33b5e02fa8f3e5e2;hpb=b65d77a754c356931b82c8edf6b29759d294ea51;p=nonrtric.git diff --git a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java index 9ef2590f..b62a9653 100644 --- a/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java +++ b/enrichment-coordinator-service/src/test/java/org/oransc/enrichment/ApplicationTest.java @@ -33,6 +33,7 @@ import com.google.gson.JsonParser; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; +import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Collection; @@ -44,8 +45,10 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.oransc.enrichment.clients.AsyncRestClient; import org.oransc.enrichment.clients.AsyncRestClientFactory; import org.oransc.enrichment.configuration.ApplicationConfig; +import org.oransc.enrichment.configuration.ImmutableHttpProxyConfig; import org.oransc.enrichment.configuration.ImmutableWebClientConfig; import org.oransc.enrichment.configuration.WebClientConfig; +import org.oransc.enrichment.configuration.WebClientConfig.HttpProxyConfig; import org.oransc.enrichment.controller.ConsumerSimulatorController; import org.oransc.enrichment.controller.ProducerSimulatorController; import org.oransc.enrichment.controllers.consumer.ConsumerConsts; @@ -64,6 +67,8 @@ import org.oransc.enrichment.repository.EiProducers; import org.oransc.enrichment.repository.EiType; import org.oransc.enrichment.repository.EiTypes; import org.oransc.enrichment.tasks.ProducerSupervision; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -91,6 +96,8 @@ import reactor.test.StepVerifier; "app.webclient.trust-store=./config/truststore.jks", // "app.vardata-directory=./target"}) class ApplicationTest { + private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private final String EI_TYPE_ID = "typeId"; private final String EI_PRODUCER_ID = "producerId"; private final String EI_JOB_PROPERTY = "\"property1\""; @@ -156,8 +163,10 @@ class ApplicationTest { ResponseEntity resp = restClient().getForEntity(url).block(); assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK); - String indented = (new JSONObject(resp.getBody())).toString(4); - try (PrintStream out = new PrintStream(new FileOutputStream("docs/api.json"))) { + JSONObject jsonObj = new JSONObject(resp.getBody()); + jsonObj.remove("host"); + String indented = jsonObj.toString(4); + try (PrintStream out = new PrintStream(new FileOutputStream("api/ecs-api.json"))) { out.print(indented); } } @@ -286,12 +295,14 @@ class ApplicationTest { ProducerJobInfo request = simulatorResults.jobsStarted.get(0); assertThat(request.id).isEqualTo("jobId"); - assertThat(simulatorResults.noOfRejectedCreate).isEqualTo(1); + // One retry --> two calls + await().untilAsserted(() -> assertThat(simulatorResults.noOfRejectedCreate).isEqualTo(2)); + assertThat(simulatorResults.noOfRejectedCreate).isEqualTo(2); resp = restClient().putForEntity(url, body).block(); assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK); EiJob job = this.eiJobs.getJob("jobId"); - assertThat(job.owner()).isEqualTo("owner"); + assertThat(job.getOwner()).isEqualTo("owner"); } @Test @@ -302,7 +313,9 @@ class ApplicationTest { testErrorCode(restClient().put(url, body), HttpStatus.CONFLICT, "Job not accepted by any producers"); ProducerSimulatorController.TestResults simulatorResults = this.producerSimulator.getTestResults(); - assertThat(simulatorResults.noOfRejectedCreate).isEqualTo(1); + // There is one retry -> 2 calls + await().untilAsserted(() -> assertThat(simulatorResults.noOfRejectedCreate).isEqualTo(2)); + assertThat(simulatorResults.noOfRejectedCreate).isEqualTo(2); } @Test @@ -458,19 +471,46 @@ class ApplicationTest { @Test void testJobStatusNotifications() throws JsonMappingException, JsonProcessingException, ServiceException { + ConsumerSimulatorController.TestResults consumerCalls = this.consumerSimulator.getTestResults(); + ProducerSimulatorController.TestResults producerCalls = this.producerSimulator.getTestResults(); + putEiProducerWithOneType("eiProducerId", EI_TYPE_ID); putEiJob(EI_TYPE_ID, "jobId"); + putEiProducerWithOneType("eiProducerId2", EI_TYPE_ID); + await().untilAsserted(() -> assertThat(producerCalls.jobsStarted.size()).isEqualTo(2)); + deleteEiProducer("eiProducerId2"); + assertThat(this.eiTypes.size()).isEqualTo(1); // The type remains, one producer left deleteEiProducer("eiProducerId"); assertThat(this.eiTypes.size()).isZero(); // The type is gone assertThat(this.eiJobs.size()).isEqualTo(1); // The job remains - ConsumerSimulatorController.TestResults consumerResults = this.consumerSimulator.getTestResults(); - await().untilAsserted(() -> assertThat(consumerResults.status.size()).isEqualTo(1)); - assertThat(consumerResults.status.get(0).state).isEqualTo(ConsumerEiJobStatus.EiJobStatusValues.DISABLED); + await().untilAsserted(() -> assertThat(consumerCalls.status.size()).isEqualTo(1)); + assertThat(consumerCalls.status.get(0).state).isEqualTo(ConsumerEiJobStatus.EiJobStatusValues.DISABLED); putEiProducerWithOneType("eiProducerId", EI_TYPE_ID); - await().untilAsserted(() -> assertThat(consumerResults.status.size()).isEqualTo(2)); - assertThat(consumerResults.status.get(1).state).isEqualTo(ConsumerEiJobStatus.EiJobStatusValues.ENABLED); + await().untilAsserted(() -> assertThat(consumerCalls.status.size()).isEqualTo(2)); + assertThat(consumerCalls.status.get(1).state).isEqualTo(ConsumerEiJobStatus.EiJobStatusValues.ENABLED); + } + + @Test + void testJobStatusNotifications2() throws JsonMappingException, JsonProcessingException, ServiceException { + // Test replacing a producer with new and removed types + + // Create a job + putEiProducerWithOneType(EI_PRODUCER_ID, EI_TYPE_ID); + putEiJob(EI_TYPE_ID, EI_JOB_ID); + + // change the type for the producer, the EI_TYPE_ID is deleted + putEiProducerWithOneType(EI_PRODUCER_ID, "junk"); + verifyJobStatus(EI_JOB_ID, "DISABLED"); + ConsumerSimulatorController.TestResults consumerCalls = this.consumerSimulator.getTestResults(); + await().untilAsserted(() -> assertThat(consumerCalls.status.size()).isEqualTo(1)); + assertThat(consumerCalls.status.get(0).state).isEqualTo(ConsumerEiJobStatus.EiJobStatusValues.DISABLED); + + putEiProducerWithOneType(EI_PRODUCER_ID, EI_TYPE_ID); + verifyJobStatus(EI_JOB_ID, "ENABLED"); + await().untilAsserted(() -> assertThat(consumerCalls.status.size()).isEqualTo(2)); + assertThat(consumerCalls.status.get(1).state).isEqualTo(ConsumerEiJobStatus.EiJobStatusValues.ENABLED); } @Test @@ -496,7 +536,7 @@ class ApplicationTest { { // Create a job putEiProducerWithOneType(EI_PRODUCER_ID, EI_TYPE_ID); - putEiJob(EI_TYPE_ID, "jobId"); + putEiJob(EI_TYPE_ID, EI_JOB_ID); deleteEiProducer(EI_PRODUCER_ID); } @@ -506,13 +546,18 @@ class ApplicationTest { this.producerSupervision.createTask().blockLast(); this.producerSupervision.createTask().blockLast(); + + // Now we have one producer that is disabled, but the job will be enabled until + // the producer/type is removed assertThat(this.eiProducers.size()).isEqualTo(1); assertProducerOpState("simulateProducerError", ProducerStatusInfo.OperationalState.DISABLED); + verifyJobStatus(EI_JOB_ID, "ENABLED"); // After 3 failed checks, the producer and the type shall be deregisterred this.producerSupervision.createTask().blockLast(); assertThat(this.eiProducers.size()).isEqualTo(0); assertThat(this.eiTypes.size()).isEqualTo(0); + verifyJobStatus(EI_JOB_ID, "DISABLED"); // Job disabled status notification shall be received ConsumerSimulatorController.TestResults consumerResults = this.consumerSimulator.getTestResults(); @@ -552,8 +597,8 @@ class ApplicationTest { jobs.restoreJobsFromDatabase(); assertThat(jobs.size()).isEqualTo(0); } - - this.eiJobs.remove("jobId1"); // removing a job when the db file is gone + logger.warn("Test removing a job when the db file is gone"); + this.eiJobs.remove("jobId1"); assertThat(this.eiJobs.size()).isEqualTo(1); } @@ -670,6 +715,10 @@ class ApplicationTest { private AsyncRestClient restClient(boolean useTrustValidation) { WebClientConfig config = this.applicationConfig.getWebClientConfig(); + HttpProxyConfig httpProxyConfig = ImmutableHttpProxyConfig.builder() // + .httpProxyHost("") // + .httpProxyPort(0) // + .build(); config = ImmutableWebClientConfig.builder() // .keyStoreType(config.keyStoreType()) // .keyStorePassword(config.keyStorePassword()) // @@ -678,10 +727,10 @@ class ApplicationTest { .isTrustStoreUsed(useTrustValidation) // .trustStore(config.trustStore()) // .trustStorePassword(config.trustStorePassword()) // - .build(); + .httpProxyConfig(httpProxyConfig).build(); AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config); - return restClientFactory.createRestClient(baseUrl()); + return restClientFactory.createRestClientNoHttpProxy(baseUrl()); } private AsyncRestClient restClient() {