Search in sources :

Example 1 with LeaderKey

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();
}
Also used : NotLeaderException(io.etcd.jetcd.election.NotLeaderException) KeyValue(io.etcd.jetcd.KeyValue) GetOption(io.etcd.jetcd.options.GetOption) LeaderKey(io.etcd.jetcd.election.LeaderKey) ExecutionException(java.util.concurrent.ExecutionException) ByteSequence(io.etcd.jetcd.ByteSequence) TestUtil.randomByteSequence(io.etcd.jetcd.impl.TestUtil.randomByteSequence) Test(org.junit.jupiter.api.Test)

Aggregations

ByteSequence (io.etcd.jetcd.ByteSequence)1 KeyValue (io.etcd.jetcd.KeyValue)1 LeaderKey (io.etcd.jetcd.election.LeaderKey)1 NotLeaderException (io.etcd.jetcd.election.NotLeaderException)1 TestUtil.randomByteSequence (io.etcd.jetcd.impl.TestUtil.randomByteSequence)1 GetOption (io.etcd.jetcd.options.GetOption)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.jupiter.api.Test)1