ApiServiceClient extends AppAdminClient { @Override public int actionFlex(String appName, Map<String, String> componentCounts) throws IOException, YarnException { int result = EXIT_SUCCESS; try { Service service = new Service(); service.setName(appName); service.setState(ServiceState.FLEX); for (Map.Entry<String, String> entry : componentCounts.entrySet()) { Component component = new Component(); component.setName(entry.getKey()); Long numberOfContainers = Long.parseLong(entry.getValue()); component.setNumberOfContainers(numberOfContainers); service.addComponent(component); } String buffer = jsonSerDeser.toJson(service); ClientResponse response = getApiClient(getServicePath(appName)) .put(ClientResponse.class, buffer); result = processResponse(response); } catch (Exception e) { LOG.error("Fail to flex application: ", e); result = EXIT_EXCEPTION_THROWN; } return result; } ApiServiceClient();  ApiServiceClient(Configuration c); String getServicePath(String appName); Builder getApiClient(); Builder getApiClient(String requestPath); Service loadAppJsonFromLocalFS(String fileName, String serviceName,
      Long lifetime, String queue); @Override int actionLaunch(String fileName, String appName, Long lifetime,
      String queue); @Override int actionStop(String appName); @Override int actionStart(String appName); @Override int actionSave(String fileName, String appName, Long lifetime,
      String queue); @Override int actionDestroy(String appName); @Override int actionFlex(String appName, Map<String, String> componentCounts); @Override int enableFastLaunch(String destinationFolder); @Override String getStatusString(String appIdOrName); @Override int actionUpgradeExpress(String appName, File path); @Override int initiateUpgrade(String appName,
      String fileName, boolean autoFinalize); @Override int actionUpgradeInstances(String appName, List<String> compInstances); @Override int actionUpgradeComponents(String appName, List<String> components); @Override int actionCleanUp(String appName, String userName); @Override String getInstances(String appName, List<String> components,
      String version, List<String> containerStates); @Override int actionCancelUpgrade(
      String appName); @Override int actionDecommissionInstances(String appName, List<String>
      componentInstances);  }
@Test public void testFlex() { String appName = "example-app"; HashMap<String, String> componentCounts = new HashMap<String, String>(); try { int result = asc.actionFlex(appName, componentCounts); assertEquals(EXIT_SUCCESS, result); } catch (IOException | YarnException e) { fail(); } }
@Test public void testBadFlex() { String appName = "unknown_app"; HashMap<String, String> componentCounts = new HashMap<String, String>(); try { int result = badAsc.actionFlex(appName, componentCounts); assertEquals(EXIT_EXCEPTION_THROWN, result); } catch (IOException | YarnException e) { fail(); } }