private async Task <ICollectionTestGrain> PickGrainInNonPrimary()
        {
            for (int i = 0; i < 500; i++)
            {
                if (i % 30 == 29)
                {
                    await Task.Delay(1000);               // give some extra time to stabilize if it can't find a suitable grain
                }
                // Create grain such that:
                // Its directory owner is not the Gateway silo. This way Gateway will use its directory cache.
                // Its activation is located on the non Gateway silo as well.
                ICollectionTestGrain grain  = this.testCluster.GrainFactory.GetGrain <ICollectionTestGrain>(i);
                GrainId     grainId         = ((GrainReference)await grain.GetGrainReference()).GrainId;
                SiloAddress primaryForGrain = (await TestUtils.GetDetailedGrainReport(this.testCluster.InternalGrainFactory, grainId, this.testCluster.Primary)).PrimaryForGrain;
                if (primaryForGrain.Equals(this.testCluster.Primary.SiloAddress))
                {
                    continue;
                }
                string siloHostingActivation = await grain.GetRuntimeInstanceId();

                if (this.testCluster.Primary.SiloAddress.ToLongString().Equals(siloHostingActivation))
                {
                    continue;
                }
                this.output.WriteLine("\nCreated grain with key {0} whose primary directory owner is silo {1} and which was activated on silo {2}\n", i, primaryForGrain.ToLongString(), siloHostingActivation);
                return(grain);
            }

            Assert.True(testCluster.GetActiveSilos().Count() > 1, "This logic requires at least 1 non-primary active silo");
            Assert.True(false, "Could not find a grain that activates on a non-primary silo, and has the partition be also managed by a non-primary silo");
            return(null);
        }
Beispiel #2
0
        public void NewCluster(string clusterId, short numSilos, Action <ClusterConfiguration> customizer = null)
        {
            TestCluster testCluster;

            lock (Clusters)
            {
                var myCount = Clusters.Count;

                WriteLog("Starting Cluster {0}  ({1})...", myCount, clusterId);

                var options = new TestClusterOptions(initialSilosCount: numSilos)
                {
                    BaseSiloPort    = GetPortBase(myCount),
                    BaseGatewayPort = GetProxyBase(myCount)
                };
                options.ClusterConfiguration.AddMemoryStorageProvider("Default");
                options.ClusterConfiguration.AddMemoryStorageProvider("MemoryStore");
                options.UseSiloBuilderFactory <TestSiloBuilderFactory>();
                customizer?.Invoke(options.ClusterConfiguration);
                testCluster = new TestCluster(options.ClusterConfiguration, null);
                testCluster.Deploy();

                Clusters[clusterId] = new ClusterInfo
                {
                    Cluster        = testCluster,
                    SequenceNumber = myCount
                };

                if (myCount == 0)
                {
                    gossipStabilizationTime = GetGossipStabilizationTime(options.ClusterConfiguration.Globals);
                }

                WriteLog("Cluster {0} started. [{1}]", clusterId, string.Join(" ", testCluster.GetActiveSilos().Select(s => s.ToString())));
            }
        }