public void UpdateData_should_return_success_if_get_update_set_data_are_successful() { const string path = "zk/default"; var bytes = new byte[] { 0, 1, 1, 2, 3, 5, 8, 13 }; zooKeeperClient.GetDataAsync(Arg.Any <GetDataRequest>()) .Returns(GetDataResult.Successful(path, bytes, Stat)); zooKeeperClient.SetDataAsync(Arg.Any <SetDataRequest>()).Returns(SetDataResult.Successful(path, Stat)); zooKeeperClient.UpdateData(new UpdateDataRequest(path, dummyUpdate)) .Should() .BeEquivalentTo(UpdateDataResult.Successful(path)); }
public void UpdateData_should_return_false_after_one_attempt_if_set_data_fails(ZooKeeperStatus failFastStatus) { const string path = "zk/default"; var bytes = new byte[] { 0, 1, 1, 2, 3, 5, 8, 13 }; zooKeeperClient.GetDataAsync(Arg.Any <GetDataRequest>()) .Returns(GetDataResult.Successful(path, bytes, Stat)); zooKeeperClient.SetDataAsync(Arg.Any <SetDataRequest>()) .Returns(SetDataResult.Unsuccessful(failFastStatus, path, null)); zooKeeperClient.UpdateData(new UpdateDataRequest(path, dummyUpdate)) .Should() .BeEquivalentTo(UpdateDataResult.Unsuccessful(failFastStatus, path, null)); zooKeeperClient.ReceivedWithAnyArgs(1).SetDataAsync(Arg.Any <SetDataRequest>()); }
public void UpdateData_should_make_all_attempts_to_set_data_and_return_fail() { const string path = "zk/default"; const int attempts = 10; var bytes = new byte[] { 0, 1, 1, 2, 3, 5, 8, 13 }; zooKeeperClient.GetDataAsync(Arg.Any <GetDataRequest>()) .Returns(GetDataResult.Successful(path, bytes, Stat)); zooKeeperClient.SetDataAsync(Arg.Any <SetDataRequest>()) .Returns(SetDataResult.Unsuccessful(ZooKeeperStatus.VersionsMismatch, path, null)); zooKeeperClient.UpdateData(new UpdateDataRequest(path, dummyUpdate) { Attempts = attempts }) .Should() .BeEquivalentTo(UpdateDataResult.Unsuccessful(ZooKeeperStatus.VersionsMismatch, path, null)); zooKeeperClient.ReceivedWithAnyArgs(attempts) .SetDataAsync(Arg.Any <SetDataRequest>()); }
public void UpdateData_should_not_apply_update_when_bytes_not_changed() { const string path = "zk/default"; const int attempts = 10; var bytes = new byte[] { 0, 1, 1, 2, 3, 5, 8, 13 }; var updatedBytes = new byte[] { 0, 1, 1, 2, 3, 5, 8, 13 }; byte[] UpdateFunc(byte[] oldBytes) => updatedBytes; zooKeeperClient.GetDataAsync(Arg.Any <GetDataRequest>()) .Returns(GetDataResult.Successful(path, bytes, Stat)); zooKeeperClient.UpdateData(new UpdateDataRequest(path, UpdateFunc) { Attempts = attempts }) .Should().BeEquivalentTo(UpdateDataResult.Successful(path)); zooKeeperClient .DidNotReceiveWithAnyArgs() .SetDataAsync(Arg.Any <SetDataRequest>()); }
public void UpdateData_should_apply_update_func_to_bytes() { const string path = "zk/default"; const int attempts = 10; var bytes = new byte[] { 0, 1, 1, 2, 3, 5, 8, 13 }; var updatedBytes = new byte[] { 3, 1, 4, 2 }; byte[] UpdateFunc(byte[] oldBytes) => updatedBytes; zooKeeperClient.GetDataAsync(Arg.Any <GetDataRequest>()) .Returns(GetDataResult.Successful(path, bytes, Stat)); zooKeeperClient.SetDataAsync(Arg.Any <SetDataRequest>()) .Returns(SetDataResult.Unsuccessful(ZooKeeperStatus.VersionsMismatch, path, null)); zooKeeperClient.UpdateData(new UpdateDataRequest(path, UpdateFunc) { Attempts = attempts }); zooKeeperClient.Received(attempts) .SetDataAsync(Arg.Is <SetDataRequest>(sendReq => sendReq.Data.Equals(updatedBytes))); }