コード例 #1
0
        public async Task HostedClient_ObserverTest()
        {
            var client = this.silo.Services.GetRequiredService <IClusterClient>();

            var handle = new AsyncResultHandle();

            var callbackCounter   = new int[1];
            var callbacksReceived = new bool[2];

            var grain    = client.GetGrain <ISimpleObserverableGrain>(0);
            var observer = new ObserverTests.SimpleGrainObserver(
                (a, b, result) =>
            {
                Assert.Null(RuntimeContext.CurrentGrainContext);
                callbackCounter[0]++;

                if (a == 3 && b == 0)
                {
                    callbacksReceived[0] = true;
                }
                else if (a == 3 && b == 2)
                {
                    callbacksReceived[1] = true;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Unexpected callback with values: a=" + a + ",b=" + b);
                }

                if (callbackCounter[0] == 1)
                {
                    // Allow for callbacks occurring in any order
                    Assert.True(callbacksReceived[0] || callbacksReceived[1]);
                }
                else if (callbackCounter[0] == 2)
                {
                    Assert.True(callbacksReceived[0] && callbacksReceived[1]);
                    result.Done = true;
                }
                else
                {
                    Assert.True(false);
                }
            },
                handle,
                client.ServiceProvider.GetRequiredService <ILogger <ISimpleGrainObserver> >());
            var reference = await client.CreateObjectReference <ISimpleGrainObserver>(observer);

            await grain.Subscribe(reference);

            await grain.SetA(3);

            await grain.SetB(2);

            Assert.True(await handle.WaitForFinished(timeout));

            await client.DeleteObjectReference <ISimpleGrainObserver>(reference);

            Assert.NotNull(observer);
        }
コード例 #2
0
        public async Task HostedClient_Disabled_ObserverTest()
        {
            var client = this.silo.Services.GetRequiredService <IGrainFactory>();

            var observer  = new ObserverTests.SimpleGrainObserver((i, i1, arg3) => { }, new AsyncResultHandle(), new NullLogger <HostedClientDisabledTests>());
            var exception = await Assert.ThrowsAsync <InvalidOperationException>(() => client.CreateObjectReference <ISimpleGrainObserver>(observer));

            Assert.Contains("not enabled", exception.Message);
        }