use of com.palantir.lock.LockDescriptor in project atlasdb by palantir.
the class LockServiceSerDeTest method testSerialisationAndDeserialisationOfHeldLocksGrant.
@Test
public void testSerialisationAndDeserialisationOfHeldLocksGrant() throws Exception {
ImmutableSortedMap<LockDescriptor, LockMode> lockDescriptorLockMode = LockServiceTestUtils.getLockDescriptorLockMode(ImmutableList.of("lock1", "lock2"));
HeldLocksGrant heldLocksGrant = new HeldLocksGrant(BigInteger.ONE, System.currentTimeMillis(), System.currentTimeMillis() + 10L, LockCollections.of(lockDescriptorLockMode), SimpleTimeDuration.of(100, TimeUnit.SECONDS), 10L);
ObjectMapper mapper = new ObjectMapper();
String serializedForm = mapper.writeValueAsString(heldLocksGrant);
HeldLocksGrant deserialzedlockServerOptions = mapper.readValue(serializedForm, HeldLocksGrant.class);
assertEquals(heldLocksGrant, deserialzedlockServerOptions);
}
use of com.palantir.lock.LockDescriptor in project atlasdb by palantir.
the class LockServiceStateLoggerTest method testDescriptors.
@Test
public void testDescriptors() throws Exception {
List<File> files = LockServiceTestUtils.logStateDirFiles();
Optional<File> descriptorsFile = files.stream().filter(file -> file.getName().startsWith(LockServiceStateLogger.DESCRIPTORS_FILE_PREFIX)).findFirst();
Map<String, String> descriptorsMap = new Yaml().loadAs(new FileInputStream(descriptorsFile.get()), Map.class);
Set<LockDescriptor> allDescriptors = getAllDescriptors();
for (LockDescriptor descriptor : allDescriptors) {
assertTrue("Existing descriptor can't be found in dumped descriptors", descriptorsMap.values().stream().anyMatch(descriptorFromFile -> descriptorFromFile.equals(descriptor.toString())));
}
}
use of com.palantir.lock.LockDescriptor in project atlasdb by palantir.
the class LockServiceStateLoggerTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
LockServiceTestUtils.cleanUpLogStateDir();
LockClient clientA = LockClient.of("Client A");
LockClient clientB = LockClient.of("Client B");
LockDescriptor descriptor1 = StringLockDescriptor.of("logger-lock");
LockDescriptor descriptor2 = StringLockDescriptor.of("logger-AAA");
LockRequest request1 = LockRequest.builder(LockCollections.of(ImmutableSortedMap.of(descriptor1, LockMode.WRITE))).blockForAtMost(SimpleTimeDuration.of(1000, TimeUnit.MILLISECONDS)).build();
LockRequest request2 = LockRequest.builder(LockCollections.of(ImmutableSortedMap.of(descriptor2, LockMode.WRITE))).blockForAtMost(SimpleTimeDuration.of(1000, TimeUnit.MILLISECONDS)).build();
outstandingLockRequestMultimap.put(clientA, request1);
outstandingLockRequestMultimap.put(clientB, request2);
outstandingLockRequestMultimap.put(clientA, request2);
HeldLocksToken token = LockServiceTestUtils.getFakeHeldLocksToken("client A", "Fake thread", new BigInteger("1"), "held-lock-1", "logger-lock");
HeldLocksToken token2 = LockServiceTestUtils.getFakeHeldLocksToken("client B", "Fake thread 2", new BigInteger("2"), "held-lock-2", "held-lock-3");
heldLocksTokenMap.putIfAbsent(token, LockServiceImpl.HeldLocks.of(token, LockCollections.of()));
heldLocksTokenMap.putIfAbsent(token2, LockServiceImpl.HeldLocks.of(token2, LockCollections.of()));
LockServiceStateLogger logger = new LockServiceStateLogger(heldLocksTokenMap, outstandingLockRequestMultimap, LockServiceTestUtils.TEST_LOG_STATE_DIR);
logger.logLocks();
}
use of com.palantir.lock.LockDescriptor in project atlasdb by palantir.
the class LockServiceTestUtils method getLockDescriptorLockMode.
public static ImmutableSortedMap<LockDescriptor, LockMode> getLockDescriptorLockMode(List<String> descriptors) {
ImmutableSortedMap.Builder<LockDescriptor, LockMode> builder = ImmutableSortedMap.naturalOrder();
for (String descriptor : descriptors) {
LockDescriptor descriptor1 = StringLockDescriptor.of(descriptor);
builder.put(descriptor1, LockMode.WRITE);
}
return builder.build();
}
Aggregations