コード例 #1
0
ファイル: ObserverTests.cs プロジェクト: sehra/dotnet-orleans
        public async Task ObserverTest_DoubleSubscriptionDifferentReferences()
        {
            TestInitialize();
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

            this.observer1 = new SimpleGrainObserver(this.ObserverTest_DoubleSubscriptionDifferentReferences_Callback, result, this.Logger);
            ISimpleGrainObserver reference1 = await this.GrainFactory.CreateObjectReference <ISimpleGrainObserver>(observer1);

            this.observer2 = new SimpleGrainObserver(this.ObserverTest_DoubleSubscriptionDifferentReferences_Callback, result, this.Logger);
            ISimpleGrainObserver reference2 = await this.GrainFactory.CreateObjectReference <ISimpleGrainObserver>(observer2);

            await grain.Subscribe(reference1);

            await grain.Subscribe(reference2);

            grain.SetA(6).Ignore();

            Assert.True(await result.WaitForFinished(timeout), string.Format("Should not timeout waiting {0} for SetA", timeout));

            await this.GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference1);

            await this.GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference2);
        }
コード例 #2
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);
        }
コード例 #3
0
        public async Task HostedClient_StreamTest()
        {
            var client = this.silo.Services.GetRequiredService <IClusterClient>();

            var handle  = new AsyncResultHandle();
            var vals    = new List <int>();
            var stream0 = client.GetStreamProvider("MemStream").GetStream <int>(Guid.Empty, "hi");
            await stream0.SubscribeAsync(
                (val, token) =>
            {
                vals.Add(val);
                if (vals.Count >= 2)
                {
                    handle.Done = true;
                }
                return(Task.CompletedTask);
            });

            var stream = client.GetStreamProvider("MemStream").GetStream <int>(Guid.Empty, "hi");
            await stream.OnNextAsync(1);

            await stream.OnNextAsync(409);

            Assert.True(await handle.WaitForFinished(timeout));
            Assert.Equal(new[] { 1, 409 }, vals);
        }
コード例 #4
0
ファイル: ObserverTests.cs プロジェクト: PaulNorth/orleans
        public async Task ObserverTest_SimpleNotification_GeneratedFactory()
        {
            TestInitialize();
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();
            observer1 = new SimpleGrainObserver(ObserverTest_SimpleNotification_Callback, result);
            ISimpleGrainObserver reference = await GrainFactory.CreateObjectReference<ISimpleGrainObserver>(observer1);
            await grain.Subscribe(reference);
            await grain.SetA(3);
            await grain.SetB(2);

            Assert.IsTrue(await result.WaitForFinished(timeout), "Should not timeout waiting {0} for {1}", timeout, "SetB");

            await GrainFactory.DeleteObjectReference<ISimpleGrainObserver>(reference);
        }
コード例 #5
0
        public async Task ObserverTest_SimpleNotification_GeneratedFactory()
        {
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

            observer1 = new SimpleGrainObserver(ObserverTest_SimpleNotification_Callback, result);
            ISimpleGrainObserver reference = await GrainFactory.CreateObjectReference <ISimpleGrainObserver>(observer1);

            await grain.Subscribe(reference);

            await grain.SetA(3);

            await grain.SetB(2);

            Assert.IsTrue(await result.WaitForFinished(timeout), "Should not timeout waiting {0} for {1}", timeout, "SetB");

            await GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference);
        }
コード例 #6
0
        public async Task ObserverTest_SimpleNotification_GeneratedFactory()
        {
            TestInitialize();
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

            this.observer1 = new SimpleGrainObserver(this.ObserverTest_SimpleNotification_Callback, result, this.Logger);
            ISimpleGrainObserver reference = this.GrainFactory.CreateObjectReference <ISimpleGrainObserver>(observer1);
            await grain.Subscribe(reference);

            await grain.SetA(3);

            await grain.SetB(2);

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

            this.GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference);
        }
コード例 #7
0
        public async Task ObserverTest_DeleteObject()
        {
            TestInitialize();
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

            this.observer1 = new SimpleGrainObserver(this.ObserverTest_DeleteObject_Callback, result, this.Logger);
            ISimpleGrainObserver reference = this.GrainFactory.CreateObjectReference <ISimpleGrainObserver>(observer1);
            await grain.Subscribe(reference);

            await grain.SetA(5);

            Assert.True(await result.WaitForContinue(timeout), $"Should not timeout waiting {timeout} for SetA");
            this.GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference);
            await grain.SetB(3);

            Assert.False(await result.WaitForFinished(timeout), $"Should timeout waiting {timeout} for SetB");
        }
コード例 #8
0
ファイル: ObserverTests.cs プロジェクト: mixlatte/orleans
        public async Task ObserverTest_DeleteObject()
        {
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

            this.observer1 = new SimpleGrainObserver(ObserverTest_DeleteObject_Callback, result);
            ISimpleGrainObserver reference = await GrainFactory.CreateObjectReference <ISimpleGrainObserver>(this.observer1);

            await grain.Subscribe(reference);

            await grain.SetA(5);

            Assert.IsTrue(await result.WaitForContinue(timeout), "Should not timeout waiting {0} for {1}", timeout, "SetA");
            await GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference);

            await grain.SetB(3);

            Assert.IsFalse(await result.WaitForFinished(timeout), "Should timeout waiting {0} for {1}", timeout, "SetB");
        }
コード例 #9
0
ファイル: ObserverTests.cs プロジェクト: sehra/dotnet-orleans
        public async Task ObserverTest_DoubleSubscriptionSameReference()
        {
            TestInitialize();
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

            this.observer1 = new SimpleGrainObserver(this.ObserverTest_DoubleSubscriptionSameReference_Callback, result, this.Logger);
            ISimpleGrainObserver reference = await this.GrainFactory.CreateObjectReference <ISimpleGrainObserver>(observer1);

            await grain.Subscribe(reference);

            await grain.SetA(1); // Use grain

            try
            {
                await grain.Subscribe(reference);
            }
            catch (TimeoutException)
            {
                throw;
            }
            catch (Exception exc)
            {
                Exception baseException = exc.GetBaseException();
                this.Logger.Info("Received exception: {0}", baseException);
                Assert.IsAssignableFrom <OrleansException>(baseException);
                if (!baseException.Message.StartsWith("Cannot subscribe already subscribed observer"))
                {
                    Assert.True(false, "Unexpected exception message: " + baseException);
                }
            }

            await grain.SetA(2); // Use grain

            Assert.False(await result.WaitForFinished(timeout), string.Format("Should timeout waiting {0} for SetA(2)", timeout));

            await this.GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference);
        }
コード例 #10
0
ファイル: ObserverTests.cs プロジェクト: raj347/orleans
        public async Task ObserverTest_DoubleSubscriptionSameReference()
        {
            TestInitialize();
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

            observer1 = new SimpleGrainObserver(ObserverTest_DoubleSubscriptionSameReference_Callback, result);
            ISimpleGrainObserver reference = await GrainFactory.CreateObjectReference <ISimpleGrainObserver>(observer1);

            await grain.Subscribe(reference);

            await grain.SetA(1); // Use grain

            try
            {
                await grain.Subscribe(reference);
            }
            catch (TimeoutException)
            {
                throw;
            }
            catch (Exception exc)
            {
                Exception baseException = exc.GetBaseException();
                logger.Info("Received exception: {0}", baseException);
                Assert.IsInstanceOfType(baseException, typeof(OrleansException));
                if (!baseException.Message.StartsWith("Cannot subscribe already subscribed observer"))
                {
                    Assert.Fail("Unexpected exception message: " + baseException);
                }
            }
            await grain.SetA(2); // Use grain

            Assert.IsFalse(await result.WaitForFinished(timeout), "Should timeout waiting {0} for {1}", timeout, "SetA(2)");

            await GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference);
        }
コード例 #11
0
        public async Task ObserverTest_SubscribeUnsubscribe()
        {
            TestInitialize();
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

            observer1 = new SimpleGrainObserver(ObserverTest_SubscribeUnsubscribe_Callback, result);
            ISimpleGrainObserver reference = await GrainFactory.CreateObjectReference <ISimpleGrainObserver>(observer1);

            await grain.Subscribe(reference);

            await grain.SetA(5);

            Assert.True(await result.WaitForContinue(timeout), string.Format("Should not timeout waiting {0} for SetA", timeout));

            await grain.Unsubscribe(reference);

            await grain.SetB(3);

            Assert.False(await result.WaitForFinished(timeout), string.Format("Should timeout waiting {0} for SetB", timeout));

            await GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference);
        }
コード例 #12
0
        public async Task ObserverTest_DoubleSubscriptionDifferentReferences()
        {
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

            observer1 = new SimpleGrainObserver(ObserverTest_DoubleSubscriptionDifferentReferences_Callback, result);
            ISimpleGrainObserver reference1 = await GrainFactory.CreateObjectReference <ISimpleGrainObserver>(observer1);

            observer2 = new SimpleGrainObserver(ObserverTest_DoubleSubscriptionDifferentReferences_Callback, result);
            ISimpleGrainObserver reference2 = await GrainFactory.CreateObjectReference <ISimpleGrainObserver>(observer2);

            await grain.Subscribe(reference1);

            await grain.Subscribe(reference2);

            grain.SetA(6).Ignore();

            Assert.IsTrue(await result.WaitForFinished(timeout), "Should not timeout waiting {0} for {1}", timeout, "SetA");

            await GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference1);

            await GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference2);
        }
コード例 #13
0
ファイル: ObserverTests.cs プロジェクト: PaulNorth/orleans
        public async Task ObserverTest_DoubleSubscriptionDifferentReferences()
        {
            TestInitialize();
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();
            observer1 = new SimpleGrainObserver(ObserverTest_DoubleSubscriptionDifferentReferences_Callback, result);
            ISimpleGrainObserver reference1 = await GrainFactory.CreateObjectReference<ISimpleGrainObserver>(observer1);
            observer2 = new SimpleGrainObserver(ObserverTest_DoubleSubscriptionDifferentReferences_Callback, result);
            ISimpleGrainObserver reference2 = await GrainFactory.CreateObjectReference<ISimpleGrainObserver>(observer2);
            await grain.Subscribe(reference1);
            await grain.Subscribe(reference2);
            grain.SetA(6).Ignore();

            Assert.IsTrue(await result.WaitForFinished(timeout), "Should not timeout waiting {0} for {1}", timeout, "SetA");

            await GrainFactory.DeleteObjectReference<ISimpleGrainObserver>(reference1);
            await GrainFactory.DeleteObjectReference<ISimpleGrainObserver>(reference2);
        }
コード例 #14
0
ファイル: ObserverTests.cs プロジェクト: PaulNorth/orleans
        public async Task ObserverTest_DoubleSubscriptionSameReference()
        {
            TestInitialize();
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();
            observer1 = new SimpleGrainObserver(ObserverTest_DoubleSubscriptionSameReference_Callback, result);
            ISimpleGrainObserver reference = await GrainFactory.CreateObjectReference<ISimpleGrainObserver>(observer1);
            await grain.Subscribe(reference);
            await grain.SetA(1); // Use grain
            try
            {
                await grain.Subscribe(reference);
            }
            catch (TimeoutException)
            {
                throw;
            }
            catch (Exception exc)
            {
                Exception baseException = exc.GetBaseException();
                logger.Info("Received exception: {0}", baseException);
                Assert.IsInstanceOfType(baseException, typeof(OrleansException));
                if (!baseException.Message.StartsWith("Cannot subscribe already subscribed observer"))
                {
                    Assert.Fail("Unexpected exception message: " + baseException);
                }
            }
            await grain.SetA(2); // Use grain

            Assert.IsFalse(await result.WaitForFinished(timeout), "Should timeout waiting {0} for {1}", timeout, "SetA(2)");

            await GrainFactory.DeleteObjectReference<ISimpleGrainObserver>(reference);
        }