Search in sources :

Example 16 with LockDescriptor

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);
}
Also used : StringLockDescriptor(com.palantir.lock.StringLockDescriptor) LockDescriptor(com.palantir.lock.LockDescriptor) HeldLocksGrant(com.palantir.lock.HeldLocksGrant) LockMode(com.palantir.lock.LockMode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 17 with LockDescriptor

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())));
    }
}
Also used : BeforeClass(org.junit.BeforeClass) HeldLocksToken(com.palantir.lock.HeldLocksToken) SimpleTimeDuration(com.palantir.lock.SimpleTimeDuration) LockServiceImpl(com.palantir.lock.impl.LockServiceImpl) ConcurrentMap(java.util.concurrent.ConcurrentMap) Yaml(org.yaml.snakeyaml.Yaml) Multimaps(com.google.common.collect.Multimaps) SortedLockCollection(com.palantir.lock.SortedLockCollection) HashMultimap(com.google.common.collect.HashMultimap) Map(java.util.Map) BigInteger(java.math.BigInteger) LockRequest(com.palantir.lock.LockRequest) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) LockDescriptor(com.palantir.lock.LockDescriptor) LockCollections(com.palantir.lock.LockCollections) AfterClass(org.junit.AfterClass) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) LockMode(com.palantir.lock.LockMode) Collectors(java.util.stream.Collectors) File(java.io.File) SetMultimap(com.google.common.collect.SetMultimap) Sets(com.google.common.collect.Sets) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) LockClient(com.palantir.lock.LockClient) Optional(java.util.Optional) StringLockDescriptor(com.palantir.lock.StringLockDescriptor) MapMaker(com.google.common.collect.MapMaker) Assert.assertEquals(org.junit.Assert.assertEquals) LockDescriptor(com.palantir.lock.LockDescriptor) StringLockDescriptor(com.palantir.lock.StringLockDescriptor) File(java.io.File) Yaml(org.yaml.snakeyaml.Yaml) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 18 with LockDescriptor

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();
}
Also used : LockDescriptor(com.palantir.lock.LockDescriptor) StringLockDescriptor(com.palantir.lock.StringLockDescriptor) HeldLocksToken(com.palantir.lock.HeldLocksToken) LockClient(com.palantir.lock.LockClient) BigInteger(java.math.BigInteger) LockRequest(com.palantir.lock.LockRequest) BeforeClass(org.junit.BeforeClass)

Example 19 with LockDescriptor

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();
}
Also used : StringLockDescriptor(com.palantir.lock.StringLockDescriptor) LockDescriptor(com.palantir.lock.LockDescriptor) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) LockMode(com.palantir.lock.LockMode)

Aggregations

LockDescriptor (com.palantir.lock.LockDescriptor)19 StringLockDescriptor (com.palantir.lock.StringLockDescriptor)12 HeldLocksToken (com.palantir.lock.HeldLocksToken)8 LockMode (com.palantir.lock.LockMode)7 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)5 LockClient (com.palantir.lock.LockClient)5 LockRefreshToken (com.palantir.lock.LockRefreshToken)5 LockRequest (com.palantir.lock.LockRequest)5 Test (org.junit.Test)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)3 AtlasCellLockDescriptor (com.palantir.lock.AtlasCellLockDescriptor)3 SimpleHeldLocksToken (com.palantir.lock.SimpleHeldLocksToken)3 BigInteger (java.math.BigInteger)3 Cell (com.palantir.atlasdb.keyvalue.api.Cell)2 TransactionLockAcquisitionTimeoutException (com.palantir.atlasdb.transaction.api.TransactionLockAcquisitionTimeoutException)2 AtlasTimestampLockDescriptor (com.palantir.lock.AtlasTimestampLockDescriptor)2 LockResponse (com.palantir.lock.LockResponse)2 SimpleTimeDuration (com.palantir.lock.SimpleTimeDuration)2 Map (java.util.Map)2