diff --git a/src/main/java/io/tarantool/driver/exceptions/errors/TarantoolErrors.java b/src/main/java/io/tarantool/driver/exceptions/errors/TarantoolErrors.java index 46c9e298c..07e82fc10 100644 --- a/src/main/java/io/tarantool/driver/exceptions/errors/TarantoolErrors.java +++ b/src/main/java/io/tarantool/driver/exceptions/errors/TarantoolErrors.java @@ -49,12 +49,9 @@ public static class TarantoolErrorsErrorFactory implements TarantoolErrorFactory private static final StringValue ERROR_MESSAGE = ValueFactory.newString("str"); private static final StringValue STACKTRACE = ValueFactory.newString("stack"); private static final Pattern NETWORK_ERROR_PATTERN = Pattern.compile( - ".*" + - "\"code\":" + - "[" + ErrorsCodes.NO_CONNECTION.getCode() + "|" + ErrorsCodes.TIMEOUT.getCode() + "]" + - ".*" + - "\"type\":\"" + CLIENT_ERROR + "\"" + - ".*", Pattern.DOTALL); + "\\B\"type\":\"" + CLIENT_ERROR + "\"\\B" + + ".*\\B\"code\":" + "[" + ErrorsCodes.NO_CONNECTION.getCode() + + "|" + ErrorsCodes.TIMEOUT.getCode() + "]\\B.*", Pattern.DOTALL); public TarantoolErrorsErrorFactory() { } diff --git a/src/test/java/io/tarantool/driver/integration/TarantoolErrorsIT.java b/src/test/java/io/tarantool/driver/integration/TarantoolErrorsIT.java index 89ebb77e9..38a11de8a 100644 --- a/src/test/java/io/tarantool/driver/integration/TarantoolErrorsIT.java +++ b/src/test/java/io/tarantool/driver/integration/TarantoolErrorsIT.java @@ -46,8 +46,8 @@ private ProxyTarantoolTupleClient setupClient() { private RetryingTarantoolTupleClient setupRetryingClient(int retries) { ProxyTarantoolTupleClient client = setupClient(); return new RetryingTarantoolTupleClient(client, - TarantoolRequestRetryPolicies - .byNumberOfAttempts(retries).build()); + TarantoolRequestRetryPolicies + .byNumberOfAttempts(retries).build()); } @Test @@ -58,14 +58,13 @@ void testNetworkError_boxErrorUnpackNoConnection() { client.callForSingleResult("box_error_unpack_no_connection", HashMap.class).get(); fail("Exception must be thrown after last retry attempt."); } catch (Throwable e) { + String message = e.getCause().getMessage(); + assertTrue(e.getCause() instanceof TarantoolInternalNetworkException); - assertTrue(e.getCause().getMessage().contains( - "code: 77\n" + - "message: Connection is not established\n" + - "base_type: ClientError\n" + - "type: ClientError\n" + - "trace:") - ); + assertTrue(message.contains("code: 77")); + assertTrue(message.contains("message: Connection is not established")); + assertTrue(message.contains("type: ClientError")); + assertTrue(message.contains("trace:")); } } @@ -80,14 +79,13 @@ void testNetworkError_boxErrorUnpackTimeout() { String.class).get(); fail("Exception must be thrown after last retry attempt."); } catch (Throwable e) { + String message = e.getCause().getMessage(); + assertTrue(e.getCause() instanceof TarantoolInternalNetworkException); - assertTrue(e.getCause().getMessage().contains( - "code: 78\n" + - "message: Timeout exceeded\n" + - "base_type: ClientError\n" + - "type: ClientError\n" + - "trace:") - ); + assertTrue(message.contains("code: 78")); + assertTrue(message.contains("message: Timeout exceeded")); + assertTrue(message.contains("type: ClientError")); + assertTrue(message.contains("trace:")); } } @@ -102,12 +100,11 @@ void testNetworkError_boxErrorTimeout() { String.class).get(); fail("Exception must be thrown after last retry attempt."); } catch (Throwable e) { + String message = e.getCause().getMessage(); + assertTrue(e.getCause() instanceof TarantoolInternalNetworkException); - assertTrue(e.getCause().getMessage().contains( - "InnerErrorMessage:\n" + - "code: 78\n" + - "message: Timeout exceeded") - ); + assertTrue(message.contains("code: 78")); + assertTrue(message.contains("message: Timeout exceeded")); } } @@ -119,13 +116,13 @@ void testNetworkError_crudErrorTimeout() { client.callForSingleResult("crud_error_timeout", HashMap.class).get(); fail("Exception must be thrown after last retry attempt."); } catch (Throwable e) { + String message = e.getCause().getMessage(); + assertTrue(e.getCause() instanceof TarantoolInternalNetworkException); - assertTrue(e.getCause().getMessage().contains( - "Function returned an error: {\"code\":78," + - "\"base_type\":\"ClientError\"," + - "\"type\":\"ClientError\"," + - "\"message\":\"Timeout exceeded\"," - )); + assertTrue(message.contains("\"code\":78")); + assertTrue(message.contains("\"type\":\"ClientError\"")); + assertTrue(message.contains("\"message\":\"Timeout exceeded\"")); + assertTrue(message.contains("\"trace\":")); } } @@ -137,33 +134,32 @@ void testNonNetworkError_boxErrorUnpack() { client.callForSingleResult("box_error_non_network_error", HashMap.class).get(); fail("Exception must be thrown after last retry attempt."); } catch (Throwable e) { + String message = e.getCause().getMessage(); + assertTrue(e.getCause() instanceof TarantoolInternalException); assertFalse(e.getCause() instanceof TarantoolInternalNetworkException); - assertTrue(e.getCause().getMessage().contains( - "code: 40\n" + - "message: Failed to write to disk\n" + - "base_type: ClientError\n" + - "type: ClientError\n" + - "trace:") - ); + assertTrue(message.contains("code: 40")); + assertTrue(message.contains("message: Failed to write to disk")); + assertTrue(message.contains("type: ClientError")); + assertTrue(message.contains("trace:")); } } - @Test - void testNonNetworkError_boxError() { - try { - ProxyTarantoolTupleClient client = setupClient(); - - client.callForSingleResult("raising_error", HashMap.class).get(); - fail("Exception must be thrown after last retry attempt."); - } catch (Throwable e) { - assertTrue(e.getCause() instanceof TarantoolInternalException); - assertFalse(e.getCause() instanceof TarantoolInternalNetworkException); - assertTrue(e.getCause().getMessage().contains( - "InnerErrorMessage:\n" + - "code: 32\n" + - "message:") - ); - } + @Test + void testNonNetworkError_boxError() { + try { + ProxyTarantoolTupleClient client = setupClient(); + + client.callForSingleResult("raising_error", HashMap.class).get(); + fail("Exception must be thrown after last retry attempt."); + } catch (Throwable e) { + String message = e.getCause().getMessage(); + + assertTrue(e.getCause() instanceof TarantoolInternalException); + assertFalse(e.getCause() instanceof TarantoolInternalNetworkException); + assertTrue(message.contains("InnerErrorMessage:")); + assertTrue(message.contains("code: 32")); + assertTrue(message.contains("message:")); } + } } diff --git a/src/test/resources/cartridge/app/roles/api_router.lua b/src/test/resources/cartridge/app/roles/api_router.lua index c83eb1b3f..f4a5059b5 100644 --- a/src/test/resources/cartridge/app/roles/api_router.lua +++ b/src/test/resources/cartridge/app/roles/api_router.lua @@ -1,6 +1,7 @@ local vshard = require('vshard') local cartridge_rpc = require('cartridge.rpc') local fiber = require('fiber') +local crud = require('crud') local log = require('log') local function get_schema() @@ -113,7 +114,7 @@ local function box_error_non_network_error() end local function crud_error_timeout() - return crud.get("test_space", ('x'):rep(2^27)) + return crud.select('test_space', { { '=', 'field1', ('x'):rep(2 ^ 27) } }, { timeout = 0.000001 }) end local function init(opts)