This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.lang.IllegalStateException: Exception thrown on Scheduler.Worker thread. Add `onError` handling. | |
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:52) | |
at android.os.Handler.handleCallback(Handler.java:739) | |
at android.os.Handler.dispatchMessage(Handler.java:95) | |
at android.os.Looper.loop(Looper.java:135) | |
at android.app.ActivityThread.main(ActivityThread.java:5221) | |
at java.lang.reflect.Method.invoke(Native Method) | |
at java.lang.reflect.Method.invoke(Method.java:372) | |
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) | |
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testJson() throws Exception { | |
Observable<String> jsonObservable = MockResponse.generateJson(736L, 1, 1000, 5); | |
String json = jsonObservable.toBlocking().single(); | |
System.out.println(json); | |
assertTrue(json.startsWith("{\"responseKey\":" + MockResponse.getResponseKey(736L) + ",\"delay\":1,\"itemSize\":1000,\"numItems\":5,\"items\"")); | |
System.out.println("json: " + json); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Observable<String> generateJson(long id, int delay, int itemSize, int numItems) { | |
return Observable.create((Subscriber<? super String> subscriber) -> { | |
Worker worker = Schedulers.computation().createWorker(); | |
subscriber.add(worker); | |
worker.schedule(() -> { | |
try { | |
StringWriter jsonString = new StringWriter(); | |
JsonGenerator json = jsonFactory.createJsonGenerator(jsonString); | |
json.writeStartObject(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.reactivex.lab.services.common; | |
import org.codehaus.jackson.map.ObjectMapper; | |
import org.codehaus.jackson.map.ObjectReader; | |
import org.codehaus.jackson.map.ObjectWriter; | |
import java.io.IOException; | |
import java.util.Map; | |
public class SimpleJson { |