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.Before;
15 import org.junit.Test;
16 import org.mockito.ArgumentCaptor;
17 import org.mockito.Mock;
18 import org.mockito.MockitoAnnotations;
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 public class ElectionTermImplTest {
30 private static final Logger LOG = LoggerFactory.getLogger(RaftActorRecoverySupportTest.class);
33 private DataPersistenceProvider mockPersistence;
37 MockitoAnnotations.initMocks(this);
40 @SuppressWarnings({ "rawtypes", "unchecked" })
42 public void testUpdateAndPersist() throws Exception {
43 ElectionTermImpl impl = new ElectionTermImpl(mockPersistence, "test", LOG);
45 impl.updateAndPersist(10, "member-1");
47 assertEquals("getCurrentTerm", 10, impl.getCurrentTerm());
48 assertEquals("getVotedFor", "member-1", impl.getVotedFor());
50 ArgumentCaptor<Object> message = ArgumentCaptor.forClass(Object.class);
51 ArgumentCaptor<Procedure> procedure = ArgumentCaptor.forClass(Procedure.class);
52 verify(mockPersistence).persist(message.capture(), procedure.capture());
54 assertEquals("Message type", UpdateElectionTerm.class, message.getValue().getClass());
55 UpdateElectionTerm update = (UpdateElectionTerm)message.getValue();
56 assertEquals("getCurrentTerm", 10, update.getCurrentTerm());
57 assertEquals("getVotedFor", "member-1", update.getVotedFor());
59 procedure.getValue().apply(null);