FSTIntegrationTestCase.mm 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /*
  2. * Copyright 2017 Google LLC
  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 "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
  17. #import <FirebaseFirestore/FIRCollectionReference.h>
  18. #import <FirebaseFirestore/FIRDocumentChange.h>
  19. #import <FirebaseFirestore/FIRDocumentReference.h>
  20. #import <FirebaseFirestore/FIRDocumentSnapshot.h>
  21. #import <FirebaseFirestore/FIRFirestore.h>
  22. #import <FirebaseFirestore/FIRFirestoreSettings.h>
  23. #import <FirebaseFirestore/FIRQuerySnapshot.h>
  24. #import <FirebaseFirestore/FIRSnapshotMetadata.h>
  25. #import <FirebaseFirestore/FIRTransaction.h>
  26. #include <memory>
  27. #include <string>
  28. #include <utility>
  29. #import "FirebaseCore/Extension/FIRAppInternal.h"
  30. #import "FirebaseCore/Extension/FIRLogger.h"
  31. #import "FirebaseCore/Extension/FIROptionsInternal.h"
  32. #import "Firestore/Example/Tests/Util/FIRFirestore+Testing.h"
  33. #import "Firestore/Example/Tests/Util/FSTEventAccumulator.h"
  34. #import "Firestore/Source/API/FIRFirestore+Internal.h"
  35. #include "Firestore/core/src/credentials/credentials_provider.h"
  36. #include "Firestore/core/src/credentials/empty_credentials_provider.h"
  37. #include "Firestore/core/src/credentials/user.h"
  38. #include "Firestore/core/src/local/leveldb_opener.h"
  39. #include "Firestore/core/src/model/database_id.h"
  40. #include "Firestore/core/src/remote/firebase_metadata_provider_apple.h"
  41. #include "Firestore/core/src/remote/grpc_connection.h"
  42. #include "Firestore/core/src/util/async_queue.h"
  43. #include "Firestore/core/src/util/autoid.h"
  44. #include "Firestore/core/src/util/filesystem.h"
  45. #include "Firestore/core/src/util/path.h"
  46. #include "Firestore/core/src/util/string_apple.h"
  47. #include "Firestore/core/test/unit/testutil/app_testing.h"
  48. #include "Firestore/core/test/unit/testutil/async_testing.h"
  49. #include "Firestore/core/test/unit/testutil/status_testing.h"
  50. #include "absl/memory/memory.h"
  51. using firebase::firestore::core::DatabaseInfo;
  52. using firebase::firestore::credentials::CredentialChangeListener;
  53. using firebase::firestore::credentials::EmptyAuthCredentialsProvider;
  54. using firebase::firestore::credentials::EmptyAppCheckCredentialsProvider;
  55. using firebase::firestore::credentials::User;
  56. using firebase::firestore::local::LevelDbOpener;
  57. using firebase::firestore::model::DatabaseId;
  58. using firebase::firestore::remote::FirebaseMetadataProviderApple;
  59. using firebase::firestore::testutil::AppForUnitTesting;
  60. using firebase::firestore::testutil::AsyncQueueForTesting;
  61. using firebase::firestore::util::AsyncQueue;
  62. using firebase::firestore::util::CreateAutoId;
  63. using firebase::firestore::util::Filesystem;
  64. using firebase::firestore::util::MakeString;
  65. using firebase::firestore::util::Path;
  66. using firebase::firestore::util::Status;
  67. using firebase::firestore::util::StatusOr;
  68. NS_ASSUME_NONNULL_BEGIN
  69. /**
  70. * Firestore databases can be subject to a ~30s "cold start" delay if they have not been used
  71. * recently, so before any tests run we "prime" the backend.
  72. */
  73. static const double kPrimingTimeout = 45.0;
  74. static NSString *defaultProjectId;
  75. static FIRFirestoreSettings *defaultSettings;
  76. static bool runningAgainstEmulator = false;
  77. // Behaves the same as `EmptyCredentialsProvider` except it can also trigger a user
  78. // change.
  79. class FakeAuthCredentialsProvider : public EmptyAuthCredentialsProvider {
  80. public:
  81. void SetCredentialChangeListener(CredentialChangeListener<User> changeListener) override {
  82. if (changeListener) {
  83. listener_ = std::move(changeListener);
  84. listener_(User::Unauthenticated());
  85. }
  86. }
  87. void ChangeUser(NSString *new_id) {
  88. if (listener_) {
  89. listener_(firebase::firestore::credentials::User::FromUid(new_id));
  90. }
  91. }
  92. private:
  93. CredentialChangeListener<User> listener_;
  94. };
  95. @implementation FSTIntegrationTestCase {
  96. NSMutableArray<FIRFirestore *> *_firestores;
  97. std::shared_ptr<EmptyAppCheckCredentialsProvider> _fakeAppCheckCredentialsProvider;
  98. std::shared_ptr<FakeAuthCredentialsProvider> _fakeAuthCredentialsProvider;
  99. }
  100. - (void)setUp {
  101. [super setUp];
  102. LoadXCTestCaseAwait();
  103. _fakeAppCheckCredentialsProvider = std::make_shared<EmptyAppCheckCredentialsProvider>();
  104. _fakeAuthCredentialsProvider = std::make_shared<FakeAuthCredentialsProvider>();
  105. [self clearPersistenceOnce];
  106. [self primeBackend];
  107. _firestores = [NSMutableArray array];
  108. self.db = [self firestore];
  109. self.eventAccumulator = [FSTEventAccumulator accumulatorForTest:self];
  110. }
  111. - (void)tearDown {
  112. @try {
  113. for (FIRFirestore *firestore in _firestores) {
  114. [self terminateFirestore:firestore];
  115. }
  116. } @finally {
  117. _firestores = nil;
  118. [super tearDown];
  119. }
  120. }
  121. /**
  122. * Clears persistence, but only the first time. This ensures that each test
  123. * run is isolated from the last test run, but doesn't allow tests to interfere
  124. * with each other.
  125. */
  126. - (void)clearPersistenceOnce {
  127. auto *fs = Filesystem::Default();
  128. static bool clearedPersistence = false;
  129. @synchronized([FSTIntegrationTestCase class]) {
  130. if (clearedPersistence) return;
  131. DatabaseInfo dbInfo;
  132. LevelDbOpener opener(dbInfo);
  133. StatusOr<Path> maybeLevelDBDir = opener.FirestoreAppDataDir();
  134. ASSERT_OK(maybeLevelDBDir.status());
  135. Path levelDBDir = std::move(maybeLevelDBDir).ValueOrDie();
  136. Status status = fs->RecursivelyRemove(levelDBDir);
  137. ASSERT_OK(status);
  138. clearedPersistence = true;
  139. }
  140. }
  141. - (FIRFirestore *)firestore {
  142. return [self firestoreWithProjectID:[FSTIntegrationTestCase projectID]];
  143. }
  144. /**
  145. * Figures out what kind of testing environment we're using, and sets up testing defaults to make
  146. * that work.
  147. *
  148. * Several configurations are supported:
  149. * * Mobile Harness, running periocally against prod and nightly, using live SSL certs
  150. * * Firestore emulator, running on localhost, with SSL disabled
  151. *
  152. * See Firestore/README.md for detailed setup instructions or comments below for which specific
  153. * values trigger which configurations.
  154. */
  155. + (void)setUpDefaults {
  156. if (defaultSettings) return;
  157. defaultSettings = [[FIRFirestoreSettings alloc] init];
  158. defaultSettings.persistenceEnabled = YES;
  159. // Check for a MobileHarness configuration, running against nightly or prod, which have live
  160. // SSL certs.
  161. NSString *project = [[NSProcessInfo processInfo] environment][@"PROJECT_ID"];
  162. NSString *host = [[NSProcessInfo processInfo] environment][@"DATASTORE_HOST"];
  163. if (project && host) {
  164. defaultProjectId = project;
  165. defaultSettings.host = host;
  166. NSLog(@"Integration tests running against %@/%@", defaultSettings.host, defaultProjectId);
  167. return;
  168. }
  169. // Check for configuration of a prod project via GoogleServices-Info.plist.
  170. FIROptions *options = [FIROptions defaultOptions];
  171. if (options && ![options.projectID isEqualToString:@"abc-xyz-123"]) {
  172. defaultProjectId = options.projectID;
  173. if (host) {
  174. // Allow access to nightly or other hosts via this mechanism too.
  175. defaultSettings.host = host;
  176. }
  177. NSLog(@"Integration tests running against %@/%@", defaultSettings.host, defaultProjectId);
  178. return;
  179. }
  180. // Otherwise fall back on assuming the emulator or localhost.
  181. defaultProjectId = @"test-db";
  182. defaultSettings.host = @"localhost:8080";
  183. defaultSettings.sslEnabled = false;
  184. runningAgainstEmulator = true;
  185. NSLog(@"Integration tests running against the emulator at %@/%@", defaultSettings.host,
  186. defaultProjectId);
  187. }
  188. + (NSString *)projectID {
  189. if (!defaultProjectId) {
  190. [self setUpDefaults];
  191. }
  192. return defaultProjectId;
  193. }
  194. + (bool)isRunningAgainstEmulator {
  195. // The only way to determine whether or not we're running against the emulator is to figure out
  196. // which testing environment we're using. Essentially `setUpDefaults` determines
  197. // `runningAgainstEmulator` as a side effect.
  198. if (!defaultProjectId) {
  199. [self setUpDefaults];
  200. }
  201. return runningAgainstEmulator;
  202. }
  203. + (FIRFirestoreSettings *)settings {
  204. [self setUpDefaults];
  205. return defaultSettings;
  206. }
  207. - (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID {
  208. FIRApp *app = AppForUnitTesting(MakeString(projectID));
  209. return [self firestoreWithApp:app];
  210. }
  211. - (FIRFirestore *)firestoreWithApp:(FIRApp *)app {
  212. NSString *persistenceKey = [NSString stringWithFormat:@"db%lu", (unsigned long)_firestores.count];
  213. FIRSetLoggerLevel(FIRLoggerLevelDebug);
  214. std::string projectID = MakeString(app.options.projectID);
  215. FIRFirestore *firestore =
  216. [[FIRFirestore alloc] initWithDatabaseID:DatabaseId(projectID)
  217. persistenceKey:MakeString(persistenceKey)
  218. authCredentialsProvider:_fakeAuthCredentialsProvider
  219. appCheckCredentialsProvider:_fakeAppCheckCredentialsProvider
  220. workerQueue:AsyncQueueForTesting()
  221. firebaseMetadataProvider:absl::make_unique<FirebaseMetadataProviderApple>(app)
  222. firebaseApp:app
  223. instanceRegistry:nil];
  224. firestore.settings = [FSTIntegrationTestCase settings];
  225. [_firestores addObject:firestore];
  226. return firestore;
  227. }
  228. - (void)triggerUserChangeWithUid:(NSString *)uid {
  229. _fakeAuthCredentialsProvider->ChangeUser(uid);
  230. }
  231. - (void)primeBackend {
  232. static dispatch_once_t onceToken;
  233. dispatch_once(&onceToken, ^{
  234. [FSTIntegrationTestCase setUpDefaults];
  235. if (runningAgainstEmulator) {
  236. // Priming not required against the emulator.
  237. return;
  238. }
  239. FIRFirestore *db = [self firestore];
  240. XCTestExpectation *watchInitialized =
  241. [self expectationWithDescription:@"Prime backend: Watch initialized"];
  242. __block XCTestExpectation *watchUpdateReceived;
  243. FIRDocumentReference *docRef = [db documentWithPath:[self documentPath]];
  244. id<FIRListenerRegistration> listenerRegistration =
  245. [docRef addSnapshotListener:^(FIRDocumentSnapshot *snapshot, NSError *) {
  246. if ([snapshot[@"value"] isEqual:@"done"]) {
  247. [watchUpdateReceived fulfill];
  248. } else {
  249. [watchInitialized fulfill];
  250. }
  251. }];
  252. // Wait for watch to initialize and deliver first event.
  253. [self awaitExpectation:watchInitialized];
  254. watchUpdateReceived = [self expectationWithDescription:@"Prime backend: Watch update received"];
  255. // Use a transaction to perform a write without triggering any local events.
  256. [docRef.firestore
  257. runTransactionWithBlock:^id(FIRTransaction *transaction, NSError **) {
  258. [transaction setData:@{@"value" : @"done"} forDocument:docRef];
  259. return nil;
  260. }
  261. completion:^(id, NSError *){
  262. }];
  263. // Wait to see the write on the watch stream.
  264. [self waitForExpectationsWithTimeout:kPrimingTimeout
  265. handler:^(NSError *_Nullable expectationError) {
  266. if (expectationError) {
  267. XCTFail(@"Error waiting for prime backend: %@",
  268. expectationError);
  269. }
  270. }];
  271. [listenerRegistration remove];
  272. [self terminateFirestore:db];
  273. });
  274. }
  275. - (void)terminateFirestore:(FIRFirestore *)firestore {
  276. XCTestExpectation *expectation = [self expectationWithDescription:@"shutdown"];
  277. [firestore terminateWithCompletion:[self completionForExpectation:expectation]];
  278. [self awaitExpectation:expectation];
  279. }
  280. - (void)deleteApp:(FIRApp *)app {
  281. XCTestExpectation *expectation = [self expectationWithDescription:@"deleteApp"];
  282. [app deleteApp:^(BOOL completion) {
  283. XCTAssertTrue(completion);
  284. [expectation fulfill];
  285. }];
  286. [self awaitExpectation:expectation];
  287. }
  288. - (NSString *)documentPath {
  289. std::string autoId = CreateAutoId();
  290. return [NSString stringWithFormat:@"test-collection/%s", autoId.c_str()];
  291. }
  292. - (FIRDocumentReference *)documentRef {
  293. return [self.db documentWithPath:[self documentPath]];
  294. }
  295. - (FIRCollectionReference *)collectionRef {
  296. std::string autoId = CreateAutoId();
  297. NSString *collectionName = [NSString stringWithFormat:@"test-collection-%s", autoId.c_str()];
  298. return [self.db collectionWithPath:collectionName];
  299. }
  300. - (FIRCollectionReference *)collectionRefWithDocuments:
  301. (NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents {
  302. FIRCollectionReference *collection = [self collectionRef];
  303. // Use a different instance to write the documents
  304. [self writeAllDocuments:documents
  305. toCollection:[[self firestore] collectionWithPath:collection.path]];
  306. return collection;
  307. }
  308. - (void)writeAllDocuments:(NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents
  309. toCollection:(FIRCollectionReference *)collection {
  310. [documents enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary<NSString *, id> *value,
  311. BOOL *) {
  312. FIRDocumentReference *ref = [collection documentWithPath:key];
  313. [self writeDocumentRef:ref data:value];
  314. }];
  315. }
  316. - (void)readerAndWriterOnDocumentRef:(void (^)(FIRDocumentReference *readerRef,
  317. FIRDocumentReference *writerRef))action {
  318. FIRFirestore *reader = self.db; // for clarity
  319. FIRFirestore *writer = [self firestore];
  320. NSString *path = [self documentPath];
  321. FIRDocumentReference *readerRef = [reader documentWithPath:path];
  322. FIRDocumentReference *writerRef = [writer documentWithPath:path];
  323. action(readerRef, writerRef);
  324. }
  325. - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref {
  326. return [self readDocumentForRef:ref source:FIRFirestoreSourceDefault];
  327. }
  328. - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref
  329. source:(FIRFirestoreSource)source {
  330. __block FIRDocumentSnapshot *result;
  331. XCTestExpectation *expectation = [self expectationWithDescription:@"getData"];
  332. [ref getDocumentWithSource:source
  333. completion:^(FIRDocumentSnapshot *doc, NSError *_Nullable error) {
  334. XCTAssertNil(error);
  335. result = doc;
  336. [expectation fulfill];
  337. }];
  338. [self awaitExpectation:expectation];
  339. return result;
  340. }
  341. - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query {
  342. return [self readDocumentSetForRef:query source:FIRFirestoreSourceDefault];
  343. }
  344. - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query source:(FIRFirestoreSource)source {
  345. if (query == nil) {
  346. XCTFail("Trying to read data from a nil query");
  347. }
  348. __block FIRQuerySnapshot *result;
  349. XCTestExpectation *expectation = [self expectationWithDescription:@"getData"];
  350. [query getDocumentsWithSource:source
  351. completion:^(FIRQuerySnapshot *documentSet, NSError *error) {
  352. XCTAssertNil(error);
  353. result = documentSet;
  354. [expectation fulfill];
  355. }];
  356. [self awaitExpectation:expectation];
  357. return result;
  358. }
  359. - (FIRDocumentSnapshot *)readSnapshotForRef:(FIRDocumentReference *)ref
  360. requireOnline:(BOOL)requireOnline {
  361. __block FIRDocumentSnapshot *result;
  362. XCTestExpectation *expectation = [self expectationWithDescription:@"listener"];
  363. id<FIRListenerRegistration> listener = [ref
  364. addSnapshotListenerWithIncludeMetadataChanges:YES
  365. listener:^(FIRDocumentSnapshot *snapshot,
  366. NSError *error) {
  367. XCTAssertNil(error);
  368. if (!requireOnline || !snapshot.metadata.fromCache) {
  369. result = snapshot;
  370. [expectation fulfill];
  371. }
  372. }];
  373. [self awaitExpectation:expectation];
  374. [listener remove];
  375. return result;
  376. }
  377. - (void)writeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data {
  378. XCTestExpectation *expectation = [self expectationWithDescription:@"setData"];
  379. [ref setData:data completion:[self completionForExpectation:expectation]];
  380. [self awaitExpectation:expectation];
  381. }
  382. - (void)updateDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<id, id> *)data {
  383. XCTestExpectation *expectation = [self expectationWithDescription:@"updateData"];
  384. [ref updateData:data completion:[self completionForExpectation:expectation]];
  385. [self awaitExpectation:expectation];
  386. }
  387. - (void)deleteDocumentRef:(FIRDocumentReference *)ref {
  388. XCTestExpectation *expectation = [self expectationWithDescription:@"deleteDocument"];
  389. [ref deleteDocumentWithCompletion:[self completionForExpectation:expectation]];
  390. [self awaitExpectation:expectation];
  391. }
  392. - (FIRDocumentReference *)addDocumentRef:(FIRCollectionReference *)ref
  393. data:(NSDictionary<NSString *, id> *)data {
  394. XCTestExpectation *expectation = [self expectationWithDescription:@"addDocument"];
  395. FIRDocumentReference *doc = [ref addDocumentWithData:data
  396. completion:[self completionForExpectation:expectation]];
  397. [self awaitExpectation:expectation];
  398. return doc;
  399. }
  400. - (void)mergeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data {
  401. XCTestExpectation *expectation = [self expectationWithDescription:@"setDataWithMerge"];
  402. [ref setData:data merge:YES completion:[self completionForExpectation:expectation]];
  403. [self awaitExpectation:expectation];
  404. }
  405. - (void)mergeDocumentRef:(FIRDocumentReference *)ref
  406. data:(NSDictionary<NSString *, id> *)data
  407. fields:(NSArray<id> *)fields {
  408. XCTestExpectation *expectation = [self expectationWithDescription:@"setDataWithMerge"];
  409. [ref setData:data mergeFields:fields completion:[self completionForExpectation:expectation]];
  410. [self awaitExpectation:expectation];
  411. }
  412. - (void)disableNetwork {
  413. XCTestExpectation *expectation = [self expectationWithDescription:@"disableNetwork"];
  414. [self.db disableNetworkWithCompletion:[self completionForExpectation:expectation]];
  415. [self awaitExpectation:expectation];
  416. }
  417. - (void)enableNetwork {
  418. XCTestExpectation *expectation = [self expectationWithDescription:@"enableNetwork"];
  419. [self.db enableNetworkWithCompletion:[self completionForExpectation:expectation]];
  420. [self awaitExpectation:expectation];
  421. }
  422. - (const std::shared_ptr<AsyncQueue> &)queueForFirestore:(FIRFirestore *)firestore {
  423. return [firestore workerQueue];
  424. }
  425. - (void)waitUntil:(BOOL (^)())predicate {
  426. NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
  427. double waitSeconds = [self defaultExpectationWaitSeconds];
  428. while (!predicate() && ([NSDate timeIntervalSinceReferenceDate] - start < waitSeconds)) {
  429. // This waits for the next event or until the 100ms timeout is reached
  430. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
  431. beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
  432. }
  433. if (!predicate()) {
  434. XCTFail(@"Timeout");
  435. }
  436. }
  437. extern "C" NSArray<NSDictionary<NSString *, id> *> *FIRQuerySnapshotGetData(
  438. FIRQuerySnapshot *docs) {
  439. NSMutableArray<NSDictionary<NSString *, id> *> *result = [NSMutableArray array];
  440. for (FIRDocumentSnapshot *doc in docs.documents) {
  441. [result addObject:doc.data];
  442. }
  443. return result;
  444. }
  445. extern "C" NSArray<NSString *> *FIRQuerySnapshotGetIDs(FIRQuerySnapshot *docs) {
  446. NSMutableArray<NSString *> *result = [NSMutableArray array];
  447. for (FIRDocumentSnapshot *doc in docs.documents) {
  448. [result addObject:doc.documentID];
  449. }
  450. return result;
  451. }
  452. extern "C" NSArray<NSArray<id> *> *FIRQuerySnapshotGetDocChangesData(FIRQuerySnapshot *docs) {
  453. NSMutableArray<NSMutableArray<id> *> *result = [NSMutableArray array];
  454. for (FIRDocumentChange *docChange in docs.documentChanges) {
  455. NSMutableArray<id> *docChangeData = [NSMutableArray array];
  456. [docChangeData addObject:@(docChange.type)];
  457. [docChangeData addObject:docChange.document.documentID];
  458. [docChangeData addObject:docChange.document.data];
  459. [result addObject:docChangeData];
  460. }
  461. return result;
  462. }
  463. @end
  464. NS_ASSUME_NONNULL_END