Search in sources :

Example 21 with Completable

use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.

the class CompletableFromSupplierTest method fromSupplierInvokesLazy.

@Test
public void fromSupplierInvokesLazy() {
    final AtomicInteger atomicInteger = new AtomicInteger();
    Completable completable = Completable.fromSupplier(new Supplier<Object>() {

        @Override
        public Object get() throws Exception {
            atomicInteger.incrementAndGet();
            return null;
        }
    });
    assertEquals(0, atomicInteger.get());
    completable.test().assertResult();
    assertEquals(1, atomicInteger.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 22 with Completable

use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.

the class CompletableDoOnLifecycleTest method onSubscribeCrash.

@Test
public void onSubscribeCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") Consumer<? super Disposable> onSubscribe = mock(Consumer.class);
        Action onDispose = mock(Action.class);
        doThrow(new TestException("First")).when(onSubscribe).accept(any());
        Disposable bs = Disposable.empty();
        new Completable() {

            @Override
            protected void subscribeActual(CompletableObserver observer) {
                observer.onSubscribe(bs);
                observer.onError(new TestException("Second"));
                observer.onComplete();
            }
        }.doOnLifecycle(onSubscribe, onDispose).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        assertTrue(bs.isDisposed());
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
        verify(onSubscribe).accept(any());
        verify(onDispose, never()).run();
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 23 with Completable

use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.

the class CompletableFromActionTest method fromActionInvokesLazy.

@Test
public void fromActionInvokesLazy() {
    final AtomicInteger atomicInteger = new AtomicInteger();
    Completable completable = Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            atomicInteger.incrementAndGet();
        }
    });
    assertEquals(0, atomicInteger.get());
    completable.test().assertResult();
    assertEquals(1, atomicInteger.get());
}
Also used : Action(io.reactivex.rxjava3.functions.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 24 with Completable

use of io.reactivex.rxjava3.core.Completable in project wildfly by wildfly.

the class HotRodStore method batch.

@Override
public CompletionStage<Void> batch(int publisherCount, Publisher<SegmentedPublisher<Object>> removePublisher, Publisher<SegmentedPublisher<MarshallableEntry<K, V>>> writePublisher) {
    Completable removeCompletable = Flowable.fromPublisher(removePublisher).flatMap(sp -> Flowable.fromPublisher(sp), publisherCount).flatMapCompletable(key -> Completable.fromCompletionStage(this.cache.removeAsync(this.marshalKey(key))), false, this.batchSize);
    Completable writeCompletable = Flowable.fromPublisher(writePublisher).flatMap(sp -> Flowable.fromPublisher(sp), publisherCount).flatMapCompletable(entry -> Completable.fromCompletionStage(this.cache.putAsync(entry.getKeyBytes(), this.marshalValue(entry.getMarshalledValue()))), false, this.batchSize);
    return removeCompletable.mergeWith(writeCompletable).toCompletionStage(null);
}
Also used : MarshalledValue(org.infinispan.persistence.spi.MarshalledValue) ByteBuffer(org.infinispan.commons.io.ByteBuffer) MarshallableEntryFactory(org.infinispan.persistence.spi.MarshallableEntryFactory) RemoteCache(org.infinispan.client.hotrod.RemoteCache) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) HotRodClientException(org.infinispan.client.hotrod.exceptions.HotRodClientException) Functions(org.wildfly.common.function.Functions) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) InfinispanLogger(org.jboss.as.clustering.infinispan.InfinispanLogger) Flag(org.infinispan.client.hotrod.Flag) Map(java.util.Map) TransactionMode(org.infinispan.client.hotrod.configuration.TransactionMode) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) ConfiguredBy(org.infinispan.commons.configuration.ConfiguredBy) DefaultTemplate(org.infinispan.client.hotrod.DefaultTemplate) RemoteCacheContainer(org.wildfly.clustering.infinispan.client.RemoteCacheContainer) EnumSet(java.util.EnumSet) Flowable(io.reactivex.rxjava3.core.Flowable) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) Predicate(java.util.function.Predicate) Publisher(org.reactivestreams.Publisher) Set(java.util.Set) IOException(java.io.IOException) OperationsFactory(org.infinispan.client.hotrod.impl.operations.OperationsFactory) Completable(io.reactivex.rxjava3.core.Completable) RemoteCacheConfigurationBuilder(org.infinispan.client.hotrod.configuration.RemoteCacheConfigurationBuilder) Objects(java.util.Objects) Consumer(java.util.function.Consumer) NearCacheMode(org.infinispan.client.hotrod.configuration.NearCacheMode) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) InitializationContext(org.infinispan.persistence.spi.InitializationContext) PingResponse(org.infinispan.client.hotrod.impl.operations.PingResponse) BlockingManager(org.infinispan.util.concurrent.BlockingManager) PersistenceException(org.infinispan.persistence.spi.PersistenceException) Completable(io.reactivex.rxjava3.core.Completable)

Example 25 with Completable

use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.

the class TransformerTest method completableTransformerThrows.

@Test
public void completableTransformerThrows() {
    try {
        Completable.complete().compose(new CompletableTransformer() {

            @Override
            public Completable apply(Completable v) {
                throw new TestException("Forced failure");
            }
        });
        fail("Should have thrown!");
    } catch (TestException ex) {
        assertEquals("Forced failure", ex.getMessage());
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test) ConverterTest(io.reactivex.rxjava3.core.ConverterTest)

Aggregations

Test (org.junit.Test)36 TestException (io.reactivex.rxjava3.exceptions.TestException)21 Action (io.reactivex.rxjava3.functions.Action)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 Disposable (io.reactivex.rxjava3.disposables.Disposable)5 IOException (java.io.IOException)4 Completable (io.reactivex.rxjava3.core.Completable)3 AtomicThrowable (io.reactivex.rxjava3.internal.util.AtomicThrowable)3 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)3 Flowable (io.reactivex.rxjava3.core.Flowable)2 TestObserver (io.reactivex.rxjava3.observers.TestObserver)2 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Pattern (java.util.regex.Pattern)2 InOrder (org.mockito.InOrder)2 ConverterTest (io.reactivex.rxjava3.core.ConverterTest)1 Observable (io.reactivex.rxjava3.core.Observable)1 Observer (io.reactivex.rxjava3.core.Observer)1 ConnectableFlowable (io.reactivex.rxjava3.flowables.ConnectableFlowable)1