Exemplo n.º 1
0
        public override async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            await base.Init(name, providerRuntime, config);

            long         grainId = GrainCallBootstrapTestConstants.GrainId;
            int          a       = GrainCallBootstrapTestConstants.A;
            int          b       = GrainCallBootstrapTestConstants.B;
            ISimpleGrain grain   = providerRuntime.GrainFactory.GetGrain <ISimpleGrain>(grainId, SimpleGrain.SimpleGrainNamePrefix);

            logger.Info("Setting A={0} on {1}", a, grainId);
            await grain.SetA(a);

            logger.Info("Setting B={0} on {1}", b, grainId);
            await grain.SetB(b);

            logger.Info("Getting AxB from {0}", grainId);
            int axb = await grain.GetAxB();

            logger.Info("Got AxB={0} from {1}", axb, grainId);

            int expected = a * b;
            int actual   = axb;

            if (expected != actual)
            {
                throw new Exception(string.Format(
                                        "Value returned to {0} by {1} should be {2} not {3}",
                                        GetType().Name, grainId, expected, actual));
            }
        }
Exemplo n.º 2
0
        public void SimpleGrain_PromiseForward()
        {
            ISimpleGrain forwardGrain = GrainClient.GrainFactory.GetGrain <IPromiseForwardGrain>(GetRandomGrainId());
            Task <int>   promise      = forwardGrain.GetAxB(5, 6);
            int          result       = promise.Result;

            Assert.Equal(30, result);
        }
Exemplo n.º 3
0
        public async Task SimpleGrainDataFlow()
        {
            ISimpleGrain grain = GetSimpleGrain();

            Task setAPromise = grain.SetA(3);
            Task setBPromise = grain.SetB(4);
            await Task.WhenAll(setAPromise, setBPromise);

            var x = await grain.GetAxB();

            Assert.AreEqual(12, x);
        }
Exemplo n.º 4
0
        public async Task SimpleGrainControlFlow()
        {
            ISimpleGrain grain = GetSimpleGrain();

            Task  setPromise = grain.SetA(2);
            await setPromise;

            setPromise = grain.SetB(3);
            await setPromise;

            Task <int> intPromise = grain.GetAxB();

            Assert.AreEqual(6, await intPromise);
        }
Exemplo n.º 5
0
        public void SimpleGrainControlFlow()
        {
            ISimpleGrain grain = GetSimpleGrain();

            Task setPromise = grain.SetA(2);

            setPromise.Wait();

            setPromise = grain.SetB(3);
            setPromise.Wait();

            Task <int> intPromise = grain.GetAxB();

            Assert.AreEqual(6, intPromise.Result);
        }
Exemplo n.º 6
0
        public async Task BootstrapProvider_GrainCall()
        {
            string providerName = "bootstrap2";
            GrainCallBootstrapper bootstrapProvider = (GrainCallBootstrapper)FindBootstrapProvider(providerName);

            Assert.IsNotNull(bootstrapProvider, "Found bootstrap provider {0}", providerName);
            Assert.AreEqual(1, bootstrapProvider.InitCount, "Init count");

            long         grainId = GrainCallBootstrapTestConstants.GrainId;
            int          a       = GrainCallBootstrapTestConstants.A;
            int          b       = GrainCallBootstrapTestConstants.B;
            ISimpleGrain grain   = GrainClient.GrainFactory.GetGrain <ISimpleGrain>(grainId, SimpleGrain.SimpleGrainNamePrefix);
            int          axb     = await grain.GetAxB();

            Assert.AreEqual((a * b), axb, "Returned value from {0}", grainId);
        }
Exemplo n.º 7
0
        public async Task BootstrapProvider_GrainCall()
        {
            string providerName = "bootstrap2";
            GrainCallBootstrapper bootstrapProvider = (GrainCallBootstrapper)FindBootstrapProvider(providerName);

            Assert.NotNull(bootstrapProvider);
            Assert.Equal(1, bootstrapProvider.InitCount); // Init count

            long         grainId = GrainCallBootstrapTestConstants.GrainId;
            int          a       = GrainCallBootstrapTestConstants.A;
            int          b       = GrainCallBootstrapTestConstants.B;
            ISimpleGrain grain   = this.GrainFactory.GetGrain <ISimpleGrain>(grainId, SimpleGrain.SimpleGrainNamePrefix);
            int          axb     = await grain.GetAxB();

            Assert.Equal((a * b), axb);
        }
Exemplo n.º 8
0
        private async Task ProcessTimerTick(object data)
        {
            string step = "TimerTick";

            LogStatus(step);
            // make sure we run in the right activation context.
            CheckRuntimeContext(step);

            string name = (string)data;

            if (name != this.timerName)
            {
                throw new ArgumentException(string.Format("Wrong timer name: Expected={0} Actual={1}", this.timerName, name));
            }

            ISimpleGrain grain = GrainFactory.GetGrain <ISimpleGrain>(0, SimpleGrain.SimpleGrainNamePrefix);

            LogStatus("Before grain call #1");
            await grain.SetA(tickCount);

            step = "After grain call #1";
            LogStatus(step);
            CheckRuntimeContext(step);

            LogStatus("Before Delay");
            await Task.Delay(TimeSpan.FromSeconds(1));

            step = "After Delay";
            LogStatus(step);
            CheckRuntimeContext(step);

            LogStatus("Before grain call #2");
            await grain.SetB(tickCount);

            step = "After grain call #2";
            LogStatus(step);
            CheckRuntimeContext(step);

            LogStatus("Before grain call #3");
            int res = await grain.GetAxB();

            step = "After grain call #3 - Result = " + res;
            LogStatus(step);
            CheckRuntimeContext(step);

            tickCount++;
        }
Exemplo n.º 9
0
        public async Task BootstrapProvider_GrainCall()
        {
            string providerName            = BootstrapProviderName2;
            bool   canGetBootstrapProvider = await CanFindBootstrapProviderInUse(providerName);

            Assert.True(canGetBootstrapProvider);
            int initCount = await GetInitCountForBootstrapProviderInUse(providerName);

            Assert.Equal(1, initCount); // Init count
            long         grainId = GrainCallBootstrapTestConstants.GrainId;
            int          a       = GrainCallBootstrapTestConstants.A;
            int          b       = GrainCallBootstrapTestConstants.B;
            ISimpleGrain grain   = this.GrainFactory.GetGrain <ISimpleGrain>(grainId, SimpleGrain.SimpleGrainNamePrefix);
            int          axb     = await grain.GetAxB();

            Assert.Equal((a * b), axb);
        }
Exemplo n.º 10
0
        public override async Task Init(string name, IProviderRuntime providerRuntime, IProviderConfiguration config)
        {
            await base.Init(name, providerRuntime, config);

            long         grainId = GrainCallBootstrapTestConstants.GrainId;
            int          a       = GrainCallBootstrapTestConstants.A;
            int          b       = GrainCallBootstrapTestConstants.B;
            ISimpleGrain grain   = providerRuntime.GrainFactory.GetGrain <ISimpleGrain>(grainId, SimpleGrain.SimpleGrainNamePrefix);

            logger.Info("Setting A={0} on {1}", a, grainId);
            await grain.SetA(a);

            logger.Info("Setting B={0} on {1}", b, grainId);
            await grain.SetB(b);

            logger.Info("Getting AxB from {0}", grainId);
            int axb = await grain.GetAxB();

            logger.Info("Got AxB={0} from {1}", axb, grainId);
            Assert.AreEqual((a * b), axb, "Value returned to {0} by {1}", this.GetType().Name, grainId);
        }
Exemplo n.º 11
0
 public async Task SimpleGrainGetGrain()
 {
     ISimpleGrain grain   = GetSimpleGrain();
     int          ignored = await grain.GetAxB();
 }
Exemplo n.º 12
0
        public async Task SimpleGrainGetGrain()
        {
            ISimpleGrain grain = GetSimpleGrain();

            _ = await grain.GetAxB();
        }