Skip to content

Commit

Permalink
add rng-seed flag to set random seed
Browse files Browse the repository at this point in the history
  • Loading branch information
rayz committed Nov 10, 2023
1 parent b6ec32e commit 5b0a2f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class AppConfig {
@Parameter(names = {"--rmi-host", "-rh"})
public String rmiHost = Defaults.JMXSERVER_RMI_INTERFACE;

@Parameter(names = {"--rng-seed", "-rs"})
public long rngSeed = 1042849;

// Can only be set via env var
public int controlPort = Defaults.JMXSERVER_CONTROL_PORT;

Expand All @@ -71,6 +74,10 @@ public void overrideFromEnv() {
if (val != null) {
this.config_path = val;
}
val = System.getenv("RNG_SEED");
if (val != null) {
this.rngSeed = Long.parseLong(val);
}
}

public void readConfigFileOnDisk () {
Expand Down Expand Up @@ -168,7 +175,7 @@ public static void main( String[] args ) throws IOException, MalformedObjectName
MetricDAO mDao = new MetricDAO();
mDao.runTickLoop();

BeanManager bm = new BeanManager(mbs, mDao);
BeanManager bm = new BeanManager(mbs, mDao, config.rngSeed);

// Set up test domain
BeanSpec testDomainBeanSpec = new BeanSpec(1, 1, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.Executors;
Expand All @@ -25,13 +26,15 @@ public class BeanManager {
private final MBeanServer mBeanServer;
private final Map<String, List<DynamicMBeanMetrics>> registeredBeans;
private final MetricDAO mDao;
private final RandomIdentifier idGen;
static final long ATTRIBUTE_REFRESH_INTERVAL = 10;
private final ScheduledExecutorService executor;

public BeanManager(MBeanServer mBeanServer, MetricDAO mDao) {
public BeanManager(MBeanServer mBeanServer, MetricDAO mDao, long rngSeed) {
this.mBeanServer = mBeanServer;
this.registeredBeans = new HashMap<>();
this.mDao = mDao;
this.idGen = new RandomIdentifier(rngSeed);
this.executor = Executors.newSingleThreadScheduledExecutor();
runAttributeUpdateLoop();
}
Expand Down Expand Up @@ -60,7 +63,6 @@ public void clearDomainBeans(String beanDomain){

public void setMBeanState(String beanDomain, BeanSpec domainSpec) {
clearDomainBeans(beanDomain);
RandomIdentifier idGen = new RandomIdentifier();
ArrayList<DynamicMBeanMetrics> beansList = new ArrayList<DynamicMBeanMetrics>();

for (int i = 0; i < domainSpec.beanCount; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public class RandomIdentifier {
private static final List<String> VOWELS = List.of("a", "e", "i", "o", "u");
private static final List<String> CONSONANTS = List.of("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z");
private static final List<String> RARE_SEQUENCES = Arrays.asList("qz", "qp", "qj", "qw", "qx", "qr", "qt", "qy", "qs", "qd", "qf", "qg", "qh", "qk", "ql", "qc", "qv", "qb", "qn", "qm", "wz", "wq", "wk", "wp", "wj", "wy", "wh", "wl");
private static final Random RANDOM = new Random();
private final Random RANDOM;

public RandomIdentifier(long seed) {
this.RANDOM = new Random(seed);
}

private String generateWord(int minLength, int maxLength) {
int wordLength = minLength + RANDOM.nextInt(maxLength - minLength + 1);
Expand Down

0 comments on commit 5b0a2f1

Please sign in to comment.