|
21 | 21 | import static org.hamcrest.Matchers.containsInAnyOrder; |
22 | 22 | import static org.hamcrest.Matchers.hasSize; |
23 | 23 | import static org.hamcrest.Matchers.is; |
| 24 | +import static org.hamcrest.Matchers.sameInstance; |
24 | 25 | import static software.amazon.awssdk.enhanced.dynamodb.TableMetadata.primaryIndexName; |
25 | 26 |
|
26 | 27 | import java.util.Collection; |
@@ -359,6 +360,43 @@ public void builderReuse_independentValidation() { |
359 | 360 | assertThat(metadata2.indexPartitionKeys("gsi1"), contains("key1", "key2")); |
360 | 361 | } |
361 | 362 |
|
| 363 | + @Test |
| 364 | + public void indexPartitionKeys_shouldReturnCachedPartitionKeysList() { |
| 365 | + StaticTableMetadata metadata = StaticTableMetadata.builder() |
| 366 | + .addIndexPartitionKey(primaryIndexName(), |
| 367 | + ATTRIBUTE_NAME, |
| 368 | + AttributeValueType.S) |
| 369 | + .build(); |
| 370 | + List<String> first = metadata.indexPartitionKeys(primaryIndexName()); |
| 371 | + List<String> second = metadata.indexPartitionKeys(primaryIndexName()); |
| 372 | + |
| 373 | + assertThat(first, sameInstance(second)); |
| 374 | + } |
| 375 | + |
| 376 | + @Test |
| 377 | + public void indexSortKeys_shouldReturnCachedSortKeysList() { |
| 378 | + StaticTableMetadata metadata = StaticTableMetadata.builder() |
| 379 | + .addIndexSortKey(primaryIndexName(), |
| 380 | + ATTRIBUTE_NAME, |
| 381 | + AttributeValueType.S) |
| 382 | + .build(); |
| 383 | + List<String> first = metadata.indexSortKeys(primaryIndexName()); |
| 384 | + List<String> second = metadata.indexSortKeys(primaryIndexName()); |
| 385 | + |
| 386 | + assertThat(first, sameInstance(second)); |
| 387 | + } |
| 388 | + |
| 389 | + @Test |
| 390 | + public void indexSortKeys_shouldReturnUnmodifiableList() { |
| 391 | + StaticTableMetadata metadata = StaticTableMetadata.builder() |
| 392 | + .addIndexSortKey(primaryIndexName(), |
| 393 | + ATTRIBUTE_NAME, |
| 394 | + AttributeValueType.S) |
| 395 | + .build(); |
| 396 | + List<String> result = metadata.indexSortKeys(primaryIndexName()); |
| 397 | + assertThatThrownBy(() -> result.add("foo")).isInstanceOf(UnsupportedOperationException.class); |
| 398 | + } |
| 399 | + |
362 | 400 | @Test |
363 | 401 | public void getIndexKeys_partitionAndSort() { |
364 | 402 | TableMetadata tableMetadata = StaticTableMetadata.builder() |
|
0 commit comments