helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject git commit: [HELIX-7]: Tune test parameters to fix random test failures
Date Mon, 19 Nov 2012 22:21:10 GMT
Updated Branches:
  refs/heads/master 11c9bcbac -> 0fff6b82d


[HELIX-7]: Tune test parameters to fix random test failures


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

Branch: refs/heads/master
Commit: 0fff6b82d8f8727d4f080eff8f3801836c2fb780
Parents: 11c9bcb
Author: zzhang <zzhang@apache.org>
Authored: Mon Nov 19 14:21:01 2012 -0800
Committer: zzhang <zzhang@apache.org>
Committed: Mon Nov 19 14:21:01 2012 -0800

----------------------------------------------------------------------
 .../helix/tools/TestResetPartitionState.java       |  324 +++++++--------
 1 files changed, 159 insertions(+), 165 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/0fff6b82/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
----------------------------------------------------------------------
diff --git a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
index 6ffcc8b..bd05d3c 100644
--- a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
+++ b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
@@ -23,11 +23,12 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.helix.NotificationContext;
+import org.apache.helix.PropertyKey.Builder;
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZNRecord;
-import org.apache.helix.PropertyKey.Builder;
 import org.apache.helix.manager.zk.ZKHelixDataAccessor;
 import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.mock.controller.ClusterController;
@@ -35,183 +36,176 @@ import org.apache.helix.mock.participant.MockParticipant;
 import org.apache.helix.mock.participant.MockParticipant.ErrTransition;
 import org.apache.helix.model.LiveInstance;
 import org.apache.helix.model.Message;
-import org.apache.helix.tools.ClusterSetup;
-import org.apache.helix.tools.ClusterStateVerifier;
 import org.apache.helix.webapp.resources.JsonParameters;
+import org.apache.log4j.Logger;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+public class TestResetPartitionState extends AdminTestBase {
+    private final static Logger LOG = Logger
+	    .getLogger(TestResetPartitionState.class);
+
+    String getClusterUrl(String cluster) {
+	return "http://localhost:" + ADMIN_PORT + "/clusters" + "/" + cluster;
+    }
 
-public class TestResetPartitionState extends AdminTestBase
-{
-  String getClusterUrl(String cluster)
-  {
-    return "http://localhost:" + ADMIN_PORT + "/clusters" + "/" + cluster;
-  }
-  
-  String getInstanceUrl(String cluster, String instance)
-  {
-    return "http://localhost:" + ADMIN_PORT + "/clusters/" + cluster + "/instances/" + instance;
-  }
-  
-  String getResourceUrl(String cluster, String resourceGroup)
-  {
-    return "http://localhost:" + ADMIN_PORT + "/clusters/" + cluster + "/resourceGroups/"
+ resourceGroup;
-  }
-  
-  int _errToOfflineInvoked = 0;
-  class ErrTransitionWithResetCnt extends ErrTransition
-  {
-    public ErrTransitionWithResetCnt(Map<String, Set<String>> errPartitions)
-    {
-      super(errPartitions);
+    String getInstanceUrl(String cluster, String instance) {
+	return "http://localhost:" + ADMIN_PORT + "/clusters/" + cluster
+		+ "/instances/" + instance;
     }
 
-    @Override
-    public void doTransition(Message message, NotificationContext context)
-    {
-      super.doTransition(message, context);
-      String fromState = message.getFromState();
-      String toState = message.getToState();
-      if (fromState.equals("ERROR") && toState.equals("OFFLINE"))
-      {
-        // System.err.println("doReset() invoked");
-        _errToOfflineInvoked++;
-      }
+    String getResourceUrl(String cluster, String resourceGroup) {
+	return "http://localhost:" + ADMIN_PORT + "/clusters/" + cluster
+		+ "/resourceGroups/" + resourceGroup;
     }
-  }
-  
-  @Test()
-  public void testResetPartitionState() throws Exception
-  {
-    String className = TestHelper.getTestClassName();
-    String methodName = TestHelper.getTestMethodName();
-    String clusterName = className + "_" + methodName;
-    final int n = 5;
-
-    System.out.println("START " + clusterName + " at "
-        + new Date(System.currentTimeMillis()));
-
-    TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
-                            "localhost", // participant name prefix
-                            "TestDB", // resource name prefix
-                            1, // resources
-                            10, // partitions per resource
-                            n, // number of nodes
-                            3, // replicas
-                            "MasterSlave",
-                            true); // do rebalance
-
-    // start admin thread
-//    AdminThread adminThread = new AdminThread(ZK_ADDR, _port);
-//    adminThread.start();
-    
-    
-    // start controller
-    ClusterController controller =
-        new ClusterController(clusterName, "controller_0", ZK_ADDR);
-    controller.syncStart();
-
-    Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>()
-    {
-      {
-        put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
-        put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
-      }
-    };
-
-    // start mock participants
-    MockParticipant[] participants = new MockParticipant[n];
-    for (int i = 0; i < n; i++)
-    {
-      String instanceName = "localhost_" + (12918 + i);
-
-      if (i == 0)
-      {
-        participants[i] =
-            new MockParticipant(clusterName,
-                                instanceName,
-                                ZK_ADDR,
-                                new ErrTransition(errPartitions));
-      }
-      else
-      {
-        participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
-      }
-      participants[i].syncStart();
+
+    AtomicInteger _errToOfflineInvoked = new AtomicInteger(0);
+
+    class ErrTransitionWithResetCnt extends ErrTransition {
+	public ErrTransitionWithResetCnt(Map<String, Set<String>> errPartitions) {
+	    super(errPartitions);
+	}
+
+	@Override
+	public void doTransition(Message message, NotificationContext context) {
+	    super.doTransition(message, context);
+	    String fromState = message.getFromState();
+	    String toState = message.getToState();
+	    if (fromState.equals("ERROR") && toState.equals("OFFLINE")) {
+		// System.err.println("doReset() invoked");
+		_errToOfflineInvoked.incrementAndGet();
+	    }
+	}
     }
 
-    // verify cluster
-    Map<String, Map<String, String>> errStateMap =
-        new HashMap<String, Map<String, String>>();
-    errStateMap.put("TestDB0", new HashMap<String, String>());
-    errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
-    errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
-    boolean result =
-        ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
-                                                                                        
              clusterName,
-                                                                                        
              errStateMap)));
-    Assert.assertTrue(result, "Cluster verification fails");
-    
-    
-    // reset a non-exist partition, should throw exception
-    String hostName = "localhost_12918";
-    String instanceUrl = getInstanceUrl(clusterName, hostName);
-
-    Map<String, String> paramMap = new HashMap<String, String>();
-    paramMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.resetPartition);
-    paramMap.put(JsonParameters.PARTITION, "TestDB0_nonExist");
-    paramMap.put(JsonParameters.RESOURCE, "TestDB0");
-    System.out.println("IGNORABLE exception: test reset non-exist partition");
-    TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, paramMap, true);
-    
-    
-    // reset one error partition
-    errPartitions.clear();  // remove("SLAVE-MASTER");
-    participants[0].setTransition(new ErrTransitionWithResetCnt(errPartitions));
-    clearStatusUpdate(clusterName, "localhost_12918", "TestDB0", "TestDB0_4");
-    _errToOfflineInvoked = 0;
-
-    paramMap.put(JsonParameters.PARTITION, "TestDB0_4 TestDB0_8");
-    TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, paramMap, false);
-
-    Thread.sleep(400); // wait reset to be done
-    System.out.println("IGNORABLE exception: test reset non-error partition");
-    TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, paramMap, true);
-
-    result =
-        ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
-                                                                                        
          clusterName));
-    Assert.assertTrue(result);
-    Assert.assertEquals(_errToOfflineInvoked, 2, "reset() should be invoked 2 times");
-    
-
-    // clean up
-    // wait for all zk callbacks done
-    Thread.sleep(1000);
-//    adminThread.stop();
-    controller.syncStop();
-    for (int i = 0; i < 5; i++)
-    {
-      participants[i].syncStop();
+    @Test()
+    public void testResetPartitionState() throws Exception {
+	String className = TestHelper.getTestClassName();
+	String methodName = TestHelper.getTestMethodName();
+	String clusterName = className + "_" + methodName;
+	final int n = 5;
+
+	System.out.println("START " + clusterName + " at "
+		+ new Date(System.currentTimeMillis()));
+
+	TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
+		"localhost", // participant name prefix
+		"TestDB", // resource name prefix
+		1, // resources
+		10, // partitions per resource
+		n, // number of nodes
+		3, // replicas
+		"MasterSlave", true); // do rebalance
+
+	// start admin thread
+	// AdminThread adminThread = new AdminThread(ZK_ADDR, _port);
+	// adminThread.start();
+
+	// start controller
+	ClusterController controller = new ClusterController(clusterName,
+		"controller_0", ZK_ADDR);
+	controller.syncStart();
+
+	Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>();
+	errPartitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
+	errPartitions.put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
+
+	// start mock participants
+	MockParticipant[] participants = new MockParticipant[n];
+	for (int i = 0; i < n; i++) {
+	    String instanceName = "localhost_" + (12918 + i);
+
+	    if (i == 0) {
+		participants[i] = new MockParticipant(clusterName,
+			instanceName, ZK_ADDR, new ErrTransition(errPartitions));
+	    } else {
+		participants[i] = new MockParticipant(clusterName,
+			instanceName, ZK_ADDR);
+	    }
+	    participants[i].syncStart();
+	}
+
+	// verify cluster
+	Map<String, Map<String, String>> errStateMap = new HashMap<String, Map<String,
String>>();
+	errStateMap.put("TestDB0", new HashMap<String, String>());
+	errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
+	errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
+	boolean result = ClusterStateVerifier
+		.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
+			ZK_ADDR, clusterName, errStateMap)));
+	Assert.assertTrue(result, "Cluster verification fails");
+
+	// reset a non-exist partition, should throw exception
+	String hostName = "localhost_12918";
+	String instanceUrl = getInstanceUrl(clusterName, hostName);
+
+	Map<String, String> paramMap = new HashMap<String, String>();
+	paramMap.put(JsonParameters.MANAGEMENT_COMMAND,
+		ClusterSetup.resetPartition);
+	paramMap.put(JsonParameters.PARTITION, "TestDB0_nonExist");
+	paramMap.put(JsonParameters.RESOURCE, "TestDB0");
+	LOG.info("IGNORABLE exception: test reset non-exist partition");
+	TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl,
+		paramMap, true);
+
+	// reset 2 error partitions
+	errPartitions.clear();
+	participants[0].setTransition(new ErrTransitionWithResetCnt(
+		errPartitions));
+	clearStatusUpdate(clusterName, "localhost_12918", "TestDB0",
+		"TestDB0_4");
+	_errToOfflineInvoked.set(0);
+
+	paramMap.put(JsonParameters.PARTITION, "TestDB0_4 TestDB0_8");
+	TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl,
+		paramMap, false);
+
+	for (int i = 0; i < 10; i++) {
+	    Thread.sleep(400); // wait reset to be done
+	    LOG.info("IGNORABLE exception: test reset non-error partition");
+	    TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl,
+		    paramMap, true);
+
+	    result = ClusterStateVerifier
+		    .verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
+			    ZK_ADDR, clusterName));
+	    if (result == true) {
+		break;
+	    }
+	}
+	
+	Assert.assertTrue(result);
+	Assert.assertEquals(_errToOfflineInvoked.get(), 2,
+		"reset() should be invoked 2 times");
+
+	// clean up
+	// wait for all zk callbacks done
+	Thread.sleep(1000);
+	// adminThread.stop();
+	controller.syncStop();
+	for (int i = 0; i < 5; i++) {
+	    participants[i].syncStop();
+	}
+
+	System.out.println("END " + clusterName + " at "
+		+ new Date(System.currentTimeMillis()));
     }
 
-    System.out.println("END " + clusterName + " at "
-        + new Date(System.currentTimeMillis()));
-  }
+    private void clearStatusUpdate(String clusterName, String instance,
+	    String resource, String partition) {
+	// clear status update for error partition so verify() will not fail on
+	// old
+	// errors
+	ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName,
+		new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
+	Builder keyBuilder = accessor.keyBuilder();
 
-  private void clearStatusUpdate(String clusterName, String instance, String resource,
-      String partition)
-  {
-    // clear status update for error partition so verify() will not fail on old
-    // errors
-    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
-    Builder keyBuilder = accessor.keyBuilder();
+	LiveInstance liveInstance = accessor.getProperty(keyBuilder
+		.liveInstance(instance));
+	accessor.removeProperty(keyBuilder.stateTransitionStatus(instance,
+		liveInstance.getSessionId(), resource, partition));
 
-    LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance(instance));
-    accessor.removeProperty(keyBuilder.stateTransitionStatus(instance, liveInstance.getSessionId(),
resource, partition));
+    }
 
-   }
-  
-  // TODO: throw exception in reset()
+    // TODO: throw exception in reset()
 }


Mime
View raw message