Search in sources :

Example 11 with LockClient

use of com.palantir.lock.LockClient in project atlasdb by palantir.

the class LockServiceSerDeTest method testSerialisationAndDeserialisationOfLockResponseWithLockHolders.

@Test
public void testSerialisationAndDeserialisationOfLockResponseWithLockHolders() throws Exception {
    HeldLocksToken token = LockServiceTestUtils.getFakeHeldLocksToken("client A", "Fake thread", new BigInteger("1"), "held-lock-1", "logger-lock");
    Map<LockDescriptor, LockClient> lockHolders = ImmutableMap.of(StringLockDescriptor.of("lock_id"), LockClient.ANONYMOUS, StringLockDescriptor.of("lock_id2"), LockClient.of("client"));
    LockResponse response = new LockResponse(token, lockHolders);
    ObjectMapper mapper = new ObjectMapper();
    LockResponse deserializedLockResponse = mapper.readValue(mapper.writeValueAsString(response), LockResponse.class);
    assertEquals(lockHolders, deserializedLockResponse.getLockHolders());
}
Also used : StringLockDescriptor(com.palantir.lock.StringLockDescriptor) LockDescriptor(com.palantir.lock.LockDescriptor) HeldLocksToken(com.palantir.lock.HeldLocksToken) LockResponse(com.palantir.lock.LockResponse) LockClient(com.palantir.lock.LockClient) BigInteger(java.math.BigInteger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 12 with LockClient

use of com.palantir.lock.LockClient in project atlasdb by palantir.

the class LockServiceSerDeTest method testPathParamSerDeOfAnonymousLockClient.

@Test
public void testPathParamSerDeOfAnonymousLockClient() throws Exception {
    LockClient lockClient = LockClient.ANONYMOUS;
    String serializedForm = lockClient.toString();
    LockClient lockClient1 = new LockClient(serializedForm);
    assertEquals(lockClient, lockClient1);
}
Also used : LockClient(com.palantir.lock.LockClient) Test(org.junit.Test)

Example 13 with LockClient

use of com.palantir.lock.LockClient 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)

Aggregations

LockClient (com.palantir.lock.LockClient)13 HeldLocksToken (com.palantir.lock.HeldLocksToken)5 LockDescriptor (com.palantir.lock.LockDescriptor)5 LockMode (com.palantir.lock.LockMode)4 LockService (com.palantir.lock.LockService)4 StringLockDescriptor (com.palantir.lock.StringLockDescriptor)4 Nullable (javax.annotation.Nullable)4 Test (org.junit.Test)4 Cleaner (com.palantir.atlasdb.cleaner.Cleaner)3 NoOpCleaner (com.palantir.atlasdb.cleaner.NoOpCleaner)3 LockRequest (com.palantir.lock.LockRequest)3 BigInteger (java.math.BigInteger)3 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)2 AtlasDbConstraintCheckingMode (com.palantir.atlasdb.transaction.api.AtlasDbConstraintCheckingMode)2 ConflictDetectionManager (com.palantir.atlasdb.transaction.impl.ConflictDetectionManager)2 SerializableTransactionManager (com.palantir.atlasdb.transaction.impl.SerializableTransactionManager)2 LockResponse (com.palantir.lock.LockResponse)2 TimestampService (com.palantir.timestamp.TimestampService)2 ExecutionException (java.util.concurrent.ExecutionException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1