Java Code Examples for io.reactivex.Completable#fromCallable()
The following examples show how to use
io.reactivex.Completable#fromCallable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImpressionStorageClientTest.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
@Before public void setup() throws IOException { initMocks(this); impressionStorageClient = new ImpressionStorageClient(storageClient); fakeRead = Maybe.fromCallable(() -> campaignImpressionList); wasWritten = false; fakeWrite = Completable.fromCallable( () -> { wasWritten = true; return null; }); when(storageClient.read(any(CampaignImpressionsParser.class))).thenReturn(fakeRead); when(storageClient.write(any(CampaignImpressionList.class))).thenReturn(fakeWrite); }
Example 2
Source File: RateLimiterClientTest.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
@Before public void setup() throws IOException { initMocks(this); limitsMap = new HashMap<>(); limitsMap.put(LIMITER_KEY, counter); storedRateLimit = RateLimitProto.RateLimit.newBuilder().putAllLimits(limitsMap).build(); fakeRead = Maybe.fromCallable(() -> storedRateLimit); fakeWrite = Completable.fromCallable( () -> { wasWritten = true; return null; }); rateLimiterClient = new RateLimiterClient(storageClient, new FakeClock(NOW)); when(storageClient.read(any(RateLimitParser.class))).thenReturn(fakeRead); when(storageClient.write(any(RateLimitProto.RateLimit.class))).thenReturn(fakeWrite); }
Example 3
Source File: ProtoStorageClient.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
/** * Write the proto to a file in the app' s file directory. * * <p>Writes are non atomic. * * <p>Readers are expected to deal with corrupt data resulting from faulty writes * * @param messageLite * @throws IOException */ public Completable write(AbstractMessageLite messageLite) { return Completable.fromCallable( () -> { // reads / writes are synchronized per client instance synchronized (this) { try (FileOutputStream output = application.openFileOutput(fileName, MODE_PRIVATE)) { output.write(messageLite.toByteArray()); return messageLite; } } }); }
Example 4
Source File: CampaignCacheClientTest.java From firebase-android-sdk with Apache License 2.0 | 5 votes |
@Before public void setup() throws IOException { initMocks(this); wasWritten = false; campaignCacheClient = new CampaignCacheClient( storageClient, (Application) RuntimeEnvironment.application.getApplicationContext(), new FakeClock(NOW)); storageWriteObserver = TestObserver.create(); fakeRead = Maybe.fromCallable(() -> fetchEligibleCampaignsResponse1); fakeWrite = Completable.fromCallable(() -> wasWritten = true); }
Example 5
Source File: GetSingleOperation.java From HighLite with Apache License 2.0 | 5 votes |
/** * Fetches a single row from a database and maps it to and object of type {@link T}, * non-blocking operation. * * @return a {@link Completable} */ @Override public Completable asCompletable() { return Completable.fromCallable(new Callable<T>() { @Override public T call() { return executeBlocking(); } }); }
Example 6
Source File: GetListOperation.java From HighLite with Apache License 2.0 | 5 votes |
/** * Fetches multiple rows from a database and maps them to objects of type {@link T}, * non-blocking operation. * * @return an {@link Completable<T>} */ @Override public Completable asCompletable() { return Completable.fromCallable(new Callable<List<T>>() { @Override public List<T> call() { return executeBlocking(); } }); }
Example 7
Source File: SaveOperation.java From HighLite with Apache License 2.0 | 5 votes |
/** * Saves one or more records in a table, non-blocking operation. * * @return a {@link Completable} */ @Override public Completable asCompletable() { return Completable.fromCallable(new Callable<Integer>() { @Override public Integer call() { return executeBlocking(); } }); }
Example 8
Source File: DeleteOperation.java From HighLite with Apache License 2.0 | 5 votes |
/** * Deletes one or more records from a table, non-blocking operation. * * @return a {@link Completable} */ @Override public Completable asCompletable() { return Completable.fromCallable(new Callable<Integer>() { @Override public Integer call() { return executeBlocking(); } }); }
Example 9
Source File: AbstractConnectionProvider.java From StompProtocolAndroid with MIT License | 5 votes |
@NonNull @Override public Completable send(String stompMessage) { return Completable.fromCallable(() -> { if (getSocket() == null) { throw new IllegalStateException("Not connected"); } else { Log.d(TAG, "Send STOMP message: " + stompMessage); rawSend(stompMessage); return null; } }); }
Example 10
Source File: WrappedEntityStore.java From requery with Apache License 2.0 | 5 votes |
@Override public <E extends T> Completable delete(final E entity) { return Completable.fromCallable(new Callable<Void>() { @Override public Void call() throws Exception { delegate.delete(entity); return null; } }); }
Example 11
Source File: WrappedEntityStore.java From requery with Apache License 2.0 | 5 votes |
@Override public <E extends T> Completable delete(final Iterable<E> entities) { return Completable.fromCallable(new Callable<Void>() { @Override public Void call() throws Exception { delegate.delete(entities); return null; } }); }
Example 12
Source File: RelationshipDeleteCall.java From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Completable deleteRelationship(Relationship229Compatible relationship) { return Completable.fromCallable(() -> { if (dhisVersionManager.is2_29()) { String whereClause = new WhereClauseBuilder() .appendKeyStringValue(CoreColumns.ID, relationship.id()).build(); relationshipStore.deleteWhereIfExists(whereClause); return RelationshipDeleteWebResponse.empty(); } else { RelationshipDeleteWebResponse httpResponse = apiCallExecutor.executeObjectCallWithAcceptedErrorCodes( relationshipService.deleteRelationship(relationship.uid()), Collections.singletonList(404), RelationshipDeleteWebResponse.class); ImportStatus status = httpResponse.response() == null ? null : httpResponse.response().status(); if (httpResponse.httpStatusCode() == 200 && ImportStatus.SUCCESS.equals(status) || httpResponse.httpStatusCode() == 404) { relationshipStore.delete(relationship.uid()); } else { // TODO Implement better handling // The relationship is marked as error, but there is no handling in the TEI. The TEI is being posted relationshipStore.setState(relationship.uid(), State.ERROR); } return httpResponse; } }); }
Example 13
Source File: DisplayCallbacksImplTest.java From firebase-android-sdk with Apache License 2.0 | 4 votes |
@Before public void setup() { MockitoAnnotations.initMocks(this); wasRecorded = false; wasIncremented = false; fakeImpressionCompletable = Completable.fromCallable(() -> wasRecorded = true); fakeRateLimitCompletable = Completable.fromCallable(() -> wasIncremented = true); application = RuntimeEnvironment.application; options = new FirebaseOptions.Builder() .setGcmSenderId("project_number") .setApplicationId("app-id") .setApiKey("apiKey") .setProjectId("fiam-integration-test") .build(); firebaseApp1 = mock(FirebaseApp.class); when(firebaseApp1.getName()).thenReturn("app1"); when(firebaseApp1.getOptions()).thenReturn(options); when(firebaseApp1.getApplicationContext()).thenReturn(application); when(schedulers.mainThread()).thenReturn(trampoline()); when(schedulers.io()).thenReturn(trampoline()); when(schedulers.computation()).thenReturn(trampoline()); when(inAppMessageStreamManager.createFirebaseInAppMessageStream()).thenReturn(fiamStream); when(impressionStorageClient.storeImpression(any(CampaignImpression.class))) .thenReturn(fakeImpressionCompletable); when(campaignCacheClient.get()).thenReturn(Maybe.just(campaignsResponse)); when(rateLimiterClient.increment(appForegroundRateLimit)).thenReturn(fakeRateLimitCompletable); when(firebaseInstallations.getId()).thenReturn(Tasks.forResult(INSTALLATION_ID)); when(firebaseInstallations.getToken(false)) .thenReturn(Tasks.forResult(INSTALLATION_TOKEN_RESULT)); when(dataCollectionHelper.isAutomaticDataCollectionEnabled()).thenReturn(true); FakeClock clock = new FakeClock(NOW); displayCallbacksFactory = new DisplayCallbacksFactory( impressionStorageClient, clock, schedulers, rateLimiterClient, campaignCacheClient, appForegroundRateLimit, metricsLoggerClient, dataCollectionHelper); displayCallbacksImpl = displayCallbacksFactory.generateDisplayCallback(BANNER_MESSAGE_MODEL, ANALYTICS_EVENT_NAME); }