internal TGrainInterface GetSystemTarget <TGrainInterface>(GrainId grainId, SiloAddress destination) where TGrainInterface : ISystemTarget { Dictionary <SiloAddress, ISystemTarget> cache; lock (typedSystemTargetReferenceCache) { if (typedSystemTargetReferenceCache.ContainsKey(grainId)) { cache = typedSystemTargetReferenceCache[grainId]; } else { cache = new Dictionary <SiloAddress, ISystemTarget>(); typedSystemTargetReferenceCache[grainId] = cache; } } lock (cache) { if (cache.ContainsKey(destination)) { return((TGrainInterface)cache[destination]); } var reference = Cast <TGrainInterface>(GrainReference.FromGrainId(grainId, null, destination)); cache[destination] = reference; return(reference); } }
internal async Task <IMembershipTable> GetMembershipTable(Silo silo) { var config = silo.GlobalConfig; IMembershipTable membershipTable; GlobalConfiguration.LivenessProviderType livenessType = config.LivenessType; if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.MembershipTableGrain)) { membershipTable = MembershipTableFactory.Cast(GrainReference.FromGrainId(Constants.SystemMembershipTableId)); } else if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.SqlServer)) { membershipTable = await SqlMembershipTable.GetMembershipTable(config, true); } else if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.AzureTable)) { membershipTable = await AzureBasedMembershipTable.GetMembershipTable(config, true); } else { throw new NotImplementedException("No membership table provider found for LivenessType=" + livenessType); } return(membershipTable); }
private static async Task Test_PersistenceProvider_WriteRead(string grainTypeName, IStorageProvider store) { GrainReference reference = GrainReference.FromGrainId(GrainId.NewId()); var state = TestStoreGrainState.NewRandomState(); Stopwatch sw = new Stopwatch(); sw.Start(); await store.WriteStateAsync(grainTypeName, reference, state); TimeSpan writeTime = sw.Elapsed; sw.Restart(); var storedGrainState = new GrainState <TestStoreGrainState> { State = new TestStoreGrainState() }; await store.ReadStateAsync(grainTypeName, reference, storedGrainState); TimeSpan readTime = sw.Elapsed; Console.WriteLine("{0} - Write time = {1} Read time = {2}", store.GetType().FullName, writeTime, readTime); var storedState = storedGrainState.State; Assert.AreEqual(state.State.A, storedState.A, "A"); Assert.AreEqual(state.State.B, storedState.B, "B"); Assert.AreEqual(state.State.C, storedState.C, "C"); }
public void GrainState_Store_WriteRead() { string name = Guid.NewGuid().ToString();//TestContext.TestName; ILocalDataStore store = new HierarchicalKeyStore(2); GrainReference reference = GrainReference.FromGrainId(GrainId.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.GetPrimaryKey().ToString("N")) }.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" }
private async Task <GrainState <TestStoreGrainState> > Test_PersistenceProvider_WriteRead(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(); 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.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); }
public void Store_WriteRead() { string name = TestContext.TestName; ILocalDataStore store = new HierarchicalKeyStore(2); GrainReference reference = GrainReference.FromGrainId(GrainId.NewId()); TestStoreGrainState state = TestStoreGrainState.NewRandomState(); Stopwatch sw = new Stopwatch(); sw.Start(); var keys = GetKeys(name, reference); store.WriteRow(keys, state.AsDictionary(), state.Etag); TimeSpan writeTime = sw.Elapsed; sw.Restart(); TestStoreGrainState storedState = new TestStoreGrainState(); var data = store.ReadRow(keys); storedState.SetAll(data); TimeSpan readTime = sw.Elapsed; Console.WriteLine("{0} - Write time = {1} Read time = {2}", store.GetType().FullName, writeTime, readTime); Assert.AreEqual(state.A, storedState.A, "A"); Assert.AreEqual(state.B, storedState.B, "B"); Assert.AreEqual(state.C, storedState.C, "C"); }
internal IMembershipTable GetMembershipTable(GlobalConfiguration.LivenessProviderType livenessType) { IMembershipTable membershipTable; if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.MembershipTableGrain)) { membershipTable = GrainReference.FromGrainId(Constants.SystemMembershipTableId).Cast <IMembershipTableGrain>(); } else if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.SqlServer)) { membershipTable = new SqlMembershipTable(); } else if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.AzureTable)) { membershipTable = AssemblyLoader.LoadAndCreateInstance <IMembershipTable>(Constants.ORLEANS_AZURE_UTILS_DLL, logger); } else if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.ZooKeeper)) { membershipTable = AssemblyLoader.LoadAndCreateInstance <IMembershipTable>(Constants.ORLEANS_ZOOKEEPER_UTILS_DLL, logger); } else { throw new NotImplementedException("No membership table provider found for LivenessType=" + livenessType); } return(membershipTable); }
private static GrainReference MakeTestGrainReference() { GrainId regularGrainId = GrainId.GetGrainIdForTesting(Guid.NewGuid()); GrainReference grainRef = GrainReference.FromGrainId(regularGrainId); return(grainRef); }
internal IMembershipTable GetMembershipTable(GlobalConfiguration globalConfig) { var livenessType = globalConfig.LivenessType; IMembershipTable membershipTable; if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.MembershipTableGrain)) { membershipTable = this.grainFactory.Cast <IMembershipTableGrain>(GrainReference.FromGrainId(Constants.SystemMembershipTableId)); } else if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.SqlServer)) { membershipTable = AssemblyLoader.LoadAndCreateInstance <IMembershipTable>(Constants.ORLEANS_SQL_UTILS_DLL, this.logger); } else if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.AzureTable)) { membershipTable = AssemblyLoader.LoadAndCreateInstance <IMembershipTable>(Constants.ORLEANS_AZURE_UTILS_DLL, this.logger); } else if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.ZooKeeper)) { membershipTable = AssemblyLoader.LoadAndCreateInstance <IMembershipTable>(Constants.ORLEANS_ZOOKEEPER_UTILS_DLL, this.logger); } else if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.Custom)) { membershipTable = AssemblyLoader.LoadAndCreateInstance <IMembershipTable>(globalConfig.MembershipTableAssembly, this.logger); } else { throw new NotImplementedException("No membership table provider found for LivenessType=" + livenessType); } return(membershipTable); }
internal TGrainInterface GetSystemTarget <TGrainInterface>(GrainId grainId, SiloAddress destination) where TGrainInterface : ISystemTarget { Dictionary <SiloAddress, ISystemTarget> cache; Tuple <GrainId, Type> key = Tuple.Create(grainId, typeof(TGrainInterface)); lock (typedSystemTargetReferenceCache) { if (typedSystemTargetReferenceCache.ContainsKey(key)) { cache = typedSystemTargetReferenceCache[key]; } else { cache = new Dictionary <SiloAddress, ISystemTarget>(); typedSystemTargetReferenceCache[key] = cache; } } ISystemTarget reference; lock (cache) { if (cache.ContainsKey(destination)) { reference = cache[destination]; } else { reference = Cast <TGrainInterface>(GrainReference.FromGrainId(grainId, null, destination)); cache[destination] = reference; // Store for next time } } return((TGrainInterface)reference); }
public void GrainReference_Test1() { Guid guid = Guid.NewGuid(); GrainId regularGrainId = GrainId.GetGrainIdForTesting(guid); GrainReference grainRef = GrainReference.FromGrainId(regularGrainId); TestGrainReference(grainRef); grainRef = GrainReference.FromGrainId(regularGrainId, "generic"); TestGrainReference(grainRef); GrainId systemTragetGrainId = GrainId.NewSystemTargetGrainIdByTypeCode(2); grainRef = GrainReference.FromGrainId(systemTragetGrainId, null, SiloAddress.NewLocalAddress(1)); TestGrainReference(grainRef); GrainId observerGrainId = GrainId.NewClientId(); grainRef = GrainReference.NewObserverGrainReference(observerGrainId, GuidId.GetNewGuidId()); TestGrainReference(grainRef); GrainId geoObserverGrainId = GrainId.NewClientId("clusterid"); grainRef = GrainReference.NewObserverGrainReference(geoObserverGrainId, GuidId.GetNewGuidId()); TestGrainReference(grainRef); }
public void GrainReference_Test1() { Guid guid = Guid.NewGuid(); GrainId regularGrainId = GrainId.GetGrainIdForTesting(guid); GrainReference grainRef = this.environment.InternalGrainFactory.GetGrain(regularGrainId); TestGrainReference(grainRef); grainRef = GrainReference.FromGrainId(regularGrainId, null, "generic"); TestGrainReference(grainRef); GrainId systemTragetGrainId = GrainId.NewSystemTargetGrainIdByTypeCode(2); grainRef = GrainReference.FromGrainId(systemTragetGrainId, null, null, SiloAddress.NewLocalAddress(1)); this.environment.GrainFactory.BindGrainReference(grainRef); TestGrainReference(grainRef); GrainId observerGrainId = GrainId.NewClientId(); grainRef = GrainReference.NewObserverGrainReference(observerGrainId, GuidId.GetNewGuidId(), this.environment.RuntimeClient.GrainReferenceRuntime); this.environment.GrainFactory.BindGrainReference(grainRef); TestGrainReference(grainRef); GrainId geoObserverGrainId = GrainId.NewClientId("clusterid"); grainRef = GrainReference.NewObserverGrainReference(geoObserverGrainId, GuidId.GetNewGuidId(), this.environment.RuntimeClient.GrainReferenceRuntime); this.environment.GrainFactory.BindGrainReference(grainRef); TestGrainReference(grainRef); }
public async Task PersistenceProvider_Memory_FixedLatency_WriteRead() { const string testName = nameof(PersistenceProvider_Memory_FixedLatency_WriteRead); TimeSpan expectedLatency = TimeSpan.FromMilliseconds(200); IStorageProvider store = new MemoryStorageWithLatency(); providerCfgProps.Add("Latency", expectedLatency.ToString()); providerCfgProps.Add("MockCalls", "true"); var cfg = new ProviderConfiguration(providerCfgProps, null); await store.Init(testName, storageProviderManager, cfg); GrainReference reference = GrainReference.FromGrainId(GrainId.NewId()); var state = TestStoreGrainState.NewRandomState(); Stopwatch sw = new Stopwatch(); sw.Start(); await store.WriteStateAsync(testName, reference, state); TimeSpan writeTime = sw.Elapsed; 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; output.WriteLine("{0} - Read time = {1}", store.GetType().FullName, readTime); Assert.True(readTime >= expectedLatency, $"Read: Expected minimum latency = {expectedLatency} Actual = {readTime}"); }
/// <summary> /// Create a reference to a grain that we expect to support the stream consumer extension. /// </summary> /// <param name="primaryKey">The primary key of the grain.</param> /// <param name="grainClassName">The name of the grain class to instantiate.</param> /// <param name="grainIfaceName">The name of the an IGrain-derived interface that `className` implements (required by MakeGrainReferenceInternal)</param> /// <returns></returns> private IStreamConsumerExtension MakeConsumerReference(Guid primaryKey, int implTypeCode) { GrainId grainId = GrainId.GetGrainId(implTypeCode, primaryKey); IAddressable addressable = GrainReference.FromGrainId(grainId); return(GrainFactory.Cast <IStreamConsumerExtension>(addressable)); }
public void Store_WriteRead() { string name = Guid.NewGuid().ToString();//TestContext.TestName; ILocalDataStore store = new HierarchicalKeyStore(2); GrainReference reference = GrainReference.FromGrainId(GrainId.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" }
private static GrainReference AsWeaklyTypedReference(this IAddressable grain) { var reference = grain as GrainReference; // When called against an instance of a grain reference class, do nothing if (reference != null) { return(reference); } var grainBase = grain as Grain; if (grainBase != null) { if (grainBase.Data == null || grainBase.Data.GrainReference == null) { throw new ArgumentException(WRONG_GRAIN_ERROR_MSG, "grain"); } return(grainBase.Data.GrainReference); } var systemTarget = grain as ISystemTargetBase; if (systemTarget != null) { return(GrainReference.FromGrainId(systemTarget.GrainId, null, systemTarget.Silo)); } throw new ArgumentException(String.Format("AsWeaklyTypedReference has been called on an unexpected type: {0}.", grain.GetType().FullName), "grain"); }
private async Task Test_PersistenceProvider_Read(string grainTypeName, IStorageProvider store, GrainState <TestStoreGrainState> grainState = null, GrainId grainId = null) { var reference = GrainReference.FromGrainId(grainId ?? GrainId.NewId()); 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; 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); }
internal IAddressable MakeGrainReferenceFromType(Type interfaceType, GrainId grainId) { return(GrainReference.FromGrainId( grainId, this.GrainReferenceRuntime, interfaceType.IsGenericType ? TypeUtils.GenericTypeArgsString(interfaceType.UnderlyingSystemType.FullName) : null)); }
/// <summary> /// Converts this grain to a <c>GrainReference</c> /// </summary> /// <param name="grain">The grain to convert.</param> /// <returns>A <c>GrainReference</c> for this grain.</returns> public static GrainReference AsReference(this Runtime.IAddressable grain) { var reference = grain as Runtime.GrainReference; // When called against an instance of a grain reference class, do nothing if (reference != null) { return(reference); } var grainBase = grain as Grain; if (grainBase != null) { return(((Grain)grain).GrainReference); } var systemTarget = grain as ISystemTargetBase; if (systemTarget != null) { return(GrainReference.FromGrainId(systemTarget.GrainId, null, systemTarget.Silo)); } throw new OrleansException(String.Format("AsReference has been called on an unexpected type: {0}.", grain.GetType().FullName)); }
internal static GrainReference AsWeaklyTypedReference(this IAddressable grain) { // When called against an instance of a grain reference class, do nothing var reference = grain as GrainReference; if (reference != null) { return(reference); } var grainBase = grain as Grain; if (grainBase != null) { if (grainBase.Data?.GrainReference == null) { throw new ArgumentException(WRONG_GRAIN_ERROR_MSG, nameof(grain)); } return(grainBase.Data.GrainReference); } var systemTarget = grain as ISystemTargetBase; if (systemTarget != null) { return(GrainReference.FromGrainId(systemTarget.GrainId, null, systemTarget.Silo)); } throw new ArgumentException( $"AsWeaklyTypedReference has been called on an unexpected type: {grain.GetType().FullName}.", nameof(grain)); }
protected internal static object DeserializeGrainReference(Type t, IDeserializationContext context) { var reader = context.StreamReader; GrainId id = reader.ReadGrainId(); byte siloAddressPresent = reader.ReadByte(); if (siloAddressPresent != 0) { // Unused: silo. // Note, this should become part of the GrainId when reading a legacy SystemTarget grain id, and therefore converting it to a new GrainId _ = reader.ReadSiloAddress(); } bool expectObserverId = id.IsClient(); if (expectObserverId) { _ = GuidId.DeserializeFromStream(reader); } // store as null, serialize as empty. var genericArg = reader.ReadString(); if (string.IsNullOrEmpty(genericArg)) { genericArg = null; } var runtimeClient = context.AdditionalContext as IRuntimeClient; var runtime = runtimeClient?.GrainReferenceRuntime; return(GrainReference.FromGrainId(id, runtime, genericArg)); }
/// <summary> /// Gets a reference to the specified system target. /// </summary> /// <typeparam name="TGrainInterface">The system target interface.</typeparam> /// <param name="grainId">The id of the target.</param> /// <param name="destination">The destination silo.</param> /// <returns>A reference to the specified system target.</returns> public TGrainInterface GetSystemTarget <TGrainInterface>(GrainId grainId, SiloAddress destination) where TGrainInterface : ISystemTarget { Dictionary <SiloAddress, ISystemTarget> cache; Tuple <GrainId, Type> key = Tuple.Create(grainId, typeof(TGrainInterface)); lock (this.typedSystemTargetReferenceCache) { if (!this.typedSystemTargetReferenceCache.TryGetValue(key, out cache)) { cache = new Dictionary <SiloAddress, ISystemTarget>(); this.typedSystemTargetReferenceCache[key] = cache; } } ISystemTarget reference; lock (cache) { if (!cache.TryGetValue(destination, out reference)) { reference = this.Cast <TGrainInterface>(GrainReference.FromGrainId(grainId, this.GrainReferenceRuntime, null, destination)); cache[destination] = reference; // Store for next time } } return((TGrainInterface)reference); }
internal IAddressable MakeGrainReferenceFromType(Type interfaceType, GrainId grainId) { var typeInfo = interfaceType.GetTypeInfo(); return(GrainReference.FromGrainId( grainId, typeInfo.IsGenericType ? TypeUtils.GenericTypeArgsString(typeInfo.UnderlyingSystemType.FullName) : null)); }
public object CreateGrainReference(Type interfaceType, GrainId grainId) { var untypedGrainReference = GrainReference.FromGrainId( grainId, this.grainReferenceRuntime, interfaceType.IsGenericType ? TypeUtils.GenericTypeArgsString(interfaceType.UnderlyingSystemType.FullName) : null); return(this.Cast(untypedGrainReference, interfaceType)); }
private ReminderEntry NewReminderEntry() { Guid guid = Guid.NewGuid(); return(new ReminderEntry { GrainRef = GrainReference.FromGrainId(GrainId.NewId()), ReminderName = string.Format("TestReminder.{0}", guid), Period = TimeSpan.FromSeconds(5), StartAt = DateTime.UtcNow }); }
private static IAddressable _MakeGrainReference( Func <int, GrainId> getGrainId, Type interfaceType, string grainClassNamePrefix = null) { CheckRuntimeEnvironmentSetup(); if (!CodeGeneration.GrainInterfaceData.IsGrainType(interfaceType)) { throw new ArgumentException("Cannot fabricate grain-reference for non-grain type: " + interfaceType.FullName); } GrainId grainId = getGrainId(GetImplementationTypeCode(interfaceType, grainClassNamePrefix)); return(GrainReference.FromGrainId(grainId, interfaceType.IsGenericType ? interfaceType.UnderlyingSystemType.FullName : null)); }
internal static IAddressable MakeGrainReference_FromType( Func <GrainClassData, GrainId> getGrainId, Type interfaceType, string grainClassNamePrefix = null) { CheckRuntimeEnvironmentSetup(); if (!GrainInterfaceData.IsGrainType(interfaceType)) { throw new ArgumentException("Cannot fabricate grain-reference for non-grain type: " + interfaceType.FullName); } var implementation = TypeCodeMapper.GetImplementation(interfaceType, grainClassNamePrefix); GrainId grainId = getGrainId(implementation); return(GrainReference.FromGrainId(grainId, interfaceType.IsGenericType ? interfaceType.UnderlyingSystemType.FullName : null)); }
public void Store_Delete() { string name = Guid.NewGuid().ToString();//TestContext.TestName; ILocalDataStore store = new HierarchicalKeyStore(2); GrainReference reference = GrainReference.FromGrainId(GrainId.NewId()); var data = TestStoreGrainState.NewRandomState(); output.WriteLine("Using store = {0}", store.GetType().FullName); Stopwatch sw = new Stopwatch(); var keys = GetKeys(name, reference); sw.Restart(); string eTag = store.WriteRow(keys, AsDictionary(data.State), null); output.WriteLine("Write returned Etag={0} after {1} {2}", eTag, sw.Elapsed, StorageProviderUtils.PrintOneWrite(keys, data, eTag)); sw.Restart(); var storedData = store.ReadRow(keys); output.WriteLine("Read returned {0} after {1}", StorageProviderUtils.PrintOneWrite(keys, storedData, eTag), sw.Elapsed); Assert.NotNull(data); // Should get some data from Read sw.Restart(); bool ok = store.DeleteRow(keys, eTag); Assert.True(ok, $"Row deleted OK after {sw.Elapsed}. Etag={eTag} Keys={StorageProviderUtils.PrintKeys(keys)}"); sw.Restart(); storedData = store.ReadRow(keys); // Try to re-read after delete output.WriteLine("Re-Read took {0} and returned {1}", sw.Elapsed, StorageProviderUtils.PrintData(storedData)); Assert.NotNull(data); // Should not get null data from Re-Read Assert.True(storedData.Count == 0, $"Should get no data from Re-Read but got: {StorageProviderUtils.PrintData(storedData)}"); sw.Restart(); const string oldEtag = null; eTag = store.WriteRow(keys, storedData, oldEtag); output.WriteLine("Write for Keys={0} Etag={1} Data={2} returned New Etag={3} after {4}", StorageProviderUtils.PrintKeys(keys), oldEtag, StorageProviderUtils.PrintData(storedData), eTag, sw.Elapsed); sw.Restart(); ok = store.DeleteRow(keys, eTag); Assert.True(ok, $"Row deleted OK after {sw.Elapsed}. Etag={eTag} Keys={StorageProviderUtils.PrintKeys(keys)}"); }
public async Task <GrainReference> CreateObjectReference(IAddressable obj, IGrainMethodInvoker invoker) { if (obj is GrainReference) { throw new ArgumentException("Argument obj is already a grain reference."); } GrainId target = GrainId.NewClientAddressableGrainId(); await transport.RegisterObserver(target); lock (localObjects) { localObjects.Add(target, new LocalObjectData(obj, target, invoker)); } return(GrainReference.FromGrainId(target)); }
public void GrainReference_Interning_Sys_DirectoryGrain() { var g1 = GrainReference.FromGrainId(Constants.DirectoryServiceId, null); var g2 = GrainReference.FromGrainId(Constants.DirectoryServiceId, 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); }