Is it possible to perform a random switch to disperse load among requests, similarly to how it is done in Scala? I could not find any resources on how to do this in Java.
Example code:
public static final ChainBuilder teacherCreateAssignmentsSetup = group("teacherCreatesAssignmentsSetup").on(
exec(sessionSetSessionVariable)
.exec(session -> session.set("teacherRefId", getUniqueIdFromTokenSub(session)))
.exec(createEdCtsAssignment)
.exec(session -> {
log.info("assignment is :" session.getString("studentsAssignment"));
return session;
})
.randomSwitch(
50.0 -> exec(nextRequest),
50.0 -> exec(anotherRequest)
)
);
CodePudding user response:
You need to create WithWeight array.
.randomSwitch().on(
new Choice.WithWeight(50.0, exec(nextRequest)),
new Choice.WithWeight(50.0, exec(anotherRequest))
)