public void RemoveRecordsOlderThanRemovesRecordsFromActionData()
        {
            // given
            var dataOne   = new BeaconCacheRecord(4000L, "One");
            var dataTwo   = new BeaconCacheRecord(3000L, "Two");
            var dataThree = new BeaconCacheRecord(2000L, "Three");
            var dataFour  = new BeaconCacheRecord(1000L, "Four");

            var target = new BeaconCacheEntry();

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

            // when removing everything older than 3000
            var obtained = target.RemoveRecordsOlderThan(dataTwo.Timestamp);

            // then
            Assert.That(obtained, Is.EqualTo(2)); // two were removed
            Assert.That(target.ActionData, Is.EqualTo(new[] { dataOne, dataTwo }));
        }
        public void RemoveOldestRecordsRemovesActionDataIfEventDataIsEmpty()
        {
            // given
            var dataOne   = new BeaconCacheRecord(4000L, "One");
            var dataTwo   = new BeaconCacheRecord(3000L, "Two");
            var dataThree = new BeaconCacheRecord(2000L, "Three");
            var dataFour  = new BeaconCacheRecord(1000L, "Four");

            var target = new BeaconCacheEntry();

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

            // when
            var obtained = target.RemoveOldestRecords(2);

            // then
            Assert.That(obtained, Is.EqualTo(2)); // two were removed
            Assert.That(target.ActionData, Is.EqualTo(new[] { dataThree, dataFour }));
        }
Exemple #3
0
        public void GetTotalNumberOfBytesCountsAddedRecordBytes()
        {
            // 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();

            // when getting total number of bytes on an empty entry, then
            Assert.That(target.TotalNumBytes, Is.EqualTo(0L));

            // and when adding first entry
            target.AddActionData(dataOne);

            // then
            Assert.That(target.TotalNumBytes, Is.EqualTo(dataOne.DataSizeInBytes));

            // and when adding next entry
            target.AddEventData(dataTwo);

            // then
            Assert.That(target.TotalNumBytes, Is.EqualTo(dataOne.DataSizeInBytes + dataTwo.DataSizeInBytes));

            // and when adding next entry
            target.AddEventData(dataThree);

            // then
            Assert.That(target.TotalNumBytes, Is.EqualTo(dataOne.DataSizeInBytes + dataTwo.DataSizeInBytes + dataThree.DataSizeInBytes));

            // and when adding next entry
            target.AddActionData(dataFour);

            // Assert.That
            Assert.That(target.TotalNumBytes, Is.EqualTo(dataOne.DataSizeInBytes + dataTwo.DataSizeInBytes
                                                         + dataThree.DataSizeInBytes + dataFour.DataSizeInBytes));
        }
Exemple #4
0
        public void RemoveOldestRecordsRemovesEventDataIfTopEventDataAndActionDataHaveSameTimestamp()
        {
            // given
            var dataOne   = new BeaconCacheRecord(1000, "One");
            var dataTwo   = new BeaconCacheRecord(1100L, "Two");
            var dataThree = new BeaconCacheRecord(dataOne.Timestamp, "Three");
            var dataFour  = new BeaconCacheRecord(dataTwo.Timestamp, "Four");

            var target = new BeaconCacheEntry();

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

            // when
            var obtained = target.RemoveOldestRecords(1);

            // then
            Assert.That(obtained, Is.EqualTo(1));
            Assert.That(target.ActionData, Is.EqualTo(new[] { dataThree, dataFour }));
            Assert.That(target.EventData, Is.EqualTo(new[] { dataTwo }));
        }
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);
        }
Exemple #6
0
        public void CopyDataForSendingMovesData()
        {
            // 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);

            // when copying data for later chunking
            target.CopyDataForSending();

            // then the data was moved
            Assert.That(target.EventDataBeingSent, Is.EqualTo(new[] { dataOne, dataFour }));
            Assert.That(target.ActionDataBeingSent, Is.EqualTo(new[] { dataTwo, dataThree }));
            Assert.That(target.EventData, Is.Empty);
            Assert.That(target.ActionData, Is.Empty);
        }
Exemple #7
0
        public void ResetDataMarkedForSendingReturnsIfDataHasNotBeenCopied()
        {
            // 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);

            // when
            target.ResetDataMarkedForSending();

            // then
            Assert.That(target.EventData, Is.EqualTo(new[] { dataOne, dataFour }));
            Assert.That(target.ActionData, Is.EqualTo(new[] { dataTwo, dataThree }));
            Assert.That(target.EventDataBeingSent, Is.Null);
            Assert.That(target.ActionDataBeingSent, Is.Null);
        }
Exemple #8
0
        public void HasDataForSendingReturnsTrueIfActionDataWasAddedBeforeCopying()
        {
            // given
            var record = new BeaconCacheRecord(1000L, "One");

            var target = new BeaconCacheEntry();

            target.AddActionData(record);

            target.CopyDataForSending();

            // when
            var obtained = target.HasDataToSend;

            // then
            Assert.That(obtained, Is.True);
        }