Пример #1
0
        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();
                    }
                }
            }
        }
Пример #2
0
        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);
                    }
                }
            }
        }
Пример #3
0
 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();
 }
Пример #4
0
 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;
 }
Пример #5
0
        public IGroupCacheClient GetClient(PeerEndpoint endpoint)
        {
            var lazy = new Lazy <IGroupCacheClient>(
                () => {
                return(new CircuitBreakerClient(new OwinClient(endpoint)));
            }
                , LazyThreadSafetyMode.ExecutionAndPublication);

            return(_cacheClients.GetOrAdd(endpoint, lazy).Value);
        }
Пример #6
0
        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();
                }
            }
        }
Пример #7
0
        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);
        }
Пример #8
0
 public void OnConnectionFailure(ConnectionId connectionId, PeerEndpoint endpoint)
 {
     OnDisconnected(connectionId);
 }