@Test
    public void testGetAndSetReload() {
        assertEquals(0, this.raftMetaStorage.getTerm());
        assertTrue(this.raftMetaStorage.getVotedFor().isEmpty());

        this.raftMetaStorage.setTerm(99);
        assertEquals(99, this.raftMetaStorage.getTerm());
        assertTrue(this.raftMetaStorage.getVotedFor().isEmpty());

        assertTrue(this.raftMetaStorage.setVotedFor(new PeerId("localhost", 8081)));
        assertEquals(99, this.raftMetaStorage.getTerm());
        Assert.assertEquals(new PeerId("localhost", 8081), this.raftMetaStorage.getVotedFor());

        assertTrue(this.raftMetaStorage.setTermAndVotedFor(100, new PeerId("localhost", 8083)));
        assertEquals(100, this.raftMetaStorage.getTerm());
        Assert.assertEquals(new PeerId("localhost", 8083), this.raftMetaStorage.getVotedFor());

        this.raftMetaStorage = new LocalRaftMetaStorage(this.path, new RaftOptions());
        Mockito.when(this.node.getNodeMetrics()).thenReturn(null);
        this.raftMetaStorage.init(newOptions());
        assertEquals(100, this.raftMetaStorage.getTerm());
        Assert.assertEquals(new PeerId("localhost", 8083), this.raftMetaStorage.getVotedFor());
    }
@author boyan (boyan@alibaba-inc.com)

2018-Apr-11 4:50:23 PM
jraft-core/src/test/java/com/alipay/sofa/jraft/storage/impl/LocalRaftMetaStorageTest.java