1 /* 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"). 5 * You may not use this file except in compliance with the License. 6 * A copy of the License is located at 7 * 8 * http://aws.amazon.com/apache2.0 9 * 10 * or in the "license" file accompanying this file. This file is distributed 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 * express or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 16 package utils.resources.tables; 17 18 import software.amazon.awssdk.services.dynamodb.DynamoDbClient; 19 import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition; 20 import software.amazon.awssdk.services.dynamodb.model.CreateTableRequest; 21 import software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex; 22 import software.amazon.awssdk.services.dynamodb.model.KeySchemaElement; 23 import software.amazon.awssdk.services.dynamodb.model.KeyType; 24 import software.amazon.awssdk.services.dynamodb.model.LocalSecondaryIndex; 25 import software.amazon.awssdk.services.dynamodb.model.Projection; 26 import software.amazon.awssdk.services.dynamodb.model.ProjectionType; 27 import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput; 28 import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType; 29 import utils.test.resources.DynamoDBTableResource; 30 import utils.test.util.DynamoDBTestBase; 31 32 /** 33 * The table used by SecondaryIndexesIntegrationTest 34 */ 35 public class TempTableWithSecondaryIndexes extends DynamoDBTableResource { 36 37 public static final String TEMP_TABLE_NAME = "java-sdk-indexes-" + System.currentTimeMillis(); 38 public static final String HASH_KEY_NAME = "hash_key"; 39 public static final String RANGE_KEY_NAME = "range_key"; 40 public static final String LSI_NAME = "local_secondary_index"; 41 public static final String LSI_RANGE_KEY_NAME = "local_secondary_index_attribute"; 42 public static final String GSI_NAME = "global_secondary_index"; 43 public static final String GSI_HASH_KEY_NAME = "global_secondary_index_hash_attribute"; 44 public static final String GSI_RANGE_KEY_NAME = "global_secondary_index_range_attribute"; 45 public static final ProvisionedThroughput GSI_PROVISIONED_THROUGHPUT = ProvisionedThroughput.builder() 46 .readCapacityUnits(5L) 47 .writeCapacityUnits(5L) 48 .build(); 49 50 @Override getClient()51 protected DynamoDbClient getClient() { 52 return DynamoDBTestBase.getClient(); 53 } 54 55 /** 56 * Table schema: 57 * Hash Key : HASH_KEY_NAME (S) 58 * Range Key : RANGE_KEY_NAME (N) 59 * LSI schema: 60 * Hash Key : HASH_KEY_NAME (S) 61 * Range Key : LSI_RANGE_KEY_NAME (N) 62 * GSI schema: 63 * Hash Key : GSI_HASH_KEY_NAME (N) 64 * Range Key : GSI_RANGE_KEY_NAME (N) 65 */ 66 @Override getCreateTableRequest()67 protected CreateTableRequest getCreateTableRequest() { 68 CreateTableRequest createTableRequest = CreateTableRequest.builder() 69 .tableName(TEMP_TABLE_NAME) 70 .keySchema( 71 KeySchemaElement.builder() 72 .attributeName(HASH_KEY_NAME) 73 .keyType(KeyType.HASH) 74 .build(), 75 KeySchemaElement.builder() 76 .attributeName(RANGE_KEY_NAME) 77 .keyType(KeyType.RANGE) 78 .build()) 79 .attributeDefinitions( 80 AttributeDefinition.builder().attributeName( 81 HASH_KEY_NAME).attributeType( 82 ScalarAttributeType.S).build(), 83 AttributeDefinition.builder().attributeName( 84 RANGE_KEY_NAME).attributeType( 85 ScalarAttributeType.N).build(), 86 AttributeDefinition.builder().attributeName( 87 LSI_RANGE_KEY_NAME).attributeType( 88 ScalarAttributeType.N).build(), 89 AttributeDefinition.builder().attributeName( 90 GSI_HASH_KEY_NAME).attributeType( 91 ScalarAttributeType.S).build(), 92 AttributeDefinition.builder().attributeName( 93 GSI_RANGE_KEY_NAME).attributeType( 94 ScalarAttributeType.N).build()) 95 .provisionedThroughput(BasicTempTable.DEFAULT_PROVISIONED_THROUGHPUT) 96 .localSecondaryIndexes( 97 LocalSecondaryIndex.builder() 98 .indexName(LSI_NAME) 99 .keySchema( 100 KeySchemaElement.builder() 101 .attributeName( 102 HASH_KEY_NAME) 103 .keyType(KeyType.HASH).build(), 104 KeySchemaElement.builder() 105 .attributeName( 106 LSI_RANGE_KEY_NAME) 107 .keyType(KeyType.RANGE).build()) 108 .projection( 109 Projection.builder() 110 .projectionType(ProjectionType.KEYS_ONLY).build()).build()) 111 .globalSecondaryIndexes( 112 GlobalSecondaryIndex.builder().indexName(GSI_NAME) 113 .keySchema( 114 KeySchemaElement.builder() 115 .attributeName( 116 GSI_HASH_KEY_NAME) 117 .keyType(KeyType.HASH).build(), 118 KeySchemaElement.builder() 119 .attributeName( 120 GSI_RANGE_KEY_NAME) 121 .keyType(KeyType.RANGE).build()) 122 .projection( 123 Projection.builder() 124 .projectionType(ProjectionType.KEYS_ONLY).build()) 125 .provisionedThroughput( 126 GSI_PROVISIONED_THROUGHPUT).build()) 127 .build(); 128 return createTableRequest; 129 } 130 131 } 132