Search in sources :

Example 81 with Function

use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.

the class ObservableWindowWithStartEndObservableTest method endError.

@Test
@SuppressUndeliverable
public void endError() {
    PublishSubject<Integer> source = PublishSubject.create();
    PublishSubject<Integer> start = PublishSubject.create();
    final PublishSubject<Integer> end = PublishSubject.create();
    TestObserver<Integer> to = source.window(start, new Function<Integer, ObservableSource<Integer>>() {

        @Override
        public ObservableSource<Integer> apply(Integer v) throws Exception {
            return end;
        }
    }).flatMap(Functions.<Observable<Integer>>identity()).test();
    start.onNext(1);
    end.onError(new TestException());
    to.assertFailure(TestException.class);
    assertFalse("Source has observers!", source.hasObservers());
    assertFalse("Start has observers!", start.hasObservers());
    assertFalse("End has observers!", end.hasObservers());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Observable(io.reactivex.rxjava3.core.Observable)

Example 82 with Function

use of io.reactivex.rxjava3.functions.Function in project RxRelay by JakeWharton.

the class BehaviorRelayTest method testUnsubscriptionCase.

@Test(timeout = 1000)
public void testUnsubscriptionCase() {
    // FIXME was plain null which is not allowed
    BehaviorRelay<String> src = BehaviorRelay.createDefault("null");
    for (int i = 0; i < 10; i++) {
        final Observer<Object> o = TestHelper.mockObserver();
        InOrder inOrder = inOrder(o);
        String v = "" + i;
        src.accept(v);
        System.out.printf("Turn: %d%n", i);
        src.firstElement().toObservable().flatMap(new Function<String, Observable<String>>() {

            @Override
            public Observable<String> apply(String t1) {
                return Observable.just(t1 + ", " + t1);
            }
        }).subscribe(new DefaultObserver<String>() {

            @Override
            public void onNext(String t) {
                o.onNext(t);
            }

            @Override
            public void onError(Throwable e) {
                o.onError(e);
            }

            @Override
            public void onComplete() {
                o.onComplete();
            }
        });
        inOrder.verify(o).onNext(v + ", " + v);
        inOrder.verify(o).onComplete();
        verify(o, never()).onError(any(Throwable.class));
    }
}
Also used : Function(io.reactivex.rxjava3.functions.Function) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 83 with Function

use of io.reactivex.rxjava3.functions.Function in project cassandra by apache.

the class DropTypeStatement method apply.

// TODO: expand types into tuples in all dropped columns of all tables
public Keyspaces apply(Keyspaces schema) {
    ByteBuffer name = bytes(typeName);
    KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);
    UserType type = null == keyspace ? null : keyspace.types.getNullable(name);
    if (null == type) {
        if (ifExists)
            return schema;
        throw ire("Type '%s.%s' doesn't exist", keyspaceName, typeName);
    }
    /*
         * We don't want to drop a type unless it's not used anymore (mainly because
         * if someone drops a type and recreates one with the same name but different
         * definition with the previous name still in use, things can get messy).
         * We have three places to check:
         * 1) UDFs and UDAs using the type
         * 2) other user type that can nest the one we drop and
         * 3) existing tables referencing the type (maybe in a nested way).
         */
    Iterable<Function> functions = keyspace.functions.referencingUserType(name);
    if (!isEmpty(functions)) {
        throw ire("Cannot drop user type '%s.%s' as it is still used by functions %s", keyspaceName, typeName, join(", ", transform(functions, f -> f.name().toString())));
    }
    Iterable<UserType> types = keyspace.types.referencingUserType(name);
    if (!isEmpty(types)) {
        throw ire("Cannot drop user type '%s.%s' as it is still used by user types %s", keyspaceName, typeName, join(", ", transform(types, UserType::getNameAsString)));
    }
    Iterable<TableMetadata> tables = keyspace.tables.referencingUserType(name);
    if (!isEmpty(tables)) {
        throw ire("Cannot drop user type '%s.%s' as it is still used by tables %s", keyspaceName, typeName, join(", ", transform(tables, t -> t.name)));
    }
    return schema.withAddedOrUpdated(keyspace.withSwapped(keyspace.types.without(type)));
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) Function(org.apache.cassandra.cql3.functions.Function) ByteBuffer(java.nio.ByteBuffer) KeyspaceMetadata(org.apache.cassandra.schema.KeyspaceMetadata) UserType(org.apache.cassandra.db.marshal.UserType)

Example 84 with Function

use of io.reactivex.rxjava3.functions.Function in project cassandra by apache.

the class DropAggregateStatement method apply.

public Keyspaces apply(Keyspaces schema) {
    String name = argumentsSpeficied ? format("%s.%s(%s)", keyspaceName, aggregateName, join(", ", transform(arguments, CQL3Type.Raw::toString))) : format("%s.%s", keyspaceName, aggregateName);
    KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);
    if (null == keyspace) {
        if (ifExists)
            return schema;
        throw ire("Aggregate '%s' doesn't exist", name);
    }
    Collection<Function> aggregates = keyspace.functions.get(new FunctionName(keyspaceName, aggregateName));
    if (aggregates.size() > 1 && !argumentsSpeficied) {
        throw ire("'DROP AGGREGATE %s' matches multiple function definitions; " + "specify the argument types by issuing a statement like " + "'DROP AGGREGATE %s (type, type, ...)'. You can use cqlsh " + "'DESCRIBE AGGREGATE %s' command to find all overloads", aggregateName, aggregateName, aggregateName);
    }
    arguments.stream().filter(raw -> !raw.isTuple() && raw.isFrozen()).findFirst().ifPresent(t -> {
        throw ire("Argument '%s' cannot be frozen; remove frozen<> modifier from '%s'", t, t);
    });
    List<AbstractType<?>> argumentTypes = prepareArgumentTypes(keyspace.types);
    Predicate<Function> filter = Functions.Filter.UDA;
    if (argumentsSpeficied)
        filter = filter.and(f -> Functions.typesMatch(f.argTypes(), argumentTypes));
    Function aggregate = aggregates.stream().filter(filter).findAny().orElse(null);
    if (null == aggregate) {
        if (ifExists)
            return schema;
        throw ire("Aggregate '%s' doesn't exist", name);
    }
    return schema.withAddedOrUpdated(keyspace.withSwapped(keyspace.functions.without(aggregate)));
}
Also used : CQL3Type(org.apache.cassandra.cql3.CQL3Type) Function(org.apache.cassandra.cql3.functions.Function) FunctionName(org.apache.cassandra.cql3.functions.FunctionName) AbstractType(org.apache.cassandra.db.marshal.AbstractType)

Example 85 with Function

use of io.reactivex.rxjava3.functions.Function in project cassandra by apache.

the class ModificationStatement method authorize.

public void authorize(ClientState state) throws InvalidRequestException, UnauthorizedException {
    state.ensureTablePermission(metadata, Permission.MODIFY);
    // CAS updates can be used to simulate a SELECT query, so should require Permission.SELECT as well.
    if (hasConditions())
        state.ensureTablePermission(metadata, Permission.SELECT);
    // MV updates need to get the current state from the table, and might update the views
    // Require Permission.SELECT on the base table, and Permission.MODIFY on the views
    Iterator<ViewMetadata> views = View.findAll(keyspace(), table()).iterator();
    if (views.hasNext()) {
        state.ensureTablePermission(metadata, Permission.SELECT);
        do {
            state.ensureTablePermission(views.next().metadata, Permission.MODIFY);
        } while (views.hasNext());
    }
    for (Function function : getFunctions()) state.ensurePermission(Permission.EXECUTE, function);
}
Also used : Function(org.apache.cassandra.cql3.functions.Function) ViewMetadata(org.apache.cassandra.schema.ViewMetadata)

Aggregations

Test (org.junit.Test)97 TestException (io.reactivex.rxjava3.exceptions.TestException)78 Observable (io.reactivex.rxjava3.core.Observable)41 InOrder (org.mockito.InOrder)36 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)21 Function (io.reactivex.rxjava3.functions.Function)20 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 IOException (java.io.IOException)13 Disposable (io.reactivex.rxjava3.disposables.Disposable)10 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)9 TestObserver (io.reactivex.rxjava3.observers.TestObserver)9 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)9 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)8 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)7 Observer (io.reactivex.rxjava3.core.Observer)7 Function (org.apache.cassandra.cql3.functions.Function)7 ImmediateThinScheduler (io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler)6 TestHelper (io.reactivex.rxjava3.testsupport.TestHelper)6 EmptyScheduler (io.reactivex.rxjava3.android.testutil.EmptyScheduler)5