public void MissingEndpointsCauseException()
        {
            var endpoints = new EndpointsCollection();
            activationContext.GetEndpoints().Returns(_ => endpoints);

            // Check for the silo endpoint.
            var exception = Assert.Throws<KeyNotFoundException>(() => new OrleansCommunicationListener(serviceContext, clusterConfig));
            Assert.Contains("OrleansSiloEndpoint", exception.Message);

            // Check for the proxy endpoint.
            endpoints.Add(CreateEndpoint("OrleansSiloEndpoint", 9082));
            exception = Assert.Throws<KeyNotFoundException>(() => new OrleansCommunicationListener(serviceContext, clusterConfig));
            Assert.Contains("OrleansProxyEndpoint", exception.Message);
        }
        public async Task SimpleUsageScenarioTest()
        {
            var endpoints = new EndpointsCollection
            {
                CreateEndpoint("OrleansSiloEndpoint", 9082),
                CreateEndpoint("OrleansProxyEndpoint", 8888)
            };

            activationContext.GetEndpoints().Returns(_ => endpoints);
            var siloHost = Substitute.For<ISiloHost>();
            var listener = new OrleansCommunicationListener(this.serviceContext, clusterConfig)
            {
                SiloHost = siloHost
            };

            siloHost.NodeConfig.Returns(_ => clusterConfig.CreateNodeConfigurationForSilo(listener.SiloName));

            var result = await listener.OpenAsync(CancellationToken.None);
            var publishedEndpoints = JsonConvert.DeserializeObject<OrleansFabricEndpoints>(result);

            var siloAddress = publishedEndpoints.SiloAddress;
            siloAddress.Generation.ShouldBeEquivalentTo(864);
            siloAddress.Endpoint.Port.ShouldBeEquivalentTo(9082);

            var gatewayAddress = publishedEndpoints.GatewayAddress;
            gatewayAddress.Generation.ShouldBeEquivalentTo(864);
            gatewayAddress.Endpoint.Port.ShouldBeEquivalentTo(8888);

            siloHost.ReceivedWithAnyArgs(1).Start(null, null);
            siloHost.DidNotReceive().Stop();

            siloHost.ClearReceivedCalls();
            await listener.CloseAsync(CancellationToken.None);
            siloHost.Received(1).Stop();
            siloHost.DidNotReceiveWithAnyArgs().Start(null, null);
        }
        public void AbortStopAndDisposesSilo()
        {
            var endpoints = new EndpointsCollection
            {
                CreateEndpoint("OrleansSiloEndpoint", 9082),
                CreateEndpoint("OrleansProxyEndpoint", 8888)
            };

            activationContext.GetEndpoints().Returns(_ => endpoints);
            var siloHost = Substitute.For<ISiloHost>();
            var listener = new OrleansCommunicationListener(
                serviceContext,
                new ClusterConfiguration())
            {
                SiloHost = siloHost
            };

            listener.Abort();
            siloHost.ReceivedWithAnyArgs(1).Stop();
            siloHost.ReceivedWithAnyArgs(1).Dispose();
            siloHost.DidNotReceiveWithAnyArgs().Start(null, null);
        }
        public async Task CloseStopsSilo()
        {
            var endpoints = new EndpointsCollection
            {
                CreateEndpoint("OrleansSiloEndpoint", 9082),
                CreateEndpoint("OrleansProxyEndpoint", 8888)
            };

            activationContext.GetEndpoints().Returns(_ => endpoints);
            var siloHost = Substitute.For<ISiloHost>();
            var listener = new OrleansCommunicationListener(
                serviceContext,
                new ClusterConfiguration())
            {
                SiloHost = siloHost
            };

            await listener.CloseAsync(CancellationToken.None);
            siloHost.ReceivedWithAnyArgs(1).Stop();
            siloHost.DidNotReceiveWithAnyArgs().Dispose();
            siloHost.DidNotReceiveWithAnyArgs().Start(null, null);
        }