Ejemplo n.º 1
0
        public static void verify_unaggregated(UserRecord ur, KinesisRecord kr)
        {
            var serialized = kr.serialize();

            Assert.AreEqual(ur.Data().ToString(Encoding.Default), serialized);
            Assert.AreEqual(ur.Partition_key(), kr.partition_key());
            if (ur.explicit_hash_key().ToString() != "-1")
            {
                Assert.AreEqual(ur.explicit_hash_key().ToString(), kr.explicit_hash_key());
            }
            else
            {
                Assert.AreEqual(KPLNETInterface.Utils.GetDecimalHashKey(ur.Partition_key()).ToString(), kr.explicit_hash_key());
            }
        }
Ejemplo n.º 2
0
        public static void verify_format(List <UserRecord> original, KinesisRecord kr, ref AggregatedRecord container)
        {
            container = null;
            byte[] serialized = kr.SerializedAggregatedRecord;

            // verify magic number
            byte[] expected_magic = null;
            unchecked
            {
                expected_magic = new byte[] { (byte)-13, (byte)-119, (byte)-102, (byte)-62 };
            }
            int magic_len = expected_magic.Length;

            byte[] magic = serialized.Take(magic_len).ToArray();
            Assert.IsTrue(KPLNETInterface.Utils.AreArrayEqual(expected_magic, magic));

            // verify protobuf payload
            byte[] payload = serialized.Skip(expected_magic.Length).Take(serialized.Length - 16 - magic_len).ToArray();
            container = AggregatedRecord.Parser.ParseFrom(Google.Protobuf.ByteString.CopyFrom(payload));
            Assert.IsNotNull(container);

            // verify md5 checksum
            Assert.IsTrue(KPLNETInterface.Utils.AreArrayEqual(KPLNETInterface.Utils.GetMD5(payload), serialized.Skip(serialized.Length - 16).Take(16).ToArray()));

            // verify the explicit hash key set on the Kinesis record
            List <string> acceptable_hash_keys = new List <string>();

            foreach (var ur in original)
            {
                if (ur.explicit_hash_key() > -1)
                {
                    acceptable_hash_keys.Add(ur.explicit_hash_key().ToString());
                }
                else
                {
                    acceptable_hash_keys.Add(KPLNETInterface.Utils.GetDecimalHashKey(ur.Partition_key()).ToString());
                }
            }

            Assert.IsTrue(acceptable_hash_keys.Exists((i) => i == kr.explicit_hash_key()));
        }