@Test public void isRateLimited_ifNoLimits_isFalse() { when(storageClient.read(any(RateLimitParser.class))).thenReturn(Maybe.empty()); RateLimit oneLimit = RateLimit.builder().setLimit(1).setLimiterKey(LIMITER_KEY).setTimeToLiveMillis(TTL).build(); TestObserver<Boolean> testObserver = rateLimiterClient.isRateLimited(oneLimit).test(); assertThat(testObserver.getEvents().get(0)).containsExactly(false); }
public Single<Boolean> isRateLimited(RateLimit limit) { return getRateLimits() .switchIfEmpty(Maybe.just(RateLimitProto.RateLimit.getDefaultInstance())) .map(storedLimits -> storedLimits.getLimitsOrDefault(limit.limiterKey(), newCounter())) .filter(counter -> isLimitExpired(counter, limit) || counter.getValue() < limit.limit()) .isEmpty(); }
RateLimiterClient { public Single<Boolean> isRateLimited(RateLimit limit) { return getRateLimits() .switchIfEmpty(Maybe.just(RateLimitProto.RateLimit.getDefaultInstance())) .map(storedLimits -> storedLimits.getLimitsOrDefault(limit.limiterKey(), newCounter())) .filter(counter -> isLimitExpired(counter, limit) || counter.getValue() < limit.limit()) .isEmpty(); } }
RateLimiterClient { public Single<Boolean> isRateLimited(RateLimit limit) { return getRateLimits() .switchIfEmpty(Maybe.just(RateLimitProto.RateLimit.getDefaultInstance())) .map(storedLimits -> storedLimits.getLimitsOrDefault(limit.limiterKey(), newCounter())) .filter(counter -> isLimitExpired(counter, limit) || counter.getValue() < limit.limit()) .isEmpty(); } @Inject  RateLimiterClient(
      @com.google.firebase.inappmessaging.internal.injection.qualifiers.RateLimit
          ProtoStorageClient storageClient,
      Clock clock); }
RateLimiterClient { public Single<Boolean> isRateLimited(RateLimit limit) { return getRateLimits() .switchIfEmpty(Maybe.just(RateLimitProto.RateLimit.getDefaultInstance())) .map(storedLimits -> storedLimits.getLimitsOrDefault(limit.limiterKey(), newCounter())) .filter(counter -> isLimitExpired(counter, limit) || counter.getValue() < limit.limit()) .isEmpty(); } @Inject  RateLimiterClient(
      @com.google.firebase.inappmessaging.internal.injection.qualifiers.RateLimit
          ProtoStorageClient storageClient,
      Clock clock); Completable increment(RateLimit limit); Single<Boolean> isRateLimited(RateLimit limit); }
RateLimiterClient { public Single<Boolean> isRateLimited(RateLimit limit) { return getRateLimits() .switchIfEmpty(Maybe.just(RateLimitProto.RateLimit.getDefaultInstance())) .map(storedLimits -> storedLimits.getLimitsOrDefault(limit.limiterKey(), newCounter())) .filter(counter -> isLimitExpired(counter, limit) || counter.getValue() < limit.limit()) .isEmpty(); } @Inject  RateLimiterClient(
      @com.google.firebase.inappmessaging.internal.injection.qualifiers.RateLimit
          ProtoStorageClient storageClient,
      Clock clock); Completable increment(RateLimit limit); Single<Boolean> isRateLimited(RateLimit limit);  }