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