Skip to content

Commit b0ea3a4

Browse files
feat: use test name to override config for a service (#48)
1 parent 7a1c7a7 commit b0ea3a4

File tree

4 files changed

+41
-18
lines changed

4 files changed

+41
-18
lines changed

integrationtest-service-framework/src/main/java/org/hypertrace/core/serviceframework/IntegrationTestServerUtil.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.net.http.HttpRequest;
99
import java.net.http.HttpResponse;
1010
import java.net.http.HttpResponse.BodyHandlers;
11+
import java.util.Optional;
1112
import java.util.concurrent.ExecutorService;
1213
import java.util.concurrent.Executors;
1314
import java.util.concurrent.TimeUnit;
@@ -25,12 +26,20 @@ public class IntegrationTestServerUtil {
2526
private static String[] services;
2627

2728
public static void startServices(String[] services) {
29+
startServices(Optional.empty(), services);
30+
}
31+
32+
public static void startServices(String testName, String[] services) {
33+
startServices(Optional.of(testName), services);
34+
}
35+
36+
private static void startServices(Optional<String> testName, String[] services) {
2837
executorService = Executors.newFixedThreadPool(services.length);
2938
IntegrationTestServerUtil.services = services;
3039
for (String service:services) {
3140
executorService.submit(() -> {
3241
try {
33-
IntegrationTestServiceLauncher.main(new String[] {service});
42+
IntegrationTestServiceLauncher.launchService(testName, service);
3443
} catch (Throwable t) {
3544
System.out.println("Error starting the service with these message: "
3645
+ t.getMessage());

integrationtest-service-framework/src/main/java/org/hypertrace/core/serviceframework/IntegrationTestServiceLauncher.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.ArrayList;
44
import java.util.List;
5+
import java.util.Optional;
6+
57
import org.hypertrace.core.serviceframework.config.ConfigClient;
68
import org.hypertrace.core.serviceframework.config.IntegrationTestConfigClientFactory;
79
import org.slf4j.Logger;
@@ -20,21 +22,18 @@ public class IntegrationTestServiceLauncher {
2022
private static final Logger LOGGER = LoggerFactory.getLogger(PlatformServiceLauncher.class);
2123
private static final List<PlatformService> PLATFORM_SERVICES = new ArrayList<>();
2224

23-
/** @param serviceNames list of services to start */
24-
public static void main(String[] serviceNames) {
25-
for (String serviceName : serviceNames) {
26-
try {
27-
LOGGER.info("Trying to start PlatformService: {}", serviceName);
28-
final ConfigClient configClient =
29-
IntegrationTestConfigClientFactory.getConfigClientForService(serviceName);
30-
PlatformService app = PlatformServiceFactory.get(configClient);
31-
app.initialize();
32-
Runtime.getRuntime().addShutdownHook(new Thread(app::shutdown));
33-
PLATFORM_SERVICES.add(app);
34-
app.start();
35-
} catch (Exception e) {
36-
LOGGER.error("Got exception while starting PlatformService: " + serviceName, e);
37-
}
25+
public static void launchService(Optional<String> testName, String serviceName) {
26+
try {
27+
LOGGER.info("Trying to start PlatformService: {}", serviceName);
28+
final ConfigClient configClient =
29+
IntegrationTestConfigClientFactory.getConfigClientForService(testName, serviceName);
30+
PlatformService app = PlatformServiceFactory.get(configClient);
31+
app.initialize();
32+
Runtime.getRuntime().addShutdownHook(new Thread(app::shutdown));
33+
PLATFORM_SERVICES.add(app);
34+
app.start();
35+
} catch (Exception e) {
36+
LOGGER.error("Got exception while starting PlatformService: " + serviceName, e);
3837
}
3938
}
4039

integrationtest-service-framework/src/main/java/org/hypertrace/core/serviceframework/config/IntegrationTestConfigClient.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.typesafe.config.Config;
44
import com.typesafe.config.ConfigFactory;
55
import java.util.Arrays;
6+
import java.util.Optional;
67
import java.util.stream.Collectors;
78

89
/**
@@ -16,9 +17,16 @@ public class IntegrationTestConfigClient implements ConfigClient {
1617
private static final String INTEGRATION_TEST_CLUSTER = "local";
1718

1819
private final String defaultServiceName;
20+
private final Optional<String> defaultTestName;
1921

2022
public IntegrationTestConfigClient(String defaultServiceName) {
2123
this.defaultServiceName = defaultServiceName;
24+
this.defaultTestName = Optional.empty();
25+
}
26+
27+
public IntegrationTestConfigClient(Optional<String> testName, String serviceName) {
28+
this.defaultTestName = testName;
29+
this.defaultServiceName = serviceName;
2230
}
2331

2432
@Override
@@ -28,7 +36,8 @@ public Config getConfig() {
2836

2937
@Override
3038
public Config getConfig(String service, String cluster, String pod, String container) {
31-
return loadConfig(service, cluster, pod, container)
39+
return defaultTestName.map(testName -> loadConfig(service, testName))
40+
.orElse(ConfigFactory.empty())
3241
.withFallback(loadConfig(service, cluster, pod))
3342
.withFallback(loadConfig(service, cluster))
3443
.withFallback(loadConfig(service))

integrationtest-service-framework/src/main/java/org/hypertrace/core/serviceframework/config/IntegrationTestConfigClientFactory.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import org.hypertrace.core.serviceframework.IntegrationTestServiceLauncher;
44

5+
import java.util.Optional;
6+
57
/**
68
* Used by {@link IntegrationTestServiceLauncher} to initialize
79
* the config client for the respective service
@@ -11,4 +13,8 @@ public class IntegrationTestConfigClientFactory {
1113
public static ConfigClient getConfigClientForService(String serviceName) {
1214
return new IntegrationTestConfigClient(serviceName);
1315
}
14-
}
16+
17+
public static ConfigClient getConfigClientForService(Optional<String> testName, String serviceName) {
18+
return new IntegrationTestConfigClient(testName, serviceName);
19+
}
20+
}

0 commit comments

Comments
 (0)