コード例 #1
0
        public static IContextLinkageOptions Convert(this ContextLinkageOptions options, IProtocolMessageFactory messageFactory)
        {
            if (options == null)
            {
                return(messageFactory.CreateContextLinkageOptions(ContextLinkageDiscoveryMode.None, Maybe <string> .Nothing));
            }

            return(messageFactory.CreateContextLinkageOptions(options.Mode,
                                                              options.SpecifiedContextId));
        }
コード例 #2
0
        public void NewAppInstanceWillBeLaunchedOnInvocationWithinContext()
        {
            var serverCreatedCount = 0;

            Task <GreetingResponse> HandleAsync(GreetingRequest greetingRequest, MethodCallContext context)
            {
                return(Task.FromResult(new GreetingResponse {
                    Greeting = greetingRequest.Name + (serverCreatedCount)
                }));
            }

            RunWith10SecTimeout(async() =>
            {
                var echoServerFactory = new TestClientFactory(
                    (broker, id) =>
                {
                    var optionsBuilder = new ClientOptionsBuilder()
                                         .WithBrokerWorkingDir(_testBrokerFixture.SharedInstance.WorkingDir)
                                         .WithAppInstanceId(id)
                                         .WithApplicationId(EchoServerClient.Id)
                                         .WithDefaultConfiguration()
                                         .WithProvidedService(
                        GreetingService.Id,
                        x => x.WithUnaryMethod <GreetingRequest, GreetingResponse>("Hello", HandleAsync));

                    serverCreatedCount++;

                    return(ClientFactory.Instance.Create(optionsBuilder.Build()));
                });

                var appLauncher = RegisterDisposable(
                    new TestAppLauncher(
                        _testBrokerFixture.SharedInstance,
                        new Dictionary <string, TestClientFactory>
                {
                    { EchoServerClient.Id, echoServerFactory }
                }
                        )
                    );
                await appLauncher.StartAsync();
                var client = CreateClient <EchoClient>();
                await client.ConnectAsync();

                var result1 = await client.GreetingService.Hello(new GreetingRequest {
                    Name = "Test1"
                });
                result1.Greeting.ShouldBe("Test11");

                var result2 = await client.GreetingService.Hello(new GreetingRequest {
                    Name = "Test2"
                });
                result2.Greeting.ShouldBe("Test21");

                serverCreatedCount.ShouldBe(1);

                var newContext  = await client.ContextLinkageService.CreateContext2(new CreateContextRequest());
                var allContexts = await client.ContextLinkageService.GetContexts(new Empty());

                allContexts.Contexts.Count.ShouldBe(1);
                allContexts.Contexts[0].Id.ShouldBe(newContext.Id);

                var result3 = await client.CallInvoker.Call(
                    GreetingService.DefaultDescriptor.HelloMethod,
                    new GreetingRequest {
                    Name = "Test3"
                },
                    ContextLinkageOptions.WithCurrentContext());

                result3.Greeting.ShouldBe("Test32");

                serverCreatedCount.ShouldBe(2);

                WriteLog("Starting to read context loaded stream");

                var contextStatus = await client.ContextLinkageService.ContextLoadedStream(newContext).ResponseStream
                                    .FirstAsync(update => update.LoadedAppDescriptors.Any(appDescriptor => appDescriptor.AppId == EchoServerClient.Id));

                contextStatus.LoadedAppDescriptors.Any(descriptor => descriptor.AppId == EchoClient.Id);

                var linkedInvocations = await client.ContextLinkageService.GetLinkedInvocations(newContext);

                linkedInvocations.Invocations
                .Single(reference => reference.AppInfo.ProvidedServices.Any(service => service.ServiceId == GreetingService.Id))
                .ShouldNotBeNull();
            });
        }