Skip to content

Commit

Permalink
for status override set and delete, do not update the dirtyTimestamp …
Browse files Browse the repository at this point in the history
…unless

specified to do so.
  • Loading branch information
qiangdavidliu committed Sep 12, 2017
1 parent 91a30fa commit 28fcb79
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {

idea {
project {
languageLevel = '1.7'
languageLevel = '1.8'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,14 @@ public boolean statusUpdate(String appName, String id,
// replica start up
info.setOverriddenStatus(newStatus);
long replicaDirtyTimestamp = 0;
info.setStatusWithoutDirty(newStatus);
if (lastDirtyTimestamp != null) {
replicaDirtyTimestamp = Long.valueOf(lastDirtyTimestamp);
}
// If the replication's dirty timestamp is more than the existing one, just update
// it to the replica's.
if (replicaDirtyTimestamp > info.getLastDirtyTimestamp()) {
info.setLastDirtyTimestamp(replicaDirtyTimestamp);
info.setStatusWithoutDirty(newStatus);
} else {
info.setStatus(newStatus);
}
info.setActionType(ActionType.MODIFIED);
recentlyChangedQueue.add(new RecentlyChangedItem(lease));
Expand Down Expand Up @@ -549,7 +547,7 @@ public boolean deleteStatusOverride(String appName, String id,
InstanceStatus currentOverride = overriddenInstanceStatusMap.remove(id);
if (currentOverride != null && info != null) {
info.setOverriddenStatus(InstanceStatus.UNKNOWN);
info.setStatus(newStatus);
info.setStatusWithoutDirty(newStatus);
long replicaDirtyTimestamp = 0;
if (lastDirtyTimestamp != null) {
replicaDirtyTimestamp = Long.valueOf(lastDirtyTimestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,34 @@ public void testGetAppsFromBothRegions() throws Exception {

@Test
public void testStatusOverrideSetAndRemoval() throws Exception {
InstanceInfo seed = createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME);

// Regular registration first
InstanceInfo myInstance = createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME);
registerInstanceLocally(myInstance);
verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.UP);
InstanceInfo myInstance1 = new InstanceInfo(seed);
registerInstanceLocally(myInstance1);
verifyLocalInstanceStatus(myInstance1.getId(), InstanceStatus.UP);

// Override status
boolean statusResult = registry.statusUpdate(LOCAL_REGION_APP_NAME, myInstance.getId(), InstanceStatus.OUT_OF_SERVICE, "0", false);
boolean statusResult = registry.statusUpdate(LOCAL_REGION_APP_NAME, seed.getId(), InstanceStatus.OUT_OF_SERVICE, "0", false);
assertThat("Couldn't override instance status", statusResult, is(true));
verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.OUT_OF_SERVICE);
verifyLocalInstanceStatus(seed.getId(), InstanceStatus.OUT_OF_SERVICE);

// Register again with status UP (this is what health check is doing)
registry.register(createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME), 10000000, false);
verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.OUT_OF_SERVICE);
// Register again with status UP to verify that the override is still in place even if the dirtytimestamp is higher
InstanceInfo myInstance2 = new InstanceInfo(seed); // clone to avoid object state in this test
myInstance2.setLastDirtyTimestamp(seed.getLastDirtyTimestamp() + 1);
registry.register(myInstance2, 10000000, false);
verifyLocalInstanceStatus(seed.getId(), InstanceStatus.OUT_OF_SERVICE);

// Now remove override
statusResult = registry.deleteStatusOverride(LOCAL_REGION_APP_NAME, myInstance.getId(), InstanceStatus.DOWN, "0", false);
statusResult = registry.deleteStatusOverride(LOCAL_REGION_APP_NAME, seed.getId(), InstanceStatus.DOWN, "0", false);
assertThat("Couldn't remove status override", statusResult, is(true));
verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.DOWN);
verifyLocalInstanceStatus(seed.getId(), InstanceStatus.DOWN);

// Register again with status UP (this is what health check is doing)
registry.register(createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME), 10000000, false);
verifyLocalInstanceStatus(myInstance.getId(), InstanceStatus.UP);
// Register again with status UP after the override deletion, keeping myInstance2's dirtyTimestamp (== no client side change)
InstanceInfo myInstance3 = new InstanceInfo(seed); // clone to avoid object state in this test
myInstance3.setLastDirtyTimestamp(seed.getLastDirtyTimestamp() + 1); // clone to avoid object state in this test
registry.register(myInstance3, 10000000, false);
verifyLocalInstanceStatus(seed.getId(), InstanceStatus.UP);
}

@Test
Expand Down

0 comments on commit 28fcb79

Please sign in to comment.