@Test public void runWithExplicitModules() throws Exception { System.setProperty("netflix.iep.guice.useServiceLoader", "false"); System.setProperty("netflix.iep.guice.modules", "com.netflix.iep.guice.TestModule"); Main m = new Main(); boolean startupFailed = false; try { m.runImpl(new String[]{}); } catch (ProvisionException e) { startupFailed = true; Assert.assertEquals("missing required argument", e.getCause().getMessage()); } finally { Assert.assertTrue(startupFailed); } }
void runImpl(String[] args, Module... additionalModules) throws Exception { try { Module argsModule = new AbstractModule() { @Override protected void configure() { Multibinder.newSetBinder(binder(), Service.class); bind(Args.class).toInstance(Args.from(args)); } }; List<Module> modules = useServiceLoader() ? GuiceHelper.getModulesUsingServiceLoader() : new ArrayList<>(); Collections.addAll(modules, additionalModules); modules.addAll(loadExplicitModules()); modules.add(argsModule); helper = new GuiceHelper(); helper.start(modules); helper.addShutdownHook(); helper.getInjector().getInstance(ServiceManager.class); LOGGER.info("service started successfully"); } catch (Throwable t) { LOGGER.error("service failed, shutting down", t); if (exitOnFailure()) { System.exit(1); } throw t; } }
Main { void runImpl(String[] args, Module... additionalModules) throws Exception { try { Module argsModule = new AbstractModule() { @Override protected void configure() { Multibinder.newSetBinder(binder(), Service.class); bind(Args.class).toInstance(Args.from(args)); } }; List<Module> modules = useServiceLoader() ? GuiceHelper.getModulesUsingServiceLoader() : new ArrayList<>(); Collections.addAll(modules, additionalModules); modules.addAll(loadExplicitModules()); modules.add(argsModule); helper = new GuiceHelper(); helper.start(modules); helper.addShutdownHook(); helper.getInjector().getInstance(ServiceManager.class); LOGGER.info("service started successfully"); } catch (Throwable t) { LOGGER.error("service failed, shutting down", t); if (exitOnFailure()) { System.exit(1); } throw t; } } }
Main { void runImpl(String[] args, Module... additionalModules) throws Exception { try { Module argsModule = new AbstractModule() { @Override protected void configure() { Multibinder.newSetBinder(binder(), Service.class); bind(Args.class).toInstance(Args.from(args)); } }; List<Module> modules = useServiceLoader() ? GuiceHelper.getModulesUsingServiceLoader() : new ArrayList<>(); Collections.addAll(modules, additionalModules); modules.addAll(loadExplicitModules()); modules.add(argsModule); helper = new GuiceHelper(); helper.start(modules); helper.addShutdownHook(); helper.getInjector().getInstance(ServiceManager.class); LOGGER.info("service started successfully"); } catch (Throwable t) { LOGGER.error("service failed, shutting down", t); if (exitOnFailure()) { System.exit(1); } throw t; } } Main(); }
Main { void runImpl(String[] args, Module... additionalModules) throws Exception { try { Module argsModule = new AbstractModule() { @Override protected void configure() { Multibinder.newSetBinder(binder(), Service.class); bind(Args.class).toInstance(Args.from(args)); } }; List<Module> modules = useServiceLoader() ? GuiceHelper.getModulesUsingServiceLoader() : new ArrayList<>(); Collections.addAll(modules, additionalModules); modules.addAll(loadExplicitModules()); modules.add(argsModule); helper = new GuiceHelper(); helper.start(modules); helper.addShutdownHook(); helper.getInjector().getInstance(ServiceManager.class); LOGGER.info("service started successfully"); } catch (Throwable t) { LOGGER.error("service failed, shutting down", t); if (exitOnFailure()) { System.exit(1); } throw t; } } Main(); static void run(String[] args, Module... additionalModules); static void main(String[] args); }
Main { void runImpl(String[] args, Module... additionalModules) throws Exception { try { Module argsModule = new AbstractModule() { @Override protected void configure() { Multibinder.newSetBinder(binder(), Service.class); bind(Args.class).toInstance(Args.from(args)); } }; List<Module> modules = useServiceLoader() ? GuiceHelper.getModulesUsingServiceLoader() : new ArrayList<>(); Collections.addAll(modules, additionalModules); modules.addAll(loadExplicitModules()); modules.add(argsModule); helper = new GuiceHelper(); helper.start(modules); helper.addShutdownHook(); helper.getInjector().getInstance(ServiceManager.class); LOGGER.info("service started successfully"); } catch (Throwable t) { LOGGER.error("service failed, shutting down", t); if (exitOnFailure()) { System.exit(1); } throw t; } } Main(); static void run(String[] args, Module... additionalModules); static void main(String[] args);  }