+ @Test
+ void testEiJobDatabase() throws Exception {
+ putEiProducerWithOneType(EI_PRODUCER_ID, EI_TYPE_ID);
+ putEiJob(EI_TYPE_ID, "jobId1");
+ putEiJob(EI_TYPE_ID, "jobId2");
+
+ assertThat(this.eiJobs.size()).isEqualTo(2);
+
+ {
+ EiJob savedJob = this.eiJobs.getJob("jobId1");
+ // Restore the jobs
+ EiJobs jobs = new EiJobs(this.applicationConfig, this.producerCallbacks);
+ jobs.restoreJobsFromDatabase();
+ assertThat(jobs.size()).isEqualTo(2);
+ EiJob restoredJob = jobs.getJob("jobId1");
+ assertThat(restoredJob.getId()).isEqualTo("jobId1");
+ assertThat(restoredJob.getLastUpdated()).isEqualTo(savedJob.getLastUpdated());
+
+ jobs.remove("jobId1", this.eiProducers);
+ jobs.remove("jobId2", this.eiProducers);
+ }
+ {
+ // Restore the jobs, no jobs in database
+ EiJobs jobs = new EiJobs(this.applicationConfig, this.producerCallbacks);
+ jobs.restoreJobsFromDatabase();
+ assertThat(jobs.size()).isEqualTo(0);
+ }
+ logger.warn("Test removing a job when the db file is gone");
+ this.eiJobs.remove("jobId1", this.eiProducers);
+ assertThat(this.eiJobs.size()).isEqualTo(1);
+
+ ProducerSimulatorController.TestResults simulatorResults = this.producerSimulator.getTestResults();
+ await().untilAsserted(() -> assertThat(simulatorResults.jobsStopped.size()).isEqualTo(3));
+ }
+
+ @Test
+ void testEiTypesDatabase() throws Exception {
+ putEiProducerWithOneType(EI_PRODUCER_ID, EI_TYPE_ID);
+
+ assertThat(this.eiTypes.size()).isEqualTo(1);
+
+ {
+ // Restore the types
+ EiTypes types = new EiTypes(this.applicationConfig);
+ types.restoreTypesFromDatabase();
+ assertThat(types.size()).isEqualTo(1);
+
+ }
+ {
+ // Restore the jobs, no jobs in database
+ EiTypes types = new EiTypes(this.applicationConfig);
+ types.clear();
+ types.restoreTypesFromDatabase();
+ assertThat(types.size()).isEqualTo(0);
+ }
+ logger.warn("Test removing a job when the db file is gone");
+ this.eiTypes.remove(this.eiTypes.getType(EI_TYPE_ID));
+ assertThat(this.eiJobs.size()).isEqualTo(0);
+ }
+
+ private void deleteEiProducer(String eiProducerId) {
+ String url = ProducerConsts.API_ROOT + "/eiproducers/" + eiProducerId;
+ restClient().deleteForEntity(url).block();
+ }
+
+ private void verifyJobStatus(String jobId, String expStatus) {
+ String url = ConsumerConsts.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 + "/eiproducers/" + producerId + "/status";
+ ResponseEntity<String> resp = restClient().getForEntity(statusUrl).block();
+ ProducerStatusInfo statusInfo = gson.fromJson(resp.getBody(), ProducerStatusInfo.class);
+ assertThat(statusInfo.opState).isEqualTo(expectedOperationalState);
+ }
+