Build optimization 26.09.2017 (#2676)
* Optimize spring-rest * Refactor RxJava * Refactor RxJava
This commit is contained in:
parent
c9a754f0e4
commit
d10d758c84
rxjava
pom.xml
src/test/java/com/baeldung/rxjava
ObservableTest.javaResourceManagementTest.javaRxJavaBackpressureLongRunningUnitTest.javaRxJavaCustomOperatorUnitTest.javaRxJavaUnitTest.javaSchedulersTest.javaSingleTest.javaSubjectTest.javaUtilityOperatorsTest.java
jdbc
AutomapClassIntegrationTest.javaAutomapInterfaceIntegrationTest.javaBasicQueryTypesIntegrationTest.javaInsertBlobIntegrationTest.javaInsertClobIntegrationTest.javaReturnKeysIntegrationTest.javaTransactionIntegrationTest.java
onerror
spring-rest/src/test/java/com/baeldung
@ -3,7 +3,6 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>rxjava</artifactId>
|
<artifactId>rxjava</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import static junit.framework.Assert.assertTrue;
|
|||||||
|
|
||||||
public class ObservableTest {
|
public class ObservableTest {
|
||||||
|
|
||||||
String result = "";
|
private String result = "";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenString_whenJustAndSubscribe_thenEmitsSingleItem() {
|
public void givenString_whenJustAndSubscribe_thenEmitsSingleItem() {
|
||||||
@ -85,7 +85,7 @@ public class ObservableTest {
|
|||||||
.groupBy(i -> 0 == (i % 2) ? "EVEN" : "ODD")
|
.groupBy(i -> 0 == (i % 2) ? "EVEN" : "ODD")
|
||||||
.subscribe(group ->
|
.subscribe(group ->
|
||||||
group.subscribe((number) -> {
|
group.subscribe((number) -> {
|
||||||
if (group.getKey().toString().equals("EVEN")) {
|
if (group.getKey().equals("EVEN")) {
|
||||||
EVEN[0] += number;
|
EVEN[0] += number;
|
||||||
} else {
|
} else {
|
||||||
ODD[0] += number;
|
ODD[0] += number;
|
||||||
@ -141,5 +141,4 @@ public class ObservableTest {
|
|||||||
|
|
||||||
assertTrue(sum[0] == 10);
|
assertTrue(sum[0] == 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,16 +12,12 @@ public class ResourceManagementTest {
|
|||||||
|
|
||||||
String[] result = {""};
|
String[] result = {""};
|
||||||
Observable<Character> values = Observable.using(
|
Observable<Character> values = Observable.using(
|
||||||
() -> {
|
() -> "MyResource",
|
||||||
return "MyResource";
|
r -> Observable.create(o -> {
|
||||||
},
|
for (Character c : r.toCharArray())
|
||||||
r -> {
|
o.onNext(c);
|
||||||
return Observable.create(o -> {
|
o.onCompleted();
|
||||||
for (Character c : r.toCharArray())
|
}),
|
||||||
o.onNext(c);
|
|
||||||
o.onCompleted();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
r -> System.out.println("Disposed: " + r)
|
r -> System.out.println("Disposed: " + r)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ public class RxJavaBackpressureLongRunningUnitTest {
|
|||||||
// then
|
// then
|
||||||
testSubscriber.awaitTerminalEvent();
|
testSubscriber.awaitTerminalEvent();
|
||||||
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -60,7 +59,6 @@ public class RxJavaBackpressureLongRunningUnitTest {
|
|||||||
// then
|
// then
|
||||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||||
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -77,7 +75,6 @@ public class RxJavaBackpressureLongRunningUnitTest {
|
|||||||
// then
|
// then
|
||||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||||
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -88,15 +85,14 @@ public class RxJavaBackpressureLongRunningUnitTest {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
source.sample(100, TimeUnit.MILLISECONDS)
|
source.sample(100, TimeUnit.MILLISECONDS)
|
||||||
// .throttleFirst(100, TimeUnit.MILLISECONDS)
|
// .throttleFirst(100, TimeUnit.MILLISECONDS)
|
||||||
.observeOn(Schedulers.computation()).subscribe(testSubscriber);
|
.observeOn(Schedulers.computation()).subscribe(testSubscriber);
|
||||||
|
|
||||||
IntStream.range(0, 1_000).forEach(source::onNext);
|
IntStream.range(0, 1_000).forEach(source::onNext);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||||
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -111,7 +107,6 @@ public class RxJavaBackpressureLongRunningUnitTest {
|
|||||||
// then
|
// then
|
||||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||||
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -120,11 +115,11 @@ public class RxJavaBackpressureLongRunningUnitTest {
|
|||||||
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Observable.range(1, 1_000_000).onBackpressureDrop().observeOn(Schedulers.computation()).subscribe(testSubscriber);
|
Observable.range(1, 1_000_000).onBackpressureDrop().observeOn(Schedulers.computation())
|
||||||
|
.subscribe(testSubscriber);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||||
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
package com.baeldung.rxjava;
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import rx.Observable;
|
||||||
|
import rx.Observable.Operator;
|
||||||
|
import rx.Observable.Transformer;
|
||||||
|
import rx.Subscriber;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static com.baelding.rxjava.operator.ToCleanString.toCleanString;
|
import static com.baelding.rxjava.operator.ToCleanString.toCleanString;
|
||||||
import static com.baelding.rxjava.operator.ToLength.toLength;
|
import static com.baelding.rxjava.operator.ToLength.toLength;
|
||||||
import static org.hamcrest.Matchers.hasItems;
|
import static org.hamcrest.Matchers.hasItems;
|
||||||
@ -7,20 +17,6 @@ import static org.hamcrest.Matchers.hasSize;
|
|||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import rx.Observable;
|
|
||||||
import rx.Observable.Operator;
|
|
||||||
import rx.Observable.Transformer;
|
|
||||||
import rx.Subscriber;
|
|
||||||
|
|
||||||
import com.baelding.rxjava.operator.ToCleanString;
|
|
||||||
import com.baelding.rxjava.operator.ToLength;
|
|
||||||
|
|
||||||
public class RxJavaCustomOperatorUnitTest {
|
public class RxJavaCustomOperatorUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -29,7 +25,7 @@ public class RxJavaCustomOperatorUnitTest {
|
|||||||
final List<String> results = new ArrayList<>();
|
final List<String> results = new ArrayList<>();
|
||||||
|
|
||||||
final Observable<String> observable = Observable.from(list)
|
final Observable<String> observable = Observable.from(list)
|
||||||
.lift(toCleanString());
|
.lift(toCleanString());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
observable.subscribe(results::add);
|
observable.subscribe(results::add);
|
||||||
@ -46,7 +42,7 @@ public class RxJavaCustomOperatorUnitTest {
|
|||||||
final List<Integer> results = new ArrayList<>();
|
final List<Integer> results = new ArrayList<>();
|
||||||
|
|
||||||
final Observable<Integer> observable = Observable.from(list)
|
final Observable<Integer> observable = Observable.from(list)
|
||||||
.compose(toLength());
|
.compose(toLength());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
observable.subscribe(results::add);
|
observable.subscribe(results::add);
|
||||||
@ -85,8 +81,8 @@ public class RxJavaCustomOperatorUnitTest {
|
|||||||
|
|
||||||
final List<String> results = new ArrayList<>();
|
final List<String> results = new ArrayList<>();
|
||||||
Observable.from(Arrays.asList("ap_p-l@e", "or-an?ge"))
|
Observable.from(Arrays.asList("ap_p-l@e", "or-an?ge"))
|
||||||
.lift(cleanStringFn)
|
.lift(cleanStringFn)
|
||||||
.subscribe(results::add);
|
.subscribe(results::add);
|
||||||
|
|
||||||
assertThat(results, notNullValue());
|
assertThat(results, notNullValue());
|
||||||
assertThat(results, hasSize(2));
|
assertThat(results, hasSize(2));
|
||||||
@ -99,8 +95,8 @@ public class RxJavaCustomOperatorUnitTest {
|
|||||||
|
|
||||||
final List<Integer> results = new ArrayList<>();
|
final List<Integer> results = new ArrayList<>();
|
||||||
Observable.from(Arrays.asList("apple", "orange"))
|
Observable.from(Arrays.asList("apple", "orange"))
|
||||||
.compose(toLengthFn)
|
.compose(toLengthFn)
|
||||||
.subscribe(results::add);
|
.subscribe(results::add);
|
||||||
|
|
||||||
assertThat(results, notNullValue());
|
assertThat(results, notNullValue());
|
||||||
assertThat(results, hasSize(2));
|
assertThat(results, hasSize(2));
|
||||||
|
@ -10,7 +10,9 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.hasItems;
|
||||||
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
public class RxJavaUnitTest {
|
public class RxJavaUnitTest {
|
||||||
@ -19,7 +21,8 @@ public class RxJavaUnitTest {
|
|||||||
// given
|
// given
|
||||||
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
||||||
List<String> results = new ArrayList<>();
|
List<String> results = new ArrayList<>();
|
||||||
Observable<String> observable = Observable.from(letters).zipWith(Observable.range(1, Integer.MAX_VALUE), (string, index) -> index + "-" + string);
|
Observable<String> observable = Observable.from(letters)
|
||||||
|
.zipWith(Observable.range(1, Integer.MAX_VALUE), (string, index) -> index + "-" + string);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
observable.subscribe(results::add);
|
observable.subscribe(results::add);
|
||||||
@ -36,7 +39,8 @@ public class RxJavaUnitTest {
|
|||||||
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
||||||
TestSubscriber<String> subscriber = new TestSubscriber<>();
|
TestSubscriber<String> subscriber = new TestSubscriber<>();
|
||||||
|
|
||||||
Observable<String> observable = Observable.from(letters).zipWith(Observable.range(1, Integer.MAX_VALUE), ((string, index) -> index + "-" + string));
|
Observable<String> observable = Observable.from(letters)
|
||||||
|
.zipWith(Observable.range(1, Integer.MAX_VALUE), ((string, index) -> index + "-" + string));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
observable.subscribe(subscriber);
|
observable.subscribe(subscriber);
|
||||||
@ -54,7 +58,9 @@ public class RxJavaUnitTest {
|
|||||||
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
List<String> letters = Arrays.asList("A", "B", "C", "D", "E");
|
||||||
TestSubscriber<String> subscriber = new TestSubscriber<>();
|
TestSubscriber<String> subscriber = new TestSubscriber<>();
|
||||||
|
|
||||||
Observable<String> observable = Observable.from(letters).zipWith(Observable.range(1, Integer.MAX_VALUE), ((string, index) -> index + "-" + string)).concatWith(Observable.error(new RuntimeException("error in Observable")));
|
Observable<String> observable = Observable.from(letters)
|
||||||
|
.zipWith(Observable.range(1, Integer.MAX_VALUE), ((string, index) -> index + "-" + string))
|
||||||
|
.concatWith(Observable.error(new RuntimeException("error in Observable")));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
observable.subscribe(subscriber);
|
observable.subscribe(subscriber);
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package com.baeldung.rxjava;
|
package com.baeldung.rxjava;
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -23,9 +21,9 @@ import static org.hamcrest.Matchers.hasItems;
|
|||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
public class SchedulersTest {
|
public class SchedulersTest {
|
||||||
String result = "";
|
private String result = "";
|
||||||
String result1 = "";
|
private String result1 = "";
|
||||||
String result2 = "";
|
private String result2 = "";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenScheduledWorker_whenScheduleAnAction_thenResultAction() throws InterruptedException {
|
public void givenScheduledWorker_whenScheduleAnAction_thenResultAction() throws InterruptedException {
|
||||||
@ -108,7 +106,6 @@ public class SchedulersTest {
|
|||||||
Assert.assertTrue(result.equals("main"));
|
Assert.assertTrue(result.equals("main"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenObservable_whenTrampolineScheduled_thenExecuteOnMainThread() throws InterruptedException {
|
public void givenObservable_whenTrampolineScheduled_thenExecuteOnMainThread() throws InterruptedException {
|
||||||
System.out.println("trampoline_1");
|
System.out.println("trampoline_1");
|
||||||
@ -161,7 +158,8 @@ public class SchedulersTest {
|
|||||||
subscriber.onNext("Alfa");
|
subscriber.onNext("Alfa");
|
||||||
subscriber.onNext("Beta");
|
subscriber.onNext("Beta");
|
||||||
subscriber.onCompleted();
|
subscriber.onCompleted();
|
||||||
});;
|
});
|
||||||
|
;
|
||||||
|
|
||||||
observable
|
observable
|
||||||
.subscribeOn(schedulerA)
|
.subscribeOn(schedulerA)
|
||||||
@ -203,10 +201,10 @@ public class SchedulersTest {
|
|||||||
|
|
||||||
Observable<Long> tick = Observable.interval(1, TimeUnit.SECONDS, scheduler);
|
Observable<Long> tick = Observable.interval(1, TimeUnit.SECONDS, scheduler);
|
||||||
|
|
||||||
Observable.from(letters)
|
Observable.from(letters)
|
||||||
.zipWith(tick, (string, index) -> index + "-" + string)
|
.zipWith(tick, (string, index) -> index + "-" + string)
|
||||||
.subscribeOn(scheduler)
|
.subscribeOn(scheduler)
|
||||||
.subscribe(subscriber);
|
.subscribe(subscriber);
|
||||||
|
|
||||||
subscriber.assertNoValues();
|
subscriber.assertNoValues();
|
||||||
subscriber.assertNotCompleted();
|
subscriber.assertNotCompleted();
|
||||||
@ -229,10 +227,9 @@ public class SchedulersTest {
|
|||||||
Scheduler schedulerA = Schedulers.from(poolA);
|
Scheduler schedulerA = Schedulers.from(poolA);
|
||||||
Observable.just('A', 'B')
|
Observable.just('A', 'B')
|
||||||
.delay(1, TimeUnit.SECONDS, schedulerA)
|
.delay(1, TimeUnit.SECONDS, schedulerA)
|
||||||
.subscribe(i -> result+= Thread.currentThread().getName() + i + " ");
|
.subscribe(i -> result += Thread.currentThread().getName() + i + " ");
|
||||||
|
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
Assert.assertTrue(result.equals("Sched1-A Sched1-B "));
|
Assert.assertTrue(result.equals("Sched1-A Sched1-B "));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,5 +20,4 @@ public class SingleTest {
|
|||||||
single.subscribe();
|
single.subscribe();
|
||||||
assertTrue(result[0].equals("Hello"));
|
assertTrue(result[0].equals("Hello"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import static junit.framework.Assert.assertTrue;
|
|||||||
public class SubjectTest {
|
public class SubjectTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubjectAndTwoSubscribers_whenSubscribeOnSubject_thenSubscriberBeginsToAdd(){
|
public void givenSubjectAndTwoSubscribers_whenSubscribeOnSubject_thenSubscriberBeginsToAdd() {
|
||||||
PublishSubject<Integer> subject = PublishSubject.create();
|
PublishSubject<Integer> subject = PublishSubject.create();
|
||||||
|
|
||||||
subject.subscribe(SubjectImpl.getFirstObserver());
|
subject.subscribe(SubjectImpl.getFirstObserver());
|
||||||
|
@ -7,6 +7,7 @@ import rx.Observable;
|
|||||||
import rx.Observer;
|
import rx.Observer;
|
||||||
import rx.exceptions.OnErrorNotImplementedException;
|
import rx.exceptions.OnErrorNotImplementedException;
|
||||||
import rx.schedulers.Schedulers;
|
import rx.schedulers.Schedulers;
|
||||||
|
import rx.schedulers.Timestamped;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -14,9 +15,9 @@ import static org.junit.Assert.assertTrue;
|
|||||||
|
|
||||||
public class UtilityOperatorsTest {
|
public class UtilityOperatorsTest {
|
||||||
|
|
||||||
int emittedTotal = 0;
|
private int emittedTotal = 0;
|
||||||
int receivedTotal = 0;
|
private int receivedTotal = 0;
|
||||||
String result = "";
|
private String result = "";
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
public ExpectedException thrown = ExpectedException.none();
|
||||||
@ -44,7 +45,6 @@ public class UtilityOperatorsTest {
|
|||||||
assertTrue(receivedTotal == 15000);
|
assertTrue(receivedTotal == 15000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenObservable_whenObserveOnBeforeOnNext_thenEmitsEventsOnComputeScheduler() throws InterruptedException {
|
public void givenObservable_whenObserveOnBeforeOnNext_thenEmitsEventsOnComputeScheduler() throws InterruptedException {
|
||||||
|
|
||||||
@ -68,7 +68,6 @@ public class UtilityOperatorsTest {
|
|||||||
assertTrue(receivedTotal == 15000);
|
assertTrue(receivedTotal == 15000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenObservable_whenSubscribeOn_thenEmitsEventsOnComputeScheduler() throws InterruptedException {
|
public void givenObservable_whenSubscribeOn_thenEmitsEventsOnComputeScheduler() throws InterruptedException {
|
||||||
|
|
||||||
@ -92,7 +91,6 @@ public class UtilityOperatorsTest {
|
|||||||
assertTrue(receivedTotal == 15000);
|
assertTrue(receivedTotal == 15000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenObservableWithOneEvent_whenSingle_thenEmitEvent() {
|
public void givenObservableWithOneEvent_whenSingle_thenEmitEvent() {
|
||||||
|
|
||||||
@ -197,15 +195,13 @@ public class UtilityOperatorsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void givenObservables_whenDelay_thenEventsStartAppearAfterATime() throws InterruptedException {
|
public void givenObservables_whenDelay_thenEventsStartAppearAfterATime() throws InterruptedException {
|
||||||
|
|
||||||
Observable source
|
Observable<Timestamped<Long>> source = Observable.interval(1, TimeUnit.SECONDS)
|
||||||
= Observable.interval(1, TimeUnit.SECONDS)
|
|
||||||
.take(5)
|
.take(5)
|
||||||
.timestamp();
|
.timestamp();
|
||||||
|
|
||||||
Observable delay
|
Observable<Timestamped<Long>> delay = source.delaySubscription(2, TimeUnit.SECONDS);
|
||||||
= source.delaySubscription(2, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
source.subscribe(
|
source.<Long>subscribe(
|
||||||
value -> System.out.println("source :" + value),
|
value -> System.out.println("source :" + value),
|
||||||
t -> System.out.println("source error"),
|
t -> System.out.println("source error"),
|
||||||
() -> System.out.println("source completed"));
|
() -> System.out.println("source completed"));
|
||||||
@ -231,14 +227,12 @@ public class UtilityOperatorsTest {
|
|||||||
|
|
||||||
Observable<Character> values = Observable.using(
|
Observable<Character> values = Observable.using(
|
||||||
() -> "resource",
|
() -> "resource",
|
||||||
r -> {
|
r -> Observable.create(o -> {
|
||||||
return Observable.create(o -> {
|
for (Character c : r.toCharArray()) {
|
||||||
for (Character c : r.toCharArray()) {
|
o.onNext(c);
|
||||||
o.onNext(c);
|
}
|
||||||
}
|
o.onCompleted();
|
||||||
o.onCompleted();
|
}),
|
||||||
});
|
|
||||||
},
|
|
||||||
r -> System.out.println("Disposed: " + r)
|
r -> System.out.println("Disposed: " + r)
|
||||||
);
|
);
|
||||||
values.subscribe(
|
values.subscribe(
|
||||||
@ -248,7 +242,6 @@ public class UtilityOperatorsTest {
|
|||||||
assertTrue(result.equals("resource"));
|
assertTrue(result.equals("resource"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenObservableCached_whenSubscribesWith2Actions_thenEmitsCachedValues() {
|
public void givenObservableCached_whenSubscribesWith2Actions_thenEmitsCachedValues() {
|
||||||
|
|
||||||
@ -269,5 +262,4 @@ public class UtilityOperatorsTest {
|
|||||||
});
|
});
|
||||||
assertTrue(receivedTotal == 8);
|
assertTrue(receivedTotal == 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,18 +8,16 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.github.davidmoten.rx.jdbc.ConnectionProvider;
|
|
||||||
import com.github.davidmoten.rx.jdbc.Database;
|
import com.github.davidmoten.rx.jdbc.Database;
|
||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
|
||||||
public class AutomapClassTest {
|
public class AutomapClassIntegrationTest {
|
||||||
|
|
||||||
ConnectionProvider connectionProvider = Connector.connectionProvider;
|
private Database db = Database.from(Connector.connectionProvider);
|
||||||
Database db = Database.from(connectionProvider);
|
|
||||||
|
|
||||||
Observable<Integer> create = null;
|
private Observable<Integer> create = null;
|
||||||
Observable<Integer> insert1, insert2 = null;
|
private Observable<Integer> insert1, insert2 = null;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
@ -58,6 +56,6 @@ public class AutomapClassTest {
|
|||||||
public void close() {
|
public void close() {
|
||||||
db.update("DROP TABLE MANAGER")
|
db.update("DROP TABLE MANAGER")
|
||||||
.dependsOn(create);
|
.dependsOn(create);
|
||||||
connectionProvider.close();
|
Connector.connectionProvider.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,18 +8,16 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.github.davidmoten.rx.jdbc.ConnectionProvider;
|
|
||||||
import com.github.davidmoten.rx.jdbc.Database;
|
import com.github.davidmoten.rx.jdbc.Database;
|
||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
|
||||||
public class AutomapInterfaceTest {
|
public class AutomapInterfaceIntegrationTest {
|
||||||
|
|
||||||
ConnectionProvider connectionProvider = Connector.connectionProvider;
|
private Database db = Database.from(Connector.connectionProvider);
|
||||||
Database db = Database.from(connectionProvider);
|
|
||||||
|
|
||||||
Observable<Integer> create = null;
|
private Observable<Integer> create = null;
|
||||||
Observable<Integer> insert1, insert2 = null;
|
private Observable<Integer> insert1, insert2 = null;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
@ -58,7 +56,7 @@ public class AutomapInterfaceTest {
|
|||||||
public void close() {
|
public void close() {
|
||||||
db.update("DROP TABLE EMPLOYEE")
|
db.update("DROP TABLE EMPLOYEE")
|
||||||
.dependsOn(create);
|
.dependsOn(create);
|
||||||
connectionProvider.close();
|
Connector.connectionProvider.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,42 +1,38 @@
|
|||||||
package com.baeldung.rxjava.jdbc;
|
package com.baeldung.rxjava.jdbc;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.github.davidmoten.rx.jdbc.Database;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.After;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.github.davidmoten.rx.jdbc.ConnectionProvider;
|
public class BasicQueryTypesIntegrationTest {
|
||||||
import com.github.davidmoten.rx.jdbc.Database;
|
|
||||||
|
|
||||||
import rx.Observable;
|
private Database db = Database.from(Connector.connectionProvider);
|
||||||
|
|
||||||
public class BasicQueryTypesTest {
|
private Observable<Integer> create;
|
||||||
|
|
||||||
ConnectionProvider connectionProvider = Connector.connectionProvider;
|
|
||||||
Database db = Database.from(connectionProvider);
|
|
||||||
|
|
||||||
Observable<Integer> create, insert1, insert2, insert3, update, delete = null;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCreateTableAndInsertRecords_thenCorrect() {
|
public void whenCreateTableAndInsertRecords_thenCorrect() {
|
||||||
create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))")
|
create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))")
|
||||||
.count();
|
.count();
|
||||||
insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')")
|
Observable<Integer> insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')")
|
||||||
.dependsOn(create)
|
.dependsOn(create)
|
||||||
.count();
|
.count();
|
||||||
update = db.update("UPDATE EMPLOYEE SET name = 'Alan' WHERE id = 1")
|
Observable<Integer> update = db.update("UPDATE EMPLOYEE SET name = 'Alan' WHERE id = 1")
|
||||||
.dependsOn(create)
|
.dependsOn(create)
|
||||||
.count();
|
.count();
|
||||||
insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')")
|
Observable<Integer> insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')")
|
||||||
.dependsOn(create)
|
.dependsOn(create)
|
||||||
.count();
|
.count();
|
||||||
insert3 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(3, 'Mike')")
|
Observable<Integer> insert3 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(3, 'Mike')")
|
||||||
.dependsOn(create)
|
.dependsOn(create)
|
||||||
.count();
|
.count();
|
||||||
delete = db.update("DELETE FROM EMPLOYEE WHERE id = 2")
|
Observable<Integer> delete = db.update("DELETE FROM EMPLOYEE WHERE id = 2")
|
||||||
.dependsOn(create)
|
.dependsOn(create)
|
||||||
.count();
|
.count();
|
||||||
List<String> names = db.select("select name from EMPLOYEE where id < ?")
|
List<String> names = db.select("select name from EMPLOYEE where id < ?")
|
||||||
@ -59,6 +55,6 @@ public class BasicQueryTypesTest {
|
|||||||
public void close() {
|
public void close() {
|
||||||
db.update("DROP TABLE EMPLOYEE")
|
db.update("DROP TABLE EMPLOYEE")
|
||||||
.dependsOn(create);
|
.dependsOn(create);
|
||||||
connectionProvider.close();
|
Connector.connectionProvider.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,30 +1,26 @@
|
|||||||
package com.baeldung.rxjava.jdbc;
|
package com.baeldung.rxjava.jdbc;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.github.davidmoten.rx.jdbc.Database;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.junit.After;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.github.davidmoten.rx.jdbc.ConnectionProvider;
|
public class InsertBlobIntegrationTest {
|
||||||
import com.github.davidmoten.rx.jdbc.Database;
|
|
||||||
|
|
||||||
import rx.Observable;
|
private Database db = Database.from(Connector.connectionProvider);
|
||||||
|
|
||||||
public class InsertBlobTest {
|
private String expectedDocument = null;
|
||||||
|
private String actualDocument = null;
|
||||||
|
|
||||||
ConnectionProvider connectionProvider = Connector.connectionProvider;
|
private Observable<Integer> create, insert = null;
|
||||||
Database db = Database.from(connectionProvider);
|
|
||||||
|
|
||||||
String expectedDocument = null;
|
|
||||||
String actualDocument = null;
|
|
||||||
|
|
||||||
Observable<Integer> create, insert = null;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws IOException {
|
public void setup() throws IOException {
|
||||||
@ -60,6 +56,6 @@ public class InsertBlobTest {
|
|||||||
public void close() {
|
public void close() {
|
||||||
db.update("DROP TABLE SERVERLOG")
|
db.update("DROP TABLE SERVERLOG")
|
||||||
.dependsOn(create);
|
.dependsOn(create);
|
||||||
connectionProvider.close();
|
Connector.connectionProvider.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,29 +1,25 @@
|
|||||||
package com.baeldung.rxjava.jdbc;
|
package com.baeldung.rxjava.jdbc;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.github.davidmoten.rx.jdbc.Database;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.junit.After;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.github.davidmoten.rx.jdbc.ConnectionProvider;
|
public class InsertClobIntegrationTest {
|
||||||
import com.github.davidmoten.rx.jdbc.Database;
|
|
||||||
|
|
||||||
import rx.Observable;
|
private Database db = Database.from(Connector.connectionProvider);
|
||||||
|
|
||||||
public class InsertClobTest {
|
private String expectedDocument = null;
|
||||||
|
private String actualDocument = null;
|
||||||
|
|
||||||
ConnectionProvider connectionProvider = Connector.connectionProvider;
|
private Observable<Integer> create, insert = null;
|
||||||
Database db = Database.from(connectionProvider);
|
|
||||||
|
|
||||||
String expectedDocument = null;
|
|
||||||
String actualDocument = null;
|
|
||||||
|
|
||||||
Observable<Integer> create, insert = null;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws IOException {
|
public void setup() throws IOException {
|
||||||
@ -58,6 +54,6 @@ public class InsertClobTest {
|
|||||||
public void close() {
|
public void close() {
|
||||||
db.update("DROP TABLE SERVERLOG")
|
db.update("DROP TABLE SERVERLOG")
|
||||||
.dependsOn(create);
|
.dependsOn(create);
|
||||||
connectionProvider.close();
|
Connector.connectionProvider.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,28 +1,24 @@
|
|||||||
package com.baeldung.rxjava.jdbc;
|
package com.baeldung.rxjava.jdbc;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import com.github.davidmoten.rx.jdbc.Database;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.github.davidmoten.rx.jdbc.ConnectionProvider;
|
|
||||||
import com.github.davidmoten.rx.jdbc.Database;
|
|
||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
|
||||||
public class ReturnKeysTest {
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
Observable<Boolean> begin, commit = null;
|
public class ReturnKeysIntegrationTest {
|
||||||
Observable<Integer> createStatement, insertStatement, updateStatement = null;
|
|
||||||
|
|
||||||
ConnectionProvider connectionProvider = Connector.connectionProvider;
|
private Observable<Integer> createStatement;
|
||||||
Database db = Database.from(connectionProvider);
|
|
||||||
|
private Database db = Database.from(Connector.connectionProvider);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
begin = db.beginTransaction();
|
Observable<Boolean> begin = db.beginTransaction();
|
||||||
createStatement = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int auto_increment primary key, name varchar(255))")
|
createStatement = db
|
||||||
|
.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int auto_increment primary key, name varchar(255))")
|
||||||
.dependsOn(begin)
|
.dependsOn(begin)
|
||||||
.count();
|
.count();
|
||||||
}
|
}
|
||||||
@ -41,8 +37,7 @@ public class ReturnKeysTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void close() {
|
public void close() {
|
||||||
db.update("DROP TABLE EMPLOYEE")
|
db.update("DROP TABLE EMPLOYEE");
|
||||||
.dependsOn(createStatement);
|
Connector.connectionProvider.close();
|
||||||
connectionProvider.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,22 +1,15 @@
|
|||||||
package com.baeldung.rxjava.jdbc;
|
package com.baeldung.rxjava.jdbc;
|
||||||
|
|
||||||
|
import com.github.davidmoten.rx.jdbc.Database;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
import rx.Observable;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import org.junit.After;
|
public class TransactionIntegrationTest {
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.github.davidmoten.rx.jdbc.ConnectionProvider;
|
private Database db = Database.from(Connector.connectionProvider);
|
||||||
import com.github.davidmoten.rx.jdbc.Database;
|
|
||||||
|
|
||||||
import rx.Observable;
|
|
||||||
|
|
||||||
public class TransactionTest {
|
|
||||||
|
|
||||||
Observable<Boolean> begin, commit = null;
|
|
||||||
Observable<Integer> createStatement, insertStatement, updateStatement = null;
|
|
||||||
|
|
||||||
ConnectionProvider connectionProvider = Connector.connectionProvider;
|
|
||||||
Database db = Database.from(connectionProvider);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCommitTransaction_thenRecordUpdated() {
|
public void whenCommitTransaction_thenRecordUpdated() {
|
||||||
@ -43,8 +36,7 @@ public class TransactionTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void close() {
|
public void close() {
|
||||||
db.update("DROP TABLE EMPLOYEE")
|
db.update("DROP TABLE EMPLOYEE");
|
||||||
.dependsOn(createStatement);
|
Connector.connectionProvider.close();
|
||||||
connectionProvider.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,9 +9,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aiet
|
|
||||||
*/
|
|
||||||
public class ExceptionHandlingTest {
|
public class ExceptionHandlingTest {
|
||||||
|
|
||||||
private Error UNKNOWN_ERROR = new Error("unknown error");
|
private Error UNKNOWN_ERROR = new Error("unknown error");
|
||||||
@ -19,10 +16,10 @@ public class ExceptionHandlingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenHandleOnErrorReturn_thenResumed() {
|
public void givenSubscriberAndError_whenHandleOnErrorReturn_thenResumed() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(UNKNOWN_ERROR)
|
.<String>error(UNKNOWN_ERROR)
|
||||||
.onErrorReturn(Throwable::getMessage)
|
.onErrorReturn(Throwable::getMessage)
|
||||||
.subscribe(testObserver);
|
.subscribe(testObserver);
|
||||||
|
|
||||||
@ -34,10 +31,10 @@ public class ExceptionHandlingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenHandleOnErrorResume_thenResumed() {
|
public void givenSubscriberAndError_whenHandleOnErrorResume_thenResumed() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(UNKNOWN_ERROR)
|
.<String>error(UNKNOWN_ERROR)
|
||||||
.onErrorResumeNext(Observable.just("one", "two"))
|
.onErrorResumeNext(Observable.just("one", "two"))
|
||||||
.subscribe(testObserver);
|
.subscribe(testObserver);
|
||||||
|
|
||||||
@ -49,10 +46,10 @@ public class ExceptionHandlingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenHandleOnErrorResumeItem_thenResumed() {
|
public void givenSubscriberAndError_whenHandleOnErrorResumeItem_thenResumed() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(UNKNOWN_ERROR)
|
.<String>error(UNKNOWN_ERROR)
|
||||||
.onErrorReturnItem("singleValue")
|
.onErrorReturnItem("singleValue")
|
||||||
.subscribe(testObserver);
|
.subscribe(testObserver);
|
||||||
|
|
||||||
@ -64,10 +61,10 @@ public class ExceptionHandlingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenHandleOnErrorResumeFunc_thenResumed() {
|
public void givenSubscriberAndError_whenHandleOnErrorResumeFunc_thenResumed() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(UNKNOWN_ERROR)
|
.<String>error(UNKNOWN_ERROR)
|
||||||
.onErrorResumeNext(throwable -> {
|
.onErrorResumeNext(throwable -> {
|
||||||
return Observable.just(throwable.getMessage(), "nextValue");
|
return Observable.just(throwable.getMessage(), "nextValue");
|
||||||
})
|
})
|
||||||
@ -81,11 +78,11 @@ public class ExceptionHandlingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenChangeStateOnError_thenErrorThrown() {
|
public void givenSubscriberAndError_whenChangeStateOnError_thenErrorThrown() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
final AtomicBoolean state = new AtomicBoolean(false);
|
final AtomicBoolean state = new AtomicBoolean(false);
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(UNKNOWN_ERROR)
|
.<String>error(UNKNOWN_ERROR)
|
||||||
.doOnError(throwable -> state.set(true))
|
.doOnError(throwable -> state.set(true))
|
||||||
.subscribe(testObserver);
|
.subscribe(testObserver);
|
||||||
|
|
||||||
@ -97,10 +94,10 @@ public class ExceptionHandlingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenExceptionOccurOnError_thenCompositeExceptionThrown() {
|
public void givenSubscriberAndError_whenExceptionOccurOnError_thenCompositeExceptionThrown() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(UNKNOWN_ERROR)
|
.<String>error(UNKNOWN_ERROR)
|
||||||
.doOnError(throwable -> {
|
.doOnError(throwable -> {
|
||||||
throw new RuntimeException("unexcepted");
|
throw new RuntimeException("unexcepted");
|
||||||
})
|
})
|
||||||
@ -113,10 +110,10 @@ public class ExceptionHandlingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndException_whenHandleOnException_thenResumed() {
|
public void givenSubscriberAndException_whenHandleOnException_thenResumed() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(UNKNOWN_EXCEPTION)
|
.<String>error(UNKNOWN_EXCEPTION)
|
||||||
.onExceptionResumeNext(Observable.just("exceptionResumed"))
|
.onExceptionResumeNext(Observable.just("exceptionResumed"))
|
||||||
.subscribe(testObserver);
|
.subscribe(testObserver);
|
||||||
|
|
||||||
@ -128,14 +125,14 @@ public class ExceptionHandlingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenHandleOnException_thenNotResumed() {
|
public void givenSubscriberAndError_whenHandleOnException_thenNotResumed() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(UNKNOWN_ERROR)
|
.<String>error(UNKNOWN_ERROR)
|
||||||
.onExceptionResumeNext(Observable.just("exceptionResumed"))
|
.onExceptionResumeNext(Observable.just("exceptionResumed"))
|
||||||
.subscribe(testObserver);
|
.subscribe(testObserver);
|
||||||
|
|
||||||
testObserver.assertError(UNKNOWN_ERROR);
|
testObserver.assertError(UNKNOWN_ERROR);
|
||||||
testObserver.assertNotComplete();
|
testObserver.assertNotComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,20 +9,17 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author aiet
|
|
||||||
*/
|
|
||||||
public class OnErrorRetryTest {
|
public class OnErrorRetryTest {
|
||||||
|
|
||||||
private Error UNKNOWN_ERROR = new Error("unknown error");
|
private Error UNKNOWN_ERROR = new Error("unknown error");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenRetryOnError_thenRetryConfirmed() {
|
public void givenSubscriberAndError_whenRetryOnError_thenRetryConfirmed() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
AtomicInteger atomicCounter = new AtomicInteger(0);
|
AtomicInteger atomicCounter = new AtomicInteger(0);
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(() -> {
|
.<String>error(() -> {
|
||||||
atomicCounter.incrementAndGet();
|
atomicCounter.incrementAndGet();
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
})
|
})
|
||||||
@ -37,12 +34,12 @@ public class OnErrorRetryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenRetryConditionallyOnError_thenRetryConfirmed() {
|
public void givenSubscriberAndError_whenRetryConditionallyOnError_thenRetryConfirmed() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
|
|
||||||
AtomicInteger atomicCounter = new AtomicInteger(0);
|
AtomicInteger atomicCounter = new AtomicInteger(0);
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(() -> {
|
.<String>error(() -> {
|
||||||
atomicCounter.incrementAndGet();
|
atomicCounter.incrementAndGet();
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
})
|
})
|
||||||
@ -57,11 +54,11 @@ public class OnErrorRetryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenRetryUntilOnError_thenRetryConfirmed() {
|
public void givenSubscriberAndError_whenRetryUntilOnError_thenRetryConfirmed() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
AtomicInteger atomicCounter = new AtomicInteger(0);
|
AtomicInteger atomicCounter = new AtomicInteger(0);
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(UNKNOWN_ERROR)
|
.<String>error(UNKNOWN_ERROR)
|
||||||
.retryUntil(() -> atomicCounter.incrementAndGet() > 3)
|
.retryUntil(() -> atomicCounter.incrementAndGet() > 3)
|
||||||
.subscribe(testObserver);
|
.subscribe(testObserver);
|
||||||
|
|
||||||
@ -73,12 +70,12 @@ public class OnErrorRetryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenRetryWhenOnError_thenRetryConfirmed() {
|
public void givenSubscriberAndError_whenRetryWhenOnError_thenRetryConfirmed() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
Exception noretryException = new Exception("don't retry");
|
Exception noretryException = new Exception("don't retry");
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(UNKNOWN_ERROR)
|
.<String>error(UNKNOWN_ERROR)
|
||||||
.retryWhen(throwableObservable -> Observable.error(noretryException))
|
.retryWhen(throwableObservable -> Observable.<String>error(noretryException))
|
||||||
.subscribe(testObserver);
|
.subscribe(testObserver);
|
||||||
|
|
||||||
testObserver.assertError(noretryException);
|
testObserver.assertError(noretryException);
|
||||||
@ -88,11 +85,11 @@ public class OnErrorRetryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenRetryWhenOnError_thenCompleted() {
|
public void givenSubscriberAndError_whenRetryWhenOnError_thenCompleted() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
AtomicInteger atomicCounter = new AtomicInteger(0);
|
AtomicInteger atomicCounter = new AtomicInteger(0);
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(() -> {
|
.<String>error(() -> {
|
||||||
atomicCounter.incrementAndGet();
|
atomicCounter.incrementAndGet();
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
})
|
})
|
||||||
@ -107,11 +104,11 @@ public class OnErrorRetryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenRetryWhenOnError_thenResubscribed() {
|
public void givenSubscriberAndError_whenRetryWhenOnError_thenResubscribed() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
AtomicInteger atomicCounter = new AtomicInteger(0);
|
AtomicInteger atomicCounter = new AtomicInteger(0);
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(() -> {
|
.<String>error(() -> {
|
||||||
atomicCounter.incrementAndGet();
|
atomicCounter.incrementAndGet();
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
})
|
})
|
||||||
@ -126,11 +123,11 @@ public class OnErrorRetryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenSubscriberAndError_whenRetryWhenForMultipleTimesOnError_thenResumed() {
|
public void givenSubscriberAndError_whenRetryWhenForMultipleTimesOnError_thenResumed() {
|
||||||
TestObserver testObserver = new TestObserver();
|
TestObserver<String> testObserver = new TestObserver<>();
|
||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
|
|
||||||
Observable
|
Observable
|
||||||
.error(UNKNOWN_ERROR)
|
.<String>error(UNKNOWN_ERROR)
|
||||||
.retryWhen(throwableObservable -> throwableObservable
|
.retryWhen(throwableObservable -> throwableObservable
|
||||||
.zipWith(Observable.range(1, 3), (throwable, integer) -> integer)
|
.zipWith(Observable.range(1, 3), (throwable, integer) -> integer)
|
||||||
.flatMap(integer -> {
|
.flatMap(integer -> {
|
||||||
|
@ -21,7 +21,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = MainApplication.class)
|
@SpringBootTest(classes = MainApplication.class)
|
||||||
public class ExamplePostControllerRequestUnitTest {
|
public class ExamplePostControllerRequestIntegrationTest {
|
||||||
|
|
||||||
MockMvc mockMvc;
|
MockMvc mockMvc;
|
||||||
@Mock private ExampleService exampleService;
|
@Mock private ExampleService exampleService;
|
@ -23,7 +23,7 @@ import org.baeldung.config.MainApplication;
|
|||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = MainApplication.class)
|
@SpringBootTest(classes = MainApplication.class)
|
||||||
public class ExamplePostControllerResponseUnitTest {
|
public class ExamplePostControllerResponseIntegrationTest {
|
||||||
|
|
||||||
MockMvc mockMvc;
|
MockMvc mockMvc;
|
||||||
@Mock private ExampleService exampleService;
|
@Mock private ExampleService exampleService;
|
@ -1,33 +0,0 @@
|
|||||||
package com.baeldung.web.log.test;
|
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
|
|
||||||
import com.baeldung.web.log.data.TaxiRide;
|
|
||||||
|
|
||||||
public class TestTaxiFareController {
|
|
||||||
|
|
||||||
private static final String URL = "http://localhost:" + 8082 + "/spring-rest/taxifare/";
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void givenRequest_whenFetchTaxiFareRateCard_thanOK() {
|
|
||||||
TestRestTemplate testRestTemplate = new TestRestTemplate();
|
|
||||||
ResponseEntity<String> response = testRestTemplate.getForEntity(URL + "get/", String.class);
|
|
||||||
|
|
||||||
assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void givenTaxiRide_whenCalculatedFare_thanStatus200() {
|
|
||||||
TestRestTemplate testRestTemplate = new TestRestTemplate();
|
|
||||||
TaxiRide taxiRide = new TaxiRide(true, 10l);
|
|
||||||
String fare = testRestTemplate.postForObject(URL + "calculate/", taxiRide, String.class);
|
|
||||||
|
|
||||||
assertThat(fare, equalTo("200"));
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user