This is an automated email from the ASF dual-hosted git repository. xyuanlu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/helix.git
commit 5fd3bd5fa5ffd5edbf1936355d22f63bf40b0edf Author: mapeng <[email protected]> AuthorDate: Tue Jan 2 13:41:21 2024 -0700 LockClient Minor Fixes --- .../helix/metaclient/recipes/lock/LockInfo.java | 22 ++++++++++------------ .../metaclient/recipes/lock/LockClientTest.java | 5 +---- .../metaclient/recipes/lock/LockInfoTest.java | 9 ++++----- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/meta-client/src/main/java/org/apache/helix/metaclient/recipes/lock/LockInfo.java b/meta-client/src/main/java/org/apache/helix/metaclient/recipes/lock/LockInfo.java index 2a08c3754..3c472902c 100644 --- a/meta-client/src/main/java/org/apache/helix/metaclient/recipes/lock/LockInfo.java +++ b/meta-client/src/main/java/org/apache/helix/metaclient/recipes/lock/LockInfo.java @@ -59,7 +59,7 @@ public class LockInfo extends DataRecord { public LockInfo() { super(DEFAULT_LOCK_INFO); setLockInfoFields(DEFAULT_LOCK_ID_TEXT, DEFAULT_OWNER_ID_TEXT, DEFAULT_CLIENT_ID_TEXT, DEFAULT_CLIENT_DATA, DEFAULT_GRANTED_AT_LONG, - DEFAULT_LAST_RENEWED_AT_LONG, DEFAULT_TIMEOUT_DURATION); + DEFAULT_LAST_RENEWED_AT_LONG, DEFAULT_TIMEOUT_DURATION); } /** @@ -75,10 +75,10 @@ public class LockInfo extends DataRecord { String clientData = dataRecord.getSimpleField(LockInfoAttribute.CLIENT_DATA.name()); long grantTime = dataRecord.getLongField(LockInfoAttribute.GRANTED_AT.name(), DEFAULT_GRANTED_AT_LONG); long lastRenewalTime = - dataRecord.getLongField(LockInfoAttribute.LAST_RENEWED_AT.name(), DEFAULT_LAST_RENEWED_AT_LONG); + dataRecord.getLongField(LockInfoAttribute.LAST_RENEWED_AT.name(), DEFAULT_LAST_RENEWED_AT_LONG); long timeout = dataRecord.getLongField(LockInfoAttribute.TIMEOUT.name(), DEFAULT_TIMEOUT_DURATION); setLockInfoFields(lockId,ownerId, clientId, clientData, grantTime, - lastRenewalTime, timeout); + lastRenewalTime, timeout); } } @@ -100,14 +100,12 @@ public class LockInfo extends DataRecord { * @param ownerId value of OWNER_ID attribute * @param clientId value of CLIENT_ID attribute * @param clientData value of CLIENT_DATA attribute - * @param grantTime the time the lock was granted - * @param lastRenewalTime the last time the lock was renewed - * @param timeout value of TIMEOUT attribute */ public LockInfo(String lockId, String ownerId, String clientId, - String clientData, long grantTime, long lastRenewalTime, long timeout) { + String clientData) { this(); - setLockInfoFields(lockId, ownerId, clientId, clientData, grantTime, lastRenewalTime, timeout); + setLockInfoFields(lockId, ownerId, clientId, clientData, DEFAULT_GRANTED_AT_LONG, + DEFAULT_LAST_RENEWED_AT_LONG, DEFAULT_TIMEOUT_DURATION); } /** @@ -171,7 +169,7 @@ public class LockInfo extends DataRecord { * Get the value for GRANTED_AT attribute of the lock * @param grantTime Long representing the time at which the lock was granted */ - public void setGrantedAt(Long grantTime) { + private void setGrantedAt(Long grantTime) { setLongField(LockInfoAttribute.GRANTED_AT.name(), grantTime); } @@ -179,7 +177,7 @@ public class LockInfo extends DataRecord { * Get the value for LAST_RENEWED_AT attribute of the lock * @param lastRenewalTime Long representing the time at which the lock was last renewed */ - public void setLastRenewedAt(Long lastRenewalTime) { + private void setLastRenewedAt(Long lastRenewalTime) { setLongField(LockInfoAttribute.LAST_RENEWED_AT.name(), lastRenewalTime); } @@ -187,7 +185,7 @@ public class LockInfo extends DataRecord { * Get the value for TIMEOUT attribute of the lock * @param timeout Long representing the duration of a lock in milliseconds. */ - public void setTimeout(long timeout) { + private void setTimeout(long timeout) { // Always store the timeout value in milliseconds for the sake of simplicity setLongField(LockInfoAttribute.TIMEOUT.name(), timeout); } @@ -251,4 +249,4 @@ public class LockInfo extends DataRecord { return getLongField(LockInfoAttribute.TIMEOUT.name(), DEFAULT_TIMEOUT_DURATION); } -} +} \ No newline at end of file diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/recipes/lock/LockClientTest.java b/meta-client/src/test/java/org/apache/helix/metaclient/recipes/lock/LockClientTest.java index 672781b08..2566a43f6 100644 --- a/meta-client/src/test/java/org/apache/helix/metaclient/recipes/lock/LockClientTest.java +++ b/meta-client/src/test/java/org/apache/helix/metaclient/recipes/lock/LockClientTest.java @@ -50,9 +50,6 @@ public class LockClientTest extends ZkMetaClientTestBase { lockInfo.setClientId(CLIENT_ID); lockInfo.setClientData(CLIENT_DATA); lockInfo.setLockId(LOCK_ID); - lockInfo.setGrantedAt(GRANT_TIME); - lockInfo.setLastRenewedAt(LAST_RENEWAL_TIME); - lockInfo.setTimeout(TIMEOUT); return lockInfo; } @@ -110,7 +107,7 @@ public class LockClientTest extends ZkMetaClientTestBase { Assert.assertEquals(lockClient.retrieveLock(key).getClientId(), CLIENT_ID); Assert.assertEquals(lockClient.retrieveLock(key).getClientData(), CLIENT_DATA); Assert.assertEquals(lockClient.retrieveLock(key).getLockId(), LOCK_ID); - Assert.assertEquals(lockClient.retrieveLock(key).getTimeout(), TIMEOUT); + Assert.assertEquals(lockClient.retrieveLock(key).getTimeout(), -1); Assert.assertNull(lockClient.retrieveLock(TEST_INVALID_PATH)); } diff --git a/meta-client/src/test/java/org/apache/helix/metaclient/recipes/lock/LockInfoTest.java b/meta-client/src/test/java/org/apache/helix/metaclient/recipes/lock/LockInfoTest.java index 4f48a5a0a..26071f423 100644 --- a/meta-client/src/test/java/org/apache/helix/metaclient/recipes/lock/LockInfoTest.java +++ b/meta-client/src/test/java/org/apache/helix/metaclient/recipes/lock/LockInfoTest.java @@ -46,16 +46,15 @@ public class LockInfoTest { @Test public void testLockInfo() { LockInfo lockInfo = - new LockInfo(LOCK_ID, OWNER_ID, CLIENT_ID, CLIENT_DATA, GRANT_TIME, - LAST_RENEWAL_TIME, TIMEOUT); + new LockInfo(LOCK_ID, OWNER_ID, CLIENT_ID, CLIENT_DATA); Assert.assertEquals(LOCK_ID, lockInfo.getLockId()); Assert.assertEquals(OWNER_ID, lockInfo.getOwnerId()); Assert.assertEquals(CLIENT_ID, lockInfo.getClientId()); Assert.assertEquals(CLIENT_DATA, lockInfo.getClientData()); - Assert.assertEquals(GRANT_TIME, (long) lockInfo.getGrantedAt()); - Assert.assertEquals(LAST_RENEWAL_TIME, (long) lockInfo.getLastRenewedAt()); - Assert.assertEquals(TIMEOUT, lockInfo.getTimeout()); + Assert.assertEquals(DEFAULT_GRANTED_AT_LONG, (long) lockInfo.getGrantedAt()); + Assert.assertEquals(DEFAULT_LAST_RENEWED_AT_LONG, (long) lockInfo.getLastRenewedAt()); + Assert.assertEquals(DEFAULT_TIMEOUT_DURATION, lockInfo.getTimeout()); DataRecord dataRecord = new DataRecord("dataRecord"); LockInfo lockInfo1 = new LockInfo(dataRecord);
