コード例 #1
0
ファイル: ObserverTests.cs プロジェクト: PaulNorth/orleans
        void ObserverTest_SimpleNotification_Callback(int a, int b, AsyncResultHandle result)
        {
            callbackCounter++;
            logger.Info("Invoking ObserverTest_SimpleNotification_Callback for {0} time with a = {1} and b = {2}", callbackCounter, a, b);

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

            if (callbackCounter == 1)
            {
                // Allow for callbacks occurring in any order
                Assert.IsTrue(callbacksRecieved[0] || callbacksRecieved[1], "Received one callback ok");
            }
            else if (callbackCounter == 2)
            {
                Assert.IsTrue(callbacksRecieved[0] && callbacksRecieved[1], "Received two callbacks ok");
                result.Done = true;
            }
            else
            {
                Assert.Fail("Callback has been called more times than was expected.");
            }
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: ObserverTests.cs プロジェクト: raj347/orleans
        public async Task ObserverTest_DeleteObject()
        {
            TestInitialize();
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

            observer1 = new SimpleGrainObserver(ObserverTest_DeleteObject_Callback, result);
            ISimpleGrainObserver reference = await GrainFactory.CreateObjectReference <ISimpleGrainObserver>(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");
        }
コード例 #4
0
ファイル: ObserverTests.cs プロジェクト: sehra/dotnet-orleans
        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 = await this.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 this.GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference);

            await grain.SetB(3);

            Assert.False(await result.WaitForFinished(timeout), string.Format("Should timeout waiting {0} for SetB", timeout));
        }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
0
        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 = this.GrainFactory.CreateObjectReference <ISimpleGrainObserver>(observer1);

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

            await grain.Subscribe(reference2);

            grain.SetA(6).Ignore();

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

            this.GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference1);
            this.GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference2);
        }
コード例 #8
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);
        }
コード例 #9
0
ファイル: ObserverTests.cs プロジェクト: sehra/dotnet-orleans
        void ObserverTest_DoubleSubscriptionDifferentReferences_Callback(int a, int b, AsyncResultHandle result)
        {
            callbackCounter++;
            this.Logger.Info("Invoking ObserverTest_DoubleSubscriptionDifferentReferences_Callback for {0} time with a = {1} and b = {2}", this.callbackCounter, a, b);
            Assert.True(callbackCounter < 3, "Callback has been called more times than was expected.");

            Assert.Equal(6, a);
            Assert.Equal(0, b);

            if (callbackCounter == 2)
            {
                result.Done = true;
            }
        }
コード例 #10
0
 public SimpleGrainObserver(Action <int, int, AsyncResultHandle> action, AsyncResultHandle result)
 {
     this.action = action;
     this.result = result;
 }
コード例 #11
0
ファイル: ObserverTests.cs プロジェクト: PaulNorth/orleans
        void ObserverTest_DoubleSubscriptionSameReference_Callback(int a, int b, AsyncResultHandle result)
        {
            callbackCounter++;
            logger.Info("Invoking ObserverTest_DoubleSubscriptionSameReference_Callback for {0} time with a={1} and b={2}", callbackCounter, a, b);
            Assert.IsTrue(callbackCounter <= 2, "Callback has been called more times than was expected {0}", callbackCounter);

            if (callbackCounter == 2)
            {
                result.Continue = true;
            }
        }
コード例 #12
0
ファイル: ObserverTests.cs プロジェクト: PaulNorth/orleans
 public SimpleGrainObserver(Action<int, int, AsyncResultHandle> action, AsyncResultHandle result)
 {
     this.action = action;
     this.result = result;
 }
コード例 #13
0
ファイル: ObserverTests.cs プロジェクト: PaulNorth/orleans
        public async Task ObserverTest_SubscriberMustBeGrainReference()
        {
            TestInitialize();
            await Xunit.Assert.ThrowsAsync(typeof(NotSupportedException), async () =>
            {
                var result = new AsyncResultHandle();

                ISimpleObserverableGrain grain = GetGrain();
                observer1 = new SimpleGrainObserver(ObserverTest_SimpleNotification_Callback, result);
                ISimpleGrainObserver reference = observer1;
                // Should be: GrainFactory.CreateObjectReference<ISimpleGrainObserver>(obj);
                await grain.Subscribe(reference);
                // Not reached
            });
        }
コード例 #14
0
ファイル: ObserverTests.cs プロジェクト: PaulNorth/orleans
        void ObserverTest_DeleteObject_Callback(int a, int b, AsyncResultHandle result)
        {
            callbackCounter++;
            logger.Info("Invoking ObserverTest_DeleteObject_Callback for {0} time with a = {1} and b = {2}", callbackCounter, a, b);
            Assert.IsTrue(callbackCounter < 2, "Callback has been called more times than was expected.");

            Assert.AreEqual(5, a);
            Assert.AreEqual(0, b);

            result.Continue = true;
        }
コード例 #15
0
ファイル: ObserverTests.cs プロジェクト: PaulNorth/orleans
        void ObserverTest_DoubleSubscriptionDifferentReferences_Callback(int a, int b, AsyncResultHandle result)
        {
            callbackCounter++;
            logger.Info("Invoking ObserverTest_DoubleSubscriptionDifferentReferences_Callback for {0} time with a = {1} and b = {2}", callbackCounter, a, b);
            Assert.IsTrue(callbackCounter < 3, "Callback has been called more times than was expected.");

            Assert.AreEqual(6, a);
            Assert.AreEqual(0, b);

            if (callbackCounter == 2)
                result.Done = true;
        }
コード例 #16
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);
        }
コード例 #17
0
ファイル: ObserverTests.cs プロジェクト: sehra/dotnet-orleans
 public SimpleGrainObserver(Action <int, int, AsyncResultHandle> action, AsyncResultHandle result, ILogger logger)
 {
     this.action = action;
     this.result = result;
     this.logger = logger;
 }
コード例 #18
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);
        }