Search in sources :

Example 1 with LockHeartbeatRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockHeartbeatRequest in project hbase by apache.

the class TestEntityLocks method testEntityLock.

/**
 * Test basic lock function - requestLock, await, unlock.
 * @throws Exception
 */
@Test
public void testEntityLock() throws Exception {
    final long procId = 100;
    // in ms
    final long workerSleepTime = 200;
    EntityLock lock = admin.namespaceLock("namespace", "description", null);
    lock.setTestingSleepTime(workerSleepTime);
    when(master.requestLock(any(), any())).thenReturn(LockResponse.newBuilder().setProcId(procId).build());
    when(master.lockHeartbeat(any(), any())).thenReturn(UNLOCKED_RESPONSE, UNLOCKED_RESPONSE, UNLOCKED_RESPONSE, LOCKED_RESPONSE);
    lock.requestLock();
    // we return unlock response 3 times, so actual wait time should be around 2 * workerSleepTime
    lock.await(4 * workerSleepTime, TimeUnit.MILLISECONDS);
    assertTrue(lock.isLocked());
    lock.unlock();
    assertTrue(!lock.getWorker().isAlive());
    assertFalse(lock.isLocked());
    // check LockRequest in requestLock()
    verify(master, times(1)).requestLock(any(), lockReqArgCaptor.capture());
    LockRequest request = lockReqArgCaptor.getValue();
    assertEquals("namespace", request.getNamespace());
    assertEquals("description", request.getDescription());
    assertEquals(LockType.EXCLUSIVE, request.getLockType());
    assertEquals(0, request.getRegionInfoCount());
    // check LockHeartbeatRequest in lockHeartbeat()
    verify(master, atLeastOnce()).lockHeartbeat(any(), lockHeartbeatReqArgCaptor.capture());
    for (LockHeartbeatRequest req : lockHeartbeatReqArgCaptor.getAllValues()) {
        assertEquals(procId, req.getProcId());
    }
}
Also used : LockHeartbeatRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockHeartbeatRequest) LockRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockRequest) Test(org.junit.Test)

Aggregations

LockHeartbeatRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockHeartbeatRequest)1 LockRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockRequest)1 Test (org.junit.Test)1