Пример #1
0
        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);
        }
Пример #2
0
        public async Task ObserverTest_SubscribeUnsubscribe()
        {
            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.IsTrue(await result.WaitForContinue(timeout), "Should not timeout waiting {0} for {1}", timeout, "SetA");
            await grain.Unsubscribe(reference);

            await grain.SetB(3);

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

            await GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference);
        }
Пример #3
0
        public async Task ObserverTest_DoubleSubscriptionDifferentReferences()
        {
            ResultHandle result = new ResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

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

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

            grain.Subscribe(reference1).Wait();
            grain.Subscribe(reference2).Wait();
            grain.SetA(6).Ignore();

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

            await GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference1);

            await GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference2);
        }
Пример #4
0
        public async Task ObserverTest_DoubleSubscriptionSameReference()
        {
            ResultHandle result = new ResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

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

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

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

            await GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference);
        }
Пример #5
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);
        }
Пример #6
0
        public async Task ObserverTest_SubscribeUnsubscribe()
        {
            TestInitialize();
            var result = new AsyncResultHandle();

            ISimpleObserverableGrain grain = GetGrain();

            this.observer1 = new SimpleGrainObserver(this.ObserverTest_SubscribeUnsubscribe_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");

            await grain.Unsubscribe(reference);

            await grain.SetB(3);

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

            this.GrainFactory.DeleteObjectReference <ISimpleGrainObserver>(reference);
        }
Пример #7
0
 public Task SetTarget(ISimpleObserverableGrain target)
 {
     Target = target;
     return(target.Subscribe(this));
 }
Пример #8
0
 public Task SetTarget(ISimpleObserverableGrain target)
 {
     Target = target;
     return target.Subscribe(this);
 }