Fix checkpointOwner copy issue for multistream lease (#1401)

This commit is contained in:
chenylee-aws 2024-11-14 14:50:22 -07:00 committed by GitHub
parent b154acf7f5
commit 3facf303bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 3 deletions

View file

@ -163,6 +163,7 @@ public class Lease {
lease.childShardIds(),
lease.pendingCheckpointState(),
lease.hashKeyRangeForLease());
checkpointOwner(lease.checkpointOwner);
}
@Deprecated
@ -458,8 +459,6 @@ public class Lease {
* @return A deep copy of this object.
*/
public Lease copy() {
final Lease lease = new Lease(this);
lease.checkpointOwner(this.checkpointOwner);
return lease;
return new Lease(this);
}
}

View file

@ -10,6 +10,7 @@ import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -109,6 +110,15 @@ public class LeaseTest {
assertFalse(shutdownRequestedLease.isEligibleForGracefulShutdown());
}
@Test
public void testCopyingLease() {
final String checkpointOwner = "checkpointOwner";
final Lease original = new Lease();
original.checkpointOwner(checkpointOwner);
final Lease copy = original.copy();
assertEquals(checkpointOwner, copy.checkpointOwner());
}
private static Lease createLease(String leaseOwner, String leaseKey, long lastCounterIncrementNanos) {
final Lease lease = new Lease();
lease.checkpoint(new ExtendedSequenceNumber("checkpoint"));

View file

@ -0,0 +1,19 @@
package software.amazon.kinesis.leases;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class MultiStreamLeaseTest {
@Test
void testCopyingMultiStreamLease() {
final String checkpointOwner = "checkpointOwner";
final MultiStreamLease original = new MultiStreamLease();
original.checkpointOwner(checkpointOwner);
original.streamIdentifier("identifier");
original.shardId("shardId");
final MultiStreamLease copy = original.copy();
assertEquals(checkpointOwner, copy.checkpointOwner());
}
}