forked from apache/helix
-
Notifications
You must be signed in to change notification settings - Fork 11
Add TestInstanceOperationMisc with independent tests #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
proud-parselmouth
wants to merge
3
commits into
dev
Choose a base branch
from
anubagar/TestInstanceOperationMisc
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
276 changes: 276 additions & 0 deletions
276
...core/src/test/java/org/apache/helix/integration/rebalancer/TestInstanceOperationMisc.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,276 @@ | ||
| package org.apache.helix.integration.rebalancer; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Date; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.helix.HelixException; | ||
| import org.apache.helix.constants.InstanceConstants; | ||
| import org.apache.helix.controller.rebalancer.strategy.CrushEdRebalanceStrategy; | ||
| import org.apache.helix.integration.manager.MockParticipantManager; | ||
| import org.apache.helix.model.ExternalView; | ||
| import org.apache.helix.model.IdealState; | ||
| import org.apache.helix.model.InstanceConfig; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.Test; | ||
|
|
||
|
|
||
| public class TestInstanceOperationMisc extends TestInstanceOperationBase { | ||
|
|
||
| @Test(expectedExceptions = HelixException.class) | ||
| public void testUnsetInstanceOperationOnSwapInWhenSwapping() throws Exception { | ||
| System.out.println( | ||
| "START TestInstanceOperationMisc.testUnsetInstanceOperationOnSwapInWhenSwapping() at " | ||
| + new Date(System.currentTimeMillis())); | ||
|
|
||
| enabledTopologyAwareRebalance(); | ||
|
|
||
| String instanceToSwapOutName = _participants.get(0).getInstanceName(); | ||
| InstanceConfig instanceToSwapOutInstanceConfig = _gSetupTool.getClusterManagementTool() | ||
| .getInstanceConfig(CLUSTER_NAME, instanceToSwapOutName); | ||
|
|
||
| String instanceToSwapInName = PARTICIPANT_PREFIX + "_" + _nextStartPort.get(); | ||
| addParticipant(instanceToSwapInName, instanceToSwapOutInstanceConfig.getLogicalId(LOGICAL_ID), | ||
| instanceToSwapOutInstanceConfig.getDomainAsMap().get(ZONE), | ||
| InstanceConstants.InstanceOperation.SWAP_IN, -1); | ||
|
|
||
| Assert.assertTrue(_bestPossibleClusterVerifier.verifyByPolling()); | ||
|
|
||
| // Should throw HelixException: cannot ENABLE a SWAP_IN instance while | ||
| // another instance with the same logicalId is still active. | ||
| _gSetupTool.getClusterManagementTool() | ||
| .setInstanceOperation(CLUSTER_NAME, instanceToSwapInName, | ||
| InstanceConstants.InstanceOperation.ENABLE); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNodeSwapAddSwapInFirst() throws Exception { | ||
| System.out.println( | ||
| "START TestInstanceOperationMisc.testNodeSwapAddSwapInFirst() at " + new Date( | ||
| System.currentTimeMillis())); | ||
|
|
||
| enabledTopologyAwareRebalance(); | ||
|
|
||
| String instanceToSwapOutName = _participants.get(0).getInstanceName(); | ||
| InstanceConfig instanceToSwapOutInstanceConfig = _gSetupTool.getClusterManagementTool() | ||
| .getInstanceConfig(CLUSTER_NAME, instanceToSwapOutName); | ||
|
|
||
| String instanceToSwapInName = PARTICIPANT_PREFIX + "_" + _nextStartPort.get(); | ||
| addParticipant(instanceToSwapInName, instanceToSwapOutInstanceConfig.getLogicalId(LOGICAL_ID), | ||
| instanceToSwapOutInstanceConfig.getDomainAsMap().get(ZONE), | ||
| InstanceConstants.InstanceOperation.SWAP_IN, -1); | ||
|
|
||
| Assert.assertTrue(_bestPossibleClusterVerifier.verifyByPolling()); | ||
| } | ||
|
|
||
| @Test(expectedExceptions = HelixException.class) | ||
| public void testSwapEvacuateAddRemoveEvacuate() throws Exception { | ||
| System.out.println( | ||
| "START TestInstanceOperationMisc.testSwapEvacuateAddRemoveEvacuate() at " + new Date( | ||
| System.currentTimeMillis())); | ||
|
|
||
| enabledTopologyAwareRebalance(); | ||
|
|
||
| String instanceToSwapOutName = _participants.get(0).getInstanceName(); | ||
| InstanceConfig instanceToSwapOutInstanceConfig = _gSetupTool.getClusterManagementTool() | ||
| .getInstanceConfig(CLUSTER_NAME, instanceToSwapOutName); | ||
| _gSetupTool.getClusterManagementTool().setInstanceOperation(CLUSTER_NAME, | ||
| instanceToSwapOutName, InstanceConstants.InstanceOperation.EVACUATE); | ||
|
|
||
| String instanceToSwapInName = PARTICIPANT_PREFIX + "_" + _nextStartPort.get(); | ||
| addParticipant(instanceToSwapInName, instanceToSwapOutInstanceConfig.getLogicalId(LOGICAL_ID), | ||
| instanceToSwapOutInstanceConfig.getDomainAsMap().get(ZONE), | ||
| InstanceConstants.InstanceOperation.ENABLE, -1); | ||
|
|
||
| // Should throw HelixException: cannot remove EVACUATE while an ENABLE instance | ||
| // with the same logicalId exists. | ||
| _gSetupTool.getClusterManagementTool() | ||
| .setInstanceOperation(CLUSTER_NAME, instanceToSwapOutName, | ||
| InstanceConstants.InstanceOperation.ENABLE); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUnknownDoesNotTriggerRebalance() throws Exception { | ||
| System.out.println( | ||
| "START TestInstanceOperationMisc.testUnknownDoesNotTriggerRebalance() at " + new Date( | ||
| System.currentTimeMillis())); | ||
|
|
||
| enabledTopologyAwareRebalance(); | ||
|
|
||
| Map<String, IdealState> idealStatesBefore = getISs(); | ||
|
|
||
| String instanceToAdd = PARTICIPANT_PREFIX + "_" + _nextStartPort.get(); | ||
| addParticipant(instanceToAdd, "foo", "bar", | ||
| InstanceConstants.InstanceOperation.UNKNOWN, -1); | ||
| List<MockParticipantManager> testParticipants = new ArrayList<>(); | ||
| testParticipants.add(_participants.get(_participants.size() - 1)); | ||
| Assert.assertTrue(_clusterVerifier.verifyByPolling()); | ||
|
|
||
| Assert.assertEquals(idealStatesBefore, getISs()); | ||
|
|
||
| String instanceToAdd2 = PARTICIPANT_PREFIX + "_" + _nextStartPort.get(); | ||
| InstanceConfig swapOutInstanceConfig = _gSetupTool.getClusterManagementTool() | ||
| .getInstanceConfig(CLUSTER_NAME, _participants.get(0).getInstanceName()); | ||
| addParticipant(instanceToAdd2, swapOutInstanceConfig.getLogicalId(LOGICAL_ID), | ||
| swapOutInstanceConfig.getDomainAsMap().get(ZONE), | ||
| InstanceConstants.InstanceOperation.UNKNOWN, -1); | ||
| testParticipants.add(_participants.get(_participants.size() - 1)); | ||
| Assert.assertTrue(_clusterVerifier.verifyByPolling()); | ||
| Assert.assertEquals(idealStatesBefore, getISs()); | ||
|
|
||
| for (MockParticipantManager participant : testParticipants) { | ||
| participant.syncStop(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testEvacuationWithOfflineInstancesInCluster() throws Exception { | ||
| System.out.println( | ||
| "START TestInstanceOperationMisc.testEvacuationWithOfflineInstancesInCluster() at " | ||
| + new Date(System.currentTimeMillis())); | ||
|
|
||
| enabledTopologyAwareRebalance(); | ||
|
|
||
| _participants.get(1).syncStop(); | ||
| _participants.get(2).syncStop(); | ||
|
|
||
| String evacuateInstanceName = _participants.get(_participants.size() - 2).getInstanceName(); | ||
| _gSetupTool.getClusterManagementTool().setInstanceOperation(CLUSTER_NAME, | ||
| evacuateInstanceName, InstanceConstants.InstanceOperation.EVACUATE); | ||
|
|
||
| verifier(() -> { | ||
| Map<String, ExternalView> assignment = getEVs(); | ||
| for (String resource : _allDBs) { | ||
| ExternalView ev = assignment.get(resource); | ||
| for (String partition : ev.getPartitionSet()) { | ||
| long activeReplicaCount = ev.getStateMap(partition).values().stream() | ||
| .filter(ACCEPTABLE_STATE_SET::contains).count(); | ||
| if (activeReplicaCount < REPLICA - 1 | ||
| || (ev.getStateMap(partition).containsKey(evacuateInstanceName) | ||
| && TOP_STATE_SET.contains( | ||
| ev.getStateMap(partition).get(evacuateInstanceName)))) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| }, 30000); | ||
|
|
||
| Map<String, ExternalView> assignment = getEVs(); | ||
| for (String resource : _allDBs) { | ||
| validateAssignmentInEv(assignment.get(resource), REPLICA - 1); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testEvacuateWithDisabledPartition() throws Exception { | ||
| System.out.println( | ||
| "START TestInstanceOperationMisc.testEvacuateWithDisabledPartition() at " + new Date( | ||
| System.currentTimeMillis())); | ||
|
|
||
| enabledTopologyAwareRebalance(); | ||
|
|
||
| StateTransitionCountStateModelFactory stateTransitionCountStateModelFactory = | ||
| new StateTransitionCountStateModelFactory(); | ||
| String testCrushedDBName = "testEvacuateWithDisabledPartition_CRUSHED_DB0"; | ||
| String testWagedDBName = "testEvacuateWithDisabledPartition_WAGED_DB1"; | ||
| String toDisableThenEvacuateInstanceName = "disable_then_evacuate_host"; | ||
| addParticipant(toDisableThenEvacuateInstanceName, stateTransitionCountStateModelFactory); | ||
| MockParticipantManager toDisableThenEvacuateParticipant = | ||
| _participants.get(_participants.size() - 1); | ||
|
|
||
| List<String> testResources = Arrays.asList(testCrushedDBName, testWagedDBName); | ||
| createResourceWithDelayedRebalance(CLUSTER_NAME, testCrushedDBName, "MasterSlave", | ||
| PARTITIONS, REPLICA, REPLICA - 1, 200000, | ||
| CrushEdRebalanceStrategy.class.getName()); | ||
| _allDBs.add(testCrushedDBName); | ||
| createResourceWithWagedRebalance(CLUSTER_NAME, testWagedDBName, "MasterSlave", PARTITIONS, | ||
| REPLICA, REPLICA - 1); | ||
| _allDBs.add(testWagedDBName); | ||
|
|
||
| Assert.assertTrue(_clusterVerifier.verifyByPolling()); | ||
| int upwardSTCountBeforeDisableThenEvacuate = | ||
| stateTransitionCountStateModelFactory.getUpwardStateTransitionCounter(); | ||
| int downwardSTCountBeforeDisableThenEvacuate = | ||
| stateTransitionCountStateModelFactory.getDownwardStateTransitionCounter(); | ||
|
|
||
| InstanceConfig instanceConfig = _gSetupTool.getClusterManagementTool() | ||
| .getInstanceConfig(CLUSTER_NAME, toDisableThenEvacuateInstanceName); | ||
| instanceConfig.setInstanceEnabledForPartition( | ||
| InstanceConstants.ALL_RESOURCES_DISABLED_PARTITION_KEY, "", false); | ||
| _gSetupTool.getClusterManagementTool() | ||
| .setInstanceConfig(CLUSTER_NAME, toDisableThenEvacuateInstanceName, instanceConfig); | ||
| Assert.assertTrue(_clusterVerifier.verifyByPolling()); | ||
|
|
||
| verifier(() -> { | ||
| for (String resource : testResources) { | ||
| ExternalView ev = _gSetupTool.getClusterManagementTool() | ||
| .getResourceExternalView(CLUSTER_NAME, resource); | ||
| for (String partition : ev.getPartitionSet()) { | ||
| if (ev.getStateMap(partition).containsKey(toDisableThenEvacuateInstanceName) | ||
| && !ev.getStateMap(partition).get(toDisableThenEvacuateInstanceName) | ||
| .equals("OFFLINE")) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| }, 5000); | ||
|
|
||
| Assert.assertEquals( | ||
| stateTransitionCountStateModelFactory.getUpwardStateTransitionCounter(), | ||
| upwardSTCountBeforeDisableThenEvacuate, | ||
| "Upward state transitions should not have been received"); | ||
| Assert.assertTrue( | ||
| stateTransitionCountStateModelFactory.getDownwardStateTransitionCounter() | ||
| > downwardSTCountBeforeDisableThenEvacuate, | ||
| "Should have received downward state transitions"); | ||
|
|
||
| _gSetupTool.getClusterManagementTool().setInstanceOperation(CLUSTER_NAME, | ||
| toDisableThenEvacuateInstanceName, InstanceConstants.InstanceOperation.EVACUATE); | ||
|
|
||
| verifier(() -> _admin.isEvacuateFinished(CLUSTER_NAME, toDisableThenEvacuateInstanceName), | ||
| 30000); | ||
| int downwardSTCountAfterEvacuateComplete = | ||
| stateTransitionCountStateModelFactory.getDownwardStateTransitionCounter(); | ||
|
|
||
| Assert.assertEquals( | ||
| stateTransitionCountStateModelFactory.getUpwardStateTransitionCounter(), | ||
| upwardSTCountBeforeDisableThenEvacuate, | ||
| "Upward state transitions should not have been received"); | ||
|
|
||
| instanceConfig = _gSetupTool.getClusterManagementTool() | ||
| .getInstanceConfig(CLUSTER_NAME, toDisableThenEvacuateInstanceName); | ||
| instanceConfig.setInstanceEnabledForPartition( | ||
| InstanceConstants.ALL_RESOURCES_DISABLED_PARTITION_KEY, "", true); | ||
| _gSetupTool.getClusterManagementTool() | ||
| .setInstanceConfig(CLUSTER_NAME, toDisableThenEvacuateInstanceName, instanceConfig); | ||
| Assert.assertTrue(_clusterVerifier.verifyByPolling()); | ||
|
|
||
| Assert.assertEquals( | ||
| stateTransitionCountStateModelFactory.getUpwardStateTransitionCounter(), | ||
| upwardSTCountBeforeDisableThenEvacuate, | ||
| "Upward state transitions should not have been received"); | ||
|
|
||
| instanceConfig = _gSetupTool.getClusterManagementTool() | ||
| .getInstanceConfig(CLUSTER_NAME, toDisableThenEvacuateInstanceName); | ||
| instanceConfig.setInstanceEnabledForPartition( | ||
| InstanceConstants.ALL_RESOURCES_DISABLED_PARTITION_KEY, "", false); | ||
| _gSetupTool.getClusterManagementTool() | ||
| .setInstanceConfig(CLUSTER_NAME, toDisableThenEvacuateInstanceName, instanceConfig); | ||
| Assert.assertTrue(_clusterVerifier.verifyByPolling()); | ||
|
|
||
| Assert.assertEquals( | ||
| stateTransitionCountStateModelFactory.getUpwardStateTransitionCounter(), | ||
| upwardSTCountBeforeDisableThenEvacuate, | ||
| "Upward state transitions should not have been received"); | ||
| Assert.assertEquals( | ||
| stateTransitionCountStateModelFactory.getDownwardStateTransitionCounter(), | ||
| downwardSTCountAfterEvacuateComplete, | ||
| "Downward state transitions should not have been received"); | ||
|
|
||
| toDisableThenEvacuateParticipant.syncStop(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this entire thing is essentially validateAssignmentInEv() in the TestInstanceOperationBase. You can directly use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abstracted out the acceptable state set check and top state set check, and added validateAssignmentInEv below