Search in sources :

Example 16 with DefaultBackupInput

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

the class DefaultAtomicMapServiceTest method testSnapshot.

@Test
@SuppressWarnings("unchecked")
public void testSnapshot() throws Exception {
    ServiceContext context = mock(ServiceContext.class);
    when(context.serviceType()).thenReturn(AtomicMapType.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));
    when(context.currentSession()).thenReturn(session);
    AbstractAtomicMapService service = new TestAtomicMapService();
    service.register(session);
    service.init(context);
    service.put("foo", "Hello world!".getBytes());
    service.lock("bar", 1, 0);
    Buffer buffer = HeapBuffer.allocate();
    service.backup(new DefaultBackupOutput(buffer, service.serializer()));
    service = new TestAtomicMapService();
    service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
    Versioned<byte[]> value = service.get("foo");
    assertNotNull(value);
    assertArrayEquals("Hello world!".getBytes(), value.value());
    assertFalse(service.isLocked("foo", 0));
    assertTrue(service.isLocked("bar", 0));
}
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 17 with DefaultBackupInput

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

the class DefaultAtomicNavigableMapServiceTest method testSnapshot.

@Test
@SuppressWarnings("unchecked")
public void testSnapshot() throws Exception {
    ServiceContext context = mock(ServiceContext.class);
    when(context.serviceType()).thenReturn(AtomicMapType.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));
    AbstractAtomicNavigableMapService service = new TestAtomicNavigableMapService();
    service.init(context);
    service.put("foo", "Hello world!".getBytes());
    Buffer buffer = HeapBuffer.allocate();
    service.backup(new DefaultBackupOutput(buffer, service.serializer()));
    service = new TestAtomicNavigableMapService();
    service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
    Versioned<byte[]> value = service.get("foo");
    assertNotNull(value);
    assertArrayEquals("Hello world!".getBytes(), value.value());
}
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 18 with DefaultBackupInput

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

the class DefaultAtomicCounterServiceTest method testSnapshot.

@Test
public void testSnapshot() throws Exception {
    DefaultAtomicCounterService service = new DefaultAtomicCounterService();
    service.set(1);
    Buffer buffer = HeapBuffer.allocate();
    service.backup(new DefaultBackupOutput(buffer, service.serializer()));
    service = new DefaultAtomicCounterService();
    service.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
    long value = service.get();
    assertEquals(1, 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)

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