FSTMockDatastore.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import "Firestore/Source/Remote/FSTDatastore.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. @interface FSTMockDatastore : FSTDatastore
  20. /**
  21. * A count of the total number of requests sent to the watch stream since the beginning of the test
  22. * case.
  23. */
  24. @property(nonatomic) int watchStreamRequestCount;
  25. /**
  26. * A count of the total number of requests sent to the write stream since the beginning of the test
  27. * case.
  28. */
  29. @property(nonatomic) int writeStreamRequestCount;
  30. #pragma mark - Watch Stream manipulation.
  31. /** Injects an Added WatchChange containing the given targetIDs. */
  32. - (void)writeWatchTargetAddedWithTargetIDs:(NSArray<FSTBoxedTargetID *> *)targetIDs;
  33. /** Injects an Added WatchChange that marks the given targetIDs current. */
  34. - (void)writeWatchCurrentWithTargetIDs:(NSArray<FSTBoxedTargetID *> *)targetIDs
  35. snapshotVersion:(FSTSnapshotVersion *)snapshotVersion
  36. resumeToken:(NSData *)resumeToken;
  37. /** Injects a WatchChange as though it had come from the backend. */
  38. - (void)writeWatchChange:(FSTWatchChange *)change snapshotVersion:(FSTSnapshotVersion *)snap;
  39. /** Injects a stream failure as though it had come from the backend. */
  40. - (void)failWatchStreamWithError:(NSError *)error;
  41. /** Returns the set of active targets on the watch stream. */
  42. - (NSDictionary<FSTBoxedTargetID *, FSTQueryData *> *)activeTargets;
  43. /** Helper method to expose watch stream state to verify in tests. */
  44. - (BOOL)isWatchStreamOpen;
  45. #pragma mark - Write Stream manipulation.
  46. /**
  47. * Returns the next write that was "sent to the backend", failing if there are no queued sent
  48. */
  49. - (NSArray<FSTMutation *> *)nextSentWrite;
  50. /** Returns the number of writes that have been sent to the backend but not waited on yet. */
  51. - (int)writesSent;
  52. /** Injects a write ack as though it had come from the backend in response to a write. */
  53. - (void)ackWriteWithVersion:(FSTSnapshotVersion *)commitVersion
  54. mutationResults:(NSArray<FSTMutationResult *> *)results;
  55. /** Injects a stream failure as though it had come from the backend. */
  56. - (void)failWriteWithError:(NSError *_Nullable)error;
  57. @end
  58. NS_ASSUME_NONNULL_END