public async Task GetSessionData_WhenNotExists() { DiagnosticsSink diagnosticsSink = new DiagnosticsSink(); const string sessionId = "sessionId"; const int ttl = 1400; const int throughput = 2000; CosmosClientBuilder builder = new CosmosClientBuilder(ConfigurationManager.AppSettings["Endpoint"], ConfigurationManager.AppSettings["MasterKey"]); IOptions <CosmosCacheOptions> options = Options.Create(new CosmosCacheOptions() { ContainerName = "session", DatabaseName = CosmosCacheEmulatorTests.databaseName, ContainerThroughput = throughput, CreateIfNotExists = true, ClientBuilder = builder, DiagnosticsHandler = diagnosticsSink.CaptureDiagnostics }); CosmosCache cache = new CosmosCache(options); DistributedCacheEntryOptions cacheOptions = new DistributedCacheEntryOptions(); cacheOptions.SlidingExpiration = TimeSpan.FromSeconds(ttl); Assert.Null(await cache.GetAsync(sessionId)); Assert.Equal(4, diagnosticsSink.CapturedDiagnostics.Count); foreach (CosmosDiagnostics diagnostics in diagnosticsSink.CapturedDiagnostics) { Assert.NotNull(diagnostics?.ToString()); } }
public CSharpMapperParameters( ImmutableArray <CSharpTypeAlias> typeAliases, ImmutableArray <string> ignoredTypeNames, int bitness, DiagnosticsSink diagnostics) { TypeAliases = typeAliases; IgnoredTypeNames = ignoredTypeNames; Bitness = bitness is 32 or 64 ? bitness : throw new NotImplementedException($"{bitness}-bit is not implemented."); DiagnosticsSink = diagnostics; SystemTypeNameAliases = GetSystemTypeNameAliases(bitness).ToImmutableDictionary(); }
private CSharpAbstractSyntaxTree MapCAbstractSyntaxTreeToCSharp( CAbstractSyntaxTree abstractSyntaxTree, ImmutableArray <CSharpTypeAlias> typeAliases, ImmutableArray <string> ignoredTypeNames, int bitness, DiagnosticsSink diagnostics) { BeginStep(); var mapperParameters = new CSharpMapperParameters( typeAliases, ignoredTypeNames, bitness, diagnostics); var mapper = new CSharpMapper(mapperParameters); var result = mapper.AbstractSyntaxTree(abstractSyntaxTree); EndStep(); return(result); }
public async Task InitializeContainerIfNotExists() { DiagnosticsSink diagnosticsSink = new DiagnosticsSink(); const string sessionId = "sessionId"; const int ttl = 2000; const int ttlInSeconds = ttl / 1000; const int throughput = 2000; CosmosClientBuilder builder = new CosmosClientBuilder(ConfigurationManager.AppSettings["Endpoint"], ConfigurationManager.AppSettings["MasterKey"]); IOptions <CosmosCacheOptions> options = Options.Create(new CosmosCacheOptions() { ContainerName = "session", DatabaseName = CosmosCacheEmulatorTests.databaseName, ContainerThroughput = throughput, CreateIfNotExists = true, ClientBuilder = builder, DefaultTimeToLiveInMs = ttl, DiagnosticsHandler = diagnosticsSink.CaptureDiagnostics }); CosmosCache cache = new CosmosCache(options); DistributedCacheEntryOptions cacheOptions = new DistributedCacheEntryOptions(); cacheOptions.SlidingExpiration = TimeSpan.FromSeconds(ttlInSeconds); await cache.SetAsync(sessionId, new byte[0], cacheOptions); // Verify that container has been created ContainerResponse response = await this.testClient.GetContainer(CosmosCacheEmulatorTests.databaseName, "session").ReadContainerAsync(); Assert.NotEqual(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(ttlInSeconds, response.Resource.DefaultTimeToLive); Assert.True(response.Resource.IndexingPolicy.ExcludedPaths.Any(e => e.Path.Equals("/*"))); int?throughputContainer = await this.testClient.GetContainer(CosmosCacheEmulatorTests.databaseName, "session").ReadThroughputAsync(); Assert.Equal(throughput, throughputContainer); Assert.Equal(4, diagnosticsSink.CapturedDiagnostics.Count); foreach (CosmosDiagnostics diagnostics in diagnosticsSink.CapturedDiagnostics) { Assert.NotNull(diagnostics?.ToString()); } }
public async Task RemoveSessionData() { DiagnosticsSink diagnosticsSink = new DiagnosticsSink(); const string sessionId = "sessionId"; const int ttl = 1400; const int throughput = 2000; byte[] data = new byte[1] { 1 }; CosmosClientBuilder builder = new CosmosClientBuilder(ConfigurationManager.AppSettings["Endpoint"], ConfigurationManager.AppSettings["MasterKey"]); IOptions <CosmosCacheOptions> options = Options.Create(new CosmosCacheOptions() { ContainerName = "session", DatabaseName = CosmosCacheEmulatorTests.databaseName, ContainerThroughput = throughput, CreateIfNotExists = true, ClientBuilder = builder, DiagnosticsHandler = diagnosticsSink.CaptureDiagnostics }); CosmosCache cache = new CosmosCache(options); DistributedCacheEntryOptions cacheOptions = new DistributedCacheEntryOptions(); cacheOptions.SlidingExpiration = TimeSpan.FromSeconds(ttl); await cache.SetAsync(sessionId, data, cacheOptions); await cache.RemoveAsync(sessionId); CosmosException exception = await Assert.ThrowsAsync <CosmosException>(() => this.testClient.GetContainer(CosmosCacheEmulatorTests.databaseName, "session").ReadItemAsync <dynamic>(sessionId, new PartitionKey(sessionId))); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); Assert.Equal(5, diagnosticsSink.CapturedDiagnostics.Count); foreach (CosmosDiagnostics diagnostics in diagnosticsSink.CapturedDiagnostics) { Assert.NotNull(diagnostics?.ToString()); } }