From cfa0ca18ffac61421cabb510dd827cf93030b26e Mon Sep 17 00:00:00 2001 From: Belonogov Nikolay Date: Mon, 29 Jan 2024 09:56:20 +0300 Subject: [PATCH] Add support for "fetch_latest_metadata" option - Add option - CHANGELOG.md Closes #465 --- CHANGELOG.md | 7 ++++ .../api/space/options/DeleteOptions.java | 3 +- .../api/space/options/InsertManyOptions.java | 4 ++- .../api/space/options/InsertOptions.java | 3 +- .../api/space/options/ReplaceManyOptions.java | 4 ++- .../api/space/options/ReplaceOptions.java | 3 +- .../api/space/options/SelectOptions.java | 4 ++- .../api/space/options/UpdateOptions.java | 3 +- .../api/space/options/UpsertOptions.java | 3 +- ...erationWithFetchLatestMetadataOptions.java | 34 +++++++++++++++++++ .../space/options/crud/enums/ProxyOption.java | 4 ++- .../options/ProxySpaceDeleteOptionsIT.java | 23 +++++++++++++ .../ProxySpaceInsertManyOptionsIT.java | 24 +++++++++++++ .../options/ProxySpaceInsertOptionsIT.java | 20 +++++++++++ .../ProxySpaceReplaceManyOptionsIT.java | 25 ++++++++++++++ .../options/ProxySpaceReplaceOptionsIT.java | 22 ++++++++++++ .../options/ProxySpaceSelectOptionsIT.java | 19 +++++++++++ .../options/ProxySpaceUpdateOptionsIT.java | 24 ++++++++++++- .../options/ProxySpaceUpsertOptionsIT.java | 21 ++++++++++++ 19 files changed, 240 insertions(+), 10 deletions(-) create mode 100644 src/main/java/io/tarantool/driver/api/space/options/crud/OperationWithFetchLatestMetadataOptions.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 287021df..12ef7865 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,13 @@ - Bump testcontainers-java-tarantool version to 1.2.0 ([#442](https://github.com/tarantool/cartridge-java/issues/442)) - Bump netty version to 4.1.104.Final ([#446](https://github.com/tarantool/cartridge-java/issues/446)) - Bump msgpack-java version to 0.9.6 +- Add support for crud `yield_every` option ([#458](https://github.com/tarantool/cartridge-java/pull/468)) +- Add support for crud `force_map_call` option ([#459](https://github.com/tarantool/cartridge-java/pull/469)) +- Add support for crud `fullscan` option ([#460](https://github.com/tarantool/cartridge-java/pull/470)) +- Add support for crud `prefer_replica` option ([#461](https://github.com/tarantool/cartridge-java/pull/471)) +- Add support for crud `balance` option ([#462](https://github.com/tarantool/cartridge-java/pull/472)) +- Add support for crud `vshard_router` option ([#463](https://github.com/tarantool/cartridge-java/pull/473)) +- Add support for crud `fetch_latest_metadata` option ([#465](https://github.com/tarantool/cartridge-java/pull/474)) ### Features 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 b6ab548a..79854d7a 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; import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions; @@ -13,5 +14,5 @@ */ public interface DeleteOptions> extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions, - OperationWithVshardRouterOptions { + OperationWithVshardRouterOptions, 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 ee1f1584..ee128056 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; @@ -13,5 +14,6 @@ */ public interface InsertManyOptions> extends OperationWithTimeoutOptions, OperationWithFieldsOptions, OperationWithRollbackOnErrorOptions, - OperationWithStopOnErrorOptions, OperationWithVshardRouterOptions { + OperationWithStopOnErrorOptions, OperationWithVshardRouterOptions, + 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 85b95e57..1570317e 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; import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions; @@ -13,5 +14,5 @@ */ public interface InsertOptions> extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions, - OperationWithVshardRouterOptions { + OperationWithVshardRouterOptions, 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 a376efd4..673f2c0a 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; @@ -13,5 +14,6 @@ */ public interface ReplaceManyOptions> extends OperationWithTimeoutOptions, OperationWithFieldsOptions, OperationWithRollbackOnErrorOptions, - OperationWithStopOnErrorOptions, OperationWithVshardRouterOptions { + OperationWithStopOnErrorOptions, OperationWithVshardRouterOptions, + 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 ca8c46cd..98b77b40 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; import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions; @@ -13,5 +14,5 @@ */ public interface ReplaceOptions> extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions, - OperationWithVshardRouterOptions { + OperationWithVshardRouterOptions, 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 68a4216a..7c1874ca 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 @@ -3,6 +3,7 @@ import io.tarantool.driver.api.space.options.crud.OperationWithBalanceOptions; 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.OperationWithFullScanOptions; import io.tarantool.driver.api.space.options.crud.OperationWithForceMapCallOptions; @@ -24,5 +25,6 @@ public interface SelectOptions> extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions, OperationWithModeOptions, OperationWithBatchSizeOptions, OperationWithYieldEveryOptions, OperationWithForceMapCallOptions, OperationWithFullScanOptions, OperationWithPreferReplicaOptions, - OperationWithBalanceOptions, OperationWithVshardRouterOptions { + OperationWithBalanceOptions, OperationWithVshardRouterOptions, + 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 52694d81..14c8e888 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; import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions; @@ -13,5 +14,5 @@ */ public interface UpdateOptions> extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions, - OperationWithVshardRouterOptions { + OperationWithVshardRouterOptions, 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 c329140a..32d7e8b7 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; import io.tarantool.driver.api.space.options.crud.OperationWithVshardRouterOptions; @@ -13,5 +14,5 @@ */ public interface UpsertOptions> extends OperationWithBucketIdOptions, OperationWithTimeoutOptions, OperationWithFieldsOptions, - OperationWithVshardRouterOptions { + OperationWithVshardRouterOptions, 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 28b99c61..cb6a61c3 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 @@ -35,7 +35,9 @@ public enum ProxyOption { BALANCE("balance"), - VSHARD_ROUTER("vshard_router"); + VSHARD_ROUTER("vshard_router"), + + 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 925d2643..e42e7d99 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 @@ -31,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 @@ -183,4 +184,26 @@ public void withVshardRouterTest() { assertEquals(1, deleteResult.size()); assertEquals(0, selectResultAfterDelete.size()); } + + @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 fbcf21ea..073a4781 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 @@ -18,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; @@ -31,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 @@ -208,4 +210,26 @@ public void withVshardRouterTest() { assertEquals(2, insertManyResult.size()); assertEquals(groupName, ((HashMap) crudInsertManyOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString())); } + + @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 ae7a5df5..fc1114a5 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 @@ -20,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; @@ -285,4 +286,23 @@ public void withVshardRouterTest() { assertEquals(1, insertResult.size()); assertEquals(groupName, ((HashMap) crudInsertOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString())); } + + @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 626052a6..2822660d 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 @@ -17,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; @@ -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 Alexey Kuzin @@ -192,4 +194,27 @@ public void withVsharRouterTest() { assertEquals(groupName, ((HashMap) crudReplaceManyOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString())); assertEquals(2, replaceResult.size()); } + + @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 10c9ec1d..a0644c7f 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 @@ -17,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; @@ -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 @@ -185,4 +187,24 @@ public void withVsharRouterTest() { assertEquals(1, replaceResult.size()); assertEquals(groupName, ((HashMap) crudReplaceOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString())); } + + @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 a62820f4..ffb3430a 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 @@ -17,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; @@ -333,4 +334,22 @@ public void withVshardRouterTest() { crudSelectOpts = client.eval("return crud_select_opts").join(); assertEquals(routerName, ((HashMap) crudSelectOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString())); } + + @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 7bb519fd..1bf81bbe 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 @@ -16,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; @@ -28,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 @@ -179,5 +181,25 @@ public void withVshardRouterTest() { assertEquals(1, updateResult.size()); assertEquals(groupName, ((HashMap) crudUpdateOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString())); } -} + @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 882daa1a..1dae2b36 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 @@ -17,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; @@ -27,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 @@ -146,4 +148,23 @@ public void withVshardRouterTest() { assertEquals(groupName, ((HashMap) crudUpsertOpts.get(0)).get(ProxyOption.VSHARD_ROUTER.toString())); } + + @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())); + } }