DownloadJarFunction implements InternalFunction<Object[]> { @Override public void execute(FunctionContext<Object[]> context) { InternalLocator locator = getLocator(); Object[] args = context.getArguments(); String group = (String) args[0]; String jarName = (String) args[1]; RemoteInputStream result = null; if (locator != null && group != null && jarName != null) { InternalConfigurationPersistenceService sharedConfig = locator.getConfigurationPersistenceService(); if (sharedConfig != null) { SystemManagementService managementService = getExistingManagementService(context); ManagementAgent managementAgent = managementService.getManagementAgent(); if (managementAgent == null) { throw new IllegalStateException( "Failed to download jar because JMX Management agent is not available. Please ensure geode property jmx-manager is set to true."); } RemoteInputStreamServer istream = null; try { File jarFile = sharedConfig.getPathToJarOnThisLocator(group, jarName).toFile(); RemoteStreamExporter exporter = managementAgent.getRemoteStreamExporter(); istream = new SimpleRemoteInputStream(new BufferedInputStream(new FileInputStream(jarFile))); result = exporter.export(istream); istream = null; } catch (Exception e) { logger.error(e); throw new IllegalStateException(e.getMessage()); } finally { if (istream != null) { istream.close(); } } } } context.getResultSender().lastResult(result); }  @Override void execute(FunctionContext<Object[]> context); @Override String getId();  }
@Test public void throwExceptionWhenManagementAgentIsNull() { assertThatThrownBy(() -> function.execute(context)).isInstanceOf(IllegalStateException.class) .hasMessageContaining("Failed to download jar"); }