Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
#69 - allows CommandFetcher to fetch >1, to allow for fact that some …
Browse files Browse the repository at this point in the history
…commands may not be replicated

Also:
- placement of mixins
- fix to wall time of TickingClockService
  • Loading branch information
danhaywood committed Feb 5, 2018
1 parent e6be86f commit e06355e
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
Expand Up @@ -44,7 +44,7 @@ public static class ActionDomainEvent extends CommandModule.ActionDomainEvent<Co
@ActionLayout(
contributed = Contributed.AS_ACTION
)
@MemberOrder(name = "exception", sequence = "3")
@MemberOrder(name = "executeIn", sequence = "1")
public CommandJdo act(final Mode mode) {

switch (mode) {
Expand Down Expand Up @@ -87,8 +87,14 @@ public Mode default0Act() {
return choices0Act().get(0);
}

public boolean hideAct() {
return !commandJdo.isComplete();
public String disableAct() {
if (!commandJdo.isComplete()) {
return "Not yet completed";
}
if (commandJdo.getExecuteIn().isReplayable() && commandJdo.getReplayState() == ReplayState.OK) {
return "Replayed OK";
}
return null;
}


Expand Down
Expand Up @@ -51,7 +51,7 @@ public CommandDto fetchCommand(

LOG.debug("finding command on master ...");

final CommandsDto commandsDto = fetchCommands(previousHwm, 1, slaveConfig);
final CommandsDto commandsDto = fetchCommands(previousHwm, slaveConfig);

if (commandsDto == null) {
return null;
Expand All @@ -69,13 +69,12 @@ public CommandDto fetchCommand(
*/
private CommandsDto fetchCommands(
final Command previousHwm,
final int batchSize,
final SlaveConfiguration slaveConfig) throws StatusException {
final UUID transactionId = previousHwm != null ? previousHwm.getTransactionId() : null;

LOG.debug("finding commands on master ...");

final URI uri = buildUri(transactionId, batchSize, slaveConfig);
final URI uri = buildUri(transactionId, slaveConfig);

final JaxRsResponse response = callMaster(slaveConfig, uri);

Expand All @@ -90,15 +89,15 @@ private CommandsDto fetchCommands(



private URI buildUri(final UUID transactionId, final int batchSize, final SlaveConfiguration slaveConfig) {
private URI buildUri(final UUID transactionId, final SlaveConfiguration slaveConfig) {
final UriBuilder uriBuilder = UriBuilder.fromUri(
transactionId != null
? String.format(
"%s%s?transactionId=%s&batchSize=%d",
slaveConfig.masterBaseUrl, URL_SUFFIX, transactionId, batchSize)
slaveConfig.masterBaseUrl, URL_SUFFIX, transactionId, slaveConfig.masterBatchSize)
: String.format(
"%s%s?batchSize=%d",
slaveConfig.masterBaseUrl, URL_SUFFIX, batchSize)
slaveConfig.masterBaseUrl, URL_SUFFIX, slaveConfig.masterBatchSize)
);
final URI uri = uriBuilder.build();
LOG.debug("uri = {}", uri);
Expand Down
Expand Up @@ -33,7 +33,7 @@ public static class ActionDomainEvent extends CommandModule.ActionDomainEvent<Co
@ActionLayout(
contributed = Contributed.AS_ACTION
)
@MemberOrder(name = "exception", sequence = "2")
@MemberOrder(name = "executeIn", sequence = "2")
public CommandJdo act() {

commandJdo.setReplayState(ReplayState.EXCLUDED);
Expand Down
Expand Up @@ -17,4 +17,6 @@ public class ConfigurationKeys {
public static final String MASTER_PASSWORD_ISIS_KEY = ISIS_KEY_PREFIX + "master.password";
public static final String MASTER_USER_ISIS_KEY = ISIS_KEY_PREFIX + "master.user";
public static final String MASTER_BASE_URL_END_USER_URL_ISIS_KEY = ISIS_KEY_PREFIX + "master.baseUrlEndUser";
public static final String MASTER_BATCH_SIZE_ISIS_KEY = ISIS_KEY_PREFIX + "master.batchSize";
public static final int MASTER_BATCH_SIZE_ISIS_DEFAULT = 10;
}
Expand Up @@ -3,6 +3,8 @@
import java.util.Map;

import static org.isisaddons.module.command.replay.impl.ConfigurationKeys.MASTER_BASE_URL_ISIS_KEY;
import static org.isisaddons.module.command.replay.impl.ConfigurationKeys.MASTER_BATCH_SIZE_ISIS_DEFAULT;
import static org.isisaddons.module.command.replay.impl.ConfigurationKeys.MASTER_BATCH_SIZE_ISIS_KEY;
import static org.isisaddons.module.command.replay.impl.ConfigurationKeys.MASTER_PASSWORD_ISIS_KEY;
import static org.isisaddons.module.command.replay.impl.ConfigurationKeys.MASTER_USER_ISIS_KEY;

Expand All @@ -11,6 +13,7 @@ public class SlaveConfiguration {
final String masterUser;
final String masterPassword;
final String masterBaseUrl;
final int masterBatchSize;

public SlaveConfiguration(final Map<String, String> map) {
masterUser = map.get(MASTER_USER_ISIS_KEY);
Expand All @@ -20,6 +23,15 @@ public SlaveConfiguration(final Map<String, String> map) {
masterBaseUrl = masterBaseUrl + "/";
}
this.masterBaseUrl= masterBaseUrl;
this.masterBatchSize = batchSizeFrom(map);
}

private static int batchSizeFrom(final Map<String, String> map) {
try {
return Integer.parseInt(map.get(MASTER_BATCH_SIZE_ISIS_KEY));
} catch (NumberFormatException e) {
return MASTER_BATCH_SIZE_ISIS_DEFAULT;
}
}

boolean isConfigured() {
Expand Down
Expand Up @@ -86,12 +86,14 @@ public void at(Timestamp timestamp, Runnable runnable) {
ensureInitialized();

final TickingFixtureClock instance = (TickingFixtureClock) TickingFixtureClock.getInstance();
final Timestamp previous = TickingFixtureClock.getTimeAsJavaSqlTimestamp();
final long previous = TickingFixtureClock.getTimeAsMillis();
final long wallTime0 = System.currentTimeMillis();
try {
instance.setTime(timestamp);
runnable.run();
} finally {
instance.setTime(previous);
final long wallTime1 = System.currentTimeMillis();
instance.setTime(previous + wallTime1 - wallTime0);
}
}

Expand Down
Expand Up @@ -46,7 +46,7 @@ public static class ActionDomainEvent extends CommandModule.ActionDomainEvent<Co
@ActionLayout(
contributed = Contributed.AS_ACTION
)
@MemberOrder(name = "exception", sequence = "1")
@MemberOrder(name = "executeIn", sequence = "3")
public CommandJdo act() throws StatusException {

// double check this is still the HWM
Expand Down

0 comments on commit e06355e

Please sign in to comment.