Ejemplo n.º 1
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.º 2
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
            }
        }