Exemple #1
0
        public SchemasIndexTests()
        {
            A.CallTo(() => grainFactory.GetGrain <ISchemasByAppIndexGrain>(appId.Id.ToString(), null))
            .Returns(index);

            var cache = new ReplicatedCache(new MemoryCache(Options.Create(new MemoryCacheOptions())), new SimplePubSub());

            sut = new SchemasIndex(grainFactory, cache);
        }
Exemple #2
0
        public AppsIndexTests()
        {
            A.CallTo(() => grainFactory.GetGrain <IAppsByNameIndexGrain>(SingleGrain.Id, null))
            .Returns(indexByName);

            A.CallTo(() => grainFactory.GetGrain <IAppsByUserIndexGrain>(userId, null))
            .Returns(indexByUser);

            var cache = new ReplicatedCache(new MemoryCache(Options.Create(new MemoryCacheOptions())), new SimplePubSub());

            sut = new AppsIndex(grainFactory, cache);
        }
Exemple #3
0
        public AppsIndexTests()
        {
            A.CallTo(() => grainFactory.GetGrain <IAppsCacheGrain>(SingleGrain.Id, null))
            .Returns(cache);

            var replicatedCache =
                new ReplicatedCache(new MemoryCache(Options.Create(new MemoryCacheOptions())), new SimplePubSub(A.Fake <ILogger <SimplePubSub> >()),
                                    Options.Create(new ReplicatedCacheOptions {
                Enable = true
            }));

            sut = new AppsIndex(appRepository, grainFactory, replicatedCache);
        }
Exemple #4
0
        public SchemasIndexTests()
        {
            A.CallTo(() => grainFactory.GetGrain <ISchemasCacheGrain>(appId.Id.ToString(), null))
            .Returns(this.cache);

            var localCache =
                new ReplicatedCache(new MemoryCache(Options.Create(new MemoryCacheOptions())), new SimplePubSub(A.Fake <ILogger <SimplePubSub> >()),
                                    Options.Create(new ReplicatedCacheOptions {
                Enable = true
            }));

            sut = new SchemasIndex(grainFactory, localCache);
        }
Exemple #5
0
        public AppsIndexTests()
        {
            A.CallTo(() => grainFactory.GetGrain <IAppsByNameIndexGrain>(SingleGrain.Id, null))
            .Returns(indexByName);

            A.CallTo(() => grainFactory.GetGrain <IAppsByUserIndexGrain>(userId, null))
            .Returns(indexForUser);

            A.CallTo(() => grainFactory.GetGrain <IAppsByUserIndexGrain>(clientId, null))
            .Returns(indexForClient);

            var cache =
                new ReplicatedCache(new MemoryCache(Options.Create(new MemoryCacheOptions())), new SimplePubSub(A.Fake <ILogger <SimplePubSub> >()),
                                    Options.Create(new ReplicatedCacheOptions {
                Enable = true
            }));

            sut = new AppsIndex(grainFactory, cache);
        }
        private static AppsIndex[] GetIndexes(bool shouldBreak, GrainEnvironment env, TestCluster cluster)
        {
            return(cluster.Silos.OfType <InProcessSiloHandle>()
                   .Select(x =>
            {
                var pubSub =
                    shouldBreak ?
                    A.Fake <IPubSub>() :
                    x.SiloHost.Services.GetRequiredService <IPubSub>();

                var cache =
                    new ReplicatedCache(
                        new MemoryCache(Options.Create(new MemoryCacheOptions())),
                        pubSub,
                        Options.Create(new ReplicatedCacheOptions {
                    Enable = true
                }));

                return new AppsIndex(env.GrainFactory, cache);
            }).ToArray());
        }
        public async Task Should_distribute_and_cache_domain_objects(short numSilos, int numRuns, int expectedCounts, bool shouldBreak)
        {
            var env = new GrainEnvironment();

            var cluster =
                new TestClusterBuilder(numSilos)
                .AddSiloBuilderConfigurator <Configurator>()
                .Build();

            await cluster.DeployAsync();

            try
            {
                var indexes =
                    cluster.Silos.OfType <InProcessSiloHandle>()
                    .Select(x =>
                {
                    var pubSub =
                        shouldBreak ?
                        A.Fake <IPubSub>() :
                        x.SiloHost.Services.GetRequiredService <IPubSub>();

                    var cache =
                        new ReplicatedCache(
                            new MemoryCache(Options.Create(new MemoryCacheOptions())),
                            pubSub,
                            Options.Create(new ReplicatedCacheOptions {
                        Enable = true
                    }));

                    return(new SchemasIndex(env.GrainFactory, cache));
                }).ToArray();

                var appId = env.AppId;

                var random = new Random();

                for (var i = 0; i < numRuns; i++)
                {
                    var fieldName    = Guid.NewGuid().ToString();
                    var fieldCommand = new AddField {
                        Name = fieldName, SchemaId = env.SchemaId, AppId = env.AppId
                    };

                    var commandContext = new CommandContext(fieldCommand, A.Fake <ICommandBus>());

                    var randomIndex = indexes[random.Next(numSilos)];

                    await randomIndex.HandleAsync(commandContext, x =>
                    {
                        if (x.Command is AddField command)
                        {
                            env.HandleCommand(command);
                        }

                        x.Complete(true);

                        return(Task.CompletedTask);
                    });

                    foreach (var index in indexes)
                    {
                        var schemaById = await index.GetSchemaAsync(appId.Id, env.SchemaId.Id, true);

                        var schemaByName = await index.GetSchemaByNameAsync(appId.Id, env.SchemaId.Name, true);

                        if (index == randomIndex || !shouldBreak || i == 0)
                        {
                            Assert.True(schemaById?.SchemaDef.FieldsByName.ContainsKey(fieldName));
                            Assert.True(schemaByName?.SchemaDef.FieldsByName.ContainsKey(fieldName));
                        }
                        else
                        {
                            Assert.False(schemaById?.SchemaDef.FieldsByName.ContainsKey(fieldName));
                            Assert.False(schemaByName?.SchemaDef.FieldsByName.ContainsKey(fieldName));
                        }
                    }
                }

                env.VerifyGrainAccess(expectedCounts);
            }
            finally
            {
                await Task.WhenAny(Task.Delay(2000), cluster.StopAllSilosAsync());
            }
        }