Search in sources :

Example 11 with DefaultBackupInput

use of io.atomix.primitive.service.impl.DefaultBackupInput in project atomix by atomix.

the class DefaultAtomicDocumentTreeServiceTest method testSnapshot.

@Test
public void testSnapshot() throws Exception {
    DefaultDocumentTreeService service = new DefaultDocumentTreeService();
    service.set(DocumentPath.from("/foo"), "Hello world!".getBytes());
    Buffer buffer = HeapBuffer.allocate();
    service.backup(new DefaultBackupOutput(buffer, service.serializer()));
    service = new DefaultDocumentTreeService();
    service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
    Versioned<byte[]> value = service.get(DocumentPath.from("/foo"));
    assertNotNull(value);
    assertArrayEquals("Hello world!".getBytes(), value.value());
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) DefaultBackupOutput(io.atomix.primitive.service.impl.DefaultBackupOutput) DefaultBackupInput(io.atomix.primitive.service.impl.DefaultBackupInput) Test(org.junit.Test)

Example 12 with DefaultBackupInput

use of io.atomix.primitive.service.impl.DefaultBackupInput in project atomix by atomix.

the class DefaultWorkQueueServiceTest method testSnapshot.

@Test
public void testSnapshot() throws Exception {
    ServiceContext context = mock(ServiceContext.class);
    when(context.serviceType()).thenReturn(WorkQueueType.instance());
    when(context.serviceName()).thenReturn("test");
    when(context.serviceId()).thenReturn(PrimitiveId.from(1));
    Session session = mock(Session.class);
    when(session.sessionId()).thenReturn(SessionId.from(1));
    when(context.currentSession()).thenReturn(session);
    DefaultWorkQueueService service = new DefaultWorkQueueService();
    service.init(context);
    service.register(session);
    service.add(Arrays.asList("Hello world!".getBytes()));
    Buffer buffer = HeapBuffer.allocate();
    service.backup(new DefaultBackupOutput(buffer, service.serializer()));
    service = new DefaultWorkQueueService();
    service.init(context);
    service.register(session);
    service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
    Collection<Task<byte[]>> value = service.take(1);
    assertNotNull(value);
    assertEquals(1, value.size());
    assertArrayEquals("Hello world!".getBytes(), value.iterator().next().payload());
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) Task(io.atomix.core.workqueue.Task) ServiceContext(io.atomix.primitive.service.ServiceContext) DefaultBackupOutput(io.atomix.primitive.service.impl.DefaultBackupOutput) Session(io.atomix.primitive.session.Session) DefaultBackupInput(io.atomix.primitive.service.impl.DefaultBackupInput) Test(org.junit.Test)

Example 13 with DefaultBackupInput

use of io.atomix.primitive.service.impl.DefaultBackupInput in project atomix by atomix.

the class DefaultDistributedSetServiceTest method testSnapshot.

@Test
@SuppressWarnings("unchecked")
public void testSnapshot() throws Exception {
    ServiceContext context = mock(ServiceContext.class);
    when(context.serviceType()).thenReturn(DistributedSetType.instance());
    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));
    DefaultDistributedSetService service = new DefaultDistributedSetService();
    service.init(context);
    service.add("foo");
    Buffer buffer = HeapBuffer.allocate();
    service.backup(new DefaultBackupOutput(buffer, service.serializer()));
    service = new DefaultDistributedSetService();
    service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
    assertTrue(service.contains("foo"));
}
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) DefaultBackupOutput(io.atomix.primitive.service.impl.DefaultBackupOutput) Session(io.atomix.primitive.session.Session) DefaultBackupInput(io.atomix.primitive.service.impl.DefaultBackupInput) Test(org.junit.Test)

Example 14 with DefaultBackupInput

use of io.atomix.primitive.service.impl.DefaultBackupInput in project atomix by atomix.

the class DefaultDistributedMultisetServiceTest method testSnapshot.

@Test
@SuppressWarnings("unchecked")
public void testSnapshot() throws Exception {
    ServiceContext context = mock(ServiceContext.class);
    when(context.serviceType()).thenReturn(DistributedSetType.instance());
    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));
    DefaultDistributedMultisetService service = new DefaultDistributedMultisetService();
    service.init(context);
    service.add("foo");
    Buffer buffer = HeapBuffer.allocate();
    service.backup(new DefaultBackupOutput(buffer, service.serializer()));
    service = new DefaultDistributedMultisetService();
    service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
    assertTrue(service.contains("foo"));
}
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) DefaultBackupOutput(io.atomix.primitive.service.impl.DefaultBackupOutput) Session(io.atomix.primitive.session.Session) DefaultBackupInput(io.atomix.primitive.service.impl.DefaultBackupInput) Test(org.junit.Test)

Example 15 with DefaultBackupInput

use of io.atomix.primitive.service.impl.DefaultBackupInput in project atomix by atomix.

the class DefaultAtomicLockServiceTest method testSnapshot.

@Test
public void testSnapshot() throws Exception {
    ServiceContext context = mock(ServiceContext.class);
    when(context.serviceType()).thenReturn(LeaderElectionType.instance());
    when(context.serviceName()).thenReturn("test");
    when(context.serviceId()).thenReturn(PrimitiveId.from(1));
    when(context.wallClock()).thenReturn(new WallClock());
    when(context.currentOperation()).thenReturn(OperationType.COMMAND);
    Session session = mock(Session.class);
    when(session.sessionId()).thenReturn(SessionId.from(1));
    when(context.currentSession()).thenReturn(session);
    DefaultAtomicLockService service = new DefaultAtomicLockService();
    service.init(context);
    service.register(session);
    service.tick(new WallClockTimestamp());
    Buffer buffer = HeapBuffer.allocate();
    service.backup(new DefaultBackupOutput(buffer, service.serializer()));
    service = new DefaultAtomicLockService();
    service.init(context);
    service.register(session);
    service.tick(new WallClockTimestamp());
    service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
    service.lock(1);
    service.lock(2, 1000);
    buffer = HeapBuffer.allocate();
    service.backup(new DefaultBackupOutput(buffer, service.serializer()));
    service = new DefaultAtomicLockService();
    service.init(context);
    service.register(session);
    service.tick(new WallClockTimestamp());
    service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
    assertTrue(service.isLocked(service.lock.index));
    assertTrue(!service.queue.isEmpty());
    assertTrue(!service.timers.isEmpty());
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) HeapBuffer(io.atomix.storage.buffer.HeapBuffer) WallClockTimestamp(io.atomix.utils.time.WallClockTimestamp) ServiceContext(io.atomix.primitive.service.ServiceContext) WallClock(io.atomix.utils.time.WallClock) DefaultBackupOutput(io.atomix.primitive.service.impl.DefaultBackupOutput) Session(io.atomix.primitive.session.Session) DefaultBackupInput(io.atomix.primitive.service.impl.DefaultBackupInput) Test(org.junit.Test)

Aggregations

DefaultBackupInput (io.atomix.primitive.service.impl.DefaultBackupInput)18 Buffer (io.atomix.storage.buffer.Buffer)17 HeapBuffer (io.atomix.storage.buffer.HeapBuffer)17 DefaultBackupOutput (io.atomix.primitive.service.impl.DefaultBackupOutput)16 Test (org.junit.Test)16 ServiceContext (io.atomix.primitive.service.ServiceContext)12 Session (io.atomix.primitive.session.Session)12 WallClock (io.atomix.utils.time.WallClock)11 MemberId (io.atomix.cluster.MemberId)1 AbstractPrimitiveTest (io.atomix.core.AbstractPrimitiveTest)1 AbstractAtomicSemaphoreService (io.atomix.core.semaphore.impl.AbstractAtomicSemaphoreService)1 AtomicSemaphoreServiceConfig (io.atomix.core.semaphore.impl.AtomicSemaphoreServiceConfig)1 DefaultAtomicSemaphoreService (io.atomix.core.semaphore.impl.DefaultAtomicSemaphoreService)1 Task (io.atomix.core.workqueue.Task)1 PrimitiveType (io.atomix.primitive.PrimitiveType)1 SessionId (io.atomix.primitive.session.SessionId)1 ReadConsistency (io.atomix.protocols.raft.ReadConsistency)1 RaftSession (io.atomix.protocols.raft.session.RaftSession)1 ConfigurationException (io.atomix.utils.config.ConfigurationException)1 WallClockTimestamp (io.atomix.utils.time.WallClockTimestamp)1