Skip to content

Commit

Permalink
build: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt committed Dec 19, 2024
1 parent 45fa080 commit 5768f90
Showing 1 changed file with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.ConsoleMonitor;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.system.ConfigurationExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.system.SystemExtension;
import org.eclipse.edc.spi.system.configuration.Config;
import org.eclipse.edc.spi.system.configuration.ConfigFactory;
import org.jetbrains.annotations.NotNull;

import java.net.URL;
import java.net.URLClassLoader;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -70,44 +71,40 @@ private EmbeddedRuntime(MultiSourceServiceLocator serviceLocator, String name, M
@Override
public void boot(boolean addShutdownHook) {
var monitor = super.createMonitor();
try {
monitor.info("Starting runtime %s".formatted(name));

// Temporarily inject system properties.
var savedProperties = (Properties) System.getProperties().clone();
properties.forEach(System::setProperty);
monitor.info("Starting runtime %s".formatted(name));

var runtimeException = new AtomicReference<Exception>();
var latch = new CountDownLatch(1);
serviceLocator.registerSystemExtension(ConfigurationExtension.class, (ConfigurationExtension) () -> ConfigFactory.fromMap(properties));

runtimeThread = executorService.submit(() -> {
try {
var classLoader = URLClassLoader.newInstance(classPathEntries);
var runtimeException = new AtomicReference<Exception>();
var latch = new CountDownLatch(1);

Thread.currentThread().setContextClassLoader(classLoader);
runtimeThread = executorService.submit(() -> {
try {
var classLoader = URLClassLoader.newInstance(classPathEntries);

super.boot(false);
Thread.currentThread().setContextClassLoader(classLoader);

latch.countDown();
super.boot(false);

isRunning.set(true);
} catch (Exception e) {
runtimeException.set(e);
throw new EdcException(e);
}
});
latch.countDown();

if (!latch.await(20, SECONDS)) {
throw new EdcException("Failed to start EDC runtime", runtimeException.get());
isRunning.set(true);
} catch (Exception e) {
runtimeException.set(e);
throw new EdcException(e);
}
});

monitor.info("Runtime %s started".formatted(name));
// Restore system properties.
System.setProperties(savedProperties);
} catch (Exception e) {
throw new EdcException(e);
try {
if (!latch.await(20, SECONDS)) {
throw new EdcException("EDC runtime didn't start in time", runtimeException.get());
}
} catch (InterruptedException e) {
throw new EdcException("Failed to start EDC runtime", runtimeException.get());
}

monitor.info("Runtime %s started".formatted(name));
}

@Override
Expand Down

0 comments on commit 5768f90

Please sign in to comment.