Search in sources :

Example 1 with WallClock

use of io.atomix.utils.time.WallClock 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);
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) ServiceContext(io.atomix.primitive.service.ServiceContext) WallClock(io.atomix.utils.time.WallClock) LeaderElectionService(io.atomix.core.election.impl.LeaderElectionService) Run(io.atomix.core.election.impl.LeaderElectionOperations.Run) Session(io.atomix.primitive.session.Session) Test(org.junit.Test)

Aggregations

Run (io.atomix.core.election.impl.LeaderElectionOperations.Run)1 LeaderElectionService (io.atomix.core.election.impl.LeaderElectionService)1 ServiceContext (io.atomix.primitive.service.ServiceContext)1 Session (io.atomix.primitive.session.Session)1 Buffer (io.atomix.storage.buffer.Buffer)1 HeapBuffer (io.atomix.storage.buffer.HeapBuffer)1 WallClock (io.atomix.utils.time.WallClock)1 Test (org.junit.Test)1