use of io.etcd.jetcd.election.LeaderKey in project jetcd by coreos.
the class ElectionTest method testProposeValueNotBeingLeader.
@Test
public void testProposeValueNotBeingLeader() throws Exception {
ByteSequence electionName = ByteSequence.from(randomString(), StandardCharsets.UTF_8);
LeaderKey leaderKey = new LeaderKey(electionName, randomByteSequence(), 1, 1);
ByteSequence proposal = ByteSequence.from("proposal", StandardCharsets.UTF_8);
try {
electionClient.proclaim(leaderKey, proposal).get(OPERATION_TIMEOUT, TimeUnit.SECONDS);
fail("Cannot proclaim proposal not being a leader");
} catch (ExecutionException e) {
assertThat(e.getCause()).isInstanceOf(NotLeaderException.class);
}
GetOption getOption = GetOption.newBuilder().isPrefix(true).build();
List<KeyValue> keys = kvClient.get(electionName, getOption).get().getKvs();
assertThat(keys).isEmpty();
}
Aggregations