public void CanGetClientForEndpoint()
        {
            var sut = new EventStoreClusterClientCache(new FakePublisher(), EventStoreClusterClientFactory);

            var client = sut.Get(new IPEndPoint(IPAddress.Loopback, 1113));

            Assert.AreEqual(client, sut.Get(new IPEndPoint(IPAddress.Loopback, 1113)));
        }
예제 #2
0
        public void Handle(GrpcMessage.SendOverGrpc message)
        {
            switch (message.Message)
            {
            case GossipMessage.SendGossip sendGossip:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendGossip(sendGossip, message.DestinationEndpoint, message.LiveUntil);
                break;

            case GossipMessage.GetGossip _:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .GetGossip(message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.ViewChange viewChange:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendViewChange(viewChange, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.ViewChangeProof proof:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendViewChangeProof(proof, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.Prepare prepare:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendPrepare(prepare, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.PrepareOk prepareOk:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendPrepareOk(prepareOk, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.Proposal proposal:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendProposal(proposal, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.Accept accept:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendAccept(accept, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.LeaderIsResigning resigning:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendLeaderIsResigning(resigning, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.LeaderIsResigningOk resigningOk:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendLeaderIsResigningOk(resigningOk, message.DestinationEndpoint, message.LiveUntil);
                break;

            default:
                throw new NotImplementedException($"Message of type {message.Message.GetType().Name} cannot be handled.");
            }
        }
        public async Task CleansCacheOnThreshold()
        {
            var interval         = TimeSpan.FromMinutes(30);
            var oldItemThreshold = TimeSpan.FromMilliseconds(500);
            var sut = new EventStoreClusterClientCache(new FakePublisher(), EventStoreClusterClientFactory, interval,
                                                       oldItemThreshold);
            var oldClient = sut.Get(new IPEndPoint(IPAddress.Loopback, 1113));

            sut.Handle(new ClusterClientMessage.CleanCache());
            await Task.Delay(oldItemThreshold.Add(TimeSpan.FromMilliseconds(500)));

            var newClient = sut.Get(new IPEndPoint(IPAddress.Loopback, 1113));

            newClient = sut.Get(new IPEndPoint(IPAddress.Loopback, 1113));
            Assert.AreNotEqual(oldClient, newClient);
        }
        public async Task ShouldDisposeClientOnceEvictedFromCache()
        {
            var interval         = TimeSpan.FromMinutes(30);
            var oldItemThreshold = TimeSpan.FromMilliseconds(500);
            var sut = new EventStoreClusterClientCache(new FakePublisher(), EventStoreClusterClientFactory, interval,
                                                       oldItemThreshold);
            var client = sut.Get(new IPEndPoint(IPAddress.Loopback, 1113));

            Assert.NotNull(client);

            await Task.Delay(oldItemThreshold.Add(TimeSpan.FromMilliseconds(500)));

            sut.Handle(new ClusterClientMessage.CleanCache());
            // Give the cache enough time to dispose the client
            await Task.Delay(oldItemThreshold);

            Assert.True(client.Disposed);
        }
예제 #5
0
        public void Handle(GrpcMessage.SendOverGrpc message)
        {
            if (message.LiveUntil < DateTime.Now)
            {
                Log.Verbose("Dropping gRPC send message due to TTL being over. {messageType} To : {endPoint}",
                            message.Message.GetType().Name, message.DestinationEndpoint);
                return;
            }

            switch (message.Message)
            {
            case GossipMessage.SendGossip sendGossip:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendGossip(sendGossip, message.DestinationEndpoint, message.LiveUntil);
                break;

            case GossipMessage.GetGossip _:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .GetGossip(message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.ViewChange viewChange:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendViewChange(viewChange, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.ViewChangeProof proof:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendViewChangeProof(proof, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.Prepare prepare:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendPrepare(prepare, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.PrepareOk prepareOk:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendPrepareOk(prepareOk, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.Proposal proposal:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendProposal(proposal, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.Accept accept:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendAccept(accept, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.LeaderIsResigning resigning:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendLeaderIsResigning(resigning, message.DestinationEndpoint, message.LiveUntil);
                break;

            case ElectionMessage.LeaderIsResigningOk resigningOk:
                _eventStoreClientCache.Get(message.DestinationEndpoint)
                .SendLeaderIsResigningOk(resigningOk, message.DestinationEndpoint, message.LiveUntil);
                break;

            default:
                throw new NotImplementedException($"Message of type {message.Message.GetType().Name} cannot be handled.");
            }
        }