Beispiel #1
0
        public void ID_Intern_FindOrCreate_derived_class()
        {
            Interner<int, A> interner = new Interner<int, A>();
            var obj1 = new A();
            var obj2 = new B();
            var obj3 = new B();

            var r1 = interner.FindOrCreate(1, () => obj1);
            Assert.AreEqual(obj1, r1, "Objects should be equal");
            Assert.AreSame(obj1, r1, "Objects should be same / intern'ed");

            var r2 = interner.FindOrCreate(2, () => obj2);
            Assert.AreEqual(obj2, r2, "Objects should be equal");
            Assert.AreSame(obj2, r2, "Objects should be same / intern'ed");

            // FindOrCreate should not replace instances of same class
            var r3 = interner.FindOrCreate(2, () => obj3);
            Assert.AreSame(obj2, r3, "FindOrCreate should return previous object");
            Assert.AreNotSame(obj3, r3, "FindOrCreate should not replace previous object of same class");

            // FindOrCreate should not replace cached instances with instances of most derived class
            var r4 = interner.FindOrCreate(1, () => obj2);
            Assert.AreSame(obj1, r4, "FindOrCreate return previously cached object");
            Assert.AreNotSame(obj2, r4, "FindOrCreate should not replace previously cached object");

            // FindOrCreate should not replace cached instances with instances of less derived class
            var r5 = interner.FindOrCreate(2, () => obj1);
            Assert.AreNotSame(obj1, r5, "FindOrCreate should not replace previously cached object");
            Assert.AreSame(obj2, r5, "FindOrCreate return previously cached object");
        }
Beispiel #2
0
 private static ActivationId FindOrCreate(UniqueKey key)
 {
     return(interner.FindOrCreate(key, k => new ActivationId(k)));
 }
Beispiel #3
0
        internal static LegacyStreamId GetStreamId(Guid guid, string providerName, string streamNamespace)
        {
            var key = new StreamIdInternerKey(guid, providerName, streamNamespace);

            return(streamIdInternCache.FindOrCreate(key, k => new LegacyStreamId(k)));
        }
Beispiel #4
0
        public void ID_Interning_string_equals()
        {
            Interner<string, string> interner = new Interner<string, string>();
            const string str = "1";
            string r1 = interner.FindOrCreate("1", () => str);
            string r2 = interner.FindOrCreate("1", () => null); // Should always be found

            Assert.AreEqual(r1, r2, "1: Objects should be equal");
            Assert.AreSame(r1, r2, "2: Objects should be same / intern'ed");

            // Round-trip through Serializer
            string r3 = (string) SerializationManager.RoundTripSerializationForTesting(r1);

            Assert.AreEqual(r1, r3, "3: Should be equal");
            Assert.AreEqual(r2, r3, "4: Should be equal");
        }
Beispiel #5
0
 /// <summary>
 /// Factory for creating new SiloAddresses with specified IP endpoint address and silo generation number.
 /// </summary>
 /// <param name="ep">IP endpoint address of the silo.</param>
 /// <param name="gen">Generation number of the silo.</param>
 /// <returns>SiloAddress object initialized with specified address and silo generation.</returns>
 public static SiloAddress New(IPEndPoint ep, int gen)
 {
     return(siloAddressInterningCache.FindOrCreate(new Key(ep, gen), k => new SiloAddress(k.Endpoint, k.Generation)));
 }
Beispiel #6
0
 /// <summary>
 /// Returns a <see cref="GuidId"/> instance corresponding to the provided <see cref="Guid"/>.
 /// </summary>
 /// <param name="guid">The <see cref="Guid"/>.</param>
 /// <returns>A <see cref="GuidId"/> instance corresponding to the provided <see cref="Guid"/>.</returns>
 private static GuidId FindOrCreateGuidId(Guid guid)
 {
     return(guidIdInternCache.FindOrCreate(guid, g => new GuidId(g)));
 }
Beispiel #7
0
 internal static ActivationId GetActivationId(UniqueKey key)
 {
     return(legacyKeyInterner.FindOrCreate(key, k => new ActivationId(k)));
 }
Beispiel #8
0
 private static LegacyGrainId FindOrCreateGrainId(UniqueKey key)
 {
     return(grainIdInternCache.FindOrCreate(key, k => new LegacyGrainId(k)));
 }
Beispiel #9
0
 private IdSpan GetGrainKey()
 {
     return(new IdSpan(grainKeyInternCache.FindOrCreate(Key, k => Encoding.UTF8.GetBytes($"{k.N0:X16}{k.N1:X16}{(k.HasKeyExt ? "+" : null)}{k.KeyExt}"))));
 }