use of io.atomix.core.semaphore.impl.AtomicSemaphoreServiceConfig in project atomix by atomix.
the class AtomicSemaphoreTest method testSnapshot.
@Test
public void testSnapshot() throws Exception {
AbstractAtomicSemaphoreService service = new DefaultAtomicSemaphoreService(new AtomicSemaphoreServiceConfig().setInitialCapacity(10));
Field available = AbstractAtomicSemaphoreService.class.getDeclaredField("available");
available.setAccessible(true);
Field holders = AbstractAtomicSemaphoreService.class.getDeclaredField("holders");
holders.setAccessible(true);
Field waiterQueue = AbstractAtomicSemaphoreService.class.getDeclaredField("waiterQueue");
waiterQueue.setAccessible(true);
Field timers = AbstractAtomicSemaphoreService.class.getDeclaredField("timers");
timers.setAccessible(true);
available.set(service, 10);
Map<Long, Integer> holdersMap = new HashMap<>();
holdersMap.put((long) 1, 2);
holdersMap.put((long) 3, 4);
holdersMap.put((long) 5, 6);
holders.set(service, holdersMap);
// Class<?> waiter = Class.forName("io.atomix.core.semaphore.impl.DistributedSemaphoreService$Waiter");
// LinkedList<Object> waiterLinkedList = new LinkedList<>();
//
// waiterLinkedList.add(waiter.getConstructors()[0].newInstance(service,10L, 20L, 30L, 40, Long.MAX_VALUE));
// waiterQueue.set(service, waiterLinkedList);
Buffer buffer = HeapBuffer.allocate();
service.backup(new DefaultBackupOutput(buffer, service.serializer()));
AbstractAtomicSemaphoreService serviceRestore = new DefaultAtomicSemaphoreService(new AtomicSemaphoreServiceConfig().setInitialCapacity(10));
serviceRestore.restore(new DefaultBackupInput(buffer.flip(), service.serializer()));
assertEquals(10, available.get(serviceRestore));
assertEquals(holdersMap, holders.get(serviceRestore));
// assertEquals(waiterQueue.get(serviceRestore), waiterLinkedList);
// assertEquals(1, ((Map) (timers.get(serviceRestore))).keySet().size());
}
Aggregations