public void TestCache() { Func <string, TableDescription> creator = tn => client.DescribeTable(tn).Table; var tableName = GetTableName(); var tableCache = SdkCache.GetCache <string, TableDescription>(client, DynamoDBTests.TableCacheIdentifier, StringComparer.Ordinal); Assert.AreEqual(0, tableCache.ItemCount); using (var counter = new ServiceResponseCounter(client)) { var table = tableCache.GetValue(tableName, creator); Assert.AreEqual(1, counter.ResponseCount); Assert.AreEqual(1, tableCache.ItemCount); // verify the item is still there table = tableCache.GetValue(tableName, creator); Assert.AreEqual(1, counter.ResponseCount); // verify item was reloaded tableCache.Clear(tableName); table = tableCache.GetValue(tableName, creator); Assert.AreEqual(2, counter.ResponseCount); Assert.AreEqual(1, tableCache.ItemCount); // test item expiration tableCache.MaximumItemLifespan = TimeSpan.FromSeconds(1); Thread.Sleep(tableCache.MaximumItemLifespan); table = tableCache.GetValue(tableName, creator); Assert.AreEqual(3, counter.ResponseCount); Assert.AreEqual(1, tableCache.ItemCount); } }
public void Init() { lastUseSdkCacheValue = AWSConfigs.UseSdkCache; AWSConfigs.UseSdkCache = true; SdkCache.Clear(); client = TestBase.CreateClient <AmazonDynamoDBClient>(); }
public void Init() { lastUseSdkCacheValue = AWSConfigs.UseSdkCache; AWSConfigs.UseSdkCache = true; SdkCache.Clear(); testTableName = UtilityMethods.GenerateName("CacheTest"); CreateTable(testTableName, true); }
public void Init() { lastUseSdkCacheValue = AWSConfigs.UseSdkCache; AWSConfigs.UseSdkCache = true; SdkCache.Clear(); client = TestBase.CreateClient <AmazonDynamoDBClient>(); testTableName = UtilityMethods.GenerateName("CacheTest"); CreateTable(testTableName, true); }
public void ChangingTableTest() { var item = new Document(new Dictionary <string, DynamoDBEntry> { { "Id", 42 }, { "Name", "Floyd" }, { "Coffee", "Yes" } }); var tableCache = SdkCache.GetCache <string, TableDescription>(client, DynamoDBTests.TableCacheIdentifier, StringComparer.Ordinal); CreateTable(defaultKeys: true); var table = Table.LoadTable(client, tableName); table.PutItem(item); using (var counter = new ServiceResponseCounter(client)) { var doc = table.GetItem(42, "Floyd"); Assert.IsNotNull(doc); Assert.AreNotEqual(0, doc.Count); Assert.AreEqual(1, counter.ResponseCount); AssertExtensions.ExpectException(() => table.GetItem("Floyd", 42)); var oldTableDescription = tableCache.GetValue(tableName, null); DeleteTable(); CreateTable(defaultKeys: false); table.PutItem(item); AssertExtensions.ExpectException(() => table.GetItem(42, "Yes")); counter.Reset(); Table.ClearTableCache(); table = Table.LoadTable(client, tableName); doc = table.GetItem(42, "Yes"); Assert.IsNotNull(doc); Assert.AreNotEqual(0, doc.Count); Assert.AreEqual(2, counter.ResponseCount); counter.Reset(); Table.ClearTableCache(); PutItem(tableCache, tableName, oldTableDescription); table = Table.LoadTable(client, tableName); doc = tableCache.UseCache(tableName, () => table.GetItem(42, "Yes"), () => table = Table.LoadTable(client, tableName), shouldRetryForException: null); Assert.IsNotNull(doc); Assert.AreNotEqual(0, doc.Count); Assert.AreEqual(2, counter.ResponseCount); } }
private Table(IAmazonDynamoDB ddbClient, string tableName, Table.DynamoDBConsumer consumer, DynamoDBEntryConversion conversion) { #if PCL || UNITY DDBClient = ddbClient as AmazonDynamoDBClient; #else DDBClient = ddbClient; #endif TableInfoCache = SdkCache.GetCache <string, TableDescription>(ddbClient, TableInfoCacheIdentifier, StringComparer.Ordinal); LoggerInstance = Logger.GetLogger(typeof(SdkCache)); TableConsumer = consumer; TableName = tableName; Conversion = conversion; ClearTableData(); }
public void Cleanup() { var tableExists = true; //var status = AWSSDK_DotNet.IntegrationTests.Tests.DynamoDB.DynamoDBTests.GetStatus(tableName); //tableExists = (status != null); var allTables = AWSSDK_DotNet.IntegrationTests.Tests.DynamoDB.DynamoDBTests.Client.ListTables().TableNames; tableExists = allTables.Contains(tableName); if (tableExists) { DeleteTable(); } AWSConfigs.UseSdkCache = lastUseSdkCacheValue; SdkCache.Clear(); }
/// <summary> /// Clears current table cache. Next time a Table is created, its information /// will be loaded from DynamoDB. /// </summary> public static void ClearTableCache() { SdkCache.Clear(TableInfoCacheIdentifier); }
private void LoadTableInfo() { ClearTableData(); var tableInfoCache = SdkCache.GetCache <string, TableDescription>(DDBClient, TableInfoCacheIdentifier, StringComparer.Ordinal); bool staleCacheData; TableDescription table = tableInfoCache.GetValue(TableName, this.DescribeTable, out staleCacheData); if (staleCacheData) { var logger = Logger.GetLogger(typeof(Table)); logger.InfoFormat("Description for table [{0}] loaded from SDK Cache", TableName); } foreach (var key in table.KeySchema) { string keyName = key.AttributeName; AttributeDefinition attributeDefinition = table.AttributeDefinitions .FirstOrDefault(a => string.Equals(a.AttributeName, keyName, StringComparison.Ordinal)); if (attributeDefinition == null) { throw new InvalidOperationException("No attribute definition found for key " + key.AttributeName); } KeyDescription keyDescription = new KeyDescription { IsHash = string.Equals(key.KeyType, "HASH", StringComparison.OrdinalIgnoreCase), Type = GetType(attributeDefinition.AttributeType) }; if (keyDescription.IsHash) { HashKeys.Add(keyName); } else { RangeKeys.Add(keyName); } Keys[keyName] = keyDescription; } if (table.LocalSecondaryIndexes != null) { foreach (var index in table.LocalSecondaryIndexes) { LocalSecondaryIndexes[index.IndexName] = index; LocalSecondaryIndexNames.Add(index.IndexName); } } if (table.GlobalSecondaryIndexes != null) { foreach (var index in table.GlobalSecondaryIndexes) { GlobalSecondaryIndexes[index.IndexName] = index; GlobalSecondaryIndexNames.Add(index.IndexName); } } foreach (var attribute in table.AttributeDefinitions) { Attributes.Add(attribute); } }
public void Init() { lastUseSdkCacheValue = AWSConfigs.UseSdkCache; AWSConfigs.UseSdkCache = true; SdkCache.Clear(); }