helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject git commit: [HELIX-109] Review Helix model package, fix failing tests
Date Mon, 09 Sep 2013 17:40:49 GMT
Updated Branches:
  refs/heads/helix-logical-model 5972a44e7 -> cf1afd53f


[HELIX-109] Review Helix model package, fix failing tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/cf1afd53
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/cf1afd53
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/cf1afd53

Branch: refs/heads/helix-logical-model
Commit: cf1afd53f9bc68bf5370e7057a56646b14b35bb0
Parents: 5972a44
Author: zzhang <zzhang5@uci.edu>
Authored: Mon Sep 9 10:40:38 2013 -0700
Committer: zzhang <zzhang5@uci.edu>
Committed: Mon Sep 9 10:40:38 2013 -0700

----------------------------------------------------------------------
 .../src/main/java/org/apache/helix/api/Resource.java     | 10 +++++++++-
 .../controller/stages/NewMessageGenerationStage.java     |  2 ++
 .../stages/TestBestPossibleCalcStageCompatibility.java   | 11 +++++++----
 .../controller/stages/TestResourceComputationStage.java  |  8 +++++++-
 4 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/cf1afd53/helix-core/src/main/java/org/apache/helix/api/Resource.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/api/Resource.java b/helix-core/src/main/java/org/apache/helix/api/Resource.java
index 8445617..deac192 100644
--- a/helix-core/src/main/java/org/apache/helix/api/Resource.java
+++ b/helix-core/src/main/java/org/apache/helix/api/Resource.java
@@ -20,6 +20,7 @@ package org.apache.helix.api;
  */
 
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -48,7 +49,14 @@ public class Resource {
     Map<PartitionId, Map<String, String>> schedulerTaskConfigMap =
         new HashMap<PartitionId, Map<String, String>>();
     Map<String, Integer> transitionTimeoutMap = new HashMap<String, Integer>();
-    for (PartitionId partitionId : idealState.getPartitionSet()) {
+    Set<PartitionId> partitionSet = idealState.getPartitionSet();
+    if (partitionSet.isEmpty() && idealState.getNumPartitions() > 0) {
+      partitionSet = new HashSet<PartitionId>();
+      for (int i = 0; i < idealState.getNumPartitions(); i++) {
+        partitionSet.add(Id.partition(id, Integer.toString(i)));
+      }
+    }
+    for (PartitionId partitionId : partitionSet) {
       partitionMap.put(partitionId, new Partition(partitionId));
 
       // TODO refactor it

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/cf1afd53/helix-core/src/main/java/org/apache/helix/controller/stages/NewMessageGenerationStage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/NewMessageGenerationStage.java
b/helix-core/src/main/java/org/apache/helix/controller/stages/NewMessageGenerationStage.java
index 0ae72cf..b32c9e9 100644
--- a/helix-core/src/main/java/org/apache/helix/controller/stages/NewMessageGenerationStage.java
+++ b/helix-core/src/main/java/org/apache/helix/controller/stages/NewMessageGenerationStage.java
@@ -179,6 +179,8 @@ public class NewMessageGenerationStage extends AbstractBaseStage {
           if (messageMap.containsKey(state)) {
             for (Message message : messageMap.get(state)) {
               output.addMessage(resourceId, partitionId, message);
+              System.err.println(state);
+              System.err.println(message);
             }
           }
         }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/cf1afd53/helix-core/src/test/java/org/apache/helix/controller/stages/TestBestPossibleCalcStageCompatibility.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/TestBestPossibleCalcStageCompatibility.java
b/helix-core/src/test/java/org/apache/helix/controller/stages/TestBestPossibleCalcStageCompatibility.java
index 82b70b1..d024ef4 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/TestBestPossibleCalcStageCompatibility.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/stages/TestBestPossibleCalcStageCompatibility.java
@@ -21,11 +21,11 @@ package org.apache.helix.controller.stages;
 
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.ZNRecord;
 import org.apache.helix.api.Id;
 import org.apache.helix.api.ParticipantId;
 import org.apache.helix.api.ResourceConfig;
@@ -130,15 +130,18 @@ public class TestBestPossibleCalcStageCompatibility extends BaseStageTest
{
 
     for (int i = 0; i < resources.length; i++) {
       String resourceName = resources[i];
-      ZNRecord record = new ZNRecord(resourceName);
+      IdealState idealState = new IdealState(resourceName);
       for (int p = 0; p < partitions; p++) {
         List<String> value = new ArrayList<String>();
         for (int r = 0; r < replicas; r++) {
           value.add("localhost_" + (p + r + 1) % nodes);
         }
-        record.setListField(resourceName + "_" + p, value);
+        idealState.setPreferenceList(resourceName + "_" + p, value);
+        Map<ParticipantId, State> preferenceMap = new HashMap<ParticipantId, State>();
+        preferenceMap.put(Id.participant("localhost_" + (p + 1) % 5), State.from("MASTER"));
+        idealState.setParticipantStateMap(
+            Id.partition(Id.resource(resourceName), Integer.toString(p)), preferenceMap);
       }
-      IdealState idealState = new IdealState(record);
       idealState.setStateModelDefRef("MasterSlave");
       idealState.setIdealStateMode(mode.toString());
       idealState.setNumPartitions(partitions);

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/cf1afd53/helix-core/src/test/java/org/apache/helix/controller/stages/TestResourceComputationStage.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/controller/stages/TestResourceComputationStage.java
b/helix-core/src/test/java/org/apache/helix/controller/stages/TestResourceComputationStage.java
index d4f3de6..de7a6b8 100644
--- a/helix-core/src/test/java/org/apache/helix/controller/stages/TestResourceComputationStage.java
+++ b/helix-core/src/test/java/org/apache/helix/controller/stages/TestResourceComputationStage.java
@@ -36,6 +36,7 @@ import org.apache.helix.controller.strategy.DefaultTwoStateStrategy;
 import org.apache.helix.model.CurrentState;
 import org.apache.helix.model.IdealState;
 import org.apache.helix.model.IdealState.RebalanceMode;
+import org.apache.helix.model.InstanceConfig;
 import org.apache.helix.model.LiveInstance;
 import org.testng.AssertJUnit;
 import org.testng.annotations.Test;
@@ -100,7 +101,7 @@ public class TestResourceComputationStage extends BaseStageTest {
       String resourceName = resources[i];
       ResourceId resourceId = Id.resource(resourceName);
       IdealState idealState = idealStates.get(i);
-      AssertJUnit.assertTrue(resourceMap.containsKey(resourceName));
+      AssertJUnit.assertTrue(resourceMap.containsKey(resourceId));
       AssertJUnit.assertEquals(resourceMap.get(resourceId).getId(), resourceId);
       AssertJUnit.assertEquals(resourceMap.get(resourceId).getRebalancerConfig()
           .getStateModelDefId(), idealState.getStateModelDefRef());
@@ -143,9 +144,14 @@ public class TestResourceComputationStage extends BaseStageTest {
     String sessionId = UUID.randomUUID().toString();
     liveInstance.setSessionId(sessionId);
 
+    InstanceConfig instanceConfig = new InstanceConfig(instanceName);
+    instanceConfig.setHostName("localhost");
+    instanceConfig.setPort("3");
+
     HelixDataAccessor accessor = manager.getHelixDataAccessor();
     Builder keyBuilder = accessor.keyBuilder();
     accessor.setProperty(keyBuilder.liveInstance(instanceName), liveInstance);
+    accessor.setProperty(keyBuilder.instanceConfig(instanceName), instanceConfig);
 
     String oldResource = "testResourceOld";
     CurrentState currentState = new CurrentState(oldResource);


Mime
View raw message