/** This tests offlining a entityGroup */
  @Test(timeout = 120000)
  public void testOfflineEntityGroup() throws Exception {
    String table = "testOfflineEntityGroup";
    try {
      EntityGroupInfo egInfo = createTableAndGetOneEntityGroup(table);

      EntityGroupStates entityGroupStates =
          TEST_UTIL.getWaspCluster().getMaster().getAssignmentManager().getEntityGroupStates();
      ServerName serverName = entityGroupStates.getFServerOfEntityGroup(egInfo);
      TEST_UTIL.assertEntityGroupOnServer(egInfo, serverName, 200);
      admin.offline(egInfo.getEntityGroupName());

      long timeoutTime = System.currentTimeMillis() + 800;
      while (true) {
        List<EntityGroupInfo> entityGroups =
            entityGroupStates.getEntityGroupsOfTable(Bytes.toBytes(table));
        if (!entityGroups.contains(egInfo)) break;
        long now = System.currentTimeMillis();
        if (now > timeoutTime) {
          fail("Failed to offline the entityGroup in time");
          break;
        }
        Thread.sleep(10);
      }
      EntityGroupState entityGroupState = entityGroupStates.getEntityGroupState(egInfo);
      assertTrue(entityGroupState.isOffline());
    } finally {
      TEST_UTIL.deleteTable(Bytes.toBytes(table));
    }
  }
 /** This tests entityGroup assignment */
 @Test(timeout = 120000)
 public void testAssignEntityGroup() throws Exception {
   String table = "testAssignEntityGroup";
   try {
     FTable desc = FMetaTestUtil.makeTable(table);
     admin.createTable(desc);
     EntityGroupInfo egInfo =
         new EntityGroupInfo(
             Bytes.toBytes(desc.getTableName()), Bytes.toBytes("A"), Bytes.toBytes("Z"));
     FMetaEditor.addEntityGroupToMeta(conf, egInfo);
     FMaster master = TEST_UTIL.getWaspCluster().getMaster();
     master.assignEntityGroup(egInfo);
     master.getAssignmentManager().waitForAssignment(egInfo);
     ServerName serverName =
         master.getAssignmentManager().getEntityGroupStates().getFServerOfEntityGroup(egInfo);
     TEST_UTIL.assertEntityGroupOnServer(egInfo, serverName, 200);
   } finally {
     TEST_UTIL.deleteTable(Bytes.toBytes(table));
   }
 }
  EntityGroupInfo createTableAndGetOneEntityGroup(final String tableName)
      throws IOException, InterruptedException {
    FTable desc = FMetaTestUtil.makeTable(tableName);
    admin.createTable(desc, Bytes.toBytes("A"), Bytes.toBytes("Z"), 5);

    // wait till the table is assigned
    FMaster master = TEST_UTIL.getWaspCluster().getMaster();
    long timeoutTime = System.currentTimeMillis() + 100;
    while (true) {
      List<EntityGroupInfo> entityGroups =
          master
              .getAssignmentManager()
              .getEntityGroupStates()
              .getEntityGroupsOfTable(Bytes.toBytes(tableName));
      if (entityGroups.size() > 3) {
        return entityGroups.get(2);
      }
      long now = System.currentTimeMillis();
      if (now > timeoutTime) {
        fail("Could not find an online entityGroup");
      }
      Thread.sleep(10);
    }
  }