Search in sources :

Example 1 with ConjureSimpleHeldLocksToken

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

the class MultiNodePaxosTimeLockServerIntegrationTest method directLegacyAndConjureLockServicesInteractCorrectly.

@Test
public void directLegacyAndConjureLockServicesInteractCorrectly() throws InterruptedException {
    LockRefreshToken token = client.legacyLockService().lock("tom", com.palantir.lock.LockRequest.builder(ImmutableSortedMap.<LockDescriptor, LockMode>naturalOrder().put(StringLockDescriptor.of("lock"), LockMode.WRITE).build()).build());
    ConjureLockRefreshToken conjureAnalogue = ConjureLockRefreshToken.of(token.getTokenId(), token.getExpirationDateMs());
    // Cannot assert equality because tokens can have different expiration dates.
    assertThat(client.legacyLockService().refreshLockRefreshTokens(ImmutableList.of(token))).as("refreshing a live token should succeed").hasOnlyOneElementSatisfying(refreshed -> assertThat(refreshed.getTokenId()).isEqualTo(refreshed.getTokenId()));
    AuthHeader authHeader = AuthHeader.valueOf("Bearer unused");
    assertThat(client.conjureLegacyLockService().refreshLockRefreshTokens(authHeader, client.namespace(), ImmutableList.of(conjureAnalogue))).as("it is possible to refresh a live token through the conjure API").hasOnlyOneElementSatisfying(refreshed -> assertThat(refreshed.getTokenId()).isEqualTo(refreshed.getTokenId()));
    ConjureSimpleHeldLocksToken conjureHeldLocksToken = ConjureSimpleHeldLocksToken.of(token.getTokenId(), 0L);
    assertThat(client.conjureLegacyLockService().unlockSimple(authHeader, client.namespace(), conjureHeldLocksToken)).as("it is possible to unlock a live token through the conjure API").isTrue();
    assertThat(client.conjureLegacyLockService().unlockSimple(authHeader, client.namespace(), conjureHeldLocksToken)).as("a token unlocked through the conjure API stays unlocked").isFalse();
    assertThat(client.legacyLockService().unlockSimple(SimpleHeldLocksToken.fromLockRefreshToken(token))).as("a token unlocked through the conjure API stays unlocked even in the legacy API").isFalse();
}
Also used : AuthHeader(com.palantir.tokens.auth.AuthHeader) ConjureSimpleHeldLocksToken(com.palantir.lock.ConjureSimpleHeldLocksToken) ConjureLockRefreshToken(com.palantir.lock.ConjureLockRefreshToken) ConjureLockRefreshToken(com.palantir.lock.ConjureLockRefreshToken) LockRefreshToken(com.palantir.lock.LockRefreshToken) Test(org.junit.Test)

Aggregations

ConjureLockRefreshToken (com.palantir.lock.ConjureLockRefreshToken)1 ConjureSimpleHeldLocksToken (com.palantir.lock.ConjureSimpleHeldLocksToken)1 LockRefreshToken (com.palantir.lock.LockRefreshToken)1 AuthHeader (com.palantir.tokens.auth.AuthHeader)1 Test (org.junit.Test)1