public async Task Test_Indexing_IndexLookup1()
        {
            IPlayer1Grain p1 = base.GetGrain <IPlayer1Grain>(1);
            await p1.SetLocation(ITC.Seattle);

            IPlayer1Grain p2 = base.GetGrain <IPlayer1Grain>(2);
            IPlayer1Grain p3 = base.GetGrain <IPlayer1Grain>(3);

            await p2.SetLocation(ITC.Seattle);

            await p3.SetLocation(ITC.SanFrancisco);

            var locIdx = await base.GetAndWaitForIndex <string, IPlayer1Grain>(ITC.LocationIndex);

            Task <int> getLocationCount(string location) => this.GetLocationCount <IPlayer1Grain, Player1Properties>(location, ITC.DelayUntilIndexesAreUpdatedLazily);

            Assert.Equal(2, await getLocationCount(ITC.Seattle));

            await p2.Deactivate();

            await Task.Delay(ITC.DelayUntilIndexesAreUpdatedLazily);

            Assert.Equal(2, await getLocationCount(ITC.Seattle));

            p2 = base.GetGrain <IPlayer1Grain>(2);
            Assert.Equal(ITC.Seattle, await p2.GetLocation());
            Assert.Equal(2, await getLocationCount(ITC.Seattle));
        }
Example #2
0
        public async Task Test_Indexing_IndexLookup1()
        {
            //await GrainClient.GrainFactory.DropAllIndexes<IPlayerGrain>();

            IPlayer1Grain p1 = GrainClient.GrainFactory.GetGrain <IPlayer1Grain>(1);
            await p1.SetLocation("Seattle");

            //bool isLocIndexCreated = await GrainClient.GrainFactory.CreateAndRegisterIndex<HashIndexSingleBucketInterface<string, IPlayerGrain>, PlayerLocIndexGen>("__GetLocation");
            //Assert.IsTrue(isLocIndexCreated);

            IPlayer1Grain p2 = GrainClient.GrainFactory.GetGrain <IPlayer1Grain>(2);
            IPlayer1Grain p3 = GrainClient.GrainFactory.GetGrain <IPlayer1Grain>(3);

            await p2.SetLocation("Seattle");

            await p3.SetLocation("San Fransisco");

            IndexInterface <string, IPlayer1Grain> locIdx = GrainClient.GrainFactory.GetIndex <string, IPlayer1Grain>("__Location");

            while (!await locIdx.IsAvailable())
            {
                Thread.Sleep(50);
            }

            Assert.Equal(2, await IndexingTestUtils.CountPlayersStreamingIn <IPlayer1Grain, Player1Properties>("Seattle", output, DELAY_UNTIL_INDEXES_ARE_UPDATED_LAZILY));

            await p2.Deactivate();

            await Task.Delay(DELAY_UNTIL_INDEXES_ARE_UPDATED_LAZILY);

            Assert.Equal(2, await IndexingTestUtils.CountPlayersStreamingIn <IPlayer1Grain, Player1Properties>("Seattle", output, DELAY_UNTIL_INDEXES_ARE_UPDATED_LAZILY));

            p2 = GrainClient.GrainFactory.GetGrain <IPlayer1Grain>(2);
            Assert.Equal("Seattle", await p2.GetLocation());

            Assert.Equal(2, await IndexingTestUtils.CountPlayersStreamingIn <IPlayer1Grain, Player1Properties>("Seattle", output, DELAY_UNTIL_INDEXES_ARE_UPDATED_LAZILY));
        }