Skip to content

Commit

Permalink
rp.client.join.launch.timeout.value and `rp.client.join.launch.time…
Browse files Browse the repository at this point in the history
…out.unit` configuration properties
  • Loading branch information
HardNorth committed Oct 25, 2024
1 parent f627b60 commit 6af9ab9
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 50 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
### Added
- `rp.client.join.launch.timeout.value` and `rp.client.join.launch.timeout.unit` configuration properties to control SecondaryLaunch start timeout on client join, by @HardNorth

## [5.2.15]
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ public class ListenerParameters implements Cloneable {
private static final String DEFAULT_CLIENT_JOIN_MODE = "FILE";
private static final String DEFAULT_LOCK_FILE_NAME = "reportportal.lock";
private static final String DEFAULT_SYNC_FILE_NAME = "reportportal.sync";
public static final long DEFAULT_FILE_WAIT_TIMEOUT_MS = TimeUnit.MINUTES.toMillis(1);
private static final int DEFAULT_CLIENT_JOIN_LOCK_PORT = 25464;
public static final long DEFAULT_FILE_WAIT_TIMEOUT = TimeUnit.MINUTES.toMillis(1);
private static final long DEFAULT_CLIENT_JOIN_TIMEOUT = TimeUnit.MINUTES.toMillis(30);
private static final long DEFAULT_CLIENT_JOIN_LAUNCH_TIMEOUT = TimeUnit.MINUTES.toMillis(1);
private static final String DEFAULT_CLIENT_JOIN_TIMEOUT_UNIT = "MILLISECONDS";
private static final String DEFAULT_CLIENT_JOIN_LOCK_TIMEOUT_UNIT = DEFAULT_CLIENT_JOIN_TIMEOUT_UNIT;
private static final int DEFAULT_CLIENT_JOIN_LOCK_PORT = 25464;
private static final String DEFAULT_CLIENT_JOIN_LAUNCH_TIMEOUT_UNIT = DEFAULT_CLIENT_JOIN_TIMEOUT_UNIT;

private static final boolean DEFAULT_TRUNCATE = true;
private static final int DEFAULT_TRUNCATE_ITEM_NAMES_LIMIT = 1024;
Expand Down Expand Up @@ -106,9 +108,10 @@ public class ListenerParameters implements Cloneable {
private LaunchIdLockMode clientJoinMode;
private String lockFileName;
private String syncFileName;
private int lockPortNumber;
private long lockWaitTimeout;
private long clientJoinTimeout;
private int lockPortNumber;
private long clientJoinLaunchTimeout;

private int rxBufferSize;

Expand Down Expand Up @@ -175,11 +178,12 @@ public ListenerParameters() {

this.clientJoin = DEFAULT_CLIENT_JOIN;
this.clientJoinMode = LaunchIdLockMode.valueOf(DEFAULT_CLIENT_JOIN_MODE);
this.clientJoinTimeout = DEFAULT_CLIENT_JOIN_TIMEOUT;
this.lockPortNumber = DEFAULT_CLIENT_JOIN_LOCK_PORT;
this.lockFileName = DEFAULT_LOCK_FILE_NAME;
this.syncFileName = DEFAULT_SYNC_FILE_NAME;
this.lockWaitTimeout = DEFAULT_FILE_WAIT_TIMEOUT_MS;
this.lockPortNumber = DEFAULT_CLIENT_JOIN_LOCK_PORT;
this.lockWaitTimeout = DEFAULT_FILE_WAIT_TIMEOUT;
this.clientJoinTimeout = DEFAULT_CLIENT_JOIN_TIMEOUT;
this.clientJoinLaunchTimeout = DEFAULT_CLIENT_JOIN_LAUNCH_TIMEOUT;

this.rxBufferSize = DEFAULT_RX_BUFFER_SIZE;

Expand Down Expand Up @@ -243,28 +247,29 @@ public ListenerParameters(PropertiesLoader properties) {

this.ioPoolSize = properties.getPropertyAsInt(IO_POOL_SIZE, DEFAULT_IO_POOL_SIZE);

// client join parameters
clientJoin = properties.getPropertyAsBoolean(CLIENT_JOIN_MODE, DEFAULT_CLIENT_JOIN);
clientJoinMode = LaunchIdLockMode.valueOf(properties.getProperty(CLIENT_JOIN_MODE_VALUE,
DEFAULT_CLIENT_JOIN_MODE
));

clientJoinTimeout = ofNullable(properties.getProperty(CLIENT_JOIN_TIMEOUT_VALUE)).map(t -> TimeUnit.valueOf(
properties.getProperty(CLIENT_JOIN_TIMEOUT_UNIT, DEFAULT_CLIENT_JOIN_TIMEOUT_UNIT))
.toMillis(Long.parseLong(t))).orElse(DEFAULT_CLIENT_JOIN_TIMEOUT);

lockPortNumber = properties.getPropertyAsInt(CLIENT_JOIN_LOCK_PORT, DEFAULT_CLIENT_JOIN_LOCK_PORT);
lockFileName = properties.getProperty(FILE_LOCK_NAME, DEFAULT_LOCK_FILE_NAME);
syncFileName = properties.getProperty(FILE_SYNC_NAME, DEFAULT_SYNC_FILE_NAME);

String waitTimeoutStr = properties.getProperty(CLIENT_JOIN_LOCK_TIMEOUT_VALUE);
if (waitTimeoutStr != null) {
TimeUnit waitTimeUnit = TimeUnit.valueOf(properties.getProperty(CLIENT_JOIN_LOCK_TIMEOUT_UNIT,
DEFAULT_CLIENT_JOIN_LOCK_TIMEOUT_UNIT
));
lockWaitTimeout = waitTimeUnit.toMillis(Long.parseLong(waitTimeoutStr));
} else {
lockWaitTimeout = DEFAULT_FILE_WAIT_TIMEOUT_MS;
}
lockPortNumber = properties.getPropertyAsInt(CLIENT_JOIN_LOCK_PORT, DEFAULT_CLIENT_JOIN_LOCK_PORT);
clientJoinTimeout = ofNullable(properties.getProperty(CLIENT_JOIN_TIMEOUT_VALUE))
.map(t -> TimeUnit.valueOf(properties.getProperty(CLIENT_JOIN_TIMEOUT_UNIT,
DEFAULT_CLIENT_JOIN_TIMEOUT_UNIT
)).toMillis(Long.parseLong(t)))
.orElse(DEFAULT_CLIENT_JOIN_TIMEOUT);
lockWaitTimeout = ofNullable(properties.getProperty(CLIENT_JOIN_LOCK_TIMEOUT_VALUE))
.map(t -> TimeUnit.valueOf(properties.getProperty(CLIENT_JOIN_LOCK_TIMEOUT_UNIT,
DEFAULT_CLIENT_JOIN_LOCK_TIMEOUT_UNIT
)).toMillis(Long.parseLong(t)))
.orElse(DEFAULT_FILE_WAIT_TIMEOUT);
clientJoinLaunchTimeout = ofNullable(properties.getProperty(CLIENT_JOIN_LAUNCH_TIMEOUT_VALUE))
.map(t -> TimeUnit.valueOf(properties.getProperty(CLIENT_JOIN_LAUNCH_TIMEOUT_UNIT,
DEFAULT_CLIENT_JOIN_LAUNCH_TIMEOUT_UNIT
)).toMillis(Long.parseLong(t)))
.orElse(DEFAULT_CLIENT_JOIN_LAUNCH_TIMEOUT);

this.rxBufferSize = properties.getPropertyAsInt(RX_BUFFER_SIZE, DEFAULT_RX_BUFFER_SIZE);

Expand Down Expand Up @@ -510,6 +515,14 @@ public void setClientJoinMode(LaunchIdLockMode clientJoinMode) {
this.clientJoinMode = clientJoinMode;
}

public int getLockPortNumber() {
return lockPortNumber;
}

public void setLockPortNumber(int lockPortNumber) {
this.lockPortNumber = lockPortNumber;
}

public String getLockFileName() {
return lockFileName;
}
Expand Down Expand Up @@ -542,12 +555,12 @@ public void setLockWaitTimeout(long timeout) {
this.lockWaitTimeout = timeout;
}

public int getLockPortNumber() {
return lockPortNumber;
public long getClientJoinLaunchTimeout() {
return clientJoinLaunchTimeout;
}

public void setLockPortNumber(int lockPortNumber) {
this.lockPortNumber = lockPortNumber;
public void setClientJoinLaunchTimeout(long clientJoinLaunchTimeout) {
this.clientJoinLaunchTimeout = clientJoinLaunchTimeout;
}

public boolean isHttpLogging() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,39 @@ public SecondaryLaunch(ReportPortalClient rpClient, ListenerParameters parameter
}

private void waitForLaunchStart() {
new Waiter("Wait for Launch start").pollingEvery(1, TimeUnit.SECONDS).timeoutFail().till(new Callable<Boolean>() {
private volatile Boolean result = null;
private final Queue<Disposable> disposables = new ConcurrentLinkedQueue<>();
new Waiter("Wait for Launch start").pollingEvery(1, TimeUnit.SECONDS)
.duration(getParameters().getClientJoinLaunchTimeout(), TimeUnit.MILLISECONDS)
.timeoutFail()
.till(new Callable<Boolean>() {
private volatile Boolean result = null;
private final Queue<Disposable> disposables = new ConcurrentLinkedQueue<>();

@Override
public Boolean call() {
if (result == null) {
disposables.add(launch.subscribe(uuid -> {
Maybe<LaunchResource> maybeRs = client.getLaunchByUuid(uuid);
if (maybeRs != null) {
disposables.add(maybeRs.subscribe(
launchResource -> result = Boolean.TRUE,
throwable -> LOGGER.debug("Unable to get a Launch: " + throwable.getLocalizedMessage(), throwable)
));
@Override
public Boolean call() {
if (result == null) {
disposables.add(launch.subscribe(uuid -> {
Maybe<LaunchResource> maybeRs = client.getLaunchByUuid(uuid);
if (maybeRs != null) {
disposables.add(maybeRs.subscribe(
launchResource -> result = Boolean.TRUE,
throwable -> LOGGER.debug(
"Unable to get a Launch: " + throwable.getLocalizedMessage(),
throwable
)
));
} else {
LOGGER.debug("RP Client returned 'null' response on get Launch by UUID call");
}
}));
} else {
LOGGER.debug("RP Client returned 'null' response on get Launch by UUID call");
Disposable disposable;
while ((disposable = disposables.poll()) != null) {
disposable.dispose();
}
}
}));
} else {
Disposable disposable;
while ((disposable = disposables.poll()) != null) {
disposable.dispose();
return result;
}
}
return result;
}
});
});
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ public enum ListenerProperty {
CLIENT_JOIN_LOCK_TIMEOUT_VALUE("rp.client.join.lock.timeout.value", false),
CLIENT_JOIN_LOCK_TIMEOUT_UNIT("rp.client.join.lock.timeout.unit", false),

/**
* Timeout of waiting for the Primary launch to start. If the primary launch does not start within this timeout, the secondary launch
* will exit.
*/
CLIENT_JOIN_LAUNCH_TIMEOUT_VALUE("rp.client.join.launch.timeout.value", false),
CLIENT_JOIN_LAUNCH_TIMEOUT_UNIT("rp.client.join.launch.timeout.unit", false),

RX_BUFFER_SIZE("rp.rx.buffer.size", false),

TRUNCATE_FIELDS("rp.truncation.field", false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void verify_lock_wait_timeout_property_set_if_it_not_present_in_property_
PropertiesLoader properties = PropertiesLoader.load("property-test/default-required.properties");
ListenerParameters listenerParameters = new ListenerParameters(properties);

assertEquals(ListenerParameters.DEFAULT_FILE_WAIT_TIMEOUT_MS, listenerParameters.getLockWaitTimeout());
assertEquals(ListenerParameters.DEFAULT_FILE_WAIT_TIMEOUT, listenerParameters.getLockWaitTimeout());
}

@Test
Expand Down

0 comments on commit 6af9ab9

Please sign in to comment.