public override void LoadUnitTestData(DataContainer dataContainer) { Console.WriteLine($"Using connection string {dataContainer.ConnectionString}"); using (var client = new DynamoDBClientBuilder(dataContainer.ConnectionString).GetClient()) { client.CreateTableAsync("CONTACTS_AUDIT", new List <KeySchemaElement>() { new KeySchemaElement("ID", KeyType.HASH) }, new List <AttributeDefinition>() { new AttributeDefinition("ID", ScalarAttributeType.S) }, new ProvisionedThroughput(10, 10) ).Wait(); client.CreateTableAsync("EMAILS", new List <KeySchemaElement>() { new KeySchemaElement("ID", KeyType.HASH) }, new List <AttributeDefinition>() { new AttributeDefinition("ID", ScalarAttributeType.S) }, new ProvisionedThroughput(10, 10) ).Wait(); client.CreateTableAsync("LEADS", new List <KeySchemaElement>() { new KeySchemaElement("ID", KeyType.HASH) }, new List <AttributeDefinition>() { new AttributeDefinition("ID", ScalarAttributeType.S) }, new ProvisionedThroughput(10, 10) ).Wait(); client.CreateTableAsync("PEOPLE", new List <KeySchemaElement>() { new KeySchemaElement("Id", KeyType.HASH) }, new List <AttributeDefinition>() { new AttributeDefinition("Id", ScalarAttributeType.S) }, new ProvisionedThroughput(10, 10) ).Wait(); var contextConfig = new DynamoDBContextConfig() { TableNamePrefix = "" }; var context = new DynamoDBContext(client, contextConfig); var people = GetPeople(200); var contactsBatch = context.CreateBatchWrite <Person>(); contactsBatch.AddPutItems(people); contactsBatch.ExecuteAsync().GetAwaiter().GetResult(); } }
public override void LoadSamples(DataEntity[] dataEntities, long count) { using (var client = new DynamoDBClientBuilder(dataEntities[0].Container.ConnectionString).GetClient()) { var attrs = new List <AttributeDefinition>();// dataEntities.Select(x => new AttributeDefinition(x.Name, ScalarAttributeType.S)).ToList(); attrs.Add(new AttributeDefinition("ID", ScalarAttributeType.S)); client.CreateTableAsync(dataEntities[0].Collection.Name, new List <KeySchemaElement>() { new KeySchemaElement("ID", KeyType.HASH) }, attrs, new ProvisionedThroughput(10, 10) ).Wait(); var table = Table.LoadTable(client, dataEntities[0].Collection.Name); long rows = 0; long batchSize = 100; var r = new Random(); while (rows < count) { if (rows % 1000 == 0) { Console.Write("."); } var batchWrite = table.CreateBatchWrite(); for (int i = 0; i < batchSize; i++) { var doc = new Document(); doc["ID"] = Guid.NewGuid().ToString(); foreach (var dataEntity in dataEntities) { switch (dataEntity.DataType) { case DataType.String: doc[dataEntity.Name] = new Guid().ToString(); break; case DataType.Int: doc[dataEntity.Name] = r.Next().ToString(); break; case DataType.Double: doc[dataEntity.Name] = r.NextDouble().ToString(); break; case DataType.Boolean: doc[dataEntity.Name] = (r.Next(100) > 50).ToString(); break; case DataType.DateTime: doc[dataEntity.Name] = DateTimeOffset .FromUnixTimeMilliseconds( DateTimeOffset.Now.ToUnixTimeMilliseconds() + r.Next()).DateTime.ToString("s"); break; default: doc[dataEntity.Name] = r.Next().ToString(); break; } } batchWrite.AddDocumentToPut(doc); } batchWrite.ExecuteAsync().Wait(); rows += batchSize; } Console.WriteLine(); } }