Skip to content

Commit

Permalink
Fix checkpointOwner copy issue for multistream lease (awslabs#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenylee-aws authored Nov 14, 2024
1 parent b154acf commit 3facf30
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ protected Lease(Lease lease) {
lease.childShardIds(),
lease.pendingCheckpointState(),
lease.hashKeyRangeForLease());
checkpointOwner(lease.checkpointOwner);
}

@Deprecated
Expand Down Expand Up @@ -458,8 +459,6 @@ public void leaseOwner(String leaseOwner) {
* @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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;

Expand Down Expand Up @@ -109,6 +110,15 @@ public void testIsEligibleForGracefulShutdownFalse_shutdownRequested_assertFalse
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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 3facf30

Please sign in to comment.