コード例 #1
0
        public static void verify(List <UserRecord> original, KinesisRecord kr)
        {
            AggregatedRecord ar = null;

            verify_format(original, kr, ref ar);
            verify_content(original, ar);
        }
コード例 #2
0
 public KinesisRecord()
 {
     unchecked
     {
         kMagic = new byte[] { (byte)-13, (byte)-119, (byte)-102, (byte)-62 };
     }
     estimated_size             = 0;
     cached_accurate_size       = 0;
     cached_accurate_size_valid = false;
     explicit_hash_keys         = new KeySet();
     partition_keys             = new KeySet();
     aggregated_record          = new AggregatedRecord();
 }
コード例 #3
0
        public static void verify_content(List <UserRecord> original, AggregatedRecord result)
        {
            // verify record count
            Assert.AreEqual(original.Count, result.Records.Count);

            for (int i = 0; i < result.Records.Count; i++)
            {
                var r = result.Records[i];
                // verify partition key
                Assert.AreEqual(original[i].Partition_key(), result.PartitionKeyTable[(int)r.PartitionKeyIndex]);

                // verify explicit hash key
                if (original[i].explicit_hash_key().ToString() != "-1")
                {
                    Assert.AreEqual(original[i].explicit_hash_key().ToString(), result.ExplicitHashKeyTable[(int)r.ExplicitHashKeyIndex]);
                }

                // verify data
                Assert.AreEqual(original[i].Data(), r.Data);
            }
        }
コード例 #4
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()));
        }