### Question:
RuntimeResourceManager extends Configured { public void setup() throws IOException, InterruptedException { if (LOG.isDebugEnabled()) { LOG.debug("Loading runtime plugins"); } List<? extends RuntimeResource> loaded = load(); this.resources = new ArrayList<>(); for (RuntimeResource resource : loaded) { if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format( "Activating runtime plugin: {0}", resource.getClass().getName())); } resource.setup(configuration); resources.add(resource); } if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format( "Loaded {0} runtime plugins", resources.size())); } } RuntimeResourceManager(Configuration configuration); void setup(); void cleanup(); static final String CONFIGURATION_FILE_NAME; static final String CONFIGURATION_FILE_PATH; }### Answer:
@Test public void setup() throws Exception { AtomicInteger passed = new AtomicInteger(); Configuration conf = new Configuration(); conf.set("test", "OK"); RuntimeResourceManager manager = new RuntimeResourceManager(conf) { @Override protected List<RuntimeResource> load() throws IOException { return Arrays.asList(new RuntimeResource() { @Override public void setup(ResourceConfiguration configuration) { passed.incrementAndGet(); assertThat(configuration.get("test", null), is("OK")); } }); } }; manager.setup(); assertThat(passed.get(), is(1)); }
@Test(expected = IOException.class) public void setup_exception() throws Exception { Configuration conf = new Configuration(); RuntimeResourceManager manager = new RuntimeResourceManager(conf) { @Override protected List<RuntimeResource> load() throws IOException { return Arrays.asList(new RuntimeResource() { @Override public void setup(ResourceConfiguration configuration) throws IOException { throw new IOException(); } }); } }; manager.setup(); }
@Test public void setup_multi() throws Exception { AtomicInteger passed = new AtomicInteger(); Configuration conf = new Configuration(); conf.set("test", "OK"); RuntimeResourceManager manager = new RuntimeResourceManager(conf) { @Override protected List<RuntimeResource> load() throws IOException { RuntimeResource adapter = new RuntimeResource() { @Override public void setup(ResourceConfiguration configuration) { passed.addAndGet(1); assertThat(configuration.get("test", null), is("OK")); } }; return Arrays.asList(adapter, adapter, adapter); } }; manager.setup(); assertThat(passed.get(), is(3)); }