public async Task TestServerSideExceptionAsync() { var host = "localhost"; var port = 50051; var handler = new BadGroupCacheHandler(); using (var server = new OwinServer(handler, port, host)) { server.Start(); var endpoint = new PeerEndpoint() { HostName = host, Port = port }; using (var client = new OwinClient(endpoint)) { using (var stream = new MemoryStream()) { await client.GetAsync("groupA", "key1", stream, new CacheControl(), CancellationToken.None); var str = stream.StreamToString(); Assert.Fail(); } } } }
public async Task TestHelloWorldAsync() { var host = "localhost"; var port = 50051; var handler = new GroupCacheHandler(); using (var server = new OwinServer(handler, port, host)){ server.Start(); var endpoint = new PeerEndpoint() { HostName = host, Port = port }; using (var client = new OwinClient(endpoint)) { using (var stream = new MemoryStream()) { var cacheControl = new CacheControl(); await client.GetAsync("groupA", "key1", stream, cacheControl, CancellationToken.None); var str = stream.StreamToString(); Assert.AreEqual(str, "HelloWorld"); Assert.IsFalse(cacheControl.NoStore); } } } }
public OwinPool(PeerEndpoint self, int concurrencyLimit = 24) { _self = self; _concurrencyLimit = concurrencyLimit; _concurrencyLimiter = new SemaphoreSlim(initialCount: _concurrencyLimit); _server = new OwinServer(this, self.Port, self.HostName); _server.Start(); }
public OwinClient(PeerEndpoint endpoint, int minuteTimeout = 2) { Endpoint = endpoint; _client = new HttpClient() { Timeout = TimeSpan.FromMinutes(minuteTimeout), BaseAddress = new UriBuilder("http", Endpoint.HostName, Endpoint.Port).Uri, }; _client.DefaultRequestHeaders.ConnectionClose = true; }
public IGroupCacheClient GetClient(PeerEndpoint endpoint) { var lazy = new Lazy <IGroupCacheClient>( () => { return(new CircuitBreakerClient(new OwinClient(endpoint))); } , LazyThreadSafetyMode.ExecutionAndPublication); return(_cacheClients.GetOrAdd(endpoint, lazy).Value); }
public async Task TestUnavailableAsync() { var host = "localhost"; var badPort = 666; var handler = new GroupCacheHandler(); var endpoint = new PeerEndpoint() { HostName = host, Port = badPort }; using (var client = new OwinClient(endpoint)) { using (var stream = new MemoryStream()) { await client.GetAsync("groupA", "key1", stream, new CacheControl(), CancellationToken.None); var str = stream.StreamToString(); Assert.Fail(); } } }
public void Setup() { var peer1 = new PeerEndpoint { HostName = "localhost", Port = 50053 }; var peer2 = new PeerEndpoint { HostName = "localhost", Port = 50054 }; var peerList = new List <PeerEndpoint> { peer1, peer2 }; // server listening on port 50053 peer1Pool = new GroupCacheStub.OwinPool(peer1); peer1Pool.GetPicker("TestGroupForwarding").Add(peerList); peer1Pool.GetPicker("Fibonacci").Add(peerList); // server listening on port 50054 peer2Pool = new GroupCacheStub.OwinPool(peer2); peer2Pool.GetPicker("TestGroupForwarding").Add(peerList); peer2Pool.GetPicker("Fibonacci").Add(peerList); }
public void OnConnectionFailure(ConnectionId connectionId, PeerEndpoint endpoint) { OnDisconnected(connectionId); }