Exemple #1
0
        public void GetChunksTakesSizeIntoAccount()
        {
            // given
            var dataOne   = new BeaconCacheRecord(0L, "One");
            var dataTwo   = new BeaconCacheRecord(0L, "Two");
            var dataThree = new BeaconCacheRecord(1L, "Three");
            var dataFour  = new BeaconCacheRecord(1L, "Four");

            var target = new BeaconCacheEntry();

            target.AddEventData(dataOne);
            target.AddEventData(dataFour);
            target.AddActionData(dataTwo);
            target.AddActionData(dataThree);

            target.CopyDataForSending();

            // when requesting first chunk
            var obtained = target.GetChunk("prefix", 1, '&');

            // then only prefix is returned, since "prefix".length > maxSize (=1)
            Assert.That(obtained, Is.EqualTo("prefix"));

            // and when retrieving something which is one character longer than "prefix"
            obtained = target.GetChunk("prefix", "prefix".Length, '&');

            // then based on the algorithm prefix and first element are retrieved
            Assert.That(obtained, Is.EqualTo("prefix&One"));

            // and when retrieving another chunk
            obtained = target.GetChunk("prefix", "prefix&One".Length, '&');

            // then
            Assert.That(obtained, Is.EqualTo("prefix&One&Four"));
        }
Exemple #2
0
        public void GetChunkGetsChunksFromEventDataBeforeActionData()
        {
            // given
            var dataOne   = new BeaconCacheRecord(0L, "One");
            var dataTwo   = new BeaconCacheRecord(0L, "Two");
            var dataThree = new BeaconCacheRecord(1L, "Three");
            var dataFour  = new BeaconCacheRecord(1L, "Four");

            var target = new BeaconCacheEntry();

            target.AddEventData(dataOne);
            target.AddEventData(dataFour);
            target.AddActionData(dataTwo);
            target.AddActionData(dataThree);

            target.CopyDataForSending();

            // when getting data to send
            var obtained = target.GetChunk("a", 2, '&');

            // then it's the first event data
            Assert.That(obtained, Is.EqualTo("a&" + dataOne.Data));

            // and when removing already sent data and getting next chunk
            target.RemoveDataMarkedForSending();
            obtained = target.GetChunk("a", 2, '&');

            // then it's second event data
            Assert.That(obtained, Is.EqualTo("a&" + dataFour.Data));

            // and when removing already sent data and getting next chunk
            target.RemoveDataMarkedForSending();
            obtained = target.GetChunk("a", 2, '&');

            // then it's the first action data
            Assert.That(obtained, Is.EqualTo("a&" + dataTwo.Data));

            // and when removing already sent data and getting next chunk
            target.RemoveDataMarkedForSending();
            obtained = target.GetChunk("a", 2, '&');

            // then it's the second action data
            Assert.That(obtained, Is.EqualTo("a&" + dataThree.Data));

            // and when removing already sent data and getting next chunk
            target.RemoveDataMarkedForSending();
            obtained = target.GetChunk("a", 2, '&');

            // then we get an empty string, since all chunks were sent & deleted
            Assert.That(obtained, Is.Empty);
        }
Exemple #3
0
        public void ResetDataMarkedForSendingResetsMarkedForSendingFlag()
        {
            // given
            var dataOne   = new BeaconCacheRecord(0L, "One");
            var dataTwo   = new BeaconCacheRecord(0L, "Two");
            var dataThree = new BeaconCacheRecord(1L, "Three");
            var dataFour  = new BeaconCacheRecord(1L, "Four");

            var target = new BeaconCacheEntry();

            target.AddEventData(dataOne);
            target.AddEventData(dataFour);
            target.AddActionData(dataTwo);
            target.AddActionData(dataThree);

            target.CopyDataForSending();

            // when data is retrieved
            target.GetChunk("", 1024, '&');

            // then all records are marked for sending
            Assert.That(dataOne.IsMarkedForSending, Is.True);
            Assert.That(dataTwo.IsMarkedForSending, Is.True);
            Assert.That(dataThree.IsMarkedForSending, Is.True);
            Assert.That(dataFour.IsMarkedForSending, Is.True);

            // and when
            target.ResetDataMarkedForSending();

            // then
            Assert.That(dataOne.IsMarkedForSending, Is.False);
            Assert.That(dataTwo.IsMarkedForSending, Is.False);
            Assert.That(dataThree.IsMarkedForSending, Is.False);
            Assert.That(dataFour.IsMarkedForSending, Is.False);
        }
Exemple #4
0
        public void GetChunkMarksRetrievedData()
        {
            // given
            var dataOne   = new BeaconCacheRecord(0L, "One");
            var dataTwo   = new BeaconCacheRecord(0L, "Two");
            var dataThree = new BeaconCacheRecord(1L, "Three");
            var dataFour  = new BeaconCacheRecord(1L, "Four");

            var target = new BeaconCacheEntry();

            target.AddEventData(dataOne);
            target.AddEventData(dataFour);
            target.AddActionData(dataTwo);
            target.AddActionData(dataThree);

            target.CopyDataForSending();

            // when retrieving data
            var obtained = target.GetChunk("prefix", 1024, '&');

            // then
            Assert.That(obtained, Is.EqualTo("prefix&" + dataOne.Data + "&" + dataFour.Data + "&" + dataTwo.Data + "&" + dataThree.Data));
            // and all of them are marked
            Assert.That(dataOne.IsMarkedForSending, Is.True);
            Assert.That(dataTwo.IsMarkedForSending, Is.True);
            Assert.That(dataThree.IsMarkedForSending, Is.True);
            Assert.That(dataFour.IsMarkedForSending, Is.True);
        }
Exemple #5
0
        public void GetChunkGetsAlreadyMarkedData()
        {
            // given
            var dataOne   = new BeaconCacheRecord(0L, "One");
            var dataTwo   = new BeaconCacheRecord(0L, "Two");
            var dataThree = new BeaconCacheRecord(1L, "Three");
            var dataFour  = new BeaconCacheRecord(1L, "Four");

            var target = new BeaconCacheEntry();

            target.AddEventData(dataOne);
            target.AddEventData(dataFour);
            target.AddActionData(dataTwo);
            target.AddActionData(dataThree);

            target.CopyDataForSending();

            // when getting data to send
            var obtained = target.GetChunk("a", 100, '&');

            // then
            Assert.That(obtained, Is.EqualTo("a&One&Four&Two&Three"));
            Assert.That(dataOne.IsMarkedForSending, Is.True);
            Assert.That(dataTwo.IsMarkedForSending, Is.True);
            Assert.That(dataThree.IsMarkedForSending, Is.True);
            Assert.That(dataFour.IsMarkedForSending, Is.True);

            // when getting data to send once more
            obtained = target.GetChunk("a", 100, '&');

            // then
            Assert.That(obtained, Is.EqualTo("a&One&Four&Two&Three"));
            Assert.That(dataOne.IsMarkedForSending, Is.True);
            Assert.That(dataTwo.IsMarkedForSending, Is.True);
            Assert.That(dataThree.IsMarkedForSending, Is.True);
            Assert.That(dataFour.IsMarkedForSending, Is.True);
        }