Search in sources :

Example 1 with Single

use of io.reactivex.rxjava3.core.Single in project redisson by redisson.

the class RedissonBatchRxTest method testConvertor.

@ParameterizedTest
@MethodSource("data")
public void testConvertor(BatchOptions batchOptions) {
    RBatchRx batch = redisson.createBatch(batchOptions);
    Single<Double> f1 = batch.getScoredSortedSet("myZKey").addScore("abc", 1d);
    Completable f2 = batch.getBucket("test").set("1");
    sync(batch.execute());
    assertThat(sync(f1)).isEqualTo(1d);
    sync(f2);
    RScoredSortedSetRx<String> set = redisson.getScoredSortedSet("myZKey");
    assertThat(sync(set.getScore("abc"))).isEqualTo(1d);
    RBucketRx<String> bucket = redisson.getBucket("test");
    assertThat(sync(bucket.get())).isEqualTo("1");
    RBatchRx batch2 = redisson.createBatch(batchOptions);
    Single<Double> b2f1 = batch2.getScoredSortedSet("myZKey2").addScore("abc", 1d);
    Single<Double> b2f2 = batch2.getScoredSortedSet("myZKey2").addScore("abc", 1d);
    sync(batch2.execute());
    assertThat(sync(b2f1)).isEqualTo(1d);
    assertThat(sync(b2f2)).isEqualTo(2d);
}
Also used : Completable(io.reactivex.rxjava3.core.Completable) RBatchRx(org.redisson.api.RBatchRx) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with Single

use of io.reactivex.rxjava3.core.Single in project redisson by redisson.

the class RedissonBatchRxTest method testOrdering.

@ParameterizedTest
@MethodSource("data")
public void testOrdering(BatchOptions batchOptions) throws InterruptedException {
    ExecutorService e = Executors.newFixedThreadPool(16);
    RBatchRx batch = redisson.createBatch(batchOptions);
    AtomicLong index = new AtomicLong(-1);
    List<Single<Long>> futures = new CopyOnWriteArrayList<>();
    for (int i = 0; i < 500; i++) {
        futures.add(null);
    }
    for (int i = 0; i < 500; i++) {
        final int j = i;
        e.execute(new Runnable() {

            @Override
            public void run() {
                synchronized (RedissonBatchRxTest.this) {
                    int i = (int) index.incrementAndGet();
                    int ind = j % 3;
                    Single<Long> f1 = batch.getAtomicLong("test" + ind).addAndGet(j);
                    futures.set(i, f1);
                }
            }
        });
    }
    e.shutdown();
    Assertions.assertTrue(e.awaitTermination(30, TimeUnit.SECONDS));
    List<?> s = sync(batch.execute()).getResponses();
    int i = 0;
    for (Object element : s) {
        Single<Long> a = futures.get(i);
        Assertions.assertEquals(sync(a), element);
        i++;
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Single(io.reactivex.rxjava3.core.Single) ExecutorService(java.util.concurrent.ExecutorService) AtomicLong(java.util.concurrent.atomic.AtomicLong) RBatchRx(org.redisson.api.RBatchRx) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with Single

use of io.reactivex.rxjava3.core.Single in project spring-framework by spring-projects.

the class HttpEntityMethodArgumentResolverTests method httpEntityWithSingleBody.

@Test
public void httpEntityWithSingleBody() {
    ServerWebExchange exchange = postExchange("line1");
    ResolvableType type = httpEntityType(Single.class, String.class);
    HttpEntity<Single<String>> httpEntity = resolveValue(exchange, type);
    assertThat(httpEntity.getHeaders()).isEqualTo(exchange.getRequest().getHeaders());
    assertThat(httpEntity.getBody().blockingGet()).isEqualTo("line1");
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) Single(io.reactivex.rxjava3.core.Single) ResolvableType(org.springframework.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 4 with Single

use of io.reactivex.rxjava3.core.Single in project spring-framework by spring-projects.

the class ModelAttributeMethodArgumentResolverTests method createAndBindToSingle.

@Test
void createAndBindToSingle() throws Exception {
    MethodParameter parameter = this.testMethod.annotPresent(ModelAttribute.class).arg(Single.class, Pojo.class);
    testBindPojo("pojoSingle", parameter, single -> {
        assertThat(single).isInstanceOf(Single.class);
        Object value = ((Single<?>) single).blockingGet();
        assertThat(value.getClass()).isEqualTo(Pojo.class);
        return (Pojo) value;
    });
}
Also used : Single(io.reactivex.rxjava3.core.Single) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.jupiter.api.Test)

Example 5 with Single

use of io.reactivex.rxjava3.core.Single in project spring-framework by spring-projects.

the class RequestBodyMethodArgumentResolverTests method emptyBodyWithSingle.

@Test
public void emptyBodyWithSingle() {
    MethodParameter param = this.testMethod.annot(requestBody()).arg(Single.class, String.class);
    Single<String> single = resolveValueWithEmptyBody(param);
    StepVerifier.create(single.toFlowable()).expectNextCount(0).expectError(ServerWebInputException.class).verify();
    param = this.testMethod.annot(requestBody().notRequired()).arg(Single.class, String.class);
    single = resolveValueWithEmptyBody(param);
    StepVerifier.create(single.toFlowable()).expectNextCount(0).expectError(ServerWebInputException.class).verify();
}
Also used : ServerWebInputException(org.springframework.web.server.ServerWebInputException) Single(io.reactivex.rxjava3.core.Single) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.Test)49 TestException (io.reactivex.rxjava3.exceptions.TestException)37 Single (io.reactivex.rxjava3.core.Single)14 InOrder (org.mockito.InOrder)13 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)9 Disposable (io.reactivex.rxjava3.disposables.Disposable)8 Test (org.junit.jupiter.api.Test)8 IOException (java.io.IOException)7 Predicate (io.reactivex.rxjava3.functions.Predicate)6 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 TimeUnit (java.util.concurrent.TimeUnit)5 MethodParameter (org.springframework.core.MethodParameter)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 ServiceResponse (org.whispersystems.signalservice.internal.ServiceResponse)4 Observable (io.reactivex.rxjava3.core.Observable)3 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)3 List (java.util.List)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Util (org.whispersystems.signalservice.internal.util.Util)3