我对AWS Dynamo DB进行了一些测试。我得到了一些集成测试,我需要加快它们的速度。 SetupTableAsync需要大约10秒,代码在我的构造函数中,因此它在每个实例/测试上运行。 是否可以在每次测试中使用相同的IAmazonDynamoDB实例?
private string TableName { get; }
IAmazonDynamoDB DDBClient { get; }
public FunctionTest()
{
this.TableName = "Table-" + DateTime.Now.Ticks;
this.DDBClient = new AmazonDynamoDBClient(RegionEndpoint.EUWest1);
SetupTableAsync().Wait();
}
//... some tests
private async Task SetupTableAsync()
{
var request = new CreateTableRequest
{
TableName = this.TableName,
ProvisionedThroughput = new ProvisionedThroughput
{
ReadCapacityUnits = 2,
WriteCapacityUnits = 2
},
KeySchema = new List<KeySchemaElement>
{
new KeySchemaElement
{
KeyType = KeyType.HASH,
AttributeName = UserFunctions.ID_QUERY_STRING_NAME
}
},
AttributeDefinitions = new List<AttributeDefinition>
{
new AttributeDefinition
{
AttributeName = UserFunctions.ID_QUERY_STRING_NAME,
AttributeType = ScalarAttributeType.S
}
}
};
await this.DDBClient.CreateTableAsync(request);
var describeRequest = new DescribeTableRequest { TableName = this.TableName };
DescribeTableResponse response = null;
do
{
Thread.Sleep(1000);
response = await this.DDBClient.DescribeTableAsync(describeRequest);
} while (response.Table.TableStatus != TableStatus.ACTIVE);
}
此代码来自Visual Studio中的“AWS Serverless with tests”模板。
答案 0 :(得分:1)
与Dunedan的建议相似:
在这些情况下,我通常依赖DynamoDB Local:https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html
我喜欢这个有几个原因:
答案 1 :(得分:0)