public void ResetChunkedDoesNothingIfEntryDoesNotExist() { // given var keyOne = new BeaconKey(1, 0); var keyTwo = new BeaconKey(666, 0); var target = new BeaconCache(logger); target.AddActionData(keyOne, 1000L, "a"); target.AddActionData(keyOne, 1001L, "iii"); target.AddEventData(keyOne, 1000L, "b"); target.AddEventData(keyOne, 1001L, "jjj"); target.PrepareDataForSending(keyOne); // do same step we'd do when we send the target.GetNextBeaconChunk(keyOne, "prefix", 10, '&'); // data has been copied, but still add some new event & action data target.AddActionData(keyOne, 6666L, "123"); target.AddEventData(keyOne, 6666L, "987"); var notifyCount = 0; target.RecordAdded += (s, a) => { notifyCount += 1; }; // and when resetting the previously copied data target.ResetChunkedData(keyTwo); // then Assert.That(target.NumBytesInCache, Is.EqualTo(12L)); Assert.That(notifyCount, Is.EqualTo(0)); }
public void RemoveChunkedDataDoesNothingIfCalledWithNonExistingBeaconId() { // given var keyOne = new BeaconKey(1, 0); var keyTwo = new BeaconKey(42, 0); var target = new BeaconCache(logger); target.AddActionData(keyOne, 1000L, "a"); target.AddActionData(keyOne, 1001L, "iii"); target.AddActionData(keyTwo, 2000L, "z"); target.AddEventData(keyOne, 1000L, "b"); target.AddEventData(keyOne, 1001L, "jjj"); target.PrepareDataForSending(keyOne); // when retrieving the first chunk and removing the wrong beacon chunk target.GetNextBeaconChunk(keyOne, "prefix", 10, '&'); target.RemoveChunkedData(keyTwo); // then Assert.That(target.GetActionsBeingSent(keyOne), Is.EqualTo(new[] { new BeaconCacheRecord(1000L, "a"), new BeaconCacheRecord(1001L, "iii") })); var expectedEventRecords = new[] { new BeaconCacheRecord(1000L, "b"), new BeaconCacheRecord(1001L, "jjj") }; foreach (var record in expectedEventRecords) { record.MarkForSending(); } Assert.That(target.GetEventsBeingSent(keyOne), Is.EqualTo(expectedEventRecords)); }
public void GetNextBeaconChunkRetrievesNextChunk() { // given var keyOne = new BeaconKey(1, 0); var keyTwo = new BeaconKey(42, 0); var target = new BeaconCache(logger); target.AddActionData(keyOne, 1000L, "a"); target.AddActionData(keyOne, 1001L, "iii"); target.AddActionData(keyTwo, 2000L, "z"); target.AddEventData(keyOne, 1000L, "b"); target.AddEventData(keyOne, 1001L, "jjj"); target.PrepareDataForSending(keyOne); // when retrieving the first chunk var obtained = target.GetNextBeaconChunk(keyOne, "prefix", 10, '&'); // then Assert.That(obtained, Is.EqualTo("prefix&b&jjj")); // then Assert.That(target.GetActionsBeingSent(keyOne), Is.EqualTo(new[] { new BeaconCacheRecord(1000L, "a"), new BeaconCacheRecord(1001L, "iii") })); var expectedEventRecords = new[] { new BeaconCacheRecord(1000L, "b"), new BeaconCacheRecord(1001L, "jjj") }; foreach (var record in expectedEventRecords) { record.MarkForSending(); } Assert.That(target.GetEventsBeingSent(keyOne), Is.EqualTo(expectedEventRecords)); }
public void IsEmptyGivesTrueIfBeaconDoesNotContainActiveData() { // given var key = new BeaconKey(1, 0); var target = new BeaconCache(logger); target.AddActionData(key, 1000L, "a"); target.AddEventData(key, 1000L, "b"); target.PrepareDataForSending(key); target.GetNextBeaconChunk(key, "prefix", 0, '&'); // then Assert.That(target.IsEmpty(key), Is.True); }
public void GetNextBeaconChunkDecreasesBeaconCacheSize() { // given var keyOne = new BeaconKey(1, 0); var keyTwo = new BeaconKey(42, 0); var target = new BeaconCache(logger); target.AddActionData(keyOne, 1000L, "a"); target.AddActionData(keyOne, 1001L, "iii"); target.AddActionData(keyTwo, 2000L, "z"); target.AddEventData(keyOne, 1000L, "b"); target.AddEventData(keyOne, 1001L, "jjj"); target.PrepareDataForSending(keyOne); // when target.GetNextBeaconChunk(keyOne, "prefix", 0, '&'); // cache stats are also adjusted Assert.That(target.NumBytesInCache, Is.EqualTo(new BeaconCacheRecord(2000L, "z").DataSizeInBytes)); }
public void RemoveChunkedDataClearsAlreadyRetrievedChunks() { // given var keyOne = new BeaconKey(1, 0); var keyTwo = new BeaconKey(42, 0); var target = new BeaconCache(logger); target.AddActionData(keyOne, 1000L, "a"); target.AddActionData(keyOne, 1001L, "iii"); target.AddActionData(keyTwo, 2000L, "z"); target.AddEventData(keyOne, 1000L, "b"); target.AddEventData(keyOne, 1001L, "jjj"); target.PrepareDataForSending(keyOne); // when retrieving the first chunk and removing retrieved chunks var obtained = target.GetNextBeaconChunk(keyOne, "prefix", 10, '&'); target.RemoveChunkedData(keyOne); // then Assert.That(obtained, Is.EqualTo("prefix&b&jjj")); Assert.That(target.GetActionsBeingSent(keyOne), Is.EqualTo(new[] { new BeaconCacheRecord(1000L, "a"), new BeaconCacheRecord(1001L, "iii") })); Assert.That(target.GetEventsBeingSent(keyOne), Is.Empty); // when retrieving the second chunk and removing retrieved chunks obtained = target.GetNextBeaconChunk(keyOne, "prefix", 10, '&'); target.RemoveChunkedData(keyOne); // then Assert.That(obtained, Is.EqualTo("prefix&a&iii")); Assert.That(target.GetActionsBeingSent(keyOne), Is.Empty); Assert.That(target.GetEventsBeingSent(keyOne), Is.Empty); }