TonyClient implements AutoCloseable { @VisibleForTesting static void validateTonyConf(Configuration tonyConf) { enforceTaskInstanceLimits(tonyConf); enforceResourceLimits(tonyConf); } TonyClient();  TonyClient(Configuration conf);  TonyClient(CallbackHandler handler, Configuration conf); @VisibleForTesting String processFinalTonyConf(); @VisibleForTesting void submitApplication(ApplicationSubmissionContext appContext); boolean init(String[] args); void initTonyConf(Configuration tonyConf, CommandLine cliParser); @VisibleForTesting void processTonyConfResources(Configuration tonyConf, FileSystem fs); Configuration getTonyConf(); ContainerLaunchContext createAMContainerSpec(long amMemory, ByteBuffer tokens); @VisibleForTesting boolean monitorApplication(); void forceKillApplication(); @VisibleForTesting CopyOnWriteArrayList<TaskUpdateListener> getListener(); @Override void close(); @VisibleForTesting int start(); static String getRmPrincipal(Configuration conf); static String getRmPrincipal(String rmPrincipal, Configuration conf); void addListener(TaskUpdateListener listener); void removeListener(TaskUpdateListener listener); static void main(String[] args);  }
@Test public void testValidateTonyConfValidConf() { Configuration conf = new Configuration(); conf.setInt("tony.foo.instances", 2); conf.setInt("tony.bar.instances", 2); TonyClient.validateTonyConf(conf); }
@Test public void testValidateTonyConfZeroInstances() { Configuration conf = new Configuration(); conf.setInt(TonyConfigurationKeys.MAX_TOTAL_INSTANCES, 0); TonyClient.validateTonyConf(conf); }
@Test(expectedExceptions = RuntimeException.class) public void testValidateTonyConfTooManyTotalInstances() { Configuration conf = new Configuration(); conf.setInt(TonyConfigurationKeys.MAX_TOTAL_INSTANCES, 3); conf.setInt("tony.foo.instances", 2); conf.setInt("tony.bar.instances", 2); TonyClient.validateTonyConf(conf); }
@Test(expectedExceptions = RuntimeException.class) public void testValidateTonyConfTooManyFooInstances() { Configuration conf = new Configuration(); conf.setInt(TonyConfigurationKeys.getMaxInstancesKey("foo"), 1); conf.setInt("tony.foo.instances", 2); TonyClient.validateTonyConf(conf); }
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = ".*amount of " + Constants.GPUS + ".*requested exceeds.*") public void testValidateTonyConfTooManyGpus() { Configuration conf = new Configuration(); conf.setInt(TonyConfigurationKeys.getResourceKey(Constants.WORKER_JOB_NAME, Constants.GPUS), 1); conf.setInt(TonyConfigurationKeys.getInstancesKey(Constants.WORKER_JOB_NAME), 10); conf.setInt(TonyConfigurationKeys.getMaxTotalResourceKey(Constants.GPUS), 5); TonyClient.validateTonyConf(conf); }
@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = ".*amount of " + Constants.GPUS + ".*requested exceeds.*") public void testValidateTonyConfTooManyGpusAcrossAllTasks() { Configuration conf = new Configuration(); conf.setInt(TonyConfigurationKeys.getResourceKey(Constants.WORKER_JOB_NAME, Constants.GPUS), 1); conf.setInt(TonyConfigurationKeys.getResourceKey(Constants.PS_JOB_NAME, Constants.GPUS), 1); conf.setInt(TonyConfigurationKeys.getInstancesKey(Constants.WORKER_JOB_NAME), 3); conf.setInt(TonyConfigurationKeys.getInstancesKey(Constants.PS_JOB_NAME), 3); conf.setInt(TonyConfigurationKeys.getMaxTotalResourceKey(Constants.GPUS), 5); TonyClient.validateTonyConf(conf); }
@Test public void testValidateTonyConfRequestedGpusUnderLimit() { Configuration conf = new Configuration(); conf.setInt(TonyConfigurationKeys.getResourceKey(Constants.WORKER_JOB_NAME, Constants.GPUS), 1); conf.setInt(TonyConfigurationKeys.getInstancesKey(Constants.WORKER_JOB_NAME), 5); conf.setInt(TonyConfigurationKeys.getMaxTotalResourceKey(Constants.GPUS), 10); TonyClient.validateTonyConf(conf); }