Skip to content

Commit

Permalink
Fix the tests for supporting expiration time
Browse files Browse the repository at this point in the history
Signed-off-by: Souvik Bose <souvbose@amazon.com>
  • Loading branch information
sbose2k21 committed Dec 16, 2024
1 parent 2cb110d commit 839250f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ void getAvailablePartition_with_no_items_from_query_returns_empty_optional(final

final int pageLimit = new Random().nextInt(20);

final Duration ttl = Duration.ofSeconds(new Random().nextInt());
final Duration ttl = Duration.ofSeconds(new Random().nextInt(5)+10);

final Optional<SourcePartitionStoreItem> result = objectUnderTest.getAvailablePartition(
ownerId, ownershipTimeout, SourcePartitionStatus.valueOf(sourcePartitionStatus), sourceStatusCombinationKey, pageLimit, ttl);
Expand Down Expand Up @@ -516,7 +516,7 @@ void getAvailablePartition_will_continue_until_tryAcquirePartition_succeeds(fina
final DynamoDbClientWrapper objectUnderTest = createObjectUnderTest();
reflectivelySetField(objectUnderTest, "table", table);

final Duration ttl = Duration.ofSeconds(new Random().nextInt());
final Duration ttl = Duration.ofSeconds(new Random().nextInt(5)+10);

final Optional<SourcePartitionStoreItem> result = objectUnderTest.getAvailablePartition(
ownerId, ownershipTimeout, SourcePartitionStatus.valueOf(sourcePartitionStatus), sourceStatusCombinationKey, new Random().nextInt(20), ttl);
Expand Down Expand Up @@ -583,7 +583,7 @@ void getAvailablePartition_with_multiple_pages_continue_until_tryAcquirePartitio
final DynamoDbClientWrapper objectUnderTest = createObjectUnderTest();
reflectivelySetField(objectUnderTest, "table", table);

final Duration ttl = Duration.ofSeconds(new Random().nextInt());
final Duration ttl = Duration.ofSeconds(new Random().nextInt(5)+10);

final Optional<SourcePartitionStoreItem> result = objectUnderTest.getAvailablePartition(
ownerId, ownershipTimeout, SourcePartitionStatus.valueOf(sourcePartitionStatus), sourceStatusCombinationKey, new Random().nextInt(20), ttl);
Expand Down Expand Up @@ -650,7 +650,7 @@ void getAvailablePartition_with_multiple_pages_will_iterate_through_all_items_wi
final DynamoDbClientWrapper objectUnderTest = createObjectUnderTest();
reflectivelySetField(objectUnderTest, "table", table);

final Duration ttl = Duration.ofSeconds(new Random().nextInt());
final Duration ttl = Duration.ofSeconds(new Random().nextInt(5)+10);

final Optional<SourcePartitionStoreItem> result = objectUnderTest.getAvailablePartition(
ownerId, ownershipTimeout, SourcePartitionStatus.valueOf(sourcePartitionStatus), sourceStatusCombinationKey, new Random().nextInt(20), ttl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,9 @@ void getAvailablePartition_with_no_item_acquired_returns_empty_optional() {
final String ownerId = UUID.randomUUID().toString();
final String sourceIdentifier = UUID.randomUUID().toString();
final Duration ownershipTimeout = Duration.ofMinutes(2);
final Duration ttl = Duration.ofSeconds(new Random().nextInt());
final Duration ttl = Duration.ofSeconds(new Random().nextInt(5)+10);

given(dynamoStoreSettings.getTtl()).willReturn(ttl);
given(dynamoDbClientWrapper.getAvailablePartition(ownerId, ownershipTimeout,
SourcePartitionStatus.ASSIGNED,
String.format(SOURCE_STATUS_COMBINATION_KEY_FORMAT, sourceIdentifier, SourcePartitionStatus.ASSIGNED),
Expand All @@ -273,8 +274,8 @@ void getAvailablePartition_with_acquired_ASSIGNED_partition_returns_the_partitio
final String ownerId = UUID.randomUUID().toString();
final String sourceIdentifier = UUID.randomUUID().toString();
final Duration ownershipTimeout = Duration.ofMinutes(2);
final Duration ttl = Duration.ofSeconds(new Random().nextInt());

final Duration ttl = Duration.ofSeconds(new Random().nextInt(5)+10);
given(dynamoStoreSettings.getTtl()).willReturn(ttl);
final DynamoDbSourcePartitionItem acquiredItem = mock(DynamoDbSourcePartitionItem.class);

given(dynamoDbClientWrapper.getAvailablePartition(ownerId, ownershipTimeout,
Expand All @@ -296,8 +297,9 @@ void getAvailablePartition_with_acquired_CLOSED_partition_returns_the_partition(
final String ownerId = UUID.randomUUID().toString();
final String sourceIdentifier = UUID.randomUUID().toString();
final Duration ownershipTimeout = Duration.ofMinutes(2);
final Duration ttl = Duration.ofSeconds(new Random().nextInt());
final Duration ttl = Duration.ofSeconds(new Random().nextInt(5)+10);

given(dynamoStoreSettings.getTtl()).willReturn(ttl);
final DynamoDbSourcePartitionItem acquiredItem = mock(DynamoDbSourcePartitionItem.class);

given(dynamoDbClientWrapper.getAvailablePartition(ownerId, ownershipTimeout,
Expand Down Expand Up @@ -329,8 +331,9 @@ void getAvailablePartition_with_acquired_UNASSIGNED_partition_returns_the_partit
final String ownerId = UUID.randomUUID().toString();
final String sourceIdentifier = UUID.randomUUID().toString();
final Duration ownershipTimeout = Duration.ofMinutes(2);
final Duration ttl = Duration.ofSeconds(new Random().nextInt());
final Duration ttl = Duration.ofSeconds(new Random().nextInt(5)+10);

given(dynamoStoreSettings.getTtl()).willReturn(ttl);
final DynamoDbSourcePartitionItem acquiredItem = mock(DynamoDbSourcePartitionItem.class);

given(dynamoDbClientWrapper.getAvailablePartition(ownerId, ownershipTimeout,
Expand Down

0 comments on commit 839250f

Please sign in to comment.