final State offline = State.from("OFFLINE");
// start: add a user config, add master and slave constraints
UserConfig userConfig = new UserConfig(Scope.cluster(clusterId));
userConfig.setSimpleField("key1", "value1");
ClusterConfig config =
new ClusterConfig.Builder(clusterId)
.addStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, master, 2)
.addStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, slave, 3)
.userConfig(userConfig).autoJoin(true).build();
// update: overwrite user config, change master constraint, remove slave constraint, add offline
// constraint, change auto join
UserConfig newUserConfig = new UserConfig(Scope.cluster(clusterId));
newUserConfig.setSimpleField("key2", "value2");
ClusterConfig updated =
new ClusterConfig.Delta(clusterId)
.addStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, master, 1)
.removeStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, slave)
.addStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, offline, "R")
.setUserConfig(newUserConfig).setAutoJoin(false).mergeInto(config);
Assert.assertEquals(
updated.getStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, master), "1");
Assert.assertEquals(
updated.getStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, slave), "-1");
Assert.assertEquals(
updated.getStateUpperBoundConstraint(Scope.cluster(clusterId), masterSlave, offline), "R");
Assert.assertNull(updated.getUserConfig().getSimpleField("key1"));
Assert.assertEquals(updated.getUserConfig().getSimpleField("key2"), "value2");
Assert.assertFalse(updated.autoJoinAllowed());
}