]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/mds/TestSessionFilter.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2012 Inktank
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
17 #include "include/stringify.h"
18 #include "mds/SessionMap.h"
20 #include "gtest/gtest.h"
22 typedef std::vector
<std::string
> args_eg
;
23 typedef std::vector
<args_eg
> args_eg_set
;
25 TEST(MDSSessionFilter
, ParseGood
)
27 args_eg_set examples
= {
29 {"auth_name=foxtrot"},
30 {"state=reconnecting"},
31 {"reconnecting=true"},
32 {"client_metadata.root=/foo/bar"},
35 {"id=34", "client_metadata.root=/foo/bar", "auth_name=foxtrot",
36 "state=reconnecting", "reconnecting=true"}
39 for (auto ex
: examples
) {
43 std::cout
<< "Testing '" << ex
<< "'" << std::endl
;
44 int r
= f
.parse(ex
, &ss
);
46 ASSERT_TRUE(ss
.str().empty());
50 TEST(MDSSessionFilter
, ParseBad
)
52 args_eg_set examples
= {
57 {"reconnecting=MAYBE"},
61 for (auto ex
: examples
) {
65 std::cout
<< "Testing '" << ex
<< "'" << std::endl
;
66 int r
= f
.parse(ex
, &ss
);
67 ASSERT_EQ(r
, -EINVAL
);
68 ASSERT_FALSE(ss
.str().empty());
72 TEST(MDSSessionFilter
, IdEquality
)
76 filter
.parse({"id=123"}, &ss
);
77 Session
*a
= new Session(nullptr);;
78 Session
*b
= new Session(nullptr);;
79 a
->info
.inst
.name
.parse("client.123");
80 b
->info
.inst
.name
.parse("client.456");
82 ASSERT_TRUE(filter
.match(*a
, [](client_t c
) -> bool {return false;}));
83 ASSERT_FALSE(filter
.match(*b
, [](client_t c
) -> bool {return false;}));
88 TEST(MDSSessionFilter
, StateEquality
)
92 filter
.parse({"state=closing"}, &ss
);
93 Session
*a
= new Session(nullptr);
94 a
->set_state(Session::STATE_CLOSING
);
95 Session
*b
= new Session(nullptr);
96 b
->set_state(Session::STATE_OPENING
);
98 ASSERT_TRUE(filter
.match(*a
, [](client_t c
) -> bool {return false;}));
99 ASSERT_FALSE(filter
.match(*b
, [](client_t c
) -> bool {return false;}));
104 TEST(MDSSessionFilter
, AuthEquality
)
106 SessionFilter filter
;
107 std::stringstream ss
;
108 filter
.parse({"auth_name=rhubarb"}, &ss
);
109 Session
*a
= new Session(nullptr);
110 a
->info
.auth_name
.set_id("rhubarb");
111 Session
*b
= new Session(nullptr);
112 b
->info
.auth_name
.set_id("custard");
114 ASSERT_TRUE(filter
.match(*a
, [](client_t c
) -> bool {return false;}));
115 ASSERT_FALSE(filter
.match(*b
, [](client_t c
) -> bool {return false;}));
120 TEST(MDSSessionFilter
, MetadataEquality
)
122 SessionFilter filter
;
123 std::stringstream ss
;
124 int r
= filter
.parse({"client_metadata.root=/rhubarb"}, &ss
);
126 Session
*a
= new Session(nullptr);
127 a
->set_client_metadata(std::map
<std::string
,std::string
>({{"root", "/rhubarb"}}));
128 Session
*b
= new Session(nullptr);
129 b
->set_client_metadata(std::map
<std::string
,std::string
>({{"root", "/custard"}}));
131 ASSERT_TRUE(filter
.match(*a
, [](client_t c
) -> bool {return false;}));
132 ASSERT_FALSE(filter
.match(*b
, [](client_t c
) -> bool {return false;}));
137 TEST(MDSSessionFilter
, ReconnectingEquality
)
139 SessionFilter filter
;
140 std::stringstream ss
;
141 int r
= filter
.parse({"reconnecting=true"}, &ss
);
143 Session
*a
= new Session(nullptr);
145 ASSERT_TRUE(filter
.match(*a
, [](client_t c
) -> bool {return true;}));
146 ASSERT_FALSE(filter
.match(*a
, [](client_t c
) -> bool {return false;}));