Fixup 143f4f13 Display the daemon id and shorten it a bit #314

This commit is contained in:
Peter Palaga
2021-01-08 23:19:40 +01:00
parent 143f4f13ab
commit ddea5d8ea8
22 changed files with 114 additions and 113 deletions

View File

@@ -121,7 +121,7 @@ public class DaemonClientConnection implements Closeable {
}
return result;
} catch (Exception e) {
DaemonDiagnostics diag = new DaemonDiagnostics(daemon.getUid(), parameters);
DaemonDiagnostics diag = new DaemonDiagnostics(daemon.getId(), parameters);
LOG.debug("Problem receiving message to the daemon. Performing 'on failure' operation...");
if (!hasReceived && newDaemon) {
throw new ConnectException("Could not receive a message from the daemon.\n" + diag.describe(), e);

View File

@@ -112,9 +112,10 @@ public class DaemonConnector {
}
// No compatible daemons available - start a new daemon
String message = handleStopEvents(idleDaemons, busyDaemons);
final String daemonId = newId();
String message = handleStopEvents(daemonId, idleDaemons, busyDaemons);
output.accept(Message.buildStatus(message));
return startDaemon();
return startDaemon(daemonId);
}
private DaemonClientConnection connectNoDaemon() {
@@ -128,7 +129,7 @@ public class DaemonConnector {
properties.put(Environment.USER_DIR.getProperty(), parameters.userDir().toString());
properties.put(Environment.USER_HOME.getProperty(), parameters.userHome().toString());
properties.put(Environment.MVND_HOME.getProperty(), parameters.mvndHome().toString());
properties.put(Environment.MVND_UID.getProperty(), daemon);
properties.put(Environment.MVND_ID.getProperty(), daemon);
properties.put(Environment.MVND_DAEMON_STORAGE.getProperty(), parameters.daemonStorage().toString());
properties.put(Environment.MVND_REGISTRY.getProperty(), parameters.registry().toString());
properties.putAll(parameters.getDaemonOptsMap());
@@ -160,7 +161,7 @@ public class DaemonConnector {
throw new RuntimeException("Unable to connect to internal daemon", throwable.get());
}
private String handleStopEvents(Collection<DaemonInfo> idleDaemons, Collection<DaemonInfo> busyDaemons) {
private String handleStopEvents(String daemonId, Collection<DaemonInfo> idleDaemons, Collection<DaemonInfo> busyDaemons) {
final List<DaemonStopEvent> stopEvents = registry.getStopEvents();
// Clean up old stop events
@@ -173,7 +174,7 @@ public class DaemonConnector {
final List<DaemonStopEvent> recentStopEvents = stopEvents.stream()
.filter(e -> e.getTimestamp() >= time)
.collect(Collectors.groupingBy(DaemonStopEvent::getUid,
.collect(Collectors.groupingBy(DaemonStopEvent::getDaemonId,
Collectors.minBy(this::compare)))
.values()
.stream()
@@ -181,13 +182,13 @@ public class DaemonConnector {
.collect(Collectors.toList());
for (DaemonStopEvent stopEvent : recentStopEvents) {
LOGGER.debug("Previous Daemon ({}) stopped at {} {}",
stopEvent.getUid(), stopEvent.getTimestamp(), stopEvent.getReason());
stopEvent.getDaemonId(), stopEvent.getTimestamp(), stopEvent.getReason());
}
return generate(busyDaemons.size(), idleDaemons.size(), recentStopEvents.size());
return generate(daemonId, busyDaemons.size(), idleDaemons.size(), recentStopEvents.size());
}
public static String generate(final int numBusy, final int numIncompatible, final int numStopped) {
public static String generate(final String daemonId, final int numBusy, final int numIncompatible, final int numStopped) {
final int totalUnavailableDaemons = numBusy + numIncompatible + numStopped;
if (totalUnavailableDaemons > 0) {
final List<String> reasons = new ArrayList<>();
@@ -200,11 +201,11 @@ public class DaemonConnector {
if (numStopped > 0) {
reasons.add(numStopped + " stopped");
}
return "Starting new daemon, "
return "Starting new daemon " + daemonId + ", "
+ String.join(" and ", reasons) + " daemon" + (totalUnavailableDaemons > 1 ? "s" : "")
+ " could not be reused, use --status for details";
} else {
return "Starting new daemon (subsequent builds will be faster)...";
return "Starting new daemon " + daemonId + " (subsequent builds will be faster)...";
}
}
@@ -254,7 +255,7 @@ public class DaemonConnector {
compatibleDaemons.add(daemon);
} else {
LOGGER.debug("{} daemon {} does not match the desired criteria: "
+ result.getWhy(), daemon.getState(), daemon.getUid());
+ result.getWhy(), daemon.getState(), daemon.getId());
}
}
return compatibleDaemons;
@@ -271,13 +272,12 @@ public class DaemonConnector {
return null;
}
public DaemonClientConnection startDaemon() {
final String daemon = newUid();
final Process process = startDaemon(daemon);
LOGGER.debug("Started Maven daemon {}", daemon);
public DaemonClientConnection startDaemon(String daemonId) {
final Process process = startDaemonProcess(daemonId);
LOGGER.debug("Started Maven daemon {}", daemonId);
long start = System.currentTimeMillis();
do {
DaemonClientConnection daemonConnection = connectToDaemonWithId(daemon, true);
DaemonClientConnection daemonConnection = connectToDaemonWithId(daemonId, true);
if (daemonConnection != null) {
return daemonConnection;
}
@@ -287,15 +287,15 @@ public class DaemonConnector {
throw new DaemonException.InterruptedException(e);
}
} while (process.isAlive() && System.currentTimeMillis() - start < DEFAULT_CONNECT_TIMEOUT);
DaemonDiagnostics diag = new DaemonDiagnostics(daemon, parameters);
DaemonDiagnostics diag = new DaemonDiagnostics(daemonId, parameters);
throw new DaemonException.ConnectException("Timeout waiting to connect to the Maven daemon.\n" + diag.describe());
}
static String newUid() {
static String newId() {
return String.format("%08x", new Random().nextInt());
}
private Process startDaemon(String uid) {
private Process startDaemonProcess(String daemonId) {
final Path mvndHome = parameters.mvndHome();
final Path workingDir = parameters.userDir();
String command = "";
@@ -353,15 +353,15 @@ public class DaemonConnector {
Environment.MVND_JAVA_HOME.addCommandLineOption(args, parameters.javaHome().toString());
Environment.LOGBACK_CONFIGURATION_FILE
.addCommandLineOption(args, parameters.logbackConfigurationPath().toString());
Environment.MVND_UID.addCommandLineOption(args, uid);
Environment.MVND_ID.addCommandLineOption(args, daemonId);
Environment.MVND_DAEMON_STORAGE.addCommandLineOption(args, parameters.daemonStorage().toString());
Environment.MVND_REGISTRY.addCommandLineOption(args, parameters.registry().toString());
parameters.discriminatingCommandLineOptions(args);
args.add(MavenDaemon.class.getName());
command = String.join(" ", args);
LOGGER.debug("Starting daemon process: uid = {}, workingDir = {}, daemonArgs: {}", uid, workingDir, command);
ProcessBuilder.Redirect redirect = ProcessBuilder.Redirect.appendTo(parameters.daemonOutLog(uid).toFile());
LOGGER.debug("Starting daemon process: id = {}, workingDir = {}, daemonArgs: {}", daemonId, workingDir, command);
ProcessBuilder.Redirect redirect = ProcessBuilder.Redirect.appendTo(parameters.daemonOutLog(daemonId).toFile());
Process process = new ProcessBuilder()
.directory(workingDir.toFile())
.command(args)
@@ -371,8 +371,8 @@ public class DaemonConnector {
return process;
} catch (Exception e) {
throw new DaemonException.StartException(
String.format("Error starting daemon: uid = %s, workingDir = %s, daemonArgs: %s",
uid, workingDir, command),
String.format("Error starting daemon: id = %s, workingDir = %s, daemonArgs: %s",
daemonId, workingDir, command),
e);
}
}
@@ -419,10 +419,10 @@ public class DaemonConnector {
public boolean maybeStaleAddress(Exception failure) {
LOGGER.debug("Removing daemon from the registry due to communication failure. Daemon information: {}", daemon);
final long timestamp = System.currentTimeMillis();
final DaemonStopEvent stopEvent = new DaemonStopEvent(daemon.getUid(), timestamp, null,
final DaemonStopEvent stopEvent = new DaemonStopEvent(daemon.getId(), timestamp, null,
"by user or operating system");
registry.storeStopEvent(stopEvent);
registry.remove(daemon.getUid());
registry.remove(daemon.getId());
return true;
}
}

View File

@@ -34,27 +34,27 @@ public class DaemonDiagnostics {
private final static int TAIL_SIZE = 200;
private final String uid;
private final String id;
private final DaemonParameters parameters;
public DaemonDiagnostics(String uid, DaemonParameters parameters) {
this.uid = uid;
public DaemonDiagnostics(String id, DaemonParameters parameters) {
this.id = id;
this.parameters = parameters;
}
@Override
public String toString() {
return "{"
+ "uid=" + uid
+ "id=" + id
+ ", parameters=" + parameters
+ '}';
}
public String describe() {
StringBuilder sb = new StringBuilder();
sb.append("Daemon uid: ").append(uid).append("\n");
tail(sb, "log file", parameters.daemonLog(uid));
tail(sb, "output", parameters.daemonOutLog(uid));
sb.append("Daemon id: ").append(id).append("\n");
tail(sb, "log file", parameters.daemonLog(id));
tail(sb, "output", parameters.daemonOutLog(id));
return sb.toString();
}

View File

@@ -170,16 +170,16 @@ public class DefaultClient implements Client {
try (DaemonRegistry registry = new DaemonRegistry(parameters.registry())) {
if (Environment.STATUS.removeCommandLineOption(args) != null) {
final String template = " %36s %7s %5s %7s %5s %23s %s";
final String template = "%8s %7s %5s %7s %5s %23s %s";
output.accept(Message.log(String.format(template,
"UUID", "PID", "Port", "Status", "RSS", "Last activity", "Java home")));
"ID", "PID", "Port", "Status", "RSS", "Last activity", "Java home")));
for (DaemonInfo d : registry.getAll()) {
if (ProcessHandle.of(d.getPid()).isEmpty()) {
/* The process does not exist anymore - remove it from the registry */
registry.remove(d.getUid());
registry.remove(d.getId());
} else {
output.accept(Message.log(String.format(template,
d.getUid(), d.getPid(), d.getAddress(), d.getState(),
d.getId(), d.getPid(), d.getAddress(), d.getState(),
OsUtils.kbTohumanReadable(OsUtils.findProcessRssInKb(d.getPid())),
LocalDateTime.ofInstant(
Instant.ofEpochMilli(Math.max(d.getLastIdle(), d.getLastBusy())),
@@ -197,9 +197,9 @@ public class DefaultClient implements Client {
try {
ProcessHandle.of(di.getPid()).ifPresent(ProcessHandle::destroyForcibly);
} catch (Exception t) {
System.out.println("Daemon " + di.getUid() + ": " + t);
System.out.println("Daemon " + di.getId() + ": " + t);
} finally {
registry.remove(di.getUid());
registry.remove(di.getId());
}
}
}
@@ -229,7 +229,7 @@ public class DefaultClient implements Client {
final DaemonConnector connector = new DaemonConnector(parameters, registry);
try (DaemonClientConnection daemon = connector.connect(output)) {
output.setDaemonId(daemon.getDaemon().getUid());
output.setDaemonId(daemon.getDaemon().getId());
output.setDaemonDispatch(daemon::dispatch);
output.setDaemonReceive(daemon::enqueue);
@@ -239,7 +239,8 @@ public class DefaultClient implements Client {
parameters.multiModuleProjectDirectory().toString(),
System.getenv()));
output.accept(Message.buildStatus("Daemon started, scanning for projects..."));
output.accept(Message
.buildStatus("Connected to daemon " + daemon.getDaemon().getId() + ", scanning for projects..."));
// We've sent the request, so it gives us a bit of time to purge the logs
AtomicReference<String> purgeMessage = new AtomicReference<>();

View File

@@ -23,9 +23,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
public class DaemonConnectorTest {
@Test
public void testUid() {
String uid = DaemonConnector.newUid();
assertNotNull(uid);
assertEquals(8, uid.length());
public void newId() {
String id = DaemonConnector.newId();
assertNotNull(id);
assertEquals(8, id.length());
}
}

View File

@@ -63,7 +63,7 @@ public class DaemonCompatibilitySpec {
final StringBuilder sb = new StringBuilder("Wanted: ");
appendFields(sb);
sb.append("\nActual: ");
context.appendNonKeyFields(sb).append("uid=").append(context.getUid()).append('\n');
context.appendNonKeyFields(sb).append("id=").append(context.getId()).append('\n');
return sb.toString();
}

View File

@@ -26,7 +26,7 @@ import static org.mvndaemon.mvnd.common.DaemonState.Idle;
*/
public class DaemonInfo {
private final String uid;
private final String id;
private final String javaHome;
private final String mvndHome;
private final int pid;
@@ -37,11 +37,11 @@ public class DaemonInfo {
private final long lastIdle;
private final long lastBusy;
public DaemonInfo(String uid, String javaHome, String mavenHome,
public DaemonInfo(String id, String javaHome, String mavenHome,
int pid, int address,
String locale, List<String> options,
DaemonState state, long lastIdle, long lastBusy) {
this.uid = uid;
this.id = id;
this.javaHome = javaHome;
this.mvndHome = mavenHome;
this.pid = pid;
@@ -53,8 +53,8 @@ public class DaemonInfo {
this.lastBusy = lastBusy;
}
public String getUid() {
return uid;
public String getId() {
return id;
}
public String getJavaHome() {
@@ -105,13 +105,13 @@ public class DaemonInfo {
li = lastIdle;
lb = lastBusy;
}
return new DaemonInfo(uid, javaHome, mvndHome, pid, address,
return new DaemonInfo(id, javaHome, mvndHome, pid, address,
locale, options, state, li, lb);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("DaemonInfo{uid=").append(uid);
final StringBuilder sb = new StringBuilder("DaemonInfo{id=").append(id);
appendNonKeyFields(sb);
return sb.append('}').toString();
}

View File

@@ -92,9 +92,9 @@ public class DaemonRegistry implements AutoCloseable {
return registryFile;
}
public DaemonInfo get(String uid) {
public DaemonInfo get(String daemonId) {
read();
return infosMap.get(uid);
return infosMap.get(daemonId);
}
public List<DaemonInfo> getAll() {
@@ -122,13 +122,13 @@ public class DaemonRegistry implements AutoCloseable {
.collect(Collectors.toList());
}
public void remove(final String uid) {
update(() -> infosMap.remove(uid));
public void remove(final String daemonId) {
update(() -> infosMap.remove(daemonId));
}
public void markState(final String uid, final DaemonState state) {
LOGGER.debug("Marking busy by uid: {}", uid);
update(() -> infosMap.computeIfPresent(uid, (id, di) -> di.withState(state)));
public void markState(final String daemonId, final DaemonState state) {
LOGGER.debug("Marking busy by id: {}", daemonId);
update(() -> infosMap.computeIfPresent(daemonId, (id, di) -> di.withState(state)));
}
public void storeStopEvent(final DaemonStopEvent stopEvent) {
@@ -148,7 +148,7 @@ public class DaemonRegistry implements AutoCloseable {
public void store(final DaemonInfo info) {
LOGGER.debug("Storing daemon {}", info);
update(() -> infosMap.put(info.getUid(), info));
update(() -> infosMap.put(info.getId(), info));
}
public static int getProcessId() {
@@ -176,7 +176,7 @@ public class DaemonRegistry implements AutoCloseable {
infosMap.clear();
int nb = buffer.getInt();
for (int i = 0; i < nb; i++) {
String uid = readString();
String daemonId = readString();
String javaHome = readString();
String mavenHome = readString();
int pid = buffer.getInt();
@@ -190,19 +190,19 @@ public class DaemonRegistry implements AutoCloseable {
DaemonState state = DaemonState.values()[buffer.get()];
long lastIdle = buffer.getLong();
long lastBusy = buffer.getLong();
DaemonInfo di = new DaemonInfo(uid, javaHome, mavenHome, pid, address, locale, opts, state,
DaemonInfo di = new DaemonInfo(daemonId, javaHome, mavenHome, pid, address, locale, opts, state,
lastIdle, lastBusy);
infosMap.putIfAbsent(di.getUid(), di);
infosMap.putIfAbsent(di.getId(), di);
}
stopEvents.clear();
nb = buffer.getInt();
for (int i = 0; i < nb; i++) {
String uid = readString();
String daemonId = readString();
long date = buffer.getLong();
int ord = buffer.get();
DaemonExpirationStatus des = ord >= 0 ? DaemonExpirationStatus.values()[ord] : null;
String reason = readString();
DaemonStopEvent se = new DaemonStopEvent(uid, date, des, reason);
DaemonStopEvent se = new DaemonStopEvent(daemonId, date, des, reason);
stopEvents.add(se);
}
@@ -211,7 +211,7 @@ public class DaemonRegistry implements AutoCloseable {
BufferCaster.cast(buffer).position((int) 0);
buffer.putInt(infosMap.size());
for (DaemonInfo di : infosMap.values()) {
writeString(di.getUid());
writeString(di.getId());
writeString(di.getJavaHome());
writeString(di.getMvndHome());
buffer.putInt(di.getPid());
@@ -227,7 +227,7 @@ public class DaemonRegistry implements AutoCloseable {
}
buffer.putInt(stopEvents.size());
for (DaemonStopEvent dse : stopEvents) {
writeString(dse.getUid());
writeString(dse.getDaemonId());
buffer.putLong(dse.getTimestamp());
buffer.put((byte) (dse.getStatus() == null ? -1 : dse.getStatus().ordinal()));
writeString(dse.getReason());

View File

@@ -29,20 +29,20 @@ import java.util.Objects;
*/
public class DaemonStopEvent implements Serializable {
private final String uid;
private final String daemonId;
private final long timestamp;
private final DaemonExpirationStatus status;
private final String reason;
public DaemonStopEvent(String uid, long timestamp, DaemonExpirationStatus status, String reason) {
this.uid = uid;
public DaemonStopEvent(String daemonId, long timestamp, DaemonExpirationStatus status, String reason) {
this.daemonId = daemonId;
this.timestamp = timestamp;
this.status = status;
this.reason = reason != null ? reason : "";
}
public String getUid() {
return uid;
public String getDaemonId() {
return daemonId;
}
public long getTimestamp() {
@@ -64,7 +64,7 @@ public class DaemonStopEvent implements Serializable {
if (o == null || getClass() != o.getClass())
return false;
DaemonStopEvent that = (DaemonStopEvent) o;
return Objects.equals(uid, that.uid)
return Objects.equals(daemonId, that.daemonId)
&& timestamp == that.timestamp
&& status == that.status
&& Objects.equals(reason, that.reason);
@@ -72,13 +72,13 @@ public class DaemonStopEvent implements Serializable {
@Override
public int hashCode() {
return Objects.hash(timestamp, uid, status, reason);
return Objects.hash(timestamp, daemonId, status, reason);
}
@Override
public String toString() {
return "DaemonStopEvent{"
+ "uid=" + uid
+ "daemonId=" + daemonId
+ ", timestamp=" + DateFormat.getDateTimeInstance().format(new Date(timestamp))
+ ", status=" + status
+ ", reason=" + reason

View File

@@ -185,7 +185,7 @@ public enum Environment {
/**
* An ID for a newly started daemon
*/
MVND_UID("mvnd.uid", null, null, OptionType.STRING, Flags.INTERNAL),
MVND_ID("mvnd.id", null, null, OptionType.STRING, Flags.INTERNAL),
/**
* Internal option to specify the maven extension classpath
*/

View File

@@ -24,7 +24,7 @@ import org.mvndaemon.mvnd.common.Message;
*/
public interface ClientOutput extends AutoCloseable {
void setDaemonId(String uid);
void setDaemonId(String daemonId);
void setDaemonDispatch(Consumer<Message> sink);

View File

@@ -609,6 +609,13 @@ public class TerminalOutput implements ClientOutput {
asb.append(name);
asb.style(AttributedStyle.DEFAULT);
/* Daemon ID */
asb
.append(" daemon: ")
.style(AttributedStyle.BOLD)
.append(daemonId)
.style(AttributedStyle.DEFAULT);
/* Threads */
asb
.append(" threads used/hidden/max: ")
@@ -636,13 +643,6 @@ public class TerminalOutput implements ClientOutput {
.append('%')
.style(AttributedStyle.DEFAULT);
/* DaemonId */
asb
.append(" daemon: ")
.style(AttributedStyle.BOLD)
.append(daemonId)
.style(AttributedStyle.DEFAULT);
} else if (buildStatus != null) {
asb
.style(AttributedStyle.BOLD)

View File

@@ -40,7 +40,7 @@ public class DaemonRegistryTest {
byte[] token = new byte[16];
new Random().nextBytes(token);
reg1.store(new DaemonInfo("the-uid", "/java/home/",
reg1.store(new DaemonInfo("12345678", "/java/home/",
"/data/reg/", 0x12345678, 7502,
Locale.getDefault().toLanguageTag(), Arrays.asList("-Xmx"),
DaemonState.Idle, System.currentTimeMillis(), System.currentTimeMillis()));

View File

@@ -666,7 +666,7 @@ public class DaemonMavenCli {
eventSpyDispatcher.onEvent(request);
slf4jLogger.info(buffer().a("Processing build on daemon ")
.strong(Environment.MVND_UID.asString()).toString());
.strong(Environment.MVND_ID.asString()).toString());
MavenExecutionResult result = maven.execute(request);

View File

@@ -100,7 +100,7 @@ public class DaemonExpiration {
static DaemonExpirationStrategy notMostRecentlyUsed() {
return daemon -> daemon.getRegistry().getIdle().stream()
.max(Comparator.comparingLong(DaemonInfo::getLastBusy))
.map(d -> Objects.equals(d.getUid(), daemon.getUid()))
.map(d -> Objects.equals(d.getId(), daemon.getDaemonId()))
.orElse(false)
? new DaemonExpirationResult(GRACEFUL_EXPIRE, "not recently used")
: NOT_TRIGGERED;
@@ -111,7 +111,7 @@ public class DaemonExpiration {
try {
if (!Files.isReadable(daemon.getRegistry().getRegistryFile())) {
return new DaemonExpirationResult(GRACEFUL_EXPIRE, "after the daemon registry became unreadable");
} else if (daemon.getRegistry().get(daemon.getUid()) == null) {
} else if (daemon.getRegistry().get(daemon.getDaemonId()) == null) {
return new DaemonExpirationResult(GRACEFUL_EXPIRE,
"after the daemon was no longer found in the daemon registry");
} else {

View File

@@ -73,7 +73,7 @@ public class Server implements AutoCloseable, Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(Server.class);
public static final int CANCEL_TIMEOUT = 10 * 1000;
private final String uid;
private final String daemonId;
private final boolean noDaemon;
private final ServerSocketChannel socket;
private final DaemonMavenCli cli;
@@ -105,7 +105,7 @@ public class Server implements AutoCloseable, Runnable {
} catch (Throwable t) {
LOGGER.warn("Unable to ignore INT and TSTP signals", t);
}
this.uid = Environment.MVND_UID.asString();
this.daemonId = Environment.MVND_ID.asString();
this.noDaemon = Environment.MVND_NO_DAEMON.asBoolean();
this.keepAliveMs = Environment.MVND_KEEP_ALIVE.asDuration().toMillis();
@@ -126,7 +126,7 @@ public class Server implements AutoCloseable, Runnable {
"\n ", "Initializing daemon with properties:\n ", "\n")));
}
long cur = System.currentTimeMillis();
info = new DaemonInfo(uid,
info = new DaemonInfo(daemonId,
Environment.MVND_JAVA_HOME.asString(),
Environment.MVND_HOME.asString(),
DaemonRegistry.getProcessId(),
@@ -200,7 +200,7 @@ public class Server implements AutoCloseable, Runnable {
} catch (Throwable t) {
LOGGER.error("Error running daemon loop", t);
} finally {
registry.remove(uid);
registry.remove(daemonId);
}
}
@@ -283,7 +283,7 @@ public class Server implements AutoCloseable, Runnable {
private void onExpire(String reason, DaemonExpirationStatus status) {
LOGGER.debug("Storing daemon stop event: {}", reason);
registry.storeStopEvent(new DaemonStopEvent(uid, System.currentTimeMillis(), status, reason));
registry.storeStopEvent(new DaemonStopEvent(daemonId, System.currentTimeMillis(), status, reason));
}
boolean awaitStop() {
@@ -616,8 +616,8 @@ public class Server implements AutoCloseable, Runnable {
return info;
}
public String getUid() {
return info.getUid();
public String getDaemonId() {
return info.getId();
}
public DaemonState getState() {

View File

@@ -32,7 +32,7 @@ public class TestClientOutput implements ClientOutput {
}
@Override
public void setDaemonId(String uid) {
public void setDaemonId(String daemonId) {
}
@Override

View File

@@ -52,7 +52,7 @@ public class ExtensionsNativeIT {
assertTrue(daemon.getOptions().contains(
"mvnd.coreExtensions=io.takari.aether:takari-local-repository:[0.11.3,);fr.jcgay.maven:maven-profiler:3.0"));
registry.awaitIdle(daemon.getUid());
registry.awaitIdle(daemon.getId());
client.execute(o, "-v").assertSuccess();
assertDaemonRegistrySize(1);

View File

@@ -58,7 +58,7 @@ public class NewManagedModuleNativeIT {
final DaemonInfo d = registry.getAll().get(0);
/* Wait, till the instance becomes idle */
registry.awaitIdle(d.getUid());
registry.awaitIdle(d.getId());
/* Do the changes */
final Path srcDir = parentDir.resolve("../changes").normalize();

View File

@@ -51,10 +51,10 @@ public class StopStatusTest {
final TestClientOutput output = new TestClientOutput();
client.execute(output, "--status").assertSuccess();
output.assertContainsMatchingSubsequence(d.getUid() + " +" + d.getPid() + " +" + d.getAddress());
output.assertContainsMatchingSubsequence(d.getId() + " +" + d.getPid() + " +" + d.getAddress());
}
/* Wait, till the instance becomes idle */
registry.awaitIdle(d.getUid());
registry.awaitIdle(d.getId());
client.execute(new TestClientOutput(), "clean").assertSuccess();
/* There should still be exactly one item in the registry after the second build */
@@ -65,13 +65,13 @@ public class StopStatusTest {
assertDaemonRegistrySize(0);
{
/* After --stop, the output of --status may not contain the UID we have seen before */
/* After --stop, the output of --status may not contain the daemon ID we have seen before */
final TestClientOutput output = new TestClientOutput();
client.execute(output, "--status").assertSuccess();
Assertions.assertThat(
output.messagesToString().stream()
.filter(m -> m.contains(d.getUid()))
.filter(m -> m.contains(d.getId()))
.collect(Collectors.toList()))
.isEmpty();
}

View File

@@ -54,7 +54,7 @@ public class UpgradesInBomNativeIT {
assertDaemonRegistrySize(1);
final DaemonInfo d = registry.getAll().get(0);
/* Wait, till the instance becomes idle */
registry.awaitIdle(d.getUid());
registry.awaitIdle(d.getId());
registry.killAll();
}
assertDaemonRegistrySize(0);
@@ -70,7 +70,7 @@ public class UpgradesInBomNativeIT {
final DaemonInfo d = registry.getAll().get(0);
/* Wait, till the instance becomes idle */
registry.awaitIdle(d.getUid());
registry.awaitIdle(d.getId());
/* Upgrade the dependency */
final Path parentPomPath = parentDir.resolve("pom.xml");

View File

@@ -49,9 +49,9 @@ public class TestRegistry extends DaemonRegistry {
exit.get(5, TimeUnit.SECONDS);
}
} catch (Exception t) {
System.out.println("Daemon " + di.getUid() + ": " + t);
System.out.println("Daemon " + di.getId() + ": " + t);
} finally {
remove(di.getUid());
remove(di.getId());
}
}
if (deadline < System.currentTimeMillis() && !getAll().isEmpty()) {
@@ -63,20 +63,20 @@ public class TestRegistry extends DaemonRegistry {
/**
* Poll the state of the daemon with the given {@code uid} until it becomes idle.
*
* @param uid the uid of the daemon to poll
* @param daemonId the ID of the daemon to poll
* @throws IllegalStateException if the daemon is not available in the registry
* @throws AssertionError if the timeout is exceeded
*/
public void awaitIdle(String uid) {
public void awaitIdle(String daemonId) {
final int timeoutMs = 5000;
final long deadline = System.currentTimeMillis() + timeoutMs;
while (getAll().stream()
.filter(di -> di.getUid().equals(uid))
.filter(di -> di.getId().equals(daemonId))
.findFirst()
.orElseThrow(() -> new IllegalStateException("Daemon " + uid + " is not available in the registry"))
.orElseThrow(() -> new IllegalStateException("Daemon " + daemonId + " is not available in the registry"))
.getState() != DaemonState.Idle) {
Assertions.assertThat(deadline)
.withFailMessage("Daemon %s should have become idle within %d", uid, timeoutMs)
.withFailMessage("Daemon %s should have become idle within %d", daemonId, timeoutMs)
.isGreaterThan(System.currentTimeMillis());
}
}