2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.raft;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.verify;
13 import akka.japi.Procedure;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.ArgumentCaptor;
17 import org.mockito.Mock;
18 import org.mockito.junit.MockitoJUnitRunner;
19 import org.opendaylight.controller.cluster.DataPersistenceProvider;
20 import org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Unit tests for ElectionTermImpl.
27 * @author Thomas Pantelis
29 @RunWith(MockitoJUnitRunner.StrictStubs.class)
30 public class ElectionTermImplTest {
31 private static final Logger LOG = LoggerFactory.getLogger(RaftActorRecoverySupportTest.class);
34 private DataPersistenceProvider mockPersistence;
37 @SuppressWarnings({ "rawtypes", "unchecked" })
38 public void testUpdateAndPersist() throws Exception {
39 ElectionTermImpl impl = new ElectionTermImpl(mockPersistence, "test", LOG);
41 impl.updateAndPersist(10, "member-1");
43 assertEquals("getCurrentTerm", 10, impl.getCurrentTerm());
44 assertEquals("getVotedFor", "member-1", impl.getVotedFor());
46 ArgumentCaptor<Object> message = ArgumentCaptor.forClass(Object.class);
47 ArgumentCaptor<Procedure> procedure = ArgumentCaptor.forClass(Procedure.class);
48 verify(mockPersistence).persist(message.capture(), procedure.capture());
50 assertEquals("Message type", UpdateElectionTerm.class, message.getValue().getClass());
51 UpdateElectionTerm update = (UpdateElectionTerm)message.getValue();
52 assertEquals("getCurrentTerm", 10, update.getCurrentTerm());
53 assertEquals("getVotedFor", "member-1", update.getVotedFor());
55 procedure.getValue().apply(null);