Skip to content

Commit 6632a33

Browse files
committed
Do not use call_16 by default
The call_16 became obsolete when tarantool-1.6 was gone. There're no reasons to continue using the old version by default. Change discovery function requirements in part of single value support. This is done to be consistent with other Tarantool connectors. Closes: #196
1 parent 2473ffa commit 6632a33

7 files changed

+26
-13
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ tarantool> function get_cluster_nodes() return { 'host1:3301', 'host2:3302', 'ho
237237
238238
You need to pay attention to a function contract we are currently supporting:
239239
* The client never passes any arguments to a discovery function.
240-
* A discovery function _should_ return a single result of strings (i.e. single
241-
string `return 'host:3301'` or array of strings `return {'host1:3301', 'host2:3301'}`).
240+
* A discovery function _must_ return an array of strings (i.e `return {'host1:3301', 'host2:3301'}`).
242241
* A discovery function _may_ return multi-results but the client takes
243242
into account only first of them (i.e. `return {'host:3301'}, discovery_delay`, where
244243
the second result is unused). Even more, any extra results __are reserved__ by the client

src/main/java/org/tarantool/AbstractTarantoolOps.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
public abstract class AbstractTarantoolOps<Space, Tuple, Operation, Result>
55
implements TarantoolClientOps<Space, Tuple, Operation, Result> {
66

7-
private Code callCode = Code.OLD_CALL;
7+
private Code callCode = Code.CALL;
88

99
protected abstract Result exec(Code code, Object... args);
1010

src/main/java/org/tarantool/TarantoolClientConfig.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ public class TarantoolClientConfig {
4444
public long writeTimeoutMillis = 60 * 1000L;
4545

4646
/**
47-
* Use old call command https://github.com/tarantool/doc/issues/54,
48-
* please ensure that you server supports new call command.
47+
* Use new call method instead of obsolete
48+
* {@code call_16} which used to work in Tarantool v1.6.
49+
*
50+
* Since 1.9.3, this flag has become enabled by default
4951
*/
50-
public boolean useNewCall = false;
52+
public boolean useNewCall = true;
5153

5254
/**
5355
* Max time to establish connection to the server

src/main/java/org/tarantool/TarantoolClientImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ private void initClient(SocketChannelProvider socketProvider, TarantoolClientCon
115115
this.syncOps = new SyncOps();
116116
this.composableAsyncOps = new ComposableAsyncOps();
117117
this.fireAndForgetOps = new FireAndForgetOps();
118-
if (config.useNewCall) {
119-
setCallCode(Code.CALL);
120-
this.syncOps.setCallCode(Code.CALL);
121-
this.fireAndForgetOps.setCallCode(Code.CALL);
122-
this.composableAsyncOps.setCallCode(Code.CALL);
118+
if (!config.useNewCall) {
119+
setCallCode(Code.OLD_CALL);
120+
this.syncOps.setCallCode(Code.OLD_CALL);
121+
this.fireAndForgetOps.setCallCode(Code.OLD_CALL);
122+
this.composableAsyncOps.setCallCode(Code.OLD_CALL);
123123
}
124124
}
125125

src/main/java/org/tarantool/cluster/TarantoolClusterStoredFunctionDiscoverer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private void checkResult(List<?> result) {
5555
if (result == null || result.isEmpty()) {
5656
throw new IllegalDiscoveryFunctionResult("Discovery function returned no data");
5757
}
58-
if (!((List<Object>)result.get(0)).stream().allMatch(item -> item instanceof String)) {
58+
if (!(result.get(0) instanceof List)) {
5959
throw new IllegalDiscoveryFunctionResult("The first value must be an array of strings");
6060
}
6161
}

src/test/java/org/tarantool/ClientReconnectClusterIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ void testDelayFunctionResultFetch() {
359359
instances.get(SRV1)
360360
.executeLua("co = coroutine.create(function() " + functionBody + " end)");
361361
instances.get(SRV1)
362-
.executeLua("function getAddressesFunction() local c, r = coroutine.resume(co); return r end");
362+
.executeLua("function getAddressesFunction() local c, r = coroutine.resume(co); return {r} end");
363363

364364
String infoFunctionScript = makeDiscoveryFunction(infoFunctionName, Collections.singletonList(service3Address));
365365
instances.get(SRV2).executeLua(infoFunctionScript);

src/test/java/org/tarantool/cluster/ClusterServiceStoredFunctionDiscovererIT.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ public void testWrongTypeResultData() {
153153
assertThrows(IllegalDiscoveryFunctionResult.class, discoverer::getInstances);
154154
}
155155

156+
@Test
157+
@DisplayName("fetched with an exception when a single string returned")
158+
public void testSingleStringResultData() {
159+
String functionCode = makeDiscoveryFunction(ENTRY_FUNCTION_NAME, "'host1:3301'");
160+
control.openConsole(INSTANCE_NAME).exec(functionCode);
161+
162+
TarantoolClusterStoredFunctionDiscoverer discoverer =
163+
new TarantoolClusterStoredFunctionDiscoverer(clusterConfig, client);
164+
165+
assertThrows(IllegalDiscoveryFunctionResult.class, discoverer::getInstances);
166+
}
167+
156168
@Test
157169
@DisplayName("fetched with an exception using no return function")
158170
public void testFunctionWithNoReturn() {

0 commit comments

Comments
 (0)