예제 #1
0
        private ActivationAddress GenerateActivationAddress()
        {
            var grainId  = GrainId.Create(GrainType.Create("test"), GrainIdKeyExtensions.CreateGuidKey(Guid.NewGuid()));
            var siloAddr = SiloAddress.New(new IPEndPoint(IPAddress.Loopback, 5000), ++generation);

            return(ActivationAddress.NewActivationAddress(siloAddr, grainId));
        }
예제 #2
0
 private GrainAddress GenerateGrainAddress(SiloAddress siloAddress = null)
 {
     return(new GrainAddress
     {
         GrainId = GrainId.Create(GrainType.Create("test"), GrainIdKeyExtensions.CreateGuidKey(Guid.NewGuid())),
         ActivationId = ActivationId.NewId(),
         SiloAddress = siloAddress ?? GenerateSiloAddress(),
         MembershipVersion = this.mockMembershipService.CurrentVersion,
     });
 }
        /// <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="subscriber">The subscriber prototype.</param>
        /// <returns></returns>
        private IStreamConsumerExtension MakeConsumerReference(
            IInternalGrainFactory grainFactory,
            StreamId streamId,
            StreamSubscriber subscriber)
        {
            var keyExtension = subscriber.IncludeNamespaceInGrainId ? streamId.Namespace : null;
            var grainId      = GrainId.Create(subscriber.GrainType, GrainIdKeyExtensions.CreateGuidKey(streamId.Guid, keyExtension));

            return(grainFactory.GetGrain <IStreamConsumerExtension>(grainId));
        }
예제 #4
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="subscriber">The subscriber prototype.</param>
        /// <returns></returns>
        private IStreamConsumerExtension MakeConsumerReference(
            IInternalGrainFactory grainFactory,
            InternalStreamId streamId,
            StreamSubscriber subscriber)
        {
            var keyExtension = subscriber.IncludeNamespaceInGrainId ? streamId.GetNamespace() : null;
            // TODO BPETIT: CHANGE THIS TO STRING
            var grainId = GrainId.Create(subscriber.GrainType, GrainIdKeyExtensions.CreateGuidKey(Guid.Parse(streamId.GetKeyAsString()), keyExtension));

            return(grainFactory.GetGrain <IStreamConsumerExtension>(grainId));
        }
예제 #5
0
        public void GrainIdShouldEncodeAndDecodePrimaryKeyGuidCorrectly()
        {
            const int repeat = 100;

            for (int i = 0; i < repeat; ++i)
            {
                Guid    expected = Guid.NewGuid();
                GrainId grainId  = GrainId.Create(GrainType.Create("foo"), GrainIdKeyExtensions.CreateGuidKey(expected));
                Guid    actual   = grainId.GetGuidKey();
                Assert.Equal(expected, actual); // Failed to encode and decode grain id
            }
        }
예제 #6
0
        public void GrainReference_Interning()
        {
            var grainId = GrainId.Create(GrainType.Create("test"), GrainIdKeyExtensions.CreateGuidKey(Guid.NewGuid()));
            var g1      = GrainReference.FromGrainId(grainId, null);
            var g2      = GrainReference.FromGrainId(grainId, null);

            Assert.Equal(g1, g2); // Should be equal GrainReferences
            Assert.Same(g1, g2);  // Should be same / interned GrainReference object

            // Round-trip through Serializer
            var g3 = this.HostedCluster.SerializationManager.RoundTripSerializationForTesting(g1);

            Assert.Equal(g3, g1);
            Assert.Equal(g3, g2);
            Assert.Same(g3, g1);
            Assert.Same(g3, g2);
        }
예제 #7
0
        public void GrainId_ToFromPrintableString()
        {
            Guid    guid         = Guid.NewGuid();
            GrainId grainId      = GrainId.Create(GrainType.Create("test"), GrainIdKeyExtensions.CreateGuidKey(guid));
            GrainId roundTripped = RoundTripGrainIdToParsable(grainId);

            Assert.Equal(grainId, roundTripped); // GrainId.ToPrintableString -- Guid key

            string extKey = "Guid-ExtKey-1";

            guid         = Guid.NewGuid();
            grainId      = GrainId.Create(GrainType.Create("test"), GrainIdKeyExtensions.CreateGuidKey(guid, extKey));
            roundTripped = RoundTripGrainIdToParsable(grainId);
            Assert.Equal(grainId, roundTripped); // GrainId.ToPrintableString -- Guid key + Extended Key

            grainId      = GrainId.Create(GrainType.Create("test"), GrainIdKeyExtensions.CreateGuidKey(guid, null));
            roundTripped = RoundTripGrainIdToParsable(grainId);
            Assert.Equal(grainId, roundTripped); // GrainId.ToPrintableString -- Guid key + null Extended Key

            long key = random.Next();

            grainId      = GrainId.Create(GrainType.Create("test"), GrainIdKeyExtensions.CreateIntegerKey(key));
            roundTripped = RoundTripGrainIdToParsable(grainId);
            Assert.Equal(grainId, roundTripped); // GrainId.ToPrintableString -- Int64 key

            extKey       = "Long-ExtKey-2";
            key          = random.Next();
            grainId      = GrainId.Create(GrainType.Create("test"), GrainIdKeyExtensions.CreateIntegerKey(key, extKey));
            roundTripped = RoundTripGrainIdToParsable(grainId);
            Assert.Equal(grainId, roundTripped); // GrainId.ToPrintableString -- Int64 key + Extended Key

            key          = UniqueKey.NewKey(key).PrimaryKeyToLong();
            grainId      = GrainId.Create(GrainType.Create("test"), GrainIdKeyExtensions.CreateIntegerKey(key, extKey));
            roundTripped = RoundTripGrainIdToParsable(grainId);
            Assert.Equal(grainId, roundTripped); // GrainId.ToPrintableString -- Int64 key + null Extended Key
        }