+ @Test
+ void testEiJobDatabase() throws Exception {
+ putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
+ putEiJob(TYPE_ID, "jobId1");
+ putEiJob(TYPE_ID, "jobId2");
+
+ assertThat(this.infoJobs.size()).isEqualTo(2);
+
+ {
+ InfoJob savedJob = this.infoJobs.getJob("jobId1");
+ // Restore the jobs
+ InfoJobs jobs = new InfoJobs(this.applicationConfig, this.producerCallbacks);
+ jobs.restoreJobsFromDatabase();
+ assertThat(jobs.size()).isEqualTo(2);
+ InfoJob restoredJob = jobs.getJob("jobId1");
+ assertThat(restoredJob.getId()).isEqualTo("jobId1");
+ assertThat(restoredJob.getLastUpdated()).isEqualTo(savedJob.getLastUpdated());
+
+ jobs.remove("jobId1", this.infoProducers);
+ jobs.remove("jobId2", this.infoProducers);
+ }
+ {
+ // Restore the jobs, no jobs in database
+ InfoJobs jobs = new InfoJobs(this.applicationConfig, this.producerCallbacks);
+ jobs.restoreJobsFromDatabase();
+ assertThat(jobs.size()).isZero();
+ }
+ logger.warn("Test removing a job when the db file is gone");
+ this.infoJobs.remove("jobId1", this.infoProducers);
+ assertThat(this.infoJobs.size()).isEqualTo(1);
+
+ ProducerSimulatorController.TestResults simulatorResults = this.producerSimulator.getTestResults();
+ await().untilAsserted(() -> assertThat(simulatorResults.jobsStopped.size()).isEqualTo(3));
+ }
+
+ @Test
+ void testEiTypesDatabase() throws Exception {
+ putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
+
+ assertThat(this.infoTypes.size()).isEqualTo(1);
+
+ {
+ // Restore the types
+ InfoTypes types = new InfoTypes(this.applicationConfig);
+ types.restoreTypesFromDatabase();
+ assertThat(types.size()).isEqualTo(1);
+
+ }
+ {
+ // Restore the jobs, no jobs in database
+ InfoTypes types = new InfoTypes(this.applicationConfig);
+ types.clear();
+ types.restoreTypesFromDatabase();
+ assertThat(types.size()).isZero();
+ }
+ logger.warn("Test removing a job when the db file is gone");
+ this.infoTypes.remove(this.infoTypes.getType(TYPE_ID));
+ assertThat(this.infoJobs.size()).isZero();
+ }
+
+ private void deleteEiProducer(String infoProducerId) {
+ String url = ProducerConsts.API_ROOT + "/info-producers/" + infoProducerId;
+ restClient().deleteForEntity(url).block();
+ }
+
+ private void verifyJobStatus(String jobId, String expStatus) {
+ String url = A1eConsts.API_ROOT + "/eijobs/" + jobId + "/status";
+ String rsp = restClient().get(url).block();
+ assertThat(rsp).contains(expStatus);
+ }
+
+ private void assertProducerOpState(String producerId,
+ ProducerStatusInfo.OperationalState expectedOperationalState) {
+ String statusUrl = ProducerConsts.API_ROOT + "/info-producers/" + producerId + "/status";
+ ResponseEntity<String> resp = restClient().getForEntity(statusUrl).block();
+ ProducerStatusInfo statusInfo = gson.fromJson(resp.getBody(), ProducerStatusInfo.class);
+ assertThat(statusInfo.opState).isEqualTo(expectedOperationalState);
+ }
+
+ ProducerInfoTypeInfo producerEiTypeRegistrationInfo(String typeId)
+ throws JsonMappingException, JsonProcessingException {
+ return new ProducerInfoTypeInfo(jsonSchemaObject());