Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org
Subject: [tarantool-patches] [PATCH 08/10] swim: allow to use cdata struct tt_uuid in Lua API
Date: Wed, 15 May 2019 22:36:45 +0300	[thread overview]
Message-ID: <dcccdb7bee53a7ae85e2cb295eabbafc7f8e13da.1557948687.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1557948686.git.v.shpilevoy@tarantool.org>

Sometimes, especially in tests, it is useful to make something
like this:

    s:add_member({uuid = member:uuid(), uri = member:uri()})

But member:uuid() is cdata struct tt_uuid. This commit allows
that.

Part of #3234
---
 src/lua/swim.lua        |  5 ++++-
 test/swim/swim.result   | 17 ++++++++++++++---
 test/swim/swim.test.lua |  3 +++
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/lua/swim.lua b/src/lua/swim.lua
index 6e55ffeba..80c7375ab 100644
--- a/src/lua/swim.lua
+++ b/src/lua/swim.lua
@@ -194,7 +194,10 @@ local function swim_check_uuid(value, func_name)
         return nil
     end
     if type(value) ~= 'string' then
-        return error(func_name..': expected string UUID')
+        if ffi.istype('struct tt_uuid', value) then
+            return value
+        end
+        return error(func_name..': expected string UUID or struct tt_uuid')
     end
     value = uuid.fromstr(value)
     if not value then
diff --git a/test/swim/swim.result b/test/swim/swim.result
index d0838af48..91a8ab6e9 100644
--- a/test/swim/swim.result
+++ b/test/swim/swim.result
@@ -45,7 +45,7 @@ swim.new({gc_mode = 0})
 ...
 swim.new({uuid = 123})
 ---
-- error: 'builtin/swim.lua:<line>: swim:cfg: expected string UUID'
+- error: 'builtin/swim.lua:<line>: swim:cfg: expected string UUID or struct tt_uuid'
 ...
 swim.new({uuid = '1234'})
 ---
@@ -253,7 +253,8 @@ s1.remove_member()
 ...
 s1:remove_member(100)
 ---
-- error: 'builtin/swim.lua:<line>: swim:remove_member: expected string UUID'
+- error: 'builtin/swim.lua:<line>: swim:remove_member: expected string UUID or struct
+    tt_uuid'
 ...
 s1:remove_member('1234')
 ---
@@ -484,12 +485,22 @@ s1:member_by_uuid(uuid(1)) ~= nil
 ...
 s1:member_by_uuid(50)
 ---
-- error: 'builtin/swim.lua:<line>: swim:member_by_uuid: expected string UUID'
+- error: 'builtin/swim.lua:<line>: swim:member_by_uuid: expected string UUID or struct
+    tt_uuid'
 ...
 s1:member_by_uuid(uuid(2))
 ---
 - null
 ...
+-- UUID can be cdata.
+s1:member_by_uuid(s:uuid())
+---
+- uri: 127.0.0.1:<port>
+  status: alive
+  incarnation: 1
+  uuid: 00000000-0000-1000-8000-000000000001
+  payload_size: 0
+...
 s1:quit()
 ---
 ...
diff --git a/test/swim/swim.test.lua b/test/swim/swim.test.lua
index 9f237a540..a744b2a29 100644
--- a/test/swim/swim.test.lua
+++ b/test/swim/swim.test.lua
@@ -159,6 +159,9 @@ s1:member_by_uuid(uuid(1)) ~= nil
 s1:member_by_uuid(50)
 s1:member_by_uuid(uuid(2))
 
+-- UUID can be cdata.
+s1:member_by_uuid(s:uuid())
+
 s1:quit()
 s:status()
 s:is_dropped()
-- 
2.20.1 (Apple Git-117)

  parent reply	other threads:[~2019-05-15 19:36 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-15 19:36 [tarantool-patches] [PATCH 00/10] swim " Vladislav Shpilevoy
2019-05-15 19:36 ` [tarantool-patches] [PATCH 01/10] swim: fix an assertion on attempt to chage timeouts Vladislav Shpilevoy
2019-05-16  7:28   ` [tarantool-patches] " Konstantin Osipov
2019-05-15 19:36 ` [tarantool-patches] [PATCH 10/10] swim: cache members in Lua member table Vladislav Shpilevoy
2019-05-16  7:31   ` [tarantool-patches] " Konstantin Osipov
2019-05-15 19:36 ` [tarantool-patches] [PATCH 02/10] swim: make swim_new_round() void Vladislav Shpilevoy
2019-05-16  7:31   ` [tarantool-patches] " Konstantin Osipov
2019-05-15 19:36 ` [tarantool-patches] [PATCH 03/10] swim: validate URI in swim_probe_member() Vladislav Shpilevoy
2019-05-16  7:31   ` [tarantool-patches] " Konstantin Osipov
2019-05-15 19:36 ` [tarantool-patches] [PATCH 04/10] swim: introduce Lua interface Vladislav Shpilevoy
2019-05-15 19:36 ` [tarantool-patches] [PATCH 05/10] swim: Lua bindings to manipulate member table Vladislav Shpilevoy
2019-05-16  7:32   ` [tarantool-patches] " Konstantin Osipov
2019-05-15 19:36 ` [tarantool-patches] [PATCH 06/10] swim: Lua bindings to access individual members Vladislav Shpilevoy
2019-05-15 19:36 ` [tarantool-patches] [PATCH 07/10] swim: pairs() function to iterate over member table Vladislav Shpilevoy
2019-05-15 19:36 ` Vladislav Shpilevoy [this message]
2019-05-15 19:36 ` [tarantool-patches] [PATCH 09/10] swim: cache decoded payload in the Lua module Vladislav Shpilevoy
2019-05-16  7:36   ` [tarantool-patches] " Konstantin Osipov
2019-05-16 11:58     ` Vladislav Shpilevoy
2019-05-16 22:46     ` Vladislav Shpilevoy
2019-05-21 16:57 ` [tarantool-patches] Re: [PATCH 00/10] swim Lua API Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dcccdb7bee53a7ae85e2cb295eabbafc7f8e13da.1557948687.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 08/10] swim: allow to use cdata struct tt_uuid in Lua API' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox