Skip to content

Commit

Permalink
Add support for "yield_every" option
Browse files Browse the repository at this point in the history
Closes #458
  • Loading branch information
nickkkccc committed Jan 23, 2024
1 parent 81655fe commit 1121209
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithModeOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions;
import io.tarantool.driver.api.space.options.crud.OperationWithYieldEveryOptions;

/**
* Marker interface for space select operation options
Expand All @@ -16,5 +17,5 @@
*/
public interface SelectOptions<T extends SelectOptions<T>>
extends OperationWithBucketIdOptions<T>, OperationWithTimeoutOptions<T>, OperationWithFieldsOptions<T>,
OperationWithModeOptions<T>, OperationWithBatchSizeOptions<T> {
OperationWithModeOptions<T>, OperationWithBatchSizeOptions<T>, OperationWithYieldEveryOptions<T> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.tarantool.driver.api.space.options.crud;

import java.util.Optional;

import io.tarantool.driver.api.space.options.Options;
import io.tarantool.driver.api.space.options.Self;
import io.tarantool.driver.api.space.options.crud.enums.ProxyOption;

public interface OperationWithYieldEveryOptions<T extends OperationWithYieldEveryOptions<T>>
extends Options, Self<T> {

/**
* Sets number of tuples processed on storage to yield after, "yield_every" should be > 0.
* @param yieldEvery number of tuples processed on storage to yield after, "yield_every" should be > 0.
* @return this option instance.
* @throws IllegalArgumentException if yieldEvery < 0.
*/
default T withYieldEvery(int yieldEvery) throws IllegalArgumentException {
if (yieldEvery <= 0) {
throw new IllegalArgumentException("Parameter \"yield_every\" must be greater than 0");
}
addOption(ProxyOption.YIELD_EVERY, yieldEvery);
return self();
}

/**
* @return "yield_every" parameter value.
*/
default Optional<Integer> getYieldEvery() {
return getOption(ProxyOption.BUCKET_ID, Integer.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public enum ProxyOption {

AFTER("after"),

FIRST("first");
FIRST("first"),

YIELD_EVERY("yield_every");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.tarantool.driver.api.space.options.SelectOptions;
import io.tarantool.driver.api.space.TarantoolSpaceOperations;
import io.tarantool.driver.api.space.options.ProxySelectOptions;
import io.tarantool.driver.api.space.options.crud.enums.ProxyOption;
import io.tarantool.driver.api.tuple.DefaultTarantoolTupleFactory;
import io.tarantool.driver.api.tuple.TarantoolTuple;
import io.tarantool.driver.api.tuple.TarantoolTupleFactory;
Expand Down Expand Up @@ -238,4 +239,20 @@ public void withAfterTest() {
profileSpace.select(Conditions.after(medianTuple)).join();
assertEquals(median - 1, resultAfterInsertWithAfterOption.size());
}

@Test
public void withYieldEveryTest() {
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> profileSpace =
client.space(TEST_SPACE_NAME);

profileSpace.select(Conditions.any()).join();
List<?> crudSelectOpts = client.eval("return crud_select_opts").join();
assertNull(((HashMap<?, ?>) crudSelectOpts.get(0)).get(ProxyOption.YIELD_EVERY.toString()));

final int yieldEvery = 2_000;
profileSpace.select(Conditions.any(), ProxySelectOptions.create().withYieldEvery(yieldEvery)).join();
crudSelectOpts = client.eval("return crud_select_opts").join();
assertEquals(yieldEvery,
((HashMap<?, ?>) crudSelectOpts.get(0)).get(ProxyOption.YIELD_EVERY.toString()));
}
}

0 comments on commit 1121209

Please sign in to comment.