Skip to content

rx.Completable support for write operations #629

Merged
merged 1 commit into from

5 participants

@geralt-encore
@artem-zinnatullin artem-zinnatullin added this to the v1.9.0 milestone
@artem-zinnatullin artem-zinnatullin self-assigned this
@artem-zinnatullin
Pushtorefresh member

Can you please squash commits? Main reason for squashing — each commit is stable state of the repo (mostly)

@artem-zinnatullin artem-zinnatullin commented on the diff
...refresh/storio/operations/PreparedWriteOperation.java
@@ -0,0 +1,18 @@
+package com.pushtorefresh.storio.operations;
+
+import android.support.annotation.CheckResult;
+import android.support.annotation.NonNull;
+
+import rx.Completable;
+
+/**
+ * Common API of prepared write operations
+ *
+ * @param <Result> type of result
+ */
+public interface PreparedWriteOperation<Result> extends PreparedOperation<Result> {
@artem-zinnatullin
Pushtorefresh member

Well, this makes PreparedOperation a little bit strange name…

Do you have a better name in mind? I did it because I didn't want to force implement asRxCompletable for read operation.

@artem-zinnatullin
Pushtorefresh member

No :(

I'm actually not sure if we want PreparedOperation in v2, @nikitin-da what's your opinion?

cc @karlicoss

I agree that prepare looks like an excess step and maybe it can be reduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@artem-zinnatullin artem-zinnatullin and 1 other commented on an outdated diff
...internal/OnSubscribeExecuteAsBlockingCompletable.java
+ this.preparedOperation = preparedOperation;
+ }
+
+ /**
+ * Creates new instance of {@link OnSubscribeExecuteAsBlockingCompletable}
+ *
+ * @param preparedOperation non-null instance of {@link PreparedOperation} which will be used to provide result to subscribers
+ * @return new instance of {@link OnSubscribeExecuteAsBlockingCompletable}
+ */
+ @NonNull
+ public static Completable.CompletableOnSubscribe newInstance(@NonNull PreparedOperation preparedOperation) {
+ return new OnSubscribeExecuteAsBlockingCompletable(preparedOperation);
+ }
+
+ @Override
+ public void call(Completable.CompletableSubscriber subscriber) {
@artem-zinnatullin
Pushtorefresh member

nullability (as you think, I understand that it's not presented in RxJava)

Not sure if I get what you meant

@artem-zinnatullin
Pushtorefresh member

Just @NonNull for subscriber :)

I mean, in StorIO we want to have nullability annotations everywhere, but sometimes you override methods that originally don't have nullability, then you can set @NonNull or @Nullable as you think

Of course, just tough morning made my brain slow, I guess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@artem-zinnatullin artem-zinnatullin commented on the diff
...lite/operations/delete/PreparedDeleteByQueryTest.java
+
+ new PreparedDeleteByQuery.Builder(storIOSQLite, DeleteQuery.builder().table("test_table").build())
+ .withDeleteResolver(deleteResolver)
+ .prepare()
+ .asRxComleatable()
+ .subscribe(testSubscriber);
+
+ testSubscriber.awaitTerminalEvent();
+ testSubscriber.assertNoValues();
+ testSubscriber.assertError(StorIOException.class);
+
+ //noinspection ThrowableResultOfMethodCallIgnored
+ StorIOException expected = (StorIOException) testSubscriber.getOnErrorEvents().get(0);
+
+ IllegalStateException cause = (IllegalStateException) expected.getCause();
+ assertThat(cause).hasMessage("test exception");
@artem-zinnatullin
Pushtorefresh member

Maybe let's check that exception is same() as expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@geralt-encore

Sure, I will squash as soon as all your comments will be fixed

@karlicoss karlicoss and 2 others commented on an outdated diff
...o/sqlite/operations/delete/PreparedDeleteByQuery.java
@@ -126,6 +128,25 @@ public DeleteResult executeAsBlocking() {
}
/**
+ * Creates {@link Completable} which will perform Delete Operation lazily when somebody subscribes to it.
+ * <dl>
+ * <dt><b>Scheduler:</b></dt>
+ * <dd>Operates on {@link Schedulers#io()}.</dd>
+ * </dl>
+ *
+ * @return non-null {@link Completable} which will perform Delete Operation.
+ */
+ @NonNull
+ @CheckResult
+ @Override
+ public Completable asRxComleatable() {

typo

@artem-zinnatullin
Pushtorefresh member

oh pipec, @geralt-encore we need tests for method names :D

wow, thank you!
pipec indeed =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@geralt-encore

Squashed

@nikitin-da

:+1: Nice work

@geralt-encore

I will do the same for ContentResolver as soon as this PR will be merged

@artem-zinnatullin
Pushtorefresh member

Yup, sorry, I'll try to finish #630 today (blocked by GitHub organization access settings…)

@artem-zinnatullin
Pushtorefresh member

Please rebase on latest master for code coverage!

@geralt-encore

Have I made it right or have I messed up?

@artem-zinnatullin
Pushtorefresh member

Messed up :)

You need to perform git rebase master on your branch, just make sure that your master is up-to-date

@codecov-io

Current coverage is 82.07%

Merging #629 into master will increase coverage by +0.27% as of ff9c283

@@            master    #629   diff @@
======================================
  Files           84      85     +1
  Stmts         2484    2522    +38
  Branches       323     323       
  Methods          0       0       
======================================
+ Hit           2032    2070    +38
  Partial         47      47       
  Missed         405     405       

Review entire Coverage Diff as of ff9c283

Powered by Codecov. Updated on successful CI builds.

@geralt-encore

I did exactly the same thing. Not sure what's went wrong =/

@artem-zinnatullin artem-zinnatullin commented on the diff
...internal/OnSubscribeExecuteAsBlockingCompletable.java
+package com.pushtorefresh.storio.operations.internal;
+
+import android.support.annotation.NonNull;
+
+import com.pushtorefresh.storio.StorIOException;
+import com.pushtorefresh.storio.operations.PreparedOperation;
+
+import rx.Completable;
+
+/**
+ * Required to avoid problems with ClassLoader when RxJava is not in ClassPath
+ * We can not use anonymous classes from RxJava directly in StorIO, ClassLoader won't be happy :(
+ * <p>
+ * For internal usage only!
+ */
+public final class OnSubscribeExecuteAsBlockingCompletable implements Completable.CompletableOnSubscribe {
@artem-zinnatullin
Pushtorefresh member

We need to cover this class with tests! Yay, thanks to coverage service!

I am not sure how and what to test in this class since both of OnSubscribeExecuteAsBlocking and OnSubscribeExecuteAsBlockingSingle are not covered with tests. Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@artem-zinnatullin artem-zinnatullin commented on the diff
...internal/OnSubscribeExecuteAsBlockingCompletable.java
+
+import android.support.annotation.NonNull;
+
+import com.pushtorefresh.storio.StorIOException;
+import com.pushtorefresh.storio.operations.PreparedOperation;
+
+import rx.Completable;
+
+/**
+ * Required to avoid problems with ClassLoader when RxJava is not in ClassPath
+ * We can not use anonymous classes from RxJava directly in StorIO, ClassLoader won't be happy :(
+ * <p>
+ * For internal usage only!
+ */
+public final class OnSubscribeExecuteAsBlockingCompletable implements Completable.CompletableOnSubscribe {
+
@artem-zinnatullin
Pushtorefresh member

Just regular unit testing, check that it executes operation correctly, handles errors and does Rx stuff right

@artem-zinnatullin
Pushtorefresh member

Damn, wrong line, sorry :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@geralt-encore

All should be good now.

@geralt-encore

100% coverage PogChamp

@artem-zinnatullin
Pushtorefresh member

Whoa, nice!

@artem-zinnatullin artem-zinnatullin commented on the diff
...rnal/OnSubscribeExecuteAsBlockingCompletableTest.java
+public class OnSubscribeExecuteAsBlockingCompletableTest {
+
+ @SuppressWarnings("ResourceType")
+ @Test
+ public void shouldExecuteAsBlockingAfterSubscription() {
+ final PreparedWriteOperation preparedOperation = mock(PreparedWriteOperation.class);
+
+ TestSubscriber testSubscriber = new TestSubscriber();
+
+ Completable.create(OnSubscribeExecuteAsBlockingCompletable.newInstance(preparedOperation))
+ .subscribe(testSubscriber);
+
+ testSubscriber.assertNoErrors();
+ testSubscriber.assertCompleted();
+
+ verify(preparedOperation).executeAsBlocking();
@artem-zinnatullin
Pushtorefresh member

Can you please also check that it's not invoked before subscribe()?

@artem-zinnatullin
Pushtorefresh member

It's okay to do it in a separate test if you want :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@artem-zinnatullin
Pushtorefresh member

Awesome, just one more test case and I'm merging this, @geralt-encore you're machine!

cc @nikitin-da, @karlicoss any input from you guys?

@artem-zinnatullin artem-zinnatullin commented on the diff
...rnal/OnSubscribeExecuteAsBlockingCompletableTest.java
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
+public class OnSubscribeExecuteAsBlockingCompletableTest {
+
+ @SuppressWarnings("ResourceType")
+ @Test
+ public void shouldExecuteAsBlockingAfterSubscription() {
+ final PreparedWriteOperation preparedOperation = mock(PreparedWriteOperation.class);
+
+ TestSubscriber testSubscriber = new TestSubscriber();
+
+ verifyZeroInteractions(preparedOperation);
@artem-zinnatullin
Pushtorefresh member

This makes no sense because you don't pass it anywhere so it won't be invoked, can you move this line after OnSubscribeExecuteAsBlockingCompletable.newInstance(preparedOperation) but before .subscribe()?

Right, not sure what I was thinking about

@artem-zinnatullin
Pushtorefresh member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@geralt-encore geralt-encore Add support for rx.Completable
deaed1f
@nikitin-da

Looks good, but CI =( failed to find target with hash string 'android-23' in: /usr/local/android-sdk

@geralt-encore

It's weird, I've just changed a couple of minor things in tests and the previous build was ok

@artem-zinnatullin
Pushtorefresh member

It's Travis…

@artem-zinnatullin
Pushtorefresh member

Don't worry, looks like it's not only we in trouble, I'll comment when issue on Travis will be resolved

@artem-zinnatullin
Pushtorefresh member

:+1:

@artem-zinnatullin artem-zinnatullin merged commit 52c1883 into pushtorefresh:master

3 checks passed

Details codecov/patch 100.00% of diff hit (target 80.00%)
Details codecov/project 82.07% (+0.27%) compared to bbb3bae at 81.80%
Details continuous-integration/travis-ci/pr The Travis CI build passed
@artem-zinnatullin
Pushtorefresh member

Thanks a lot, @geralt-encore!

@geralt-encore geralt-encore deleted the geralt-encore:rx-completable branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.