Repository: apache/hadoop
File: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/conf/TestZKConfigurationStore.java (Java)

Code before:
    byte[] data = null;
    ((ZKConfigurationStore) confStore).setZkData(logsPath, data);

    prepareLogMutation("key1", "val1");

    data = ((ZKConfigurationStore) confStore).getZkData(logsPath);
    assertEquals("Failed to Disable Audit Logs", 0, data.length);
  }

  @Test
  public void testZkData() throws Exception {
    conf.setInt(YarnConfiguration.RM_SCHEDCONF_STORE_ZK_READ_RETRY_SECS, 0);
    confStore.initialize(conf, schedConf, rmContext);
    String confStorePath = getZkPath("CONF_STORE");
    byte[] data = ((ZKConfigurationStore) confStore).getZkData(confStorePath);
    assertTrue("ConfStore data expected to be not null.", data.length > 0);
  }

  @Test
  public void testEmptyZkData() throws Exception {
    conf.setInt(YarnConfiguration.RM_SCHEDCONF_STORE_ZK_READ_RETRY_SECS, 0);
    confStore.initialize(conf, schedConf, rmContext);
    confStore.format();
    String confStorePath = getZkPath("CONF_STORE");
    byte[] data = ((ZKConfigurationStore) confStore).getZkData(confStorePath);
    assertEquals("ConfStore data expected to be empty.", 0,
        data.length);
  }

  public Configuration createRMHAConf(String rmIds, String rmId,
      int adminPort) {
    Configuration conf = new YarnConfiguration();
    this.conf.setClass(YarnConfiguration.RM_SCHEDULER,
        CapacityScheduler.class, CapacityScheduler.class);
    conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
    conf.set(YarnConfiguration.RM_HA_IDS, rmIds);
    conf.setBoolean(YarnConfiguration.RECOVERY_ENABLED, true);
    conf.set(YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS,
        YarnConfiguration.ZK_CONFIGURATION_STORE);
    conf.set(YarnConfiguration.RM_STORE, ZKRMStateStore.class.getName());
    conf.set(YarnConfiguration.RM_ZK_ADDRESS,
        curatorTestingServer.getConnectString());
    conf.set(YarnConfiguration.RM_HA_ID, rmId);
    conf.set(YarnConfiguration.RM_WEBAPP_ADDRESS, "localhost:0");
    conf.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false);
    for (String rpcAddress :
        YarnConfiguration.getServiceAddressConfKeys(conf)) {
      for (String id : HAUtil.getRMHAIds(conf)) {
        conf.set(HAUtil.addSuffix(rpcAddress, id), "localhost:0");
      }
    }

Review comment (suggestion):
Also, FYI, at least in my IDE. It suggests me to reorder the assertEquals as the followings:

`assertEquals( 0,
        data.length, "ConfStore data expected to be empty.");`

Code after:
    byte[] data = null;
    ((ZKConfigurationStore) confStore).setZkData(logsPath, data);

    prepareLogMutation("key1", "val1");

    data = ((ZKConfigurationStore) confStore).getZkData(logsPath);
    assertEquals(0, data.length, "Failed to Disable Audit Logs");
  }

  @Test
  public void testZkData() throws Exception {
    conf.setInt(YarnConfiguration.RM_SCHEDCONF_STORE_ZK_READ_RETRY_SECS, 0);
    schedConf.set("key", "val");
    confStore.initialize(conf, schedConf, rmContext);
    String confStorePath = getZkPath("CONF_STORE");
    byte[] data = ((ZKConfigurationStore) confStore).getZkData(confStorePath);
    assertTrue(data.length > 0, "ConfStore data expected to be not null.");
  }

  @Test
  public void testEmptyZkData() throws Exception {
    conf.setInt(YarnConfiguration.RM_SCHEDCONF_STORE_ZK_READ_RETRY_SECS, 0);
    schedConf.set("key", "val");
    confStore.initialize(conf, schedConf, rmContext);
    confStore.format();
    String confStorePath = getZkPath("CONF_STORE");
    byte[] data = ((ZKConfigurationStore) confStore).getZkData(confStorePath);
    assertEquals(0, data.length, "ConfStore data expected to be empty.");
  }

  public Configuration createRMHAConf(String rmIds, String rmId,
      int adminPort) {
    Configuration conf = new YarnConfiguration();
    this.conf.setClass(YarnConfiguration.RM_SCHEDULER,
        CapacityScheduler.class, CapacityScheduler.class);
    conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
    conf.set(YarnConfiguration.RM_HA_IDS, rmIds);
    conf.setBoolean(YarnConfiguration.RECOVERY_ENABLED, true);
    conf.set(YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS,
        YarnConfiguration.ZK_CONFIGURATION_STORE);
    conf.set(YarnConfiguration.RM_STORE, ZKRMStateStore.class.getName());
    conf.set(YarnConfiguration.RM_ZK_ADDRESS,
        curatorTestingServer.getConnectString());
    conf.set(YarnConfiguration.RM_HA_ID, rmId);
    conf.set(YarnConfiguration.RM_WEBAPP_ADDRESS, "localhost:0");
    conf.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false);
    for (String rpcAddress :
        YarnConfiguration.getServiceAddressConfKeys(conf)) {
      for (String id : HAUtil.getRMHAIds(conf)) {
        conf.set(HAUtil.addSuffix(rpcAddress, id), "localhost:0");
      }