Exemple #1
0
 public static ActivationAddress ToActivationAddress(this GrainAddress addr)
 {
     return(ActivationAddress.GetAddress(
                SiloAddress.FromParsableString(addr.SiloAddress),
                LegacyGrainId.FromParsableString(addr.GrainId),
                ActivationId.GetActivationId(UniqueKey.Parse(addr.ActivationId.AsSpan()))));
 }
        public async Task PersistenceProvider_Azure_ChangeWriteFormat(int?stringLength, bool useJsonForFirstWrite, bool useJsonForSecondWrite)
        {
            var testName = string.Format("{0}({1}={2},{3}={4},{5}={6})",
                                         nameof(PersistenceProvider_Azure_ChangeWriteFormat),
                                         nameof(stringLength), stringLength == null ? "default" : stringLength.ToString(),
                                         "json1stW", useJsonForFirstWrite,
                                         "json2ndW", useJsonForSecondWrite);

            var grainState = TestStoreGrainState.NewRandomState(stringLength);

            EnsureEnvironmentSupportsState(grainState);

            var grainId = LegacyGrainId.NewId();

            var store = await InitAzureTableGrainStorage(useJsonForFirstWrite);

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

            grainState      = TestStoreGrainState.NewRandomState(stringLength);
            grainState.ETag = "*";

            store = await InitAzureTableGrainStorage(useJsonForSecondWrite);

            await Test_PersistenceProvider_WriteRead(testName, store, grainState, grainId);
        }
Exemple #3
0
        private GrainId RoundTripGrainIdToParsable(GrainId input)
        {
            string  str    = ((LegacyGrainId)input).ToParsableString();
            GrainId output = LegacyGrainId.FromParsableString(str);

            return(output);
        }
Exemple #4
0
        public void GrainID_AsGuid()
        {
            string  guidString  = "0699605f-884d-4343-9977-f40a39ab7b2b";
            Guid    grainIdGuid = Guid.Parse(guidString);
            GrainId grainId     = LegacyGrainId.GetGrainIdForTesting(grainIdGuid);
            //string grainIdToKeyString = grainId.ToKeyString();
            string grainIdToFullString = ((LegacyGrainId)grainId).ToFullString();
            string grainIdToGuidString = GrainIdToGuidString(grainId);
            string grainIdKeyString    = grainId.Key.ToString();

            output.WriteLine("Guid={0}", grainIdGuid);
            output.WriteLine("GrainId={0}", grainId);
            //output.WriteLine("GrainId.ToKeyString={0}", grainIdToKeyString);
            output.WriteLine("GrainId.Key.ToString={0}", grainIdKeyString);
            output.WriteLine("GrainIdToGuidString={0}", grainIdToGuidString);
            output.WriteLine("GrainId.ToFullString={0}", grainIdToFullString);

            // Equal: Public APIs
            //Assert.Equal(guidString, grainIdToKeyString); // GrainId.ToKeyString
            Assert.Equal(guidString, grainIdToGuidString);                       // GrainIdToGuidString
            // Equal: Internal APIs
            Assert.Equal(grainIdGuid, ((LegacyGrainId)grainId).GetPrimaryKey()); // GetPrimaryKey Guid
            // NOT-Equal: Internal APIs
            Assert.NotEqual(guidString, grainIdKeyString);                       // GrainId.Key.ToString
        }
        private GrainReference MakeTestGrainReference()
        {
            GrainId        regularGrainId = LegacyGrainId.GetGrainId(12345, Guid.NewGuid(), "foo/bar\\#baz?");
            GrainReference grainRef       = this.ClusterFixture.InternalGrainFactory.GetGrain(regularGrainId);

            return(grainRef);
        }
Exemple #6
0
        public void GrainState_Store_WriteRead()
        {
            string name = Guid.NewGuid().ToString();//TestContext.TestName;

            ILocalDataStore store = new HierarchicalKeyStore(2);

            GrainReference reference  = this.fixture.InternalGrainFactory.GetGrain(LegacyGrainId.NewId());
            var            grainState = TestStoreGrainState.NewRandomState();
            var            state      = grainState.State;
            Stopwatch      sw         = new Stopwatch();

            sw.Start();
            IList <Tuple <string, string> > keys = new[]
            {
                Tuple.Create("GrainType", name),
                Tuple.Create("GrainId", reference.GrainId.ToString())
            }.ToList();

            store.WriteRow(keys, AsDictionary(state), grainState.ETag);
            TimeSpan writeTime = sw.Elapsed;

            sw.Restart();
            var      data     = store.ReadRow(keys);
            TimeSpan readTime = sw.Elapsed;

            output.WriteLine("{0} - Write time = {1} Read time = {2}", store.GetType().FullName, writeTime, readTime);
            Assert.Equal(state.A, data["A"]);   // "A"
            Assert.Equal(state.B, data["B"]);   // "B"
            Assert.Equal(state.C, data["C"]);   // "C"
        }
Exemple #7
0
        public void Store_WriteRead()
        {
            string name = Guid.NewGuid().ToString();//TestContext.TestName;

            ILocalDataStore store = new HierarchicalKeyStore(2);

            GrainReference reference = fixture.InternalGrainFactory.GetGrain(LegacyGrainId.NewId());
            var            state     = TestStoreGrainState.NewRandomState();
            Stopwatch      sw        = new Stopwatch();

            sw.Start();
            var keys            = GetKeys(name, reference);
            var stateProperties = AsDictionary(state.State);

            store.WriteRow(keys, stateProperties, state.ETag);
            TimeSpan writeTime = sw.Elapsed;

            sw.Restart();
            var      data     = store.ReadRow(keys);
            TimeSpan readTime = sw.Elapsed;

            output.WriteLine("{0} - Write time = {1} Read time = {2}", store.GetType().FullName, writeTime, readTime);
            Assert.Equal(state.State.A, data["A"]);   // "A"
            Assert.Equal(state.State.B, data["B"]);   // "B"
            Assert.Equal(state.State.C, data["C"]);   // "C"
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject jo      = JObject.Load(reader);
            GrainId grainId = LegacyGrainId.FromParsableString(jo["GrainId"].ToObject <string>());

            return(grainId);
        }
Exemple #9
0
        public async Task PersistenceProvider_Memory_FixedLatency_WriteRead()
        {
            const string testName               = nameof(PersistenceProvider_Memory_FixedLatency_WriteRead);
            TimeSpan     expectedLatency        = TimeSpan.FromMilliseconds(200);
            MemoryGrainStorageWithLatency store = new MemoryGrainStorageWithLatency(testName, new MemoryStorageWithLatencyOptions()
            {
                Latency       = expectedLatency,
                MockCallsOnly = true
            }, NullLoggerFactory.Instance, this.providerRuntime.ServiceProvider.GetService <IGrainFactory>());

            GrainReference reference = this.fixture.InternalGrainFactory.GetGrain(LegacyGrainId.NewId());
            var            state     = TestStoreGrainState.NewRandomState();
            Stopwatch      sw        = new Stopwatch();

            sw.Start();
            await store.WriteStateAsync(testName, reference, state);

            TimeSpan writeTime = sw.Elapsed;

            this.output.WriteLine("{0} - Write time = {1}", store.GetType().FullName, writeTime);
            Assert.True(writeTime >= expectedLatency, $"Write: Expected minimum latency = {expectedLatency} Actual = {writeTime}");

            sw.Restart();
            var storedState = new GrainState <TestStoreGrainState>();
            await store.ReadStateAsync(testName, reference, storedState);

            TimeSpan readTime = sw.Elapsed;

            this.output.WriteLine("{0} - Read time = {1}", store.GetType().FullName, readTime);
            Assert.True(readTime >= expectedLatency, $"Read: Expected minimum latency = {expectedLatency} Actual = {readTime}");
        }
Exemple #10
0
        public OutsideRuntimeClient(
            ILoggerFactory loggerFactory,
            IOptions <ClientMessagingOptions> clientMessagingOptions,
            IOptions <TypeManagementOptions> typeManagementOptions,
            IOptions <StatisticsOptions> statisticsOptions,
            ApplicationRequestsStatisticsGroup appRequestStatistics,
            StageAnalysisStatisticsGroup schedulerStageStatistics,
            ClientStatisticsManager clientStatisticsManager,
            MessagingTrace messagingTrace)
        {
            this.loggerFactory            = loggerFactory;
            this.statisticsOptions        = statisticsOptions;
            this.appRequestStatistics     = appRequestStatistics;
            this.schedulerStageStatistics = schedulerStageStatistics;
            this.ClientStatistics         = clientStatisticsManager;
            this.messagingTrace           = messagingTrace;
            this.logger   = loggerFactory.CreateLogger <OutsideRuntimeClient>();
            this.clientId = LegacyGrainId.NewClientId();
            callbacks     = new ConcurrentDictionary <CorrelationId, CallbackData>();
            this.clientMessagingOptions = clientMessagingOptions.Value;
            this.typeMapRefreshInterval = typeManagementOptions.Value.TypeMapRefreshInterval;

            this.sharedCallbackData = new SharedCallbackData(
                msg => this.UnregisterCallback(msg.Id),
                this.loggerFactory.CreateLogger <CallbackData>(),
                this.clientMessagingOptions,
                this.appRequestStatistics,
                this.clientMessagingOptions.ResponseTimeout);
        }
Exemple #11
0
        private ActivationAddress GenerateActivationAddress()
        {
            var grainId  = LegacyGrainId.GetGrainIdForTesting(Guid.NewGuid());
            var siloAddr = SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 5000), ++generation);

            return(ActivationAddress.NewActivationAddress(siloAddr, grainId));
        }
        public bool TryGetGrainType(Type grainClass, out GrainType grainType)
        {
            if (!LegacyGrainId.IsLegacyGrainType(grainClass))
            {
                grainType = default;
                return(false);
            }

            Type canonicalGrainClass;

            if (grainClass.IsConstructedGenericType)
            {
                canonicalGrainClass = grainClass.GetGenericTypeDefinition();
            }
            else
            {
                canonicalGrainClass = grainClass;
            }

            var isKeyExt = LegacyGrainId.IsLegacyKeyExtGrainType(canonicalGrainClass);
            var typeCode = GrainInterfaceUtils.GetGrainClassTypeCode(canonicalGrainClass);

            grainType = LegacyGrainId.GetGrainType(typeCode, isKeyExt);

            if (grainClass.IsGenericType)
            {
                grainType = GrainType.Create($"{grainType}`{canonicalGrainClass.GetGenericArguments().Length}");
            }

            return(true);
        }
Exemple #13
0
        /// <summary>
        /// Create a subscriptionId that is unique per grainId, grainType, namespace combination.
        /// </summary>
        /// <param name="grainId"></param>
        /// <param name="streamId"></param>
        /// <returns></returns>
        private Guid MakeSubscriptionGuid(GrainId grainId, StreamId streamId)
        {
            // first int in guid is grain type code
            int grainIdTypeCode = LegacyGrainId.FromGrainId(grainId).TypeCode;

            return(MakeSubscriptionGuid(grainIdTypeCode, streamId));
        }
Exemple #14
0
        public async Task <IPersistentStreamPullingManager> InitializePullingAgents(
            string streamProviderName,
            IQueueAdapterFactory adapterFactory,
            IQueueAdapter queueAdapter)
        {
            IStreamQueueBalancer queueBalancer = CreateQueueBalancer(streamProviderName);
            var managerId           = LegacyGrainId.NewSystemTargetGrainIdByTypeCode(Constants.PULLING_AGENTS_MANAGER_SYSTEM_TARGET_TYPE_CODE);
            var pubsubOptions       = this.ServiceProvider.GetOptionsByName <StreamPubSubOptions>(streamProviderName);
            var pullingAgentOptions = this.ServiceProvider.GetOptionsByName <StreamPullingAgentOptions>(streamProviderName);
            var manager             = new PersistentStreamPullingManager(
                managerId,
                streamProviderName,
                this,
                this.PubSub(pubsubOptions.PubSubType),
                adapterFactory,
                queueBalancer,
                pullingAgentOptions,
                this.loggerFactory,
                this.siloDetails.SiloAddress);

            this.RegisterSystemTarget(manager);
            // Init the manager only after it was registered locally.
            var pullingAgentManager = manager.AsReference <IPersistentStreamPullingManager>();
            // Need to call it as a grain reference though.
            await pullingAgentManager.Initialize(queueAdapter.AsImmutable());

            return(pullingAgentManager);
        }
Exemple #15
0
        /// <inheritdoc />
        public TGrainInterface GetGrain <TGrainInterface>(long primaryKey, string grainClassNamePrefix = null) where TGrainInterface : IGrainWithIntegerKey
        {
            Type interfaceType  = typeof(TGrainInterface);
            var  implementation = this.GetGrainClassData(interfaceType, grainClassNamePrefix);
            var  grainId        = LegacyGrainId.GetGrainId(implementation.GetTypeCode(interfaceType), primaryKey, null);

            return(this.Cast <TGrainInterface>(this.MakeGrainReferenceFromType(interfaceType, grainId.ToGrainId())));
        }
Exemple #16
0
        /// <summary>
        /// Take responsibility for a set of new queues that were assigned to me via a new range.
        /// We first create one pulling agent for every new queue and store them in our internal data structure, then try to initialize the agents.
        /// ERROR HANDLING:
        ///     The responsibility to handle initialization and shutdown failures is inside the Agents code.
        ///     The manager will call Initialize once and log an error. It will not call initialize again and will assume initialization has succeeded.
        ///     Same applies to shutdown.
        /// </summary>
        /// <param name="myQueues"></param>
        /// <param name="failOnInit"></param>
        /// <returns></returns>
        private async Task AddNewQueues(IEnumerable <QueueId> myQueues, bool failOnInit)
        {
            // Create agents for queues in range that we don't yet have.
            // First create them and store in local queuesToAgentsMap.
            // Only after that Initialize them all.
            var agents = new List <PersistentStreamPullingAgent>();

            foreach (var queueId in myQueues)
            {
                if (queuesToAgentsMap.ContainsKey(queueId))
                {
                    continue;
                }
                try
                {
                    var agentId = LegacyGrainId.NewSystemTargetGrainIdByTypeCode(Constants.PULLING_AGENT_SYSTEM_TARGET_TYPE_CODE);
                    var agent   = new PersistentStreamPullingAgent(agentId, streamProviderName, providerRuntime, this.loggerFactory, pubSub, queueId, this.options, this.Silo);
                    providerRuntime.RegisterSystemTarget(agent);
                    queuesToAgentsMap.Add(queueId, agent);
                    agents.Add(agent);
                }
                catch (Exception exc)
                {
                    logger.Error(ErrorCode.PersistentStreamPullingManager_07, "Exception while creating PersistentStreamPullingAgent.", exc);
                    // What should we do? This error is not recoverable and considered a bug. But we don't want to bring the silo down.
                    // If this is when silo is starting and agent is initializing, fail the silo startup. Otherwise, just swallow to limit impact on other receivers.
                    if (failOnInit)
                    {
                        throw;
                    }
                }
            }

            try
            {
                var initTasks = new List <Task>();
                foreach (var agent in agents)
                {
                    initTasks.Add(InitAgent(agent));
                }
                await Task.WhenAll(initTasks);
            }
            catch
            {
                // Just ignore this exception and proceed as if Initialize has succeeded.
                // We already logged individual exceptions for individual calls to Initialize. No need to log again.
            }
            if (agents.Count > 0)
            {
                Log(ErrorCode.PersistentStreamPullingManager_08, "Added {0} new queues: {1}. Now own total of {2} queues: {3}",
                    agents.Count,
                    Utils.EnumerableToString(agents, agent => agent.QueueId.ToString()),
                    NumberRunningAgents,
                    PrintQueues(queuesToAgentsMap.Keys));
            }
        }
Exemple #17
0
        /// <summary>
        /// Create a reference to a grain that we expect to support the stream consumer extension.
        /// </summary>
        /// <param name="grainFactory">The grain factory used to get consumer references.</param>
        /// <param name="streamId">The stream ID to use for the grain ID construction.</param>
        /// <param name="implTypeCode">The type code of the grain interface.</param>
        /// <returns></returns>
        private IStreamConsumerExtension MakeConsumerReference(IInternalGrainFactory grainFactory, StreamId streamId,
                                                               int implTypeCode)
        {
            var keyExtension = grainsWithKeyExtensions.Contains(implTypeCode)
                ? streamId.Namespace
                : null;
            GrainId grainId = LegacyGrainId.GetGrainId(implTypeCode, streamId.Guid, keyExtension);

            return(grainFactory.GetGrain <IStreamConsumerExtension>(grainId));
        }
Exemple #18
0
        public void GrainReference_Test1()
        {
            Guid           guid           = Guid.NewGuid();
            GrainId        regularGrainId = LegacyGrainId.GetGrainIdForTesting(guid);
            GrainReference grainRef       = (GrainReference)this.environment.InternalGrainFactory.GetGrain(regularGrainId);

            TestGrainReference(grainRef);

            grainRef = (GrainReference)this.environment.InternalGrainFactory.GetGrain(regularGrainId);
            TestGrainReference(grainRef);
        }
Exemple #19
0
        /// <summary>
        /// Returns the <see langword="string"/> primary key of the grain.
        /// </summary>
        /// <param name="grain">The grain to find the primary key for.</param>
        /// <returns>A <see langword="string"/> representing the primary key for this grain.</returns>
        public static string GetPrimaryKeyString(this IAddressable grain)
        {
            var grainId = GetGrainId(grain);

            if (LegacyGrainId.TryConvertFromGrainId(grainId, out var legacyId))
            {
                return(legacyId.GetPrimaryKeyString());
            }

            return(grainId.Key.ToStringUtf8());
        }
Exemple #20
0
        /// <inheritdoc />
        public TGrainInterface GetGrain <TGrainInterface>(Guid primaryKey, string keyExtension, string grainClassNamePrefix = null)
            where TGrainInterface : IGrainWithGuidCompoundKey
        {
            GrainFactoryBase.DisallowNullOrWhiteSpaceKeyExtensions(keyExtension);

            Type interfaceType  = typeof(TGrainInterface);
            var  implementation = this.GetGrainClassData(interfaceType, grainClassNamePrefix);
            var  grainId        = LegacyGrainId.GetGrainId(implementation.GetTypeCode(interfaceType), primaryKey, keyExtension);

            return(this.Cast <TGrainInterface>(this.MakeGrainReferenceFromType(interfaceType, grainId.ToGrainId())));
        }
        public bool TryGetGrainType(Type grainClass, out GrainType grainType)
        {
            if (LegacyGrainId.IsLegacyGrainType(grainClass))
            {
                grainType = LegacyGrainId.GetGrainId(GrainInterfaceUtils.GetGrainClassTypeCode(grainClass), Guid.Empty).ToGrainId().Type;
                return(true);
            }

            grainType = default;
            return(false);
        }
Exemple #22
0
        public void GrainIdShouldEncodeAndDecodePrimaryKeyGuidCorrectly()
        {
            const int repeat = 100;

            for (int i = 0; i < repeat; ++i)
            {
                Guid    expected = Guid.NewGuid();
                GrainId grainId  = LegacyGrainId.GetGrainIdForTesting(expected);
                Guid    actual   = ((LegacyGrainId)grainId).Key.PrimaryKeyToGuid();
                Assert.Equal(expected, actual); // Failed to encode and decode grain id
            }
        }
        public void Serialize_GrainReference()
        {
            GrainId        grainId = LegacyGrainId.NewId();
            GrainReference input   = (GrainReference)environment.InternalGrainFactory.GetGrain(grainId);

            object deserialized = OrleansSerializationLoop(environment.Serializer, environment.DeepCopier, input);

            var grainRef = Assert.IsAssignableFrom <GrainReference>(deserialized); //GrainReference copied as wrong type

            Assert.Equal(grainId, grainRef.GrainId);                               //GrainId different after copy
            Assert.Equal(input, grainRef);                                         //Wrong contents after round-trip of input
        }
Exemple #24
0
        private ReminderEntry NewReminderEntry()
        {
            Guid guid = Guid.NewGuid();

            return(new ReminderEntry
            {
                GrainRef = this.fixture.InternalGrainFactory.GetGrain(LegacyGrainId.NewId()),
                ReminderName = string.Format("TestReminder.{0}", guid),
                Period = TimeSpan.FromSeconds(5),
                StartAt = DateTime.UtcNow
            });
        }
Exemple #25
0
        public void CodeGen_GrainId_TypeCode()
        {
            var           g1Key = GetRandomGrainId();
            ITestGrain    g1    = this.GrainFactory.GetGrain <ITestGrain>(g1Key);
            LegacyGrainId id1   = ((GrainReference)g1).GrainId;
            var           k1    = id1.Key;

            Assert.True(id1.IsGrain, "GrainReference should be for a grain");
            Assert.Equal(UniqueKey.Category.Grain, k1.IdCategory); // "GrainId should be for self-managed type"
            Assert.Equal(g1Key, k1.PrimaryKeyToLong());            // "Encoded primary key should match"
            Assert.Equal(1146670029, k1.BaseTypeCode);             // "Encoded type code data should match"
        }
Exemple #26
0
        public void CollectionTest_GrainId_TypeCode()
        {
            var g1Key = GetRandomGrainId();
            ICollectionTestGrain g1  = this.GrainFactory.GetGrain <ICollectionTestGrain>(g1Key);
            LegacyGrainId        id1 = ((GrainReference)g1).GrainId;
            UniqueKey            k1  = id1.Key;

            output.WriteLine("GrainId={0} UniqueKey={1} PK={2} KeyType={3} IdCategory={4}",
                             id1, k1, id1.GetPrimaryKeyLong(), k1.IdCategory, k1.BaseTypeCode);
            Assert.True(id1.IsGrain, "GrainReference should be for a grain");
            Assert.Equal(UniqueKey.Category.Grain, k1.IdCategory); // "GrainId should be for self-managed type"
            Assert.Equal(g1Key, k1.PrimaryKeyToLong());            // "Encoded primary key should match"
            Assert.Equal(1381240679, k1.BaseTypeCode);             // "Encoded type code data should match"
        }
Exemple #27
0
        public void ID_Interning_GrainID()
        {
            Guid    guid = new Guid();
            GrainId gid1 = LegacyGrainId.FromParsableString(guid.ToString("B"));
            GrainId gid2 = LegacyGrainId.FromParsableString(guid.ToString("N"));

            Assert.Equal(gid1, gid2); // Should be equal GrainId's

            // Round-trip through Serializer
            GrainId gid3 = this.environment.Serializer.Deserialize <GrainId>(environment.Serializer.SerializeToArray(gid1));

            Assert.Equal(gid1, gid3); // Should be equal GrainId's
            Assert.Equal(gid2, gid3); // Should be equal GrainId's
        }
Exemple #28
0
        public void ID_Interning_GrainID()
        {
            Guid    guid = new Guid();
            GrainId gid1 = LegacyGrainId.FromParsableString(guid.ToString("B"));
            GrainId gid2 = LegacyGrainId.FromParsableString(guid.ToString("N"));

            Assert.Equal(gid1, gid2); // Should be equal GrainId's

            // Round-trip through Serializer
            GrainId gid3 = (GrainId)this.environment.SerializationManager.RoundTripSerializationForTesting(gid1);

            Assert.Equal(gid1, gid3); // Should be equal GrainId's
            Assert.Equal(gid2, gid3); // Should be equal GrainId's
        }
        private static IGrainService GrainServiceFactory(Type serviceType, IServiceProvider services)
        {
            var grainServiceInterfaceType = serviceType.GetInterfaces().FirstOrDefault(x => x.GetInterfaces().Contains(typeof(IGrainService)));

            if (grainServiceInterfaceType == null)
            {
                throw new InvalidOperationException(String.Format($"Cannot find an interface on {serviceType.FullName} which implements IGrainService"));
            }
            var typeCode     = GrainInterfaceUtils.GetGrainClassTypeCode(grainServiceInterfaceType);
            var grainId      = (GrainId)LegacyGrainId.GetGrainServiceGrainId(0, typeCode);
            var grainService = (GrainService)ActivatorUtilities.CreateInstance(services, serviceType, grainId);

            return(grainService);
        }
Exemple #30
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       = LegacyGrainId.NewId();
            resp.TargetGrain        = LegacyGrainId.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);

            var resp1 = RoundTripMessage(resp);

            //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.BodyObject);

            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)(requestBody[k]), (string)(responseList[k])); //Body list item " + k + " is incorrect
            }
        }