Skip to content

2.1.4 Observable.concat only executes first source #6037

@novodimaporo

Description

@novodimaporo

RxJava 2.1.4

Hello Im having trouble with contact, what I was trying tot do is reactively chose source depending on the result of the source before it. Im not sure if I understand how Observable.concat works, but this test is failing.

class RxTest {

    val source1 = "first"

    val source2 = "second"

    val source3 = "third"

    val SOURCE_1_FLAG = 0

    val SOURCE_2_FLAG = 1

    val SOURCE_3_FLAG = 2

    @Test
    fun unsatisfiedResultFromSource1ProceedToSource2Test() {
        val observer: TestObserver<String> = TestObserver()

        val loadData = ObservableTransformer<Int, String> {
            it.publish {
                Observable.concat(
                        it.filter { it == SOURCE_1_FLAG }
                                .flatMap { Observable.just(source1) }
                                .doOnNext{ System.out.println(it) }
                                .filter { false },
                        it.filter { it <= SOURCE_2_FLAG }
                                .flatMap { Observable.just(source2) }
                                .doOnNext{ System.out.println(it) },
                        it.filter { it <= SOURCE_3_FLAG }
                                .flatMap { Observable.just(source3) }
                                .doOnNext{ System.out.println(it) }
                ).take(1)
            }
        }
        val observable = Observable.just(SOURCE_1_FLAG).compose(loadData)

        observable.subscribe(observer)

        observer.assertComplete()
        observer.assertNoErrors()

        observer.assertValue { it == source2 }

        observer.assertNever { it == source1 }
        observer.assertNever { it == source3 }
    }
}

In this test I was expecting that the source1 will be executed and then because of the filter { false } it will proceed to source2. But what actually happens is it executes the first source and then completes without any emitted data, source2 havent got a chance to be executed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions