Ejemplo n.º 1
0
        public void KinesisRecordUnitTest_AccurateSize()
        {
            for (int i = 0; i < 100; i++)
            {
                KinesisRecord r           = new KinesisRecord();
                long          num_records = new Random().Next(1, 512);
                for (long j = 0; j < num_records; j++)
                {
                    int key_size  = new Random().Next(1, 256);
                    int data_size = new Random().Next(1, 64 * 1024);

                    var ur = TestUtil.make_user_record(new string('a', key_size),
                                                       new string('a', data_size),
                                                       new Random().Next() % 2 == 0 ? "" : "123");
                    r.add(ur);
                }
                int    predicted  = (int)r.accurate_size();
                string serialized = r.serialize();

                if (r.Items().Count > 1)
                {
                    Assert.AreEqual(predicted, serialized.Length - 16);
                }
                else
                {
                    Assert.AreEqual(predicted, serialized.Length);
                }
            }
        }
Ejemplo n.º 2
0
        public void KinesisRecordUnitTest_EstimatedSize()
        {
            for (int i = 0; i < 50; i++)
            {
                KinesisRecord r           = new KinesisRecord();
                int           num_records = new Random().Next(2, 512);

                // non repeated partition keys
                for (int j = 0; j < num_records; j++)
                {
                    int key_size  = new Random().Next(1, 256);
                    int data_size = new Random().Next(1, 64 * 1024);
                    var ur        = TestUtil.make_user_record(new string('a', key_size),
                                                              new string('a', data_size),
                                                              new Random().Next() % 2 == 0 ? "" : "123");
                    r.add(ur);
                }

                // repeated partition keys
                int key_size1 = new Random().Next(1, 256);
                for (long j = 0; j < num_records; j++)
                {
                    int data_size = new Random().Next(1, 64 * 1024);
                    var ur        = TestUtil.make_user_record(new string('a', key_size1),
                                                              new string('a', data_size),
                                                              new Random().Next() % 2 == 0 ? "" : "123");
                    r.add(ur);
                }

                // small keys small data
                for (long j = 0; j < num_records; j++)
                {
                    var ur = TestUtil.make_user_record(new string('a', 2),
                                                       new string('a', 2),
                                                       new Random().Next() % 2 == 0 ? "" : "123");
                    r.add(ur);
                }

                int    estimated  = (int)r.Estimated_size();
                string serialized = r.serialize();

                double diff            = (double)serialized.Length - estimated;
                double percentage_diff = diff / serialized.Length * 100;
                percentage_diff *= percentage_diff < 0 ? -1 : 1;

                StringBuilder ss = new StringBuilder();
                ss.Append("Estimated size should be within 1 percent or 32 bytes of actual ")
                .Append("size, estimate was ").Append(estimated).Append(", actual size was ")
                .Append(serialized.Length).Append(" (").Append(percentage_diff).Append("% difference)");
                //BOOST_CHECK_MESSAGE(percentage_diff < 1 || diff < 32, ss.ToString());
            }
        }
Ejemplo n.º 3
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.º 4
0
        public void KinesisRecordUnitTest_Empty()
        {
            KinesisRecord r = new KinesisRecord();

            Assert.AreEqual(0, (int)r.accurate_size());
            Assert.AreEqual(0, (int)r.Estimated_size());

            try
            {
                r.serialize();
                Assert.Fail("Calling serialize on empty KinesisRecord should cause exception");
            }
            catch (Exception e)
            {
                // expected
            }
        }