コード例 #1
0
        private async Task TestTableInsertRate(IReminderTable reminderTable, double numOfInserts)
        {
            DateTime startedAt = DateTime.UtcNow;

            try
            {
                List <Task <bool> > promises = new List <Task <bool> >();
                for (int i = 0; i < numOfInserts; i++)
                {
                    //"177BF46E-D06D-44C0-943B-C12F26DF5373"
                    string s = string.Format("177BF46E-D06D-44C0-943B-C12F26D{0:d5}", i);

                    var e = new ReminderEntry
                    {
                        //GrainId = GrainId.GetGrainId(new Guid(s)),
                        GrainRef     = GrainReference.FromGrainId(GrainId.NewId()),
                        ReminderName = "MY_REMINDER_" + i,
                        Period       = TimeSpan.FromSeconds(5),
                        StartAt      = DateTime.UtcNow
                    };

                    int         capture = i;
                    Task <bool> promise = Task.Run(async() =>
                    {
                        await reminderTable.UpsertRow(e);
                        Console.WriteLine("Done " + capture);
                        return(true);
                    });
                    promises.Add(promise);
                    log.Info("Started " + capture);
                }
                log.Info("Started all, now waiting...");
                await Task.WhenAll(promises).WithTimeout(TimeSpan.FromSeconds(500));
            }
            catch (Exception exc)
            {
                log.Info("Exception caught {0}", exc);
            }
            TimeSpan dur = DateTime.UtcNow - startedAt;

            log.Info("Inserted {0} rows in {1}, i.e., {2:f2} upserts/sec", numOfInserts, dur, (numOfInserts / dur.TotalSeconds));
        }
コード例 #2
0
        public void Store_Read()
        {
            string name = Guid.NewGuid().ToString();//TestContext.TestName;

            ILocalDataStore store = new HierarchicalKeyStore(2);

            GrainReference reference = GrainReference.FromGrainId(GrainId.NewId());
            TestStoreGrainState state = new TestStoreGrainState();
            var stateProperties = AsDictionary(state);
            var keys = GetKeys(name, reference);
            store.WriteRow(keys, stateProperties, null);
            Stopwatch sw = new Stopwatch();
            sw.Start();
            var data = store.ReadRow(keys);
            TimeSpan readTime = sw.Elapsed;
            output.WriteLine("{0} - Read time = {1}", store.GetType().FullName, readTime);
            Assert.AreEqual(state.A, data["A"], "A");
            Assert.AreEqual(state.B, data["B"], "B");
            Assert.AreEqual(state.C, data["C"], "C");
        }
コード例 #3
0
        public async Task PersistenceProvider_Azure_ChangeReadFormat(int?stringLength, string useJsonForWrite,
                                                                     string useJsonForRead)
        {
            var testName = string.Format("{0}({1} = {2}, {3} = {4}, {5} = {6})",
                                         nameof(PersistenceProvider_Azure_ChangeReadFormat),
                                         nameof(stringLength), stringLength == null ? "default" : stringLength.ToString(),
                                         nameof(useJsonForWrite), useJsonForWrite,
                                         nameof(useJsonForRead), useJsonForRead);

            var grainState = TestStoreGrainState.NewRandomState(stringLength);
            var grainId    = GrainId.NewId();

            var store = await InitAzureTableStorageProvider(useJsonForWrite, testName);

            grainState = await Test_PersistenceProvider_WriteRead(testName, store,
                                                                  grainState, grainId);

            store = await InitAzureTableStorageProvider(useJsonForRead, testName);

            await Test_PersistenceProvider_Read(testName, store, grainState, grainId);
        }
コード例 #4
0
        public async Task PersistenceProvider_DynamoDB_ChangeReadFormat(int?stringLength, bool useJsonForWrite, bool useJsonForRead)
        {
            var testName = string.Format("{0}({1} = {2}, {3} = {4}, {5} = {6})",
                                         nameof(PersistenceProvider_DynamoDB_ChangeReadFormat),
                                         nameof(stringLength), stringLength == null ? "default" : stringLength.ToString(),
                                         nameof(useJsonForWrite), useJsonForWrite,
                                         nameof(useJsonForRead), useJsonForRead);

            var grainState = TestStoreGrainState.NewRandomState(stringLength);

            EnsureEnvironmentSupportsState(grainState);
            var grainId = GrainId.NewId();

            var store = await InitDynamoDBGrainStorage(useJsonForWrite);

            grainState = await Test_PersistenceProvider_WriteRead(testName, store,
                                                                  grainState, grainId);

            store = await InitDynamoDBGrainStorage(useJsonForRead);

            await Test_PersistenceProvider_Read(testName, store, grainState, grainId);
        }
コード例 #5
0
        private static async Task Test_PersistenceProvider_Read(string grainTypeName, IStorageProvider store)
        {
            GrainReference      reference = GrainReference.FromGrainId(GrainId.NewId());
            TestStoreGrainState state     = new TestStoreGrainState();
            Stopwatch           sw        = new Stopwatch();
            var storedGrainState          = new GrainState <TestStoreGrainState>
            {
                State = new TestStoreGrainState()
            };

            sw.Start();
            await store.ReadStateAsync(grainTypeName, reference, storedGrainState);

            TimeSpan readTime = sw.Elapsed;

            Console.WriteLine("{0} - Read time = {1}", store.GetType().FullName, readTime);
            var storedState = storedGrainState.State;

            Assert.AreEqual(state.A, storedState.A, "A");
            Assert.AreEqual(state.B, storedState.B, "B");
            Assert.AreEqual(state.C, storedState.C, "C");
        }
コード例 #6
0
        private async Task <GrainState <TestStoreGrainState> > Test_PersistenceProvider_WriteClearRead(string grainTypeName,
                                                                                                       IStorageProvider store, GrainState <TestStoreGrainState> grainState = null, GrainId grainId = null)
        {
            GrainReference reference = GrainReference.FromGrainId(grainId ?? GrainId.NewId());

            if (grainState == null)
            {
                grainState = TestStoreGrainState.NewRandomState();
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            await store.WriteStateAsync(grainTypeName, reference, grainState);

            TimeSpan writeTime = sw.Elapsed;

            sw.Restart();

            await store.ClearStateAsync(grainTypeName, reference, grainState);

            var storedGrainState = new GrainState <TestStoreGrainState>
            {
                State = new TestStoreGrainState()
            };
            await store.ReadStateAsync(grainTypeName, reference, storedGrainState);

            TimeSpan readTime = sw.Elapsed;

            output.WriteLine("{0} - Write time = {1} Read time = {2}", store.GetType().FullName, writeTime, readTime);
            Assert.NotNull(storedGrainState.State);
            Assert.Equal(default(string), storedGrainState.State.A);
            Assert.Equal(default(int), storedGrainState.State.B);
            Assert.Equal(default(long), storedGrainState.State.C);

            return(storedGrainState);
        }
コード例 #7
0
ファイル: LocalStoreTests.cs プロジェクト: felipegtx/orleans
        public void Store_Read()
        {
            string name = TestContext.TestName;

            ILocalDataStore store = new HierarchicalKeyStore(2);

            GrainReference      reference = GrainReference.FromGrainId(GrainId.NewId());
            TestStoreGrainState state     = new TestStoreGrainState();
            Stopwatch           sw        = new Stopwatch();

            sw.Start();
            var keys = GetKeys(name, reference);
            TestStoreGrainState storedState = new TestStoreGrainState();
            var data = store.ReadRow(keys);

            storedState.SetAll(data);
            TimeSpan readTime = sw.Elapsed;

            Console.WriteLine("{0} - Read time = {1}", store.GetType().FullName, readTime);
            Assert.AreEqual(state.A, storedState.A, "A");
            Assert.AreEqual(state.B, storedState.B, "B");
            Assert.AreEqual(state.C, storedState.C, "C");
        }
コード例 #8
0
        private void RunTest(int numItems)
        {
            InvokeMethodRequest request = new InvokeMethodRequest(0, 2, 0, null);
            Message             resp    = this.messageFactory.CreateMessage(request, InvokeMethodOptions.None);

            resp.Id                 = new CorrelationId();
            resp.SendingSilo        = SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 200), 0);
            resp.TargetSilo         = SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 300), 0);
            resp.SendingGrain       = GrainId.NewId();
            resp.TargetGrain        = GrainId.NewId();
            resp.IsAlwaysInterleave = true;
            Assert.True(resp.IsUsingInterfaceVersions);

            List <object> requestBody = new List <object>();

            for (int k = 0; k < numItems; k++)
            {
                requestBody.Add(k + ": test line");
            }

            resp.BodyObject = requestBody;

            string s = resp.ToString();

            output.WriteLine(s);

            int dummy;
            var serialized = resp.Serialize(this.fixture.SerializationManager, out dummy, out dummy);
            int length     = serialized.Sum <ArraySegment <byte> >(x => x.Count);

            byte[] data = new byte[length];
            int    n    = 0;

            foreach (var buffer in serialized)
            {
                Array.Copy(buffer.Array, buffer.Offset, data, n, buffer.Count);
                n += buffer.Count;
            }
            resp.ReleaseBodyAndHeaderBuffers();

            int headerLength = BitConverter.ToInt32(data, 0);
            int bodyLength   = BitConverter.ToInt32(data, 4);

            Assert.Equal <int>(length, headerLength + bodyLength + 8); //Serialized lengths are incorrect
            byte[] header = new byte[headerLength];
            Array.Copy(data, 8, header, 0, headerLength);
            byte[] body = new byte[bodyLength];
            Array.Copy(data, 8 + headerLength, body, 0, bodyLength);
            var headerList = new List <ArraySegment <byte> >();

            headerList.Add(new ArraySegment <byte>(header));
            var bodyList = new List <ArraySegment <byte> >();

            bodyList.Add(new ArraySegment <byte>(body));
            var context = new DeserializationContext(this.fixture.SerializationManager)
            {
                StreamReader = new BinaryTokenStreamReader(headerList)
            };
            var resp1 = new Message
            {
                Headers = SerializationManager.DeserializeMessageHeaders(context)
            };

            resp1.SetBodyBytes(bodyList);

            //byte[] serialized = resp.FormatForSending();
            //Message resp1 = new Message(serialized, serialized.Length);
            Assert.Equal(resp.Category, resp1.Category);                               //Category is incorrect"
            Assert.Equal(resp.Direction, resp1.Direction);                             //Direction is incorrect
            Assert.Equal(resp.Id, resp1.Id);                                           //Correlation ID is incorrect
            Assert.Equal(resp.IsAlwaysInterleave, resp1.IsAlwaysInterleave);           //Foo Boolean is incorrect
            Assert.Equal(resp.CacheInvalidationHeader, resp1.CacheInvalidationHeader); //Bar string is incorrect
            Assert.True(resp.TargetSilo.Equals(resp1.TargetSilo));
            Assert.True(resp.TargetGrain.Equals(resp1.TargetGrain));
            Assert.True(resp.SendingGrain.Equals(resp1.SendingGrain));
            Assert.True(resp.SendingSilo.Equals(resp1.SendingSilo)); //SendingSilo is incorrect
            Assert.True(resp1.IsUsingInterfaceVersions);
            List <object> responseList = Assert.IsAssignableFrom <List <object> >(resp1.GetDeserializedBody(this.fixture.SerializationManager));

            Assert.Equal <int>(numItems, responseList.Count); //Body list has wrong number of entries
            for (int k = 0; k < numItems; k++)
            {
                Assert.IsAssignableFrom <string>(responseList[k]);                          //Body list item " + k + " has wrong type
                Assert.Equal <string>((string)(requestBody[k]), (string)(responseList[k])); //Body list item " + k + " is incorrect
            }
        }
コード例 #9
0
ファイル: ExceptionsTests.cs プロジェクト: vitorlans/orleans
        public void SerializationTests_Exception_Orleans()
        {
            ActivationAddress activationAddress        = ActivationAddress.NewActivationAddress(SiloAddress.NewLocalAddress(12345), GrainId.NewId());
            SiloAddress       primaryDirectoryForGrain = SiloAddress.NewLocalAddress(6789);

            Catalog.DuplicateActivationException original = new Catalog.DuplicateActivationException(activationAddress, primaryDirectoryForGrain);
            Catalog.DuplicateActivationException output   = SerializationManager.RoundTripSerializationForTesting(original);

            Assert.Equal(original.Message, output.Message);
            Assert.Equal(original.ActivationToUse, output.ActivationToUse);
            Assert.Equal(original.PrimaryDirectoryForGrain, output.PrimaryDirectoryForGrain);
        }
コード例 #10
0
        private async Task <GrainState <TestStoreGrainState> > Test_PersistenceProvider_WriteRead(string grainTypeName,
                                                                                                  IGrainStorage store, GrainState <TestStoreGrainState> grainState = null, GrainId grainId = null)
        {
            GrainReference reference = this.fixture.InternalGrainFactory.GetGrain(grainId ?? GrainId.NewId());

            if (grainState == null)
            {
                grainState = TestStoreGrainState.NewRandomState();
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            await store.WriteStateAsync(grainTypeName, reference, grainState);

            TimeSpan writeTime = sw.Elapsed;

            sw.Restart();

            var storedGrainState = new GrainState <TestStoreGrainState>
            {
                State = new TestStoreGrainState()
            };
            await store.ReadStateAsync(grainTypeName, reference, storedGrainState);

            TimeSpan readTime = sw.Elapsed;

            this.output.WriteLine("{0} - Write time = {1} Read time = {2}", store.GetType().FullName, writeTime, readTime);
            Assert.Equal(grainState.State.A, storedGrainState.State.A);
            Assert.Equal(grainState.State.B, storedGrainState.State.B);
            Assert.Equal(grainState.State.C, storedGrainState.State.C);

            return(storedGrainState);
        }
コード例 #11
0
        private void RunTest(int numItems)
        {
            InvokeMethodRequest request = new InvokeMethodRequest(0, 0, null);
            Message             resp    = Message.CreateMessage(request, InvokeMethodOptions.None);

            resp.Id           = new CorrelationId();
            resp.SendingSilo  = SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 200), 0);
            resp.TargetSilo   = SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 300), 0);
            resp.SendingGrain = GrainId.NewId();
            resp.TargetGrain  = GrainId.NewId();
            resp.SetHeader(Message.Header.ALWAYS_INTERLEAVE, true);
            resp.SetHeader(Message.Header.CACHE_INVALIDATION_HEADER, "TestBar");
            //resp.SetStringBody("This is test data");

            List <object> requestBody = new List <object>();

            for (int k = 0; k < numItems; k++)
            {
                requestBody.Add(k + ": test line");
            }

            resp.BodyObject = requestBody;

            string s = resp.ToString();

            output.WriteLine(s);

            int dummy      = 0;
            var serialized = resp.Serialize(out dummy);
            int length     = serialized.Sum <ArraySegment <byte> >(x => x.Count);

            byte[] data = new byte[length];
            int    n    = 0;

            foreach (var buffer in serialized)
            {
                Array.Copy(buffer.Array, buffer.Offset, data, n, buffer.Count);
                n += buffer.Count;
            }
            resp.ReleaseBodyAndHeaderBuffers();

            int headerLength = BitConverter.ToInt32(data, 0);
            int bodyLength   = BitConverter.ToInt32(data, 4);

            Assert.AreEqual <int>(length, headerLength + bodyLength + 8, "Serialized lengths are incorrect");
            byte[] header = new byte[headerLength];
            Array.Copy(data, 8, header, 0, headerLength);
            byte[] body = new byte[bodyLength];
            Array.Copy(data, 8 + headerLength, body, 0, bodyLength);
            var headerList = new List <ArraySegment <byte> >();

            headerList.Add(new ArraySegment <byte>(header));
            var bodyList = new List <ArraySegment <byte> >();

            bodyList.Add(new ArraySegment <byte>(body));
            var resp1 = new Message(headerList, bodyList);

            //byte[] serialized = resp.FormatForSending();
            //Message resp1 = new Message(serialized, serialized.Length);
            Assert.AreEqual <Message.Categories>(resp.Category, resp1.Category, "Category is incorrect");
            Assert.AreEqual <Message.Directions>(resp.Direction, resp1.Direction, "Direction is incorrect");
            Assert.AreEqual <CorrelationId>(resp.Id, resp1.Id, "Correlation ID is incorrect");
            Assert.AreEqual <bool>((bool)resp.GetHeader(Message.Header.ALWAYS_INTERLEAVE), (bool)resp1.GetHeader(Message.Header.ALWAYS_INTERLEAVE), "Foo Boolean is incorrect");
            Assert.AreEqual <string>((string)resp.GetHeader(Message.Header.CACHE_INVALIDATION_HEADER), (string)resp1.GetHeader(Message.Header.CACHE_INVALIDATION_HEADER), "Bar string is incorrect");
            Assert.IsTrue(resp.TargetSilo.Equals(resp1.TargetSilo), "TargetSilo is incorrect");
            Assert.IsTrue(resp.SendingSilo.Equals(resp1.SendingSilo), "SendingSilo is incorrect");
            Assert.IsInstanceOfType(resp1.BodyObject, typeof(List <object>), "Body object is wrong type");
            List <object> responseList = resp1.BodyObject as List <object>;

            Assert.AreEqual <int>(numItems, responseList.Count, "Body list has wrong number of entries");
            for (int k = 0; k < numItems; k++)
            {
                Assert.IsInstanceOfType(responseList[k], typeof(string), "Body list item " + k + " has wrong type");
                Assert.AreEqual <string>((string)(requestBody[k]), (string)(responseList[k]), "Body list item " + k + " is incorrect");
            }
        }
コード例 #12
0
        public void SerializationTests_Exception_Orleans()
        {
            var activationAddress = ActivationAddress.NewActivationAddress(SiloAddress.NewLocalAddress(12345), GrainId.NewId());

            var original = new Catalog.NonExistentActivationException("Some message", activationAddress, false);
            var output   = this.fixture.SerializationManager.RoundTripSerializationForTesting(original);

            Assert.Equal(original.Message, output.Message);
            Assert.Equal(original.NonExistentActivation, output.NonExistentActivation);
            Assert.Equal(original.IsStatelessWorker, output.IsStatelessWorker);
        }
コード例 #13
0
        public void SerializationTests_Exception_DotNet()
        {
            var activationAddress = ActivationAddress.NewActivationAddress(SiloAddress.NewLocalAddress(12345), GrainId.NewId());

            var original = new Catalog.NonExistentActivationException("Some message", activationAddress, false);
            var output   = TestingUtils.RoundTripDotNetSerializer(original, this.fixture.GrainFactory, this.fixture.SerializationManager);

            Assert.Equal(original.Message, output.Message);
            Assert.Equal(original.NonExistentActivation, output.NonExistentActivation);
            Assert.Equal(original.IsStatelessWorker, output.IsStatelessWorker);
        }
コード例 #14
0
 public PushExtension(IRuntimeClient client, StreamPubSubMatch match)
     : base(FromGrainId(GrainId.NewId(), client))
 {
     handler = match.Handler;
 }
コード例 #15
0
        public void SerializationTests_Exception_DotNet()
        {
            ActivationAddress activationAddress        = ActivationAddress.NewActivationAddress(SiloAddress.NewLocalAddress(12345), GrainId.NewId());
            SiloAddress       primaryDirectoryForGrain = SiloAddress.NewLocalAddress(6789);

            Catalog.DuplicateActivationException original = new Catalog.DuplicateActivationException(activationAddress, primaryDirectoryForGrain);
            Catalog.DuplicateActivationException output   = TestingUtils.RoundTripDotNetSerializer(original, this.fixture.GrainFactory);

            Assert.Equal(original.Message, output.Message);
            Assert.Equal(original.ActivationToUse, output.ActivationToUse);
            Assert.Equal(original.PrimaryDirectoryForGrain, output.PrimaryDirectoryForGrain);
        }