Example #1
0
 public void FailSideCastAfterContinueWith()
 {
     Assert.Throws <InvalidCastException>(() =>
     {
         // GeneratorTestDerivedGrain1Reference extends GeneratorTestGrainReference
         // GeneratorTestDerivedGrain2Reference extends GeneratorTestGrainReference
         try
         {
             IGeneratorTestDerivedGrain1 grain = GrainClient.GrainFactory.GetGrain <IGeneratorTestDerivedGrain1>(GetRandomGrainId());
             IGeneratorTestDerivedGrain2 cast  = null;
             Task <bool> av  = grain.StringIsNullOrEmpty();
             Task <bool> av2 = av.ContinueWith((Task <bool> t) => Assert.True(t.Result)).ContinueWith((_AppDomain) =>
             {
                 cast = grain.AsReference <IGeneratorTestDerivedGrain2>();
             }).ContinueWith((_) => cast.StringConcat("a", "b", "c")).ContinueWith((_) => cast.StringIsNullOrEmpty().Result);
             Assert.False(av2.Result);
         }
         catch (AggregateException ae)
         {
             Exception ex = ae.InnerException;
             while (ex is AggregateException)
             {
                 ex = ex.InnerException;
             }
             throw ex;
         }
         Assert.True(false, "Exception should have been raised");
     });
 }
Example #2
0
        public async Task GeneratorDerivedGrain1ControlFlow()
        {
            IGeneratorTestDerivedGrain1 grain = this.GrainFactory.GetGrain <IGeneratorTestDerivedGrain1>(GetRandomGrainId());

            bool isNull = await grain.StringIsNullOrEmpty();

            Assert.True(isNull);

            await grain.StringSet("Begin");

            isNull = await grain.StringIsNullOrEmpty();

            Assert.False(isNull);

            MemberVariables members = await grain.GetMemberVariables();

            Assert.Equal("Begin", members.stringVar);

            ASCIIEncoding encoding = new ASCIIEncoding();

            byte[]          bytes           = encoding.GetBytes("ByteBegin");
            string          str             = "StringBegin";
            MemberVariables memberVariables = new MemberVariables(bytes, str, ReturnCode.Fail);

            await grain.SetMemberVariables(memberVariables);

            members = await grain.GetMemberVariables();

            ASCIIEncoding enc = new ASCIIEncoding();

            Assert.Equal("ByteBegin", enc.GetString(members.byteArray));
            Assert.Equal("StringBegin", members.stringVar);
            Assert.Equal(ReturnCode.Fail, members.code);
        }
 public void FailSideCastAfterResolve()
 {
     // GeneratorTestDerivedGrain1Reference extends GeneratorTestGrainReference
     // GeneratorTestDerivedGrain2Reference extends GeneratorTestGrainReference
     try
     {
         IGeneratorTestDerivedGrain1 grain = GrainClient.GrainFactory.GetGrain <IGeneratorTestDerivedGrain1>(GetRandomGrainId());
         Assert.IsTrue(grain.StringIsNullOrEmpty().Result);
         // Fails the next line as grain reference is already resolved
         IGeneratorTestDerivedGrain2 cast = grain.AsReference <IGeneratorTestDerivedGrain2>();
         Task <string> av = cast.StringConcat("a", "b", "c");
         av.Wait();
         Assert.IsFalse(cast.StringIsNullOrEmpty().Result); // Not reached
     }
     catch (AggregateException ae)
     {
         Exception ex = ae.InnerException;
         while (ex is AggregateException)
         {
             ex = ex.InnerException;
         }
         throw ex;
     }
     Assert.Fail("Exception should have been raised");
 }
Example #4
0
        public async Task FailOperationAfterSideCast()
        {
            // GeneratorTestDerivedGrain1Reference extends GeneratorTestGrainReference
            // GeneratorTestDerivedGrain2Reference extends GeneratorTestGrainReference
            IGeneratorTestDerivedGrain1 grain = GrainClient.GrainFactory.GetGrain <IGeneratorTestDerivedGrain1>(GetRandomGrainId());

            // Cast works optimistically when the grain reference is not already resolved
            IGeneratorTestDerivedGrain2 cast = grain.AsReference <IGeneratorTestDerivedGrain2>();

            // Operation fails when grain reference is completely resolved
            await Assert.ThrowsAsync <InvalidCastException>(() => cast.StringConcat("a", "b", "c"));
        }
Example #5
0
        public async Task FailSideCastAfterResolve()
        {
            // GeneratorTestDerivedGrain1Reference extends GeneratorTestGrainReference
            // GeneratorTestDerivedGrain2Reference extends GeneratorTestGrainReference
            IGeneratorTestDerivedGrain1 grain = GrainClient.GrainFactory.GetGrain <IGeneratorTestDerivedGrain1>(GetRandomGrainId());

            Assert.True(grain.StringIsNullOrEmpty().Result);

            // Fails the next line as grain reference is already resolved
            IGeneratorTestDerivedGrain2 cast = grain.AsReference <IGeneratorTestDerivedGrain2>();

            await Assert.ThrowsAsync <InvalidCastException>(() => cast.StringConcat("a", "b", "c"));
        }
Example #6
0
        public void CastCallMethodInheritedFromBaseClass()
        {
            // GeneratorTestDerivedGrain1Reference derives from GeneratorTestGrainReference
            // GeneratorTestDerivedGrain2Reference derives from GeneratorTestGrainReference
            // GeneratorTestDerivedDerivedGrainReference derives from GeneratorTestDerivedGrain2Reference

            Task <bool> isNullStr;

            IGeneratorTestDerivedGrain1 grain = GrainClient.GrainFactory.GetGrain <IGeneratorTestDerivedGrain1>(GetRandomGrainId());

            isNullStr = grain.StringIsNullOrEmpty();
            Assert.True(isNullStr.Result, "Value should be null initially");

            isNullStr = grain.StringSet("a").ContinueWith((_) => grain.StringIsNullOrEmpty()).Unwrap();
            Assert.False(isNullStr.Result, "Value should not be null after SetString(a)");

            isNullStr = grain.StringSet(null).ContinueWith((_) => grain.StringIsNullOrEmpty()).Unwrap();
            Assert.True(isNullStr.Result, "Value should be null after SetString(null)");

            IGeneratorTestGrain cast = grain.AsReference <IGeneratorTestGrain>();

            isNullStr = cast.StringSet("b").ContinueWith((_) => grain.StringIsNullOrEmpty()).Unwrap();
            Assert.False(isNullStr.Result, "Value should not be null after cast.SetString(b)");
        }
 public void FailOperationAfterSideCast()
 {
     // GeneratorTestDerivedGrain1Reference extends GeneratorTestGrainReference
     // GeneratorTestDerivedGrain2Reference extends GeneratorTestGrainReference
     try
     {
         IGeneratorTestDerivedGrain1 grain = GrainClient.GrainFactory.GetGrain <IGeneratorTestDerivedGrain1>(GetRandomGrainId());
         // Cast works optimistically when the grain reference is not already resolved
         IGeneratorTestDerivedGrain2 cast = grain.AsReference <IGeneratorTestDerivedGrain2>();
         // Operation fails when grain reference is completely resolved
         Task <string> av  = cast.StringConcat("a", "b", "c");
         string        val = av.Result;
     }
     catch (AggregateException ae)
     {
         Exception ex = ae.InnerException;
         while (ex is AggregateException)
         {
             ex = ex.InnerException;
         }
         throw ex;
     }
     Assert.Fail("Exception should have been raised");
 }