public void GetLastIdReturnsMaxMessageId() { var store = new InProcessMessageStore(garbageCollectMessages: false); store.Save("a", "1").Wait(); store.Save("a", "2").Wait(); store.Save("a", "3").Wait(); Assert.Equal("3", store.GetLastId().Result); }
public void ReturnsNoMessagesWhenLastMessageIdIsEqualToLastMessage() { // id = 27 // 24, 25, 27 // ^ var store = new InProcessMessageStore(false); store.Save("foo", "1").Wait(); store.Save("foo", "2").Wait(); var result = store.GetAllSince(new[] { "foo" }, "2").Result.ToList(); Assert.Equal(0, result.Count); }
public void GetAllSinceReturnsAllMessagesAfterIdOrderedById() { var store = new InProcessMessageStore(garbageCollectMessages: false); store.Save("a", "1").Wait(); store.Save("a", "2").Wait(); store.Save("a", "3").Wait(); var messages = store.GetAllSince("a", 1).Result.ToList(); Assert.Equal(2, messages.Count); Assert.Equal("2", messages[0].Value); Assert.Equal("3", messages[1].Value); }
public Task Save(string key, object value) { // Save it locally then broadcast to other peers return(GetMessageId(key) .Success(idTask => { var message = new Message(key, idTask.Result, value); return Task.Factory.ContinueWhenAll(new[] { _store.Save(message), SendMessageToPeers(message) }, _ => { }); }) .Unwrap()); }
public void ReturnsNoMessagesWhenLastMessageIdIsOnlyMessage() { // id = 27 // 27 // ^ var store = new InProcessMessageStore(false); store.Save("bar", "1").Wait(); store.Save("foo", "2").Wait(); var result = store.GetAllSince(new[] { "foo" }, "2").Result.ToList(); Assert.Equal(0, result.Count); }
public void ReturnsAllMessagesWhenLastMessageIdIsLessThanAllMessages() { // id = 27 // _, 28, 29, 32 // ^ var store = new InProcessMessageStore(false); store.Save("bar", "1").Wait(); store.Save("bar", "2").Wait(); store.Save("foo", "3").Wait(); store.Save("foo", "4").Wait(); var result = store.GetAllSince(new[] { "foo" }, "1").Result.ToList(); Assert.Equal(2, result.Count); }
public void GetAllSinceReturnsAllMessagesIfIdGreaterThanMaxId() { var store = new InProcessMessageStore(garbageCollectMessages: false); for (int i = 0; i < 10; i++) { store.Save("a", i).Wait(); } var messages = store.GetAllSince("a", 100).Result.ToList(); Assert.Equal(10, messages.Count); for (int i = 0; i < 10; i++) { Assert.Equal(i, messages[i].Value); } }
public void GetAllSinceReturnsAllMessagesIfIdGreaterThanMaxId() { var store = new InProcessMessageStore(garbageCollectMessages: false); for (int i = 0; i < 10; i++) { store.Save("a", i.ToString(CultureInfo.InvariantCulture)).Wait(); } var messages = store.GetAllSince("a", 100).Result.ToList(); Assert.Equal(10, messages.Count); for (int i = 0; i < 10; i++) { Assert.Equal(i, messages[i].Value); } }
public void ReturnsMessagesGreaterThanLastMessageIdWhenLastMessageIdNotInStore() { // id = 27 // 24, 25, 28, 30, 45 // ^ var store = new InProcessMessageStore(false); store.Save("bar", "1").Wait(); store.Save("foo", "2").Wait(); store.Save("bar", "3").Wait(); store.Save("foo", "4").Wait(); store.Save("bar", "5").Wait(); store.Save("foo", "6").Wait(); var result = store.GetAllSince(new[] { "foo" }, "3").Result.ToList(); Assert.Equal(2, result.Count); }
public void ReturnsNoMessagesWhenLastMessageIdIsGreaterThanAllMessages() { // id = 27 // 14, 18, 25, 26 // ^ var store = new InProcessMessageStore(false); store.Save("foo", "1").Wait(); store.Save("foo", "2").Wait(); store.Save("bar", "3").Wait(); store.Save("bar", "4").Wait(); var result = store.GetAllSince(new[] { "foo" }, "3").Result.ToList(); Assert.Equal(0, result.Count); }