diff --git a/src/main/java/io/tarantool/driver/api/space/options/DeleteOptions.java b/src/main/java/io/tarantool/driver/api/space/options/DeleteOptions.java index 82a97343..86b6500a 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/DeleteOptions.java +++ b/src/main/java/io/tarantool/driver/api/space/options/DeleteOptions.java @@ -1,6 +1,7 @@ package io.tarantool.driver.api.space.options; import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions; +import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions; import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions; import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions; @@ -11,5 +12,6 @@ * @author Alexey Kuzin */ public interface DeleteOptions> - extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions { + extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions, + OperationWithFetchLatestMetadataOptions { } diff --git a/src/main/java/io/tarantool/driver/api/space/options/InsertManyOptions.java b/src/main/java/io/tarantool/driver/api/space/options/InsertManyOptions.java index 49f147fe..31a1b5f9 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/InsertManyOptions.java +++ b/src/main/java/io/tarantool/driver/api/space/options/InsertManyOptions.java @@ -1,5 +1,6 @@ package io.tarantool.driver.api.space.options; +import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions; import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions; import io.tarantool.driver.api.space.options.crud.OperationWithRollbackOnErrorOptions; import io.tarantool.driver.api.space.options.crud.OperationWithStopOnErrorOptions; @@ -12,5 +13,5 @@ */ public interface InsertManyOptions> extends OperationWithTimeoutOptions, OperationWithFieldsOptions, OperationWithRollbackOnErrorOptions, - OperationWithStopOnErrorOptions { + OperationWithStopOnErrorOptions, OperationWithFetchLatestMetadataOptions { } diff --git a/src/main/java/io/tarantool/driver/api/space/options/InsertOptions.java b/src/main/java/io/tarantool/driver/api/space/options/InsertOptions.java index 140c03ac..62af32cf 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/InsertOptions.java +++ b/src/main/java/io/tarantool/driver/api/space/options/InsertOptions.java @@ -1,6 +1,7 @@ package io.tarantool.driver.api.space.options; import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions; +import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions; import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions; import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions; @@ -11,5 +12,6 @@ * @author Alexey Kuzin */ public interface InsertOptions> - extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions { + extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions, + OperationWithFetchLatestMetadataOptions { } diff --git a/src/main/java/io/tarantool/driver/api/space/options/ReplaceManyOptions.java b/src/main/java/io/tarantool/driver/api/space/options/ReplaceManyOptions.java index c34a4eb7..c827d75f 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/ReplaceManyOptions.java +++ b/src/main/java/io/tarantool/driver/api/space/options/ReplaceManyOptions.java @@ -1,5 +1,6 @@ package io.tarantool.driver.api.space.options; +import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions; import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions; import io.tarantool.driver.api.space.options.crud.OperationWithRollbackOnErrorOptions; import io.tarantool.driver.api.space.options.crud.OperationWithStopOnErrorOptions; @@ -12,5 +13,5 @@ */ public interface ReplaceManyOptions> extends OperationWithTimeoutOptions, OperationWithFieldsOptions, OperationWithRollbackOnErrorOptions, - OperationWithStopOnErrorOptions { + OperationWithStopOnErrorOptions, OperationWithFetchLatestMetadataOptions { } diff --git a/src/main/java/io/tarantool/driver/api/space/options/ReplaceOptions.java b/src/main/java/io/tarantool/driver/api/space/options/ReplaceOptions.java index cead190f..0534759d 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/ReplaceOptions.java +++ b/src/main/java/io/tarantool/driver/api/space/options/ReplaceOptions.java @@ -1,6 +1,7 @@ package io.tarantool.driver.api.space.options; import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions; +import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions; import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions; import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions; @@ -11,5 +12,6 @@ * @author Alexey Kuzin */ public interface ReplaceOptions> - extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions { + extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions, + OperationWithFetchLatestMetadataOptions { } diff --git a/src/main/java/io/tarantool/driver/api/space/options/SelectOptions.java b/src/main/java/io/tarantool/driver/api/space/options/SelectOptions.java index c7c6815d..4118ee68 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/SelectOptions.java +++ b/src/main/java/io/tarantool/driver/api/space/options/SelectOptions.java @@ -2,6 +2,7 @@ import io.tarantool.driver.api.space.options.crud.OperationWithBatchSizeOptions; import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions; +import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions; 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; @@ -16,5 +17,5 @@ */ public interface SelectOptions> extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions, - OperationWithModeOptions, OperationWithBatchSizeOptions { + OperationWithModeOptions, OperationWithBatchSizeOptions, OperationWithFetchLatestMetadataOptions { } diff --git a/src/main/java/io/tarantool/driver/api/space/options/UpdateOptions.java b/src/main/java/io/tarantool/driver/api/space/options/UpdateOptions.java index 8f463f62..bb95c69c 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/UpdateOptions.java +++ b/src/main/java/io/tarantool/driver/api/space/options/UpdateOptions.java @@ -1,6 +1,7 @@ package io.tarantool.driver.api.space.options; import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions; +import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions; import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions; import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions; @@ -11,5 +12,6 @@ * @author Alexey Kuzin */ public interface UpdateOptions> - extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions { + extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions, + OperationWithFetchLatestMetadataOptions { } diff --git a/src/main/java/io/tarantool/driver/api/space/options/UpsertOptions.java b/src/main/java/io/tarantool/driver/api/space/options/UpsertOptions.java index df93d261..430d950e 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/UpsertOptions.java +++ b/src/main/java/io/tarantool/driver/api/space/options/UpsertOptions.java @@ -1,6 +1,7 @@ package io.tarantool.driver.api.space.options; import io.tarantool.driver.api.space.options.crud.OperationWithBucketIdOptions; +import io.tarantool.driver.api.space.options.crud.OperationWithFetchLatestMetadataOptions; import io.tarantool.driver.api.space.options.crud.OperationWithFieldsOptions; import io.tarantool.driver.api.space.options.crud.OperationWithTimeoutOptions; @@ -11,5 +12,6 @@ * @author Alexey Kuzin */ public interface UpsertOptions> - extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions { + extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions, + OperationWithFetchLatestMetadataOptions { } diff --git a/src/main/java/io/tarantool/driver/api/space/options/crud/OperationWithFetchLatestMetadataOptions.java b/src/main/java/io/tarantool/driver/api/space/options/crud/OperationWithFetchLatestMetadataOptions.java new file mode 100644 index 00000000..ee21e3ef --- /dev/null +++ b/src/main/java/io/tarantool/driver/api/space/options/crud/OperationWithFetchLatestMetadataOptions.java @@ -0,0 +1,34 @@ +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; + +/** + * Base interface for all operation options that may have a configurable "fetch_latest_metadata" option. + * + * @author Belonogov Nikolay + */ +public interface OperationWithFetchLatestMetadataOptions> + extends Options, Self { + + /** + * Sets "fetch_latest_metadata" option value to true. Guarantees the up-to-date metadata (space format) in first + * return value, otherwise it may not take into account the latest migration of the data format. Performance + * overhead is up to 15%. False by default. + * @return this options instance. + */ + default T fetchLatestMetadata() { + addOption(ProxyOption.FETCH_LATEST_METADATA, true); + return self(); + } + + /** + * @return "fetch_latest_metadata" option value. + */ + default Optional getFetchLatestMetadata() { + return getOption(ProxyOption.FETCH_LATEST_METADATA, Boolean.class); + } +} diff --git a/src/main/java/io/tarantool/driver/api/space/options/crud/enums/ProxyOption.java b/src/main/java/io/tarantool/driver/api/space/options/crud/enums/ProxyOption.java index c2b9de5f..c5eac144 100644 --- a/src/main/java/io/tarantool/driver/api/space/options/crud/enums/ProxyOption.java +++ b/src/main/java/io/tarantool/driver/api/space/options/crud/enums/ProxyOption.java @@ -23,7 +23,9 @@ public enum ProxyOption { AFTER("after"), - FIRST("first"); + FIRST("first"), + + FETCH_LATEST_METADATA("fetch_latest_metadata"); private final String name; diff --git a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceDeleteOptionsIT.java b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceDeleteOptionsIT.java index c8f51faf..c8efdb5f 100644 --- a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceDeleteOptionsIT.java +++ b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceDeleteOptionsIT.java @@ -9,6 +9,7 @@ import io.tarantool.driver.api.space.options.ProxyDeleteOptions; import io.tarantool.driver.api.space.options.ProxyInsertOptions; import io.tarantool.driver.api.space.options.DeleteOptions; +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; @@ -30,6 +31,7 @@ import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Artyom Dubinin @@ -161,4 +163,26 @@ public void withFieldsTest() throws ExecutionException, InterruptedException { assertEquals(1, tuple.getInteger(0)); assertEquals("FIO", tuple.getString(1)); } + + @Test + public void withFetchLatestMetadata() { + TarantoolSpaceOperations> profileSpace = + client.space(TEST_SPACE_NAME); + + TarantoolTuple tarantoolTuple = tupleFactory.create(1, null, "FIO", 50, 100); + profileSpace.insert(tarantoolTuple).join(); + + Conditions conditions = Conditions.equals(PK_FIELD_NAME, 1); + DeleteOptions options = ProxyDeleteOptions.create().fetchLatestMetadata(); + + assertTrue(options.getFetchLatestMetadata().isPresent()); + assertTrue(options.getFetchLatestMetadata().get()); + + TarantoolResult deleteResultWithOptions = profileSpace.delete(conditions, options).join(); + List crudDeleteOpts = client.eval("return crud_delete_opts").join(); + + assertEquals(true, + ((HashMap) crudDeleteOpts.get(0)).get(ProxyOption.FETCH_LATEST_METADATA.toString())); + assertEquals(1, deleteResultWithOptions.size()); + } } diff --git a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceInsertManyOptionsIT.java b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceInsertManyOptionsIT.java index ccb4ed1a..97342206 100644 --- a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceInsertManyOptionsIT.java +++ b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceInsertManyOptionsIT.java @@ -6,6 +6,7 @@ import io.tarantool.driver.api.conditions.Conditions; import io.tarantool.driver.api.space.TarantoolSpaceOperations; import io.tarantool.driver.api.space.options.InsertManyOptions; +import io.tarantool.driver.api.space.options.crud.enums.ProxyOption; import io.tarantool.driver.api.space.options.crud.enums.RollbackOnError; import io.tarantool.driver.api.space.options.crud.enums.StopOnError; import io.tarantool.driver.api.space.options.ProxyInsertManyOptions; @@ -17,6 +18,7 @@ import io.tarantool.driver.core.ProxyTarantoolTupleClient; import io.tarantool.driver.integration.SharedCartridgeContainer; import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,6 +32,7 @@ import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Alexey Kuzin @@ -188,4 +191,26 @@ public void withFieldsTest() throws ExecutionException, InterruptedException { assertEquals(String.valueOf(i), tuple.getString(1)); } } + + @Test + public void withFetchLatestMetadata() { + TarantoolSpaceOperations> profileSpace = + client.space(TEST_SPACE_NAME); + + List tarantoolTuples = Arrays.asList( + tupleFactory.create(0, null, "0", 0, 0), + tupleFactory.create(1, null, "1", 1, 1) + ); + InsertManyOptions options = ProxyInsertManyOptions.create().fetchLatestMetadata(); + + assertTrue(options.getFetchLatestMetadata().isPresent()); + assertTrue(options.getFetchLatestMetadata().get()); + + TarantoolResult insertManyResult = profileSpace.insertMany(tarantoolTuples, options).join(); + List crudInsertManyOpts = client.eval("return crud_insert_many_opts").join(); + + assertEquals(2, insertManyResult.size()); + Assertions.assertEquals(true, ((HashMap) crudInsertManyOpts.get(0)) + .get(ProxyOption.FETCH_LATEST_METADATA.toString())); + } } diff --git a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceInsertOptionsIT.java b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceInsertOptionsIT.java index 9e3389ad..2e1c4e50 100644 --- a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceInsertOptionsIT.java +++ b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceInsertOptionsIT.java @@ -9,6 +9,7 @@ import io.tarantool.driver.api.space.options.SelectOptions; import io.tarantool.driver.api.space.options.ProxyInsertOptions; 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; @@ -19,6 +20,7 @@ import io.tarantool.driver.integration.SharedCartridgeContainer; import io.tarantool.driver.integration.Utils; import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -267,4 +269,23 @@ public void withFieldsTest() throws ExecutionException, InterruptedException { assertEquals(1, tuple.getInteger(0)); assertEquals("FIO", tuple.getString(1)); } + + @Test + public void withFetchLatestMetadata() { + TarantoolSpaceOperations> profileSpace = + client.space(TEST_SPACE_NAME); + + TarantoolTuple tarantoolTuple = tupleFactory.create(0, null, "0", 0, 0); + InsertOptions options = ProxyInsertOptions.create().fetchLatestMetadata(); + + assertTrue(options.getFetchLatestMetadata().isPresent()); + assertTrue(options.getFetchLatestMetadata().get()); + + TarantoolResult insertResult = profileSpace.insert(tarantoolTuple, options).join(); + List crudInsertOpts = client.eval("return crud_insert_opts").join(); + + assertEquals(1, insertResult.size()); + Assertions.assertEquals(true, ((HashMap) crudInsertOpts.get(0)) + .get(ProxyOption.FETCH_LATEST_METADATA.toString())); + } } diff --git a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceReplaceManyOptionsIT.java b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceReplaceManyOptionsIT.java index 6a93323c..ef3bfd86 100644 --- a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceReplaceManyOptionsIT.java +++ b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceReplaceManyOptionsIT.java @@ -5,6 +5,7 @@ import io.tarantool.driver.api.TarantoolResult; import io.tarantool.driver.api.space.TarantoolSpaceOperations; import io.tarantool.driver.api.space.options.ReplaceManyOptions; +import io.tarantool.driver.api.space.options.crud.enums.ProxyOption; import io.tarantool.driver.api.space.options.crud.enums.RollbackOnError; import io.tarantool.driver.api.space.options.crud.enums.StopOnError; import io.tarantool.driver.api.space.options.ProxyReplaceManyOptions; @@ -16,6 +17,7 @@ import io.tarantool.driver.core.ProxyTarantoolTupleClient; import io.tarantool.driver.integration.SharedCartridgeContainer; import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,6 +31,7 @@ import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Alexey Kuzin @@ -171,4 +174,27 @@ public void withFieldsTest() throws ExecutionException, InterruptedException { assertEquals(String.valueOf(i), tuple.getString(1)); } } + + @Test + public void withFetchLatestMetadata() { + TarantoolSpaceOperations> profileSpace = + client.space(TEST_SPACE_NAME); + + List tarantoolTuples = Arrays.asList( + tupleFactory.create(0, null, "0", 0, 0), + tupleFactory.create(1, null, "1", 1, 1) + ); + + ReplaceManyOptions options = ProxyReplaceManyOptions.create().fetchLatestMetadata(); + + assertTrue(options.getFetchLatestMetadata().isPresent()); + assertTrue(options.getFetchLatestMetadata().get()); + + TarantoolResult replaceManyResult = profileSpace.replaceMany(tarantoolTuples, options).join(); + List crudReplaceManyOpts = client.eval("return crud_replace_many_opts").join(); + + assertEquals(2, replaceManyResult.size()); + Assertions.assertEquals(true, ((HashMap) crudReplaceManyOpts.get(0)) + .get(ProxyOption.FETCH_LATEST_METADATA.toString())); + } } diff --git a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceReplaceOptionsIT.java b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceReplaceOptionsIT.java index 5d8a5c78..2bcef3d1 100644 --- a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceReplaceOptionsIT.java +++ b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceReplaceOptionsIT.java @@ -8,6 +8,7 @@ import io.tarantool.driver.api.space.options.ReplaceOptions; import io.tarantool.driver.api.space.options.ProxyDeleteOptions; import io.tarantool.driver.api.space.options.ProxyReplaceOptions; +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; @@ -16,6 +17,7 @@ import io.tarantool.driver.core.ProxyTarantoolTupleClient; import io.tarantool.driver.integration.SharedCartridgeContainer; import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,6 +31,7 @@ import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Artyom Dubinin @@ -167,4 +170,24 @@ public void withFieldsTest() throws ExecutionException, InterruptedException { assertEquals(1, tuple.getInteger(0)); assertEquals("FIO", tuple.getString(1)); } + + @Test + public void withFetchLatestMetadata() { + TarantoolSpaceOperations> profileSpace = + client.space(TEST_SPACE_NAME); + + TarantoolTuple tarantoolTuple = tupleFactory.create(1, null, "FIO", 50, 100); + + ReplaceOptions options = ProxyReplaceOptions.create().fetchLatestMetadata(); + + assertTrue(options.getFetchLatestMetadata().isPresent()); + assertTrue(options.getFetchLatestMetadata().get()); + + TarantoolResult replaceResult = profileSpace.replace(tarantoolTuple, options).join(); + List crudReplaceOpts = client.eval("return crud_replace_opts").join(); + + assertEquals(1, replaceResult.size()); + Assertions.assertEquals(true, ((HashMap) crudReplaceOpts.get(0)) + .get(ProxyOption.FETCH_LATEST_METADATA.toString())); + } } diff --git a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceSelectOptionsIT.java b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceSelectOptionsIT.java index 8c023dd7..86b5841e 100644 --- a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceSelectOptionsIT.java +++ b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceSelectOptionsIT.java @@ -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; @@ -16,6 +17,7 @@ import io.tarantool.driver.core.ProxyTarantoolTupleClient; import io.tarantool.driver.integration.SharedCartridgeContainer; import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -28,6 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Artyom Dubinin @@ -174,4 +177,22 @@ public void withModeTest() throws ExecutionException, InterruptedException { crudSelectOpts = client.eval("return crud_select_opts").get(); assertEquals(Mode.WRITE.value(), ((HashMap) crudSelectOpts.get(0)).get("mode")); } + + @Test + public void withFetchLatestMetadata() { + TarantoolSpaceOperations> profileSpace = + client.space(TEST_SPACE_NAME); + + SelectOptions options = ProxySelectOptions.create().fetchLatestMetadata(); + + assertTrue(options.getFetchLatestMetadata().isPresent()); + assertTrue(options.getFetchLatestMetadata().get()); + + TarantoolResult selectResult = profileSpace.select(Conditions.any(), options).join(); + List crudSelectOpts = client.eval("return crud_select_opts").join(); + + assertEquals(0, selectResult.size()); + Assertions.assertEquals(true, ((HashMap) crudSelectOpts.get(0)) + .get(ProxyOption.FETCH_LATEST_METADATA.toString())); + } } diff --git a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceUpdateOptionsIT.java b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceUpdateOptionsIT.java index c528ab3b..b440bd79 100644 --- a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceUpdateOptionsIT.java +++ b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceUpdateOptionsIT.java @@ -7,6 +7,7 @@ import io.tarantool.driver.api.space.TarantoolSpaceOperations; import io.tarantool.driver.api.space.options.UpdateOptions; import io.tarantool.driver.api.space.options.ProxyUpdateOptions; +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; @@ -15,6 +16,7 @@ import io.tarantool.driver.core.ProxyTarantoolTupleClient; import io.tarantool.driver.integration.SharedCartridgeContainer; import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -27,6 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Artyom Dubinin @@ -158,4 +161,25 @@ public void withFieldsTest() throws ExecutionException, InterruptedException { assertEquals(1, tuple.getInteger(0)); assertEquals("FIO", tuple.getString(1)); } + + @Test + public void withFetchLatestMetadata() { + TarantoolSpaceOperations> profileSpace = + client.space(TEST_SPACE_NAME); + + TarantoolTuple tarantoolTuple = tupleFactory.create(1, null, "FIO", 50, 100); + Conditions conditions = Conditions.equals(PK_FIELD_NAME, 1); + UpdateOptions options = ProxyUpdateOptions.create().fetchLatestMetadata(); + + assertTrue(options.getFetchLatestMetadata().isPresent()); + assertTrue(options.getFetchLatestMetadata().get()); + + TarantoolTuple insertTuple = profileSpace.insert(tarantoolTuple).join().get(0); + TarantoolResult updateResult = profileSpace.update(conditions, insertTuple, options).join(); + List crudUpdateOpts = client.eval("return crud_update_opts").join(); + + assertEquals(1, updateResult.size()); + Assertions.assertEquals(true, ((HashMap) crudUpdateOpts.get(0)) + .get(ProxyOption.FETCH_LATEST_METADATA.toString())); + } } diff --git a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceUpsertOptionsIT.java b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceUpsertOptionsIT.java index 91b47c93..36d395bb 100644 --- a/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceUpsertOptionsIT.java +++ b/src/test/java/io/tarantool/driver/integration/proxy/options/ProxySpaceUpsertOptionsIT.java @@ -6,6 +6,8 @@ import io.tarantool.driver.api.conditions.Conditions; import io.tarantool.driver.api.space.TarantoolSpaceOperations; import io.tarantool.driver.api.space.options.ProxyUpsertOptions; +import io.tarantool.driver.api.space.options.UpsertOptions; +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; @@ -15,6 +17,7 @@ import io.tarantool.driver.core.ProxyTarantoolTupleClient; import io.tarantool.driver.integration.SharedCartridgeContainer; import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -25,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Artyom Dubinin @@ -127,4 +131,23 @@ public void withBucketIdTest() throws ExecutionException, InterruptedException { crudUpsertOpts = client.eval("return crud_upsert_opts").get(); assertEquals(bucketId, ((HashMap) crudUpsertOpts.get(0)).get("bucket_id")); } + + @Test + public void withFetchLatestMetadata() { + TarantoolSpaceOperations> profileSpace = + client.space(TEST_SPACE_NAME); + + TarantoolTuple tarantoolTuple = tupleFactory.create(1, null, "FIO", 50, 100); + Conditions conditions = Conditions.equals(PK_FIELD_NAME, 1); + UpsertOptions options = ProxyUpsertOptions.create().fetchLatestMetadata(); + + assertTrue(options.getFetchLatestMetadata().isPresent()); + assertTrue(options.getFetchLatestMetadata().get()); + + profileSpace.upsert(conditions, tarantoolTuple, TupleOperations.set("age", 50), options).join(); + List crudUpsertOpts = client.eval("return crud_upsert_opts").join(); + + Assertions.assertEquals(true, ((HashMap) crudUpsertOpts.get(0)) + .get(ProxyOption.FETCH_LATEST_METADATA.toString())); + } }