pkuwm commented on a change in pull request #514: The WAGED rebalancer returns the previously calculated assignment on calculation failure URL: https://github.com/apache/helix/pull/514#discussion_r336821407
########## File path: helix-core/src/test/java/org/apache/helix/controller/rebalancer/waged/TestWagedRebalancer.java ########## @@ -289,24 +297,44 @@ public void testInvalidRebalancerStatus() throws IOException { @Test(dependsOnMethods = "testRebalance") public void testAlgorithmException() throws IOException, HelixRebalanceException { - RebalanceAlgorithm badAlgorithm = Mockito.mock(RebalanceAlgorithm.class); - when(badAlgorithm.calculate(any())).thenThrow(new HelixRebalanceException("Algorithm fails.", - HelixRebalanceException.Type.FAILED_TO_CALCULATE)); - _metadataStore.clearMetadataStore(); WagedRebalancer rebalancer = - new WagedRebalancer(_metadataStore, badAlgorithm, new DelayedAutoRebalancer()); + new WagedRebalancer(_metadataStore, _algorithm, new DelayedAutoRebalancer()); ResourceControllerDataProvider clusterData = setupClusterDataCache(); - Map<String, Resource> resourceMap = clusterData.getIdealStates().keySet().stream().collect( - Collectors.toMap(resourceName -> resourceName, resourceName -> new Resource(resourceName))); + Map<String, Resource> resourceMap = clusterData.getIdealStates().entrySet().stream() + .collect(Collectors.toMap(entry -> entry.getKey(), entry -> { + Resource resource = new Resource(entry.getKey()); + entry.getValue().getPartitionSet().stream() + .forEach(partition -> resource.addPartition(partition)); + return resource; + })); + // Rebalance with normal configuration. So the assignment will be persisted in the metadata store. + Map<String, IdealState> result = + rebalancer.computeNewIdealStates(clusterData, resourceMap, new CurrentStateOutput()); + + // Recreate a rebalance with the same metadata store but bad algorithm instance. + RebalanceAlgorithm badAlgorithm = Mockito.mock(RebalanceAlgorithm.class); + when(badAlgorithm.calculate(any())).thenThrow(new HelixRebalanceException("Algorithm fails.", + HelixRebalanceException.Type.FAILED_TO_CALCULATE)); + rebalancer = new WagedRebalancer(_metadataStore, badAlgorithm, new DelayedAutoRebalancer()); + + // Calculation will fail try { - rebalancer.computeNewIdealStates(clusterData, resourceMap, new CurrentStateOutput()); + rebalancer.computeBestPossibleStates(clusterData, resourceMap, new CurrentStateOutput()); Assert.fail("Rebalance shall fail."); } catch (HelixRebalanceException ex) { Assert.assertEquals(ex.getFailureType(), HelixRebalanceException.Type.FAILED_TO_CALCULATE); Assert.assertEquals(ex.getMessage(), "Algorithm fails. Failure Type: FAILED_TO_CALCULATE"); } + // But if call with the public method computeNewIdealStates(), the rebalance will return with the previous rebalance result. Review comment: Exceeding 100 chars. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org For additional commands, e-mail: reviews-h...@helix.apache.org