Skip to content

Commit 663403c

Browse files
committed
Add details in Metadata extraction problem
Closes #200
1 parent 526bf46 commit 663403c

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
## [Unreleased]
44
- Remove config request timeout as default parameter in crud client
5+
- Add details for the case of space metadata fetching failure ([#200](https://github.com/tarantool/cartridge-java/issues/200))
56
- Close public access to TarantoolResult*Impl ([#326](https://github.com/tarantool/cartridge-java/issues/326))
67
- Split retrying into more detailed modules ([#341](https://github.com/tarantool/cartridge-java/issues/341))
7-
- Add deep copy instead of shallow copy in default message pack mapper
8+
- Add deep copy instead of shallow copy in default message pack mapper ([#166](https://github.com/tarantool/cartridge-java/issues/166))
89
- Add a factory builder for constructing mapper hierarchies
910

1011
## [0.10.1] - 2023-01-13

src/main/java/io/tarantool/driver/core/metadata/DDLTarantoolSpaceMetadataConverter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import io.tarantool.driver.api.metadata.TarantoolIndexType;
77
import io.tarantool.driver.api.metadata.TarantoolMetadataContainer;
88
import io.tarantool.driver.exceptions.TarantoolClientException;
9+
import io.tarantool.driver.exceptions.TarantoolEmptyMetadataException;
910
import io.tarantool.driver.mappers.converters.ValueConverter;
1011
import org.msgpack.value.ArrayValue;
1112
import org.msgpack.value.StringValue;
1213
import org.msgpack.value.Value;
1314
import org.msgpack.value.ValueFactory;
15+
import org.msgpack.value.ValueType;
1416

1517
import java.util.HashMap;
1618
import java.util.List;
@@ -59,7 +61,11 @@ private DDLTarantoolSpaceMetadataConverter() {
5961
public TarantoolMetadataContainer fromValue(Value value) {
6062

6163
if (!value.isMapValue()) {
62-
throw new TarantoolClientException("Unsupported space metadata format: expected map");
64+
if (value.getValueType().equals(ValueType.ARRAY) && value.asArrayValue().size() == 0) {
65+
throw new TarantoolEmptyMetadataException();
66+
}
67+
throw new TarantoolClientException("Unsupported space metadata format: expected map, got %s",
68+
value.getValueType());
6369
}
6470

6571
Map<Value, Value> spacesMap = value.asMapValue().map();

src/main/java/io/tarantool/driver/core/metadata/TarantoolMetadata.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package io.tarantool.driver.core.metadata;
22

3+
import io.tarantool.driver.api.TarantoolClient;
34
import io.tarantool.driver.api.metadata.TarantoolIndexMetadata;
45
import io.tarantool.driver.api.metadata.TarantoolMetadataOperations;
56
import io.tarantool.driver.api.metadata.TarantoolMetadataProvider;
67
import io.tarantool.driver.api.metadata.TarantoolSpaceMetadata;
78
import io.tarantool.driver.exceptions.TarantoolClientException;
9+
import io.tarantool.driver.exceptions.TarantoolEmptyMetadataException;
10+
import io.tarantool.driver.exceptions.TarantoolFunctionCallException;
11+
import io.tarantool.driver.exceptions.TarantoolMetadataRequestException;
812
import io.tarantool.driver.exceptions.TarantoolNoSuchProcedureException;
913
import io.tarantool.driver.utils.Assert;
1014

@@ -97,6 +101,9 @@ private CompletableFuture<Void> populateMetadata() {
97101
CompletableFuture<Void> result = new CompletableFuture<>();
98102
try {
99103
result = metadataProvider.getMetadata().thenAccept(container -> {
104+
if (container == null) {
105+
throw new TarantoolEmptyMetadataException();
106+
}
100107
spaceMetadataByName.clear();
101108
spaceMetadataById.clear();
102109
indexMetadataBySpaceName.clear();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.tarantool.driver.exceptions;
2+
3+
/**
4+
* The exception occurs when no metadata returned by proxy function when expected something
5+
*
6+
* @author Artyom Dubinin
7+
*/
8+
public class TarantoolEmptyMetadataException extends TarantoolClientException {
9+
private static final String message = "No space metadata returned";
10+
11+
public TarantoolEmptyMetadataException() {
12+
super(message);
13+
}
14+
}

src/test/java/io/tarantool/driver/integration/TarantoolErrorsIT.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
import io.tarantool.driver.core.ProxyTarantoolTupleClient;
88
import io.tarantool.driver.exceptions.TarantoolAccessDeniedException;
99
import io.tarantool.driver.exceptions.TarantoolClientException;
10+
import io.tarantool.driver.exceptions.TarantoolEmptyMetadataException;
11+
import io.tarantool.driver.exceptions.TarantoolFunctionCallException;
1012
import io.tarantool.driver.exceptions.TarantoolInternalException;
1113
import io.tarantool.driver.exceptions.TarantoolInternalNetworkException;
14+
import io.tarantool.driver.exceptions.TarantoolMetadataRequestException;
1215
import io.tarantool.driver.exceptions.TarantoolNoSuchProcedureException;
16+
import io.tarantool.driver.exceptions.TarantoolSpaceNotFoundException;
17+
1318
import org.junit.jupiter.api.BeforeAll;
1419
import org.junit.jupiter.api.Test;
1520

@@ -213,4 +218,40 @@ void test_should_throwTarantoolAccessDenied_ifUserHasRestrictions() {
213218
assertTrue(cause.getMessage()
214219
.contains("Execute access to function 'ddl.get_schema' is denied for user 'restricted_user'"));
215220
}
221+
222+
@Test
223+
void test_failedToRefreshMetadata_shouldHasReasonOfException_ifDdlReturnNull() {
224+
ProxyTarantoolTupleClient adminClient = setupAdminClient();
225+
226+
adminClient.eval("true_ddl = ddl; " +
227+
"ddl = {get_schema = function() return nil end}").join();
228+
229+
TarantoolClientException exception = assertThrows(TarantoolClientException.class,
230+
() -> adminClient.space("test_space").select(Conditions.any()));
231+
assertEquals("Failed to refresh spaces and indexes metadata", exception.getMessage());
232+
Throwable cause = exception.getCause();
233+
assertEquals(TarantoolEmptyMetadataException.class, cause.getClass());
234+
assertEquals("No space metadata returned", cause.getMessage());
235+
adminClient.eval("ddl = true_ddl").join();
236+
}
237+
238+
@Test
239+
void test_failedToRefreshMetadata_shouldHasReasonOfException_ifDdlReturnEmptyTable() {
240+
ProxyTarantoolTupleClient adminClient = setupAdminClient();
241+
242+
adminClient.eval("true_ddl = ddl; " +
243+
"ddl = {get_schema = function() return {} end}").join();
244+
245+
TarantoolClientException exception = assertThrows(TarantoolClientException.class,
246+
() -> adminClient.space("test_space").select(Conditions.any()));
247+
assertEquals("Failed to refresh spaces and indexes metadata", exception.getMessage());
248+
Throwable cause = exception.getCause();
249+
assertEquals(TarantoolMetadataRequestException.class, cause.getClass());
250+
cause = cause.getCause();
251+
assertEquals(CompletionException.class, cause.getClass());
252+
cause = cause.getCause();
253+
assertEquals(TarantoolEmptyMetadataException.class, cause.getClass());
254+
assertEquals("No space metadata returned", cause.getMessage());
255+
adminClient.eval("ddl = true_ddl").join();
256+
}
216257
}

0 commit comments

Comments
 (0)