FSTMockDatastore.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. + (instancetype)mockDatastoreWithWorkerDispatchQueue:(FSTDispatchQueue *)workerDispatchQueue;
  31. #pragma mark - Watch Stream manipulation.
  32. /** Injects an Added WatchChange containing the given targetIDs. */
  33. - (void)writeWatchTargetAddedWithTargetIDs:(NSArray<FSTBoxedTargetID *> *)targetIDs;
  34. /** Injects an Added WatchChange that marks the given targetIDs current. */
  35. - (void)writeWatchCurrentWithTargetIDs:(NSArray<FSTBoxedTargetID *> *)targetIDs
  36. snapshotVersion:(FSTSnapshotVersion *)snapshotVersion
  37. resumeToken:(NSData *)resumeToken;
  38. /** Injects a WatchChange as though it had come from the backend. */
  39. - (void)writeWatchChange:(FSTWatchChange *)change snapshotVersion:(FSTSnapshotVersion *)snap;
  40. /** Injects a stream failure as though it had come from the backend. */
  41. - (void)failWatchStreamWithError:(NSError *)error;
  42. /** Returns the set of active targets on the watch stream. */
  43. - (NSDictionary<FSTBoxedTargetID *, FSTQueryData *> *)activeTargets;
  44. /** Helper method to expose watch stream state to verify in tests. */
  45. - (BOOL)isWatchStreamOpen;
  46. #pragma mark - Write Stream manipulation.
  47. /**
  48. * Returns the next write that was "sent to the backend", failing if there are no queued sent
  49. */
  50. - (NSArray<FSTMutation *> *)nextSentWrite;
  51. /** Returns the number of writes that have been sent to the backend but not waited on yet. */
  52. - (int)writesSent;
  53. /** Injects a write ack as though it had come from the backend in response to a write. */
  54. - (void)ackWriteWithVersion:(FSTSnapshotVersion *)commitVersion
  55. mutationResults:(NSArray<FSTMutationResult *> *)results;
  56. /** Injects a stream failure as though it had come from the backend. */
  57. - (void)failWriteWithError:(NSError *_Nullable)error;
  58. @end
  59. NS_ASSUME_NONNULL_END