public void TestSerializeTooLargeTagContext()
        {
            ITagContextBuilder builder = tagger.EmptyBuilder;

            for (int i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8 - 1; i++)
            {
                // Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
                String str;
                if (i < 10)
                {
                    str = "000" + i;
                }
                else if (i < 100)
                {
                    str = "00" + i;
                }
                else if (i < 1000)
                {
                    str = "0" + i;
                }
                else
                {
                    str = i.ToString();
                }
                builder.Put(TagKey.Create(str), TagValue.Create(str));
            }
            // The last tag will be of size 9, so the total size of the TagContext (8193) will be one byte
            // more than limit.
            builder.Put(TagKey.Create("last"), TagValue.Create("last1"));

            ITagContext tagContext = builder.Build();

            Assert.Throws <TagContextSerializationException>(() => serializer.ToByteArray(tagContext));
        }
        public void TestRoundtrip_TagContextWithMaximumSize()
        {
            ITagContextBuilder builder = tagger.EmptyBuilder;

            for (int i = 0; i < SerializationUtils.TagContextSerializedSizeLimit / 8; i++)
            {
                // Each tag will be with format {key : "0123", value : "0123"}, so the length of it is 8.
                // Add 1024 tags, the total size should just be 8192.
                String str;
                if (i < 10)
                {
                    str = "000" + i;
                }
                else if (i < 100)
                {
                    str = "00" + i;
                }
                else if (i < 1000)
                {
                    str = "0" + i;
                }
                else
                {
                    str = "" + i;
                }
                builder.Put(TagKey.Create(str), TagValue.Create(str));
            }
            TestRoundtripSerialization(builder.Build());
        }
        private void TestSerialize(params ITag[] tags)
        {
            ITagContextBuilder builder = tagger.EmptyBuilder;

            foreach (var tag in tags)
            {
                builder.Put(tag.Key, tag.Value);
            }

            byte[]        actual          = serializer.ToByteArray(builder.Build());
            var           tagsList        = tags.ToList();
            var           tagPermutation  = Permutate(tagsList, tagsList.Count);
            ISet <String> possibleOutPuts = new HashSet <String>();

            foreach (List <ITag> list in tagPermutation)
            {
                MemoryStream expected = new MemoryStream();
                expected.WriteByte(SerializationUtils.VersionId);
                foreach (ITag tag in list)
                {
                    expected.WriteByte(SerializationUtils.TagFieldId);
                    EncodeString(tag.Key.Name, expected);
                    EncodeString(tag.Value.AsString, expected);
                }
                var bytes = expected.ToArray();
                possibleOutPuts.Add(Encoding.UTF8.GetString(bytes));
            }
            var exp = Encoding.UTF8.GetString(actual);

            Assert.Contains(exp, possibleOutPuts);
        }
Exemplo n.º 4
0
        public void Put_NullValue()
        {
            TagContext tags = new TagContext(new Dictionary <ITagKey, ITagValue>()
            {
                { K1, V1 }
            });
            ITagContextBuilder builder = tagger.ToBuilder(tags);

            Assert.Throws <ArgumentNullException>(() => builder.Put(K2, null));
        }
Exemplo n.º 5
0
        public void NoopTagContextBuilder_Put_DisallowsNullValue()
        {
            ITagContextBuilder noopBuilder = NoopTags.NoopTagContextBuilder;

            Assert.Throws <ArgumentNullException>(() => noopBuilder.Put(KEY, null));
        }
Exemplo n.º 6
0
        public void NoopTagContextBuilder_Put_DisallowsNullKey()
        {
            ITagContextBuilder noopBuilder = NoopTags.NoopTagContextBuilder;

            Assert.Throws <ArgumentNullException>(() => noopBuilder.Put(null, VALUE));
        }