@Test @Ignore("the code doesn't currently enforce a single token fetch at a time") public void testGetAuthToken_multipleCallsForceRefresh_fetchedNewTokenTwice() throws Exception { persistedInstallation.insertOrUpdatePersistedInstallationEntry( PersistedInstallationEntry.INSTANCE.withRegisteredFid( TEST_FID_1, TEST_REFRESH_TOKEN, utils.currentTimeInSecs(), TEST_AUTH_TOKEN, TEST_TOKEN_EXPIRATION_TIMESTAMP)); doAnswer( AdditionalAnswers.answersWithDelay( 500, (unused) -> TokenResult.builder() .setToken(TEST_AUTH_TOKEN_3) .setTokenExpirationTimestamp(TEST_TOKEN_EXPIRATION_TIMESTAMP) .setResponseCode(TokenResult.ResponseCode.OK) .build())) .doAnswer( AdditionalAnswers.answersWithDelay( 500, (unused) -> TokenResult.builder() .setToken(TEST_AUTH_TOKEN_4) .setTokenExpirationTimestamp(TEST_TOKEN_EXPIRATION_TIMESTAMP) .setResponseCode(TokenResult.ResponseCode.OK) .build())) .when(mockBackend) .generateAuthToken(anyString(), anyString(), anyString(), anyString()); Task<InstallationTokenResult> task1 = firebaseInstallations.getToken(true); Task<InstallationTokenResult> task2 = firebaseInstallations.getToken(true); TestOnCompleteListener<InstallationTokenResult> onCompleteListener1 = new TestOnCompleteListener<>(); task1.addOnCompleteListener(executor, onCompleteListener1); TestOnCompleteListener<InstallationTokenResult> onCompleteListener2 = new TestOnCompleteListener<>(); task2.addOnCompleteListener(executor, onCompleteListener2); onCompleteListener1.await(); onCompleteListener2.await(); assertWithMessage("Persisted Auth Token doesn't match") .that(task1.getResult().getToken()) .isEqualTo(TEST_AUTH_TOKEN_3); assertWithMessage("Persisted Auth Token doesn't match") .that(task2.getResult().getToken()) .isEqualTo(TEST_AUTH_TOKEN_3); verify(mockBackend, times(1)) .generateAuthToken(TEST_API_KEY, TEST_FID_1, TEST_PROJECT_ID, TEST_REFRESH_TOKEN); PersistedInstallationEntry entry = persistedInstallation.readPersistedInstallationEntryValue(); assertThat(entry.getAuthToken(), equalTo(TEST_AUTH_TOKEN_3)); }
@NonNull @Override public Task<InstallationTokenResult> getToken(boolean forceRefresh) { preConditionChecks(); Task<InstallationTokenResult> task = addGetAuthTokenListener(); backgroundExecutor.execute(() -> doRegistrationOrRefresh(forceRefresh)); return task; }
FirebaseInstallations implements FirebaseInstallationsApi { @NonNull @Override public Task<InstallationTokenResult> getToken(boolean forceRefresh) { preConditionChecks(); Task<InstallationTokenResult> task = addGetAuthTokenListener(); backgroundExecutor.execute(() -> doRegistrationOrRefresh(forceRefresh)); return task; } }
FirebaseInstallations implements FirebaseInstallationsApi { @NonNull @Override public Task<InstallationTokenResult> getToken(boolean forceRefresh) { preConditionChecks(); Task<InstallationTokenResult> task = addGetAuthTokenListener(); backgroundExecutor.execute(() -> doRegistrationOrRefresh(forceRefresh)); return task; } FirebaseInstallations(
      FirebaseApp firebaseApp,
      @NonNull Provider<UserAgentPublisher> publisher,
      @NonNull Provider<HeartBeatInfo> heartbeatInfo);   FirebaseInstallations(
      ExecutorService backgroundExecutor,
      FirebaseApp firebaseApp,
      FirebaseInstallationServiceClient serviceClient,
      PersistedInstallation persistedInstallation,
      Utils utils,
      IidStore iidStore,
      RandomFidGenerator fidGenerator); }
FirebaseInstallations implements FirebaseInstallationsApi { @NonNull @Override public Task<InstallationTokenResult> getToken(boolean forceRefresh) { preConditionChecks(); Task<InstallationTokenResult> task = addGetAuthTokenListener(); backgroundExecutor.execute(() -> doRegistrationOrRefresh(forceRefresh)); return task; } FirebaseInstallations(
      FirebaseApp firebaseApp,
      @NonNull Provider<UserAgentPublisher> publisher,
      @NonNull Provider<HeartBeatInfo> heartbeatInfo);   FirebaseInstallations(
      ExecutorService backgroundExecutor,
      FirebaseApp firebaseApp,
      FirebaseInstallationServiceClient serviceClient,
      PersistedInstallation persistedInstallation,
      Utils utils,
      IidStore iidStore,
      RandomFidGenerator fidGenerator); @NonNull static FirebaseInstallations getInstance(); @NonNull static FirebaseInstallations getInstance(@NonNull FirebaseApp app); @NonNull @Override Task<String> getId(); @NonNull @Override Task<InstallationTokenResult> getToken(boolean forceRefresh); @NonNull @Override Task<Void> delete(); }
FirebaseInstallations implements FirebaseInstallationsApi { @NonNull @Override public Task<InstallationTokenResult> getToken(boolean forceRefresh) { preConditionChecks(); Task<InstallationTokenResult> task = addGetAuthTokenListener(); backgroundExecutor.execute(() -> doRegistrationOrRefresh(forceRefresh)); return task; } FirebaseInstallations(
      FirebaseApp firebaseApp,
      @NonNull Provider<UserAgentPublisher> publisher,
      @NonNull Provider<HeartBeatInfo> heartbeatInfo);   FirebaseInstallations(
      ExecutorService backgroundExecutor,
      FirebaseApp firebaseApp,
      FirebaseInstallationServiceClient serviceClient,
      PersistedInstallation persistedInstallation,
      Utils utils,
      IidStore iidStore,
      RandomFidGenerator fidGenerator); @NonNull static FirebaseInstallations getInstance(); @NonNull static FirebaseInstallations getInstance(@NonNull FirebaseApp app); @NonNull @Override Task<String> getId(); @NonNull @Override Task<InstallationTokenResult> getToken(boolean forceRefresh); @NonNull @Override Task<Void> delete();  }