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)); }
static MessageBenchmark() { var body = new Response("yess!"); Value = (new Message { TargetActivation = ActivationId.NewId(), TargetSilo = SiloAddress.New(IPEndPoint.Parse("210.50.4.44:40902"), 5423123), TargetGrain = GrainId.Create("sys.mygrain", "borken_thee_doggo"), BodyObject = body, InterfaceType = GrainInterfaceType.Create("imygrain"), SendingActivation = ActivationId.NewId(), SendingSilo = SiloAddress.New(IPEndPoint.Parse("10.50.4.44:40902"), 5423123), SendingGrain = GrainId.Create("sys.mygrain", "fluffy_g"), TraceContext = new TraceContext { ActivityId = Guid.NewGuid() }, Id = CorrelationId.GetNext() }).Headers; // var services = new ServiceCollection() .AddSerializer() .BuildServiceProvider(); Serializer = services.GetRequiredService <Serializer <Message.HeadersContainer> >(); var bytes = new byte[4000]; Session = services.GetRequiredService <SerializerSessionPool>().GetSession(); var writer = new SingleSegmentBuffer(bytes).CreateWriter(Session); Serializer.Serialize(Value, ref writer); Input = bytes; }
public async Task PersistenceProvider_DynamoDB_ChangeWriteFormat(int?stringLength, bool useJsonForFirstWrite, bool useJsonForSecondWrite) { var testName = string.Format("{0}({1}={2},{3}={4},{5}={6})", nameof(PersistenceProvider_DynamoDB_ChangeWriteFormat), nameof(stringLength), stringLength == null ? "default" : stringLength.ToString(), "json1stW", useJsonForFirstWrite, "json2ndW", useJsonForSecondWrite); var grainState = TestStoreGrainState.NewRandomState(stringLength); EnsureEnvironmentSupportsState(grainState); var grainId = GrainId.Create("test", Guid.NewGuid().ToString("N")); var store = await InitDynamoDBGrainStorage(useJsonForFirstWrite); await Test_PersistenceProvider_WriteRead(testName, store, grainState, grainId); grainState = TestStoreGrainState.NewRandomState(stringLength); grainState.ETag = "*"; store = await InitDynamoDBGrainStorage(useJsonForSecondWrite); await Test_PersistenceProvider_WriteRead(testName, store, grainState, grainId); }
/// <inheritdoc/> public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { var id = GrainId.Create(info.GetString("type"), info.GetString("key")); var iface = GrainInterfaceType.Create(info.GetString("interface")); return(_activator.CreateReference(id, iface)); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jo = JObject.Load(reader); GrainId grainId = GrainId.Create(jo["Type"].ToObject <string>(), jo["Key"].ToObject <string>()); return(grainId); }
public void GrainIdUniformHashCodeIsStable() { var id = GrainId.Create("type", "key"); var hashCode = id.GetUniformHashCode(); Assert.Equal((uint)2618661990, hashCode); }
/// <summary> /// Creates a new grain and a grain reference pair. /// </summary> /// <param name="grainId">The grain ID.</param> /// <param name="version">The initial version of the state.</param> /// <returns>A grain reference and a state pair.</returns> internal (GrainReference GrainReference, GrainState <TestState1> GrainState) GetTestReferenceAndState(string grainId, string version) { var grainReference = (GrainReference)_grainFactory.GetGrain(GrainId.Create("my-grain-type", grainId)); var grainState = new GrainState <TestState1> { State = new TestState1(), ETag = version }; return(grainReference, grainState); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jo = JObject.Load(reader); var id = jo["Id"]; GrainId grainId = GrainId.Create(id["Type"].ToObject <string>(), id["Key"].ToObject <string>()); var iface = GrainInterfaceType.Create(jo["Interface"].ToString()); return(this.referenceActivator.CreateReference(grainId, iface)); }
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)); }
/// <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)); }
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 } }
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); }
public async Task Record() { var grain = this.fixture.GrainFactory.GetGrain <ICountersGrain>(GrainId.Create("simple-counters-grain", "0")); var currentstate = await grain.GetTentativeState(); Assert.NotNull(currentstate); Assert.Empty(currentstate); await grain.Add("Alice", 1, false); await grain.Add("Alice", 1, false); await grain.Add("Alice", 1, false); // all three updates should be visible in the tentative count (even if not confirmed yet) Assert.Equal(3, await grain.GetTentativeCount("Alice")); // reset all counters to zero, and wait for confirmation await grain.Reset(true); Assert.Empty((await grain.GetTentativeState())); }
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 }
internal GrainId GetGrainId(InternalStreamId streamId) { var grainKeyId = this.streamIdMapper.GetGrainKeyId(this.GrainBindings, streamId); return(GrainId.Create(this.GrainType, grainKeyId)); }
internal GrainId GetGrainId(InternalChannelId channelId) { var grainKeyId = channelIdMapper.GetGrainKeyId(GrainBindings, channelId); return(GrainId.Create(GrainType, grainKeyId)); }
private async Task <GrainState <TestStoreGrainState> > Test_PersistenceProvider_WriteClearRead(string grainTypeName, IGrainStorage store, GrainState <TestStoreGrainState> grainState = null, GrainId grainId = default) { GrainReference reference = (GrainReference)this.fixture.InternalGrainFactory.GetGrain(grainId.IsDefault ? GrainId.Create("test", Guid.NewGuid().ToString("N")) : grainId); 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; this.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); }
private async Task Test_PersistenceProvider_Read(string grainTypeName, IGrainStorage store, GrainState <TestStoreGrainState> grainState = null, GrainId grainId = default) { var reference = (GrainReference)this.fixture.InternalGrainFactory.GetGrain(grainId.IsDefault ? GrainId.Create("test", Guid.NewGuid().ToString("N")) : grainId); if (grainState == null) { grainState = new GrainState <TestStoreGrainState>(new TestStoreGrainState()); } var storedGrainState = new GrainState <TestStoreGrainState>(new TestStoreGrainState()); Stopwatch sw = new Stopwatch(); sw.Start(); await store.ReadStateAsync(grainTypeName, reference, storedGrainState); TimeSpan readTime = sw.Elapsed; this.output.WriteLine("{0} - Read time = {1}", store.GetType().FullName, readTime); var storedState = storedGrainState.State; Assert.Equal(grainState.State.A, storedState.A); Assert.Equal(grainState.State.B, storedState.B); Assert.Equal(grainState.State.C, storedState.C); }
public async Task ConcurrentIncrements() { var grain = this.fixture.GrainFactory.GetGrain <ICountersGrain>(GrainId.Create("simple-counters-grain", "0")); await ConcurrentIncrementsRunner(grain, 50, false); }