Ejemplo n.º 1
0
        public virtual async Task Start(int siloPort = 11111, int gatewayPort = 30000, string serviceId = null, string clusterId = null)
        {
            EnsureClusterIsNotRunning();
            var clusterBuilder = new LocalClusterBuilder(siloPort, gatewayPort, serviceId, clusterId);

            // Storage provider setup
            var storageProviders = GetType().GetCustomAttributes(typeof(MockStorageProvider), true).Select(p => (MockStorageProvider)p);

            foreach (var provider in storageProviders)
            {
                clusterBuilder.ConfigureServices(services =>
                {
                    services.AddSingletonNamedService <IGrainStorage>(provider.ProviderName, (sp, n) => ActivatorUtilities.CreateInstance <MockMemoryStorageProvider>(sp, provider.ProviderName));

                    if (typeof(ILifecycleParticipant <ISiloLifecycle>).IsAssignableFrom(typeof(MockMemoryStorageProvider)))
                    {
                        services.AddSingletonNamedService <ILifecycleParticipant <ISiloLifecycle> >(provider.ProviderName, (svc, n) => (ILifecycleParticipant <ISiloLifecycle>)svc.GetRequiredServiceByName <IGrainStorage>(provider.ProviderName));
                    }

                    if (typeof(IControllable).IsAssignableFrom(typeof(MockMemoryStorageProvider)))
                    {
                        services.AddSingletonNamedService <IControllable>(provider.ProviderName, (svc, n) => (IControllable)svc.GetRequiredServiceByName <IGrainStorage>(provider.ProviderName));
                    }
                });
            }

            // Stream provider setup
            var streamProviders = GetType().GetCustomAttributes(typeof(MockStreamProvider), true).Select(p => (MockStreamProvider)p);

            foreach (var provider in streamProviders)
            {
                clusterBuilder.ConfigureHost(s => s.AddSimpleMessageStreamProvider(provider.ProviderName));
            }

            // Stream storage setup
            var streamStorageProviders = GetType().GetCustomAttributes(typeof(MockStreamStorage), true).Select(p => (MockStreamStorage)p);

            foreach (var storage in streamStorageProviders)
            {
                clusterBuilder.ConfigureHost(s => s.AddMemoryGrainStorage(storage.StorageName));
            }

            OnConfigure(clusterBuilder);
            clusterBuilder.ConfigureHost(OnConfigure);

            clusterBuilder
            .ConfigureServices(s =>
            {
                s.AddTransient <IGrainFactoryProvider>(services => new GrainFactoryProvider(_mocker.Mock.Object));
                s.AddTransient(services => _logger);
                OnConfigureServices(s);
            });

            Cluster = clusterBuilder.Build();
            await Cluster.StartAsync();

            _mocker = new GrainFactoryMocker(GrainFactory);
            await OnReady();
        }
Ejemplo n.º 2
0
 protected virtual void OnConfigure(LocalClusterBuilder clusterBuilder)
 {
 }