Search in sources :

Example 1 with ConjureLockV1Request

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

the class MultiNodePaxosTimeLockServerIntegrationTest method lockAcquiredByConjureLockServiceIsAlsoAcquiredInLegacy.

@Test
public void lockAcquiredByConjureLockServiceIsAlsoAcquiredInLegacy() throws InterruptedException {
    com.palantir.lock.LockRequest lockRequest = com.palantir.lock.LockRequest.builder(ImmutableSortedMap.<LockDescriptor, LockMode>naturalOrder().put(StringLockDescriptor.of("lock"), LockMode.WRITE).build()).doNotBlock().build();
    String anonymousId = LockClient.ANONYMOUS.getClientId();
    ConjureLockV1Request conjureLockRequest = ConjureLockV1Request.builder().lockClient(anonymousId).lockRequest(lockRequest).build();
    HeldLocksToken token = client.conjureLegacyLockService().lockAndGetHeldLocks(AuthHeader.valueOf("Bearer unused"), client.namespace(), conjureLockRequest).orElseThrow(() -> new RuntimeException("We should have been able to get the lock"));
    assertThat(client.legacyLockService().lockAndGetHeldLocks(anonymousId, lockRequest)).as("if the conjure impl has taken a lock, the legacy impl mustn't be able to take it").isNull();
    assertThat(client.legacyLockService().unlock(token.getLockRefreshToken())).as("legacy impl can unlock a lock taken by conjure impl").isTrue();
    assertThat(client.legacyLockService().lockAndGetHeldLocks(anonymousId, lockRequest)).as("lock taken by conjure impl that was unlocked can now be acquired by legacy impl").isNotNull();
    assertThat(client.conjureLegacyLockService().lockAndGetHeldLocks(AuthHeader.valueOf("Bearer unused"), client.namespace(), conjureLockRequest)).as("if the legacy impl has taken a lock, the conjure impl mustn't be able to take it").isEmpty();
}
Also used : HeldLocksToken(com.palantir.lock.HeldLocksToken) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) ConjureSimpleHeldLocksToken(com.palantir.lock.ConjureSimpleHeldLocksToken) ConjureLockV1Request(com.palantir.lock.ConjureLockV1Request) Test(org.junit.Test)

Aggregations

ConjureLockV1Request (com.palantir.lock.ConjureLockV1Request)1 ConjureSimpleHeldLocksToken (com.palantir.lock.ConjureSimpleHeldLocksToken)1 HeldLocksToken (com.palantir.lock.HeldLocksToken)1 SimpleHeldLocksToken (com.palantir.lock.SimpleHeldLocksToken)1 Test (org.junit.Test)1