use of io.atomix.core.election.impl.LeaderElectionOperations.Run in project atomix by atomix.
the class LeaderElectionServiceTest method testSnapshot.
@Test
public void testSnapshot() throws Exception {
ServiceContext context = mock(ServiceContext.class);
when(context.serviceType()).thenReturn(PrimitiveTypes.leaderElection());
when(context.serviceName()).thenReturn("test");
when(context.serviceId()).thenReturn(PrimitiveId.from(1));
when(context.wallClock()).thenReturn(new WallClock());
Session session = mock(Session.class);
when(session.sessionId()).thenReturn(SessionId.from(1));
LeaderElectionService service = new LeaderElectionService();
service.init(context);
byte[] id = "a".getBytes();
service.run(new DefaultCommit<>(2, RUN, new Run(id), session, System.currentTimeMillis()));
Buffer buffer = HeapBuffer.allocate();
service.backup(buffer);
service = new LeaderElectionService();
service.init(context);
service.restore(buffer.flip());
Leadership<byte[]> value = service.getLeadership();
assertNotNull(value);
assertArrayEquals(value.leader().id(), id);
}
Aggregations