Search in sources :

Example 1 with DatabaseException

use of org.openhab.binding.dbquery.internal.error.DatabaseException in project openhab-addons by openhab.

the class InfluxDBClientFacadeMock method query.

@Override
public void query(String queryString, BiConsumer<Cancellable, FluxRecord> onNext, Consumer<? super Throwable> onError, Runnable onComplete) {
    if (!connected) {
        throw new DatabaseException("Client not connected");
    }
    if (INVALID_QUERY.equals(queryString)) {
        onError.accept(new RuntimeException("Invalid query"));
    } else if (EMPTY_QUERY.equals(queryString)) {
        onComplete.run();
    } else if (SCALAR_QUERY.equals(queryString)) {
        FluxRecord scalar = new FluxRecord(0);
        scalar.getValues().put("result", "_result");
        scalar.getValues().put("table", 0);
        scalar.getValues().put(VALUE_COLUMN, SCALAR_RESULT);
        onNext.accept(mock(Cancellable.class), scalar);
        onComplete.run();
    } else if (MULTIPLE_ROWS_QUERY.equals(queryString)) {
        onNext.accept(mock(Cancellable.class), createRowRecord(0, MULTIPLE_ROWS_VALUE_PREFIX + 1));
        onNext.accept(mock(Cancellable.class), createRowRecord(0, MULTIPLE_ROWS_VALUE_PREFIX + 2));
        onNext.accept(mock(Cancellable.class), createRowRecord(1, MULTIPLE_ROWS_VALUE_PREFIX + 3));
        onComplete.run();
    }
}
Also used : Cancellable(com.influxdb.Cancellable) DatabaseException(org.openhab.binding.dbquery.internal.error.DatabaseException) FluxRecord(com.influxdb.query.FluxRecord)

Aggregations

Cancellable (com.influxdb.Cancellable)1 FluxRecord (com.influxdb.query.FluxRecord)1 DatabaseException (org.openhab.binding.dbquery.internal.error.DatabaseException)1