Beispiel #1
0
        public ExceptionTests()
        {
            this.silo = SiloHostBuilder.CreateDefault().ConfigureApplicationParts(parts => parts.AddFromAppDomain()).ConfigureLocalHostPrimarySilo().Build();
            this.silo.StartAsync().GetAwaiter().GetResult();

            this.client = ClientBuilder.CreateDefault().ConfigureApplicationParts(parts => parts.AddFromAppDomain()).UseConfiguration(ClientConfiguration.LocalhostSilo()).Build();
            this.client.Connect().GetAwaiter().GetResult();
        }
Beispiel #2
0
        public void ClientBuilder_DoubleSpecifyConfigurationTest()
        {
            var builder = ClientBuilder.CreateDefault().ConfigureServices(RemoveConfigValidators)
                          .UseConfiguration(new ClientConfiguration())
                          .UseConfiguration(new ClientConfiguration());

            Assert.Throws <InvalidOperationException>(() => builder.Build());
        }
Beispiel #3
0
        public void ClientBuilder_DoubleBuildTest()
        {
            var builder = ClientBuilder.CreateDefault().ConfigureServices(RemoveConfigValidators);

            using (builder.Build())
            {
                Assert.Throws <InvalidOperationException>(() => builder.Build());
            }
        }
Beispiel #4
0
        public void ClientBuilder_NoSpecifiedConfigurationTest()
        {
            var builder = ClientBuilder.CreateDefault().ConfigureServices(RemoveConfigValidators);

            using (var client = builder.Build())
            {
                Assert.NotNull(client);
            }
        }
Beispiel #5
0
        public void ClientBuilder_DoubleBuildTest()
        {
            var builder = ClientBuilder.CreateDefault().ConfigureServices(RemoveConfigValidators)
                          .ConfigureServices(services => services.AddSingleton <IGatewayListProvider, NoOpGatewaylistProvider>());

            using (builder.Build())
            {
                Assert.Throws <InvalidOperationException>(() => builder.Build());
            }
        }
Beispiel #6
0
        public void ClientBuilder_NoSpecifiedConfigurationTest()
        {
            var builder = ClientBuilder.CreateDefault().ConfigureServices(RemoveConfigValidators)
                          .ConfigureServices(services => services.AddSingleton <IGatewayListProvider, NoOpGatewaylistProvider>());

            using (var client = builder.Build())
            {
                Assert.NotNull(client);
            }
        }
Beispiel #7
0
        static async Task InitializeOrleans()
        {
            //var config = new ClusterConfiguration();
            //config.Globals.DataConnectionString = "Server=tnwli-pc.dmtnprod.lan;Database=ApprovalSystem;User Id=QTIP;Password=QTIP; ";
            //config.Globals.ClusterId = "AprovalSiloID";
            //config.Globals.LivenessType = GlobalConfiguration.LivenessProviderType.SqlServer;
            //config.Globals.ReminderServiceType = GlobalConfiguration.ReminderServiceProviderType.SqlServer;
            //config.Defaults.PropagateActivityId = true;
            //config.Defaults.ProxyGatewayEndpoint = new System.Net.IPEndPoint(IPAddress.Any, 18000);


            var config = new ClientConfiguration();

            config.ClusterId           = "AprovalSiloID";
            config.PropagateActivityId = true;
            config.AdoInvariant        = "System.Data.SqlClient";

            config.DataConnectionString = "Server=tnwli-pc.dmtnprod.lan;Database=ApprovalSystem;User Id=QTIP;Password=QTIP; ";
            config.GatewayProvider      = ClientConfiguration.GatewayProviderType.SqlServer;
            Console.WriteLine("Initializing ... ");
            client = new ClientBuilder()
                     .ConfigureApplicationParts(p => p.AddFromAppDomain().AddFromApplicationBaseDirectory())
                     .UseConfiguration(config).Build();

            var builder = ClientBuilder.CreateDefault()
                          .UseConfiguration(config)
                          .ConfigureApplicationParts(parts => parts.AddFromAppDomain().AddFromApplicationBaseDirectory());

            client = builder.Build();

            try
            {
                await client.Connect();

                running = true;
                Console.WriteLine("Initialized.");
                var grain = client.GetGrain <IUser>(Guid.Empty);
                while (running)
                {
                    string proposal = "ACED Proposal";
                    //int num = 15;
                    var response = await grain.Approve(proposal);

                    Console.WriteLine($"{proposal} was Approved : { response}");
                    await Task.Delay(1000);
                }
                client.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #8
0
            protected override TestCluster CreateTestCluster()
            {
                var options = new TestClusterOptions();

                options.UseSiloBuilderFactory <SiloBuilder>();
                options.ClientBuilderFactory = cfg => ClientBuilder
                                               .CreateDefault()
                                               .UseConfiguration(cfg)
                                               .ConfigureApplicationParts(
                    parts => parts.AddApplicationPart(typeof(IRuntimeCodeGenGrain).Assembly).WithCodeGeneration());

                return(new TestCluster(options));
            }
Beispiel #9
0
        public void ClientBuilder_AssembliesTest()
        {
            var builder = ClientBuilder.CreateDefault();

            Assert.Throws <OrleansConfigurationException>(() => builder.Build());

            // Adding an application assembly causes the
            builder = ClientBuilder.CreateDefault().AddApplicationPart(typeof(IAccountGrain).Assembly);
            using (var client = builder.Build())
            {
                Assert.NotNull(client);
            }
        }
        public SerializationTestEnvironment(ClientConfiguration config = null, Action <IClientBuilder> configureClientBuilder = null)
        {
            if (config == null)
            {
                config = this.DefaultConfig();
            }

            var builder = ClientBuilder.CreateDefault();

            builder.UseConfiguration(config);
            builder.ConfigureApplicationParts(parts => parts.AddFromAppDomain().AddFromApplicationBaseDirectory());
            configureClientBuilder?.Invoke(builder);
            this.Client        = builder.Build();
            this.RuntimeClient = this.Client.ServiceProvider.GetRequiredService <OutsideRuntimeClient>();
        }
            protected override TestCluster CreateTestCluster()
            {
                var            options = new TestClusterOptions();
                ILoggerFactory codeGenLoggerFactory = new LoggerFactory();

                codeGenLoggerFactory.AddProvider(new FileLoggerProvider("ClientCodeGeneration.log"));
                options.UseSiloBuilderFactory <SiloBuilder>();
                options.ClientBuilderFactory = cfg => ClientBuilder
                                               .CreateDefault()
                                               .UseConfiguration(cfg)
                                               .ConfigureApplicationParts(
                    parts => parts.AddApplicationPart(typeof(IRuntimeCodeGenGrain).Assembly).WithCodeGeneration(codeGenLoggerFactory.CreateLogger("RuntimeCodeGen")));

                return(new TestCluster(options));
            }
Beispiel #12
0
        public void ClientBuilder_ServiceProviderTest()
        {
            var builder = ClientBuilder.CreateDefault().ConfigureServices(RemoveConfigValidators)
                          .ConfigureServices(services => services.AddSingleton <IGatewayListProvider, NoOpGatewaylistProvider>());

            Assert.Throws <ArgumentNullException>(() => builder.ConfigureServices(null));

            var registeredFirst = new int[1];

            var one = new MyService {
                Id = 1
            };

            builder.ConfigureServices(
                services =>
            {
                Interlocked.CompareExchange(ref registeredFirst[0], 1, 0);
                services.AddSingleton(one);
            });

            var two = new MyService {
                Id = 2
            };

            builder.ConfigureServices(
                services =>
            {
                Interlocked.CompareExchange(ref registeredFirst[0], 2, 0);
                services.AddSingleton(two);
            });

            using (var client = builder.Build())
            {
                var services = client.ServiceProvider.GetServices <MyService>()?.ToList();
                Assert.NotNull(services);

                // Both services should be registered.
                Assert.Equal(2, services.Count);
                Assert.NotNull(services.FirstOrDefault(svc => svc.Id == 1));
                Assert.NotNull(services.FirstOrDefault(svc => svc.Id == 2));

                // Service 1 should have been registered first - the pipeline order should be preserved.
                Assert.Equal(1, registeredFirst[0]);

                // The last registered service should be provided by default.
                Assert.Equal(2, client.ServiceProvider.GetRequiredService <MyService>().Id);
            }
        }
Beispiel #13
0
        public ExceptionTests()
        {
            this.silo = SiloHostBuilder.CreateDefault()
                        .ConfigureApplicationParts(
                parts =>
                parts.AddApplicationPart(typeof(ExceptionGrain).Assembly).WithReferences())
                        .ConfigureLocalHostPrimarySilo()
                        .Build();
            this.silo.StartAsync().GetAwaiter().GetResult();

            this.client = ClientBuilder.CreateDefault()
                          .ConfigureApplicationParts(parts =>
                                                     parts.AddApplicationPart(typeof(IExceptionGrain).Assembly).WithReferences())
                          .UseConfiguration(ClientConfiguration.LocalhostSilo())
                          .Build();
            this.client.Connect().GetAwaiter().GetResult();
        }
Beispiel #14
0
        private static async Task Run()
        {
            ClientConfiguration clientConfig  = ClientConfiguration.LoadFromFile("ClientConfiguration.xml");
            IClientBuilder      clientBuilder = ClientBuilder.CreateDefault();

            IClusterClient clusterClient = clientBuilder.UseConfiguration(clientConfig)
                                           .Build();
            await clusterClient.Connect();

            Console.WriteLine("输入手机号");
            var number      = Console.ReadLine();
            var userService = clusterClient.GetGrain <IUserService>(1);
            var result      = userService.Exist(number);

            while (!result.IsCompleted)
            {
            }
            if (result.Status == TaskStatus.Faulted)
            {
                foreach (var exceptionInnerException in result.Exception.InnerExceptions)
                {
                    Console.WriteLine(exceptionInnerException.Message);
                }
            }
            //try
            //{
            //    result.Wait();
            //}
            //catch (AggregateException e)
            //{
            //    foreach (var eInnerException in e.InnerExceptions)
            //    {
            //        Console.WriteLine(eInnerException.Message);
            //    }
            //    Console.WriteLine(e.Message);
            //}
            Console.WriteLine(result.Result);

            await clusterClient.Close();
        }
Beispiel #15
0
        public void ClientBuilder_NullConfigurationTest()
        {
            var builder = ClientBuilder.CreateDefault().ConfigureServices(RemoveConfigValidators);

            Assert.Throws <ArgumentNullException>(() => builder.UseConfiguration(null));
        }