Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Uni.or - The list didn't include the upstream Uni. #167

Merged
merged 3 commits into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.smallrye.mutiny.helpers.ParameterValidation.nonNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

Expand All @@ -23,7 +24,9 @@ public Uni<T> uni(Uni<T> other) {

@SafeVarargs
public final Uni<T> unis(Uni<T>... other) {
List<Uni<T>> list = Arrays.asList(other);
List<Uni<T>> list = new ArrayList<>();
list.add(upstream);
list.addAll(Arrays.asList(other));
return Infrastructure.onUniCreation(new UniOrCombination<>(list));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
*/
public interface MultiInterceptor {

/**
* Default ordinal value.
*/
int DEFAULT_ORDINAL = 100;

/**
* @return the interceptor ordinal. The ordinal is used to sort the interceptor. Lower value are executed first.
* Default is 100.
*/
default int ordinal() {
return 100;
return DEFAULT_ORDINAL;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.smallrye.mutiny.infrastructure;

import static org.assertj.core.api.Assertions.assertThat;

import org.reactivestreams.Subscriber;
import org.testng.annotations.Test;

import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.operators.AbstractMulti;
import io.smallrye.mutiny.test.Mocks;

public class MultiInterceptorTest {

@Test
public void testDefaultInterceptorBehavior() {
MultiInterceptor interceptor = new MultiInterceptor() {
// Default.
};

assertThat(interceptor.ordinal()).isEqualTo(MultiInterceptor.DEFAULT_ORDINAL);
Multi<String> multi = new AbstractMulti<String>() {
// Do nothing
};
assertThat(interceptor.onMultiCreation(multi)).isSameAs(multi);

Subscriber<Object> subscriber = Mocks.subscriber();
assertThat(interceptor.onSubscription(multi, subscriber)).isSameAs(subscriber);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,26 @@ public void testWithThreeImmediateChallengers() {
subscriber.assertCompletedSuccessfully().assertItem(1);
}

@Test
public void testUniOrWithAnotherUni() {
UniAssertSubscriber<String> subscriber = UniAssertSubscriber.create();
Uni.createFrom().item("foo").or().uni(Uni.createFrom().item("bar")).subscribe()
.withSubscriber(subscriber);
subscriber.assertCompletedSuccessfully().assertItem("foo");
}

@Test
public void testUniOrWithDelayedUni() {
Uni<String> first = Uni.createFrom().item("foo").onItem().delayIt().onExecutor(executor)
.by(Duration.ofMillis(10));
Uni<String> second = Uni.createFrom().item("bar").onItem().delayIt().onExecutor(executor)
.by(Duration.ofMillis(1000));
Uni<String> third = Uni.createFrom().item("baz").onItem().delayIt().onExecutor(executor)
.by(Duration.ofMillis(10000));

assertThat(third.or().unis(first, second).await().indefinitely()).isEqualTo("foo");
assertThat(second.or().unis(third, first).await().indefinitely()).isEqualTo("foo");
assertThat(first.or().unis(third, second).await().indefinitely()).isEqualTo("foo");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.smallrye.mutiny.subscription;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.testng.annotations.Test;

public class UniSubscriptionTest {
@Test
public void testDefaultRequestMethod() {
UniSubscription subscription = () -> {
// do nothing
};

subscription.request(12);
assertThatThrownBy(() -> subscription.request(-23)).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> subscription.request(0)).isInstanceOf(IllegalArgumentException.class);
subscription.request(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class ReactiveStreamsEngineImplTck extends ReactiveStreamsTck<Engine> {

static TestEnvironment ENV = new TestEnvironment(true);
static TestEnvironment ENV = new TestEnvironment();

public ReactiveStreamsEngineImplTck() {
super(ENV);
Expand Down