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);
}
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++;
}
}
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");
}
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;
});
}
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();
}
Aggregations