Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

scheduler synchronize rest api issue: when policy is updated without … #366

Merged
merged 2 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,10 @@ public SynchronizeResult synchronizeSchedules(){
updateCount++;
continue;
}
}else{
// there is no schedule in the new policy, so the old schedules of this app should be deleted.
toDeletedAppIds.add(appIdInPolicy);
deleteCount++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still update, not deleteCount

}
}

Expand All @@ -832,6 +836,7 @@ public SynchronizeResult synchronizeSchedules(){
}
for(String appId : toDeletedAppIds){
this.deleteSchedules(appId);

}

for(ApplicationSchedules schedule : toCreateScheduleList){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ public void testSynchronizeSchedules_with_no_policy_and_existed_schedules() {
}

@Test
public void testSynchronizeSchedules_with_both_policy_and_schedules_existed_and_guid_are_different() throws JsonProcessingException {
public void testSynchronizeSchedules_with_both_policy_with_schedules_and_schedules_existed_and_guid_are_different() throws JsonProcessingException {
String appId = TestDataSetupHelper.generateAppIds(1)[0];
String guid = TestDataSetupHelper.generateGuid();
String anotherGuid = TestDataSetupHelper.generateGuid();
Expand Down Expand Up @@ -784,6 +784,42 @@ public void testSynchronizeSchedules_with_both_policy_and_schedules_existed_and_
noOfDOWRecurringSchedules);
}

@Test
public void testSynchronizeSchedules_with_both_policy_without_schedule_and_schedules_existed() throws JsonProcessingException {
String appId = TestDataSetupHelper.generateAppIds(1)[0];
String guid = TestDataSetupHelper.generateGuid();
String anotherGuid = TestDataSetupHelper.generateGuid();
int noOfSpecificDateSchedules = 3;
int noOfDOMRecurringSchedules = 3;
int noOfDOWRecurringSchedules = 3;

List<RecurringScheduleEntity> recurringEntities = new RecurringScheduleEntitiesBuilder(noOfDOMRecurringSchedules, noOfDOWRecurringSchedules).setAppId(appId).setGuid(guid).setTimeZone("timeZone").setDefaultInstanceMinCount(1).setDefaultInstanceMaxCount(5).setScheduleId().build();
List<SpecificDateScheduleEntity> specificDateEntities = new SpecificDateScheduleEntitiesBuilder(noOfSpecificDateSchedules).setAppid(appId).setGuid(guid).setTimeZone("timeZone").setDefaultInstanceMinCount(1).setDefaultInstanceMaxCount(5).setScheduleId().build();
Schedules schedules = new ScheduleBuilder().setSpecificDate(specificDateEntities).setRecurringSchedule(recurringEntities).setTimeZone("tomeZone").build();

ApplicationSchedules anotherApplicationSchedule = new ApplicationPolicyBuilder(1,5).setSchedules(null).build();

String[] appIdAndGuid = {appId, guid};

List<PolicyJsonEntity> policyJsonList = new ArrayList<PolicyJsonEntity>() {
{
add(new PolicyJsonEntityBuilder(appId, anotherGuid, anotherApplicationSchedule).build());
}
};
when(policyJsonDao.getAllPolicies()).thenReturn(policyJsonList);
when(specificDateScheduleDao.getDistinctAppIdAndGuidList()).thenReturn(new ArrayList(){{add(appIdAndGuid);}});
when(recurringScheduleDao.getDistinctAppIdAndGuidList()).thenReturn(new ArrayList(){{add(appIdAndGuid);}});
when(specificDateScheduleDao.findAllSpecificDateSchedulesByAppId(appId))
.thenReturn(schedules.getSpecificDate());
when(recurringScheduleDao.findAllRecurringSchedulesByAppId(appId)).thenReturn(schedules.getRecurringSchedule());

SynchronizeResult result = scheduleManager.synchronizeSchedules();

assertThat("It should update the shedules",result, is(new SynchronizeResult(0, 0, 1)));

this.assertDeleteSchedules(schedules);
}

@Test
public void testSynchronizeSchedules_with_both_policy_and_schedules_existed_and_guid_are_the_same() throws JsonProcessingException {
String appId = TestDataSetupHelper.generateAppIds(1)[0];
Expand Down