Пример #1
0
        public void ForgetPayloadCopy_NotWrapped()
        {
            var names = new List <string> {
                "Kozloff", "Sergeev", "Aroyan", "Gurevich"
            };

            var parcel = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), names);

            Assert.AreEqual(ParcelState.Creating, parcel.State);
            Assert.IsTrue(parcel.PayloadUnwrapped);
            Assert.IsFalse(parcel.HasWrappedPayload);

            parcel.Seal(FakeNOPBank.Instance);        //SEAL!!!!!!!!!!!!!!!!

            Assert.IsTrue(parcel.PayloadUnwrapped);
            Assert.IsFalse(parcel.HasWrappedPayload);

            parcel.ForgetPayloadCopy();        //FORGET!!!!!!!!!!!!!!!!!!!!

            Assert.IsFalse(parcel.PayloadUnwrapped);
            Assert.IsFalse(parcel.HasWrappedPayload);        //because NotWrapped mode

            //even after forget payload, i can get my payload back
            var payload = parcel.Payload;

            Assert.IsTrue(parcel.PayloadUnwrapped);
            Assert.IsFalse(parcel.HasWrappedPayload);        //because NotWrapped mode

            Assert.AreEqual(4, payload.Count);
            Assert.AreEqual("Kozloff", payload[0]);
            Assert.AreEqual("Sergeev", payload[1]);
            Assert.AreEqual("Aroyan", payload[2]);
            Assert.AreEqual("Gurevich", payload[3]);
        }
Пример #2
0
        public void Parcel_DeepClone_Benchmark_Parallel_NotWrapped()
        {
            const int CNT = 100000;

            var names = new List <string> {
                "Kozloff", "Sergeev", "Aroyan", "Gurevich"
            };
            var p1 = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), names);

            p1.Seal(FakeNOPBank.Instance);

            var sw = System.Diagnostics.Stopwatch.StartNew();

            System.Threading.Tasks.Parallel.For(0, CNT,
                                                (i) =>
            {
                var p2 = p1.DeepClone() as PeopleNamesParcel_NotWrapped;

                Assert.IsFalse(object.ReferenceEquals(p1, p2));
                Assert.IsFalse(object.ReferenceEquals(p1.Payload, p2.Payload));

                Assert.IsTrue(p1.Payload.Count == p2.Payload.Count);
                Assert.AreEqual(p1.GDID, p2.GDID);
            });
            sw.Stop();
            Console.WriteLine("NOTE: Core i7 x 6 cores 3.2Ghz 61000+ ops/sec on subsequent runs w/o optimization in non-server GC mode");
            Console.WriteLine("Cloned {0} times in {1} ms at {2} ops/sec", CNT, sw.ElapsedMilliseconds, CNT / (sw.ElapsedMilliseconds / 1000d));
        }
Пример #3
0
        public void StateError_5_NotWrapped()
        {
            var names = new List <string> {
                "Kozloff", "Sergeev", "NoAroyan", "Gurevich"
            };

            var parcel = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), names);

            Assert.AreEqual(ParcelState.Creating, parcel.State);
            Assert.AreEqual(true, parcel.PayloadUnwrapped);
            parcel.ForgetPayloadCopy();
        }
Пример #4
0
        public void StateError_2_NotWrapped()
        {
            var names = new List <string> {
                "Kozloff", "Sergeev", "Aroyan", "Gurevich"
            };

            var parcel = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), names);

            Assert.AreEqual(ParcelState.Creating, parcel.State);
            Assert.AreEqual(true, parcel.PayloadUnwrapped);
            parcel.Seal(FakeNOPBank.Instance);
            parcel.Validate(FakeNOPBank.Instance);
        }
Пример #5
0
        public void Parcel_DeepClone_2_Equals_ToString_NotWrapped()
        {
            var names = new List <string> {
                "Kozloff", "Sergeev", "Aroyan", "Gurevich"
            };
            var p1 = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), names);

            p1.Seal(FakeNOPBank.Instance);
            var p2 = p1.DeepClone() as PeopleNamesParcel_NotWrapped;

            Assert.IsFalse(object.ReferenceEquals(p1, p2));
            Assert.IsTrue(p1.Equals(p2));

            Console.WriteLine(p1.ToString());
        }
Пример #6
0
        public void Parcel_DeepClone_1_NotWrapped()
        {
            var names = new List <string> {
                "Kozloff", "Sergeev", "Aroyan", "Gurevich"
            };
            var p1 = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), names);

            p1.Seal(FakeNOPBank.Instance);
            var p2 = p1.DeepClone() as PeopleNamesParcel_NotWrapped;

            Assert.IsFalse(object.ReferenceEquals(p1, p2));
            Assert.IsFalse(object.ReferenceEquals(p1.Payload, p2.Payload));

            Assert.IsTrue(p1.Payload.SequenceEqual(p2.Payload));
            Assert.AreEqual(p1.GDID, p2.GDID);
        }
Пример #7
0
        public void Create_Seal_Wrap_NotWrapped()
        {
            var names = new List <string> {
                "Kozloff", "Sergeev", "Aroyan", "Gurevich"
            };

            var parcel = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), names);

            Assert.AreEqual(ParcelState.Creating, parcel.State);
            Assert.AreEqual(true, parcel.PayloadUnwrapped);
            parcel.Seal(FakeNOPBank.Instance);

            var buf = parcel.WrappedPayload;

            Assert.IsNull(buf);         //because NotWrapped mode
        }
Пример #8
0
        public void StateError_4_NotWrapped()
        {
            var names = new List <string> {
                "Kozloff", "Sergeev", "Aroyan", "Gurevich"
            };

            var parcel = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), names);

            Assert.AreEqual(ParcelState.Creating, parcel.State);
            Assert.AreEqual(true, parcel.PayloadUnwrapped);
            //not sealed
            var ser = new SlimSerializer(Parcel.STANDARD_KNOWN_SERIALIZER_TYPES);

            var ms = new MemoryStream();

            ser.Serialize(ms, parcel);    //can not serialize open parcel
        }
Пример #9
0
        public void FullLifecycle_NotWrapped()
        {
            var names = new List <string> {
                "Kozloff", "Sergeev", "Aroyan", "Gurevich"
            };

            var parcel = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), names);

            Assert.AreEqual(ParcelState.Creating, parcel.State);
            Assert.AreEqual(true, parcel.PayloadUnwrapped);
            parcel.Seal(FakeNOPBank.Instance);

            var ser = new SlimSerializer(Parcel.STANDARD_KNOWN_SERIALIZER_TYPES);

            var ms = new MemoryStream();

            ser.Serialize(ms, parcel);
            ms.Position = 0;
            var parcel2 = ser.Deserialize(ms) as PeopleNamesParcel_NotWrapped;

            Assert.IsNotNull(parcel2);

            Assert.IsFalse(parcel2.HasWrappedPayload);      //mode unwrapped
            parcel2.Open();                                 // no effect
            Assert.IsFalse(parcel2.HasWrappedPayload);      //mode unwrapped

            parcel2.Payload[1] = "Boyarskiy";
            parcel2.Seal(FakeNOPBank.Instance);

            ms.Position = 0;
            ser.Serialize(ms, parcel2);
            ms.Position = 0;
            var parcel3 = ser.Deserialize(ms) as PeopleNamesParcel_NotWrapped;

            Assert.IsTrue(new List <string> {
                "Kozloff", "Boyarskiy", "Aroyan", "Gurevich"
            }.SequenceEqual(parcel3.Payload));
        }
Пример #10
0
        public void Create_Seal_SerializeDeserialize_Read_NotWrapped()
        {
            var names = new List <string> {
                "Kozloff", "Sergeev", "Aroyan", "Gurevich"
            };

            var parcel = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), names);

            Assert.AreEqual(ParcelState.Creating, parcel.State);
            Assert.AreEqual(true, parcel.PayloadUnwrapped);
            parcel.Seal(FakeNOPBank.Instance);



            var ser = new SlimSerializer(Parcel.STANDARD_KNOWN_SERIALIZER_TYPES);

            var ms = new MemoryStream();

            ser.Serialize(ms, parcel);
            ms.Position = 0;
            var parcel2 = ser.Deserialize(ms) as PeopleNamesParcel_NotWrapped;

            Assert.IsNotNull(parcel2);
            Assert.IsFalse(parcel2.PayloadUnwrapped);
            Assert.IsFalse(parcel2.HasWrappedPayload);      //mode unwrapped
            var payload2 = parcel2.Payload;

            Assert.IsNotNull(payload2);
            Assert.IsTrue(parcel2.PayloadUnwrapped);

            Assert.IsFalse(parcel2.HasWrappedPayload); //mode unwrapped
            parcel2.ForgetWrappedPayloadCopy();        //no effect in wnwrapped mode
            Assert.IsFalse(parcel2.HasWrappedPayload);


            Assert.AreEqual(payload2.Count, names.Count);
            Assert.IsTrue(payload2.SequenceEqual(names));
        }
Пример #11
0
        public void StateError_3_NotWrapped()
        {
            var parcel = new PeopleNamesParcel_NotWrapped(new GDID(0, 123), null);

            parcel.Open();
        }