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

Commit

Permalink
scheduler synchronize rest api issue: when policy is updated without … (
Browse files Browse the repository at this point in the history
#366)

* scheduler synchronize rest api issue: when policy is updated without schedule, the old schedules do not deleted.

[#159327430]

* update per comments
  • Loading branch information
qibobo authored and boyang9527 committed Aug 2, 2018
1 parent 35f309c commit daef4aa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
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);
updateCount++;
}
}

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, 1, 0)));

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

0 comments on commit daef4aa

Please sign in to comment.