|
| 1 | +package com.exasol.udfdebugging; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | +import java.util.stream.Collectors; |
| 5 | + |
| 6 | +import org.slf4j.Logger; |
| 7 | +import org.slf4j.LoggerFactory; |
| 8 | + |
| 9 | +import com.exasol.udfdebugging.modules.debugging.DebuggingModuleFactory; |
| 10 | + |
| 11 | +/** |
| 12 | + * Test setup for testing UDFs in the database. |
| 13 | + */ |
| 14 | +public class UdfTestSetup { |
| 15 | + private static final List<ModuleFactory> AVAILABLE_MODULES = List.of(new DebuggingModuleFactory()); |
| 16 | + private static final Logger LOGGER = LoggerFactory.getLogger(UdfTestSetup.class); |
| 17 | + private final List<Module> enabledModules; |
| 18 | + |
| 19 | + /** |
| 20 | + * Create a new instance of {@link UdfTestSetup}. |
| 21 | + * |
| 22 | + * @param testHostIpAddress IP address of the host running this UDF Test Setup under which UDFs can reach it |
| 23 | + */ |
| 24 | + public UdfTestSetup(final String testHostIpAddress) { |
| 25 | + this.enabledModules = AVAILABLE_MODULES.stream().filter(ModuleFactory::isEnabled) |
| 26 | + .map(moduleFactory -> moduleFactory.buildModule(testHostIpAddress)).collect(Collectors.toList()); |
| 27 | + printInfoMessage(); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Get JVM options required for this setup. |
| 32 | + * |
| 33 | + * @return array of JVM options |
| 34 | + */ |
| 35 | + public String[] getJvmOptions() { |
| 36 | + return this.enabledModules.stream().flatMap(Module::getJvmOptions).toArray(String[]::new); |
| 37 | + } |
| 38 | + |
| 39 | + private void printInfoMessage() { |
| 40 | + if (LOGGER.isInfoEnabled()) { |
| 41 | + LOGGER.info(getInfoMessage()); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + private String getInfoMessage() { |
| 46 | + final StringBuilder messageBuilder = new StringBuilder("Udf Test Setup Configuration:\n"); |
| 47 | + AVAILABLE_MODULES.forEach(module -> { |
| 48 | + messageBuilder.append(module.getModulePropertyName()); |
| 49 | + messageBuilder.append(":\t"); |
| 50 | + messageBuilder.append(module.isEnabled() ? "enabled" : "disabled"); |
| 51 | + messageBuilder.append("\n"); |
| 52 | + }); |
| 53 | + return messageBuilder.toString(); |
| 54 | + } |
| 55 | +} |
0 commit comments