]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/mds/TestSessionFilter.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / test / mds / TestSessionFilter.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2012 Inktank
7 *
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.
12 *
13 */
14
15#include <iostream>
16
17#include "include/stringify.h"
18#include "mds/SessionMap.h"
19
20#include "gtest/gtest.h"
21
22typedef std::vector<std::string> args_eg;
23typedef std::vector<args_eg> args_eg_set;
24
25TEST(MDSSessionFilter, ParseGood)
26{
27 args_eg_set examples = {
28 {"id=34"},
29 {"auth_name=foxtrot"},
30 {"state=reconnecting"},
31 {"reconnecting=true"},
32 {"client_metadata.root=/foo/bar"},
33 {},
34 {"id=123"},
35 {"id=34", "client_metadata.root=/foo/bar", "auth_name=foxtrot",
36 "state=reconnecting", "reconnecting=true"}
37 };
38
39 for (auto ex : examples) {
40 SessionFilter f;
41 std::stringstream ss;
42
43 std::cout << "Testing '" << ex << "'" << std::endl;
44 int r = f.parse(ex, &ss);
45 ASSERT_EQ(r, 0);
46 ASSERT_TRUE(ss.str().empty());
47 }
48}
49
50TEST(MDSSessionFilter, ParseBad)
51{
52 args_eg_set examples = {
53 {"rhubarb"},
54 {"id="},
55 {"id=custard"},
56 {"=custard"},
57 {"reconnecting=MAYBE"},
58 {"reconnecting=2"}
59 };
60
61 for (auto ex : examples) {
62 SessionFilter f;
63 std::stringstream ss;
64
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());
69 }
70}
71
72TEST(MDSSessionFilter, IdEquality)
73{
74 SessionFilter filter;
75 std::stringstream ss;
76 filter.parse({"id=123"}, &ss);
a8e16298
TL
77 Session *a = new Session(nullptr);;
78 Session *b = new Session(nullptr);;
7c673cae
FG
79 a->info.inst.name.parse("client.123");
80 b->info.inst.name.parse("client.456");
81
82 ASSERT_TRUE(filter.match(*a, [](client_t c) -> bool {return false;}));
83 ASSERT_FALSE(filter.match(*b, [](client_t c) -> bool {return false;}));
84 a->put();
85 b->put();
86}
87
88TEST(MDSSessionFilter, StateEquality)
89{
90 SessionFilter filter;
91 std::stringstream ss;
92 filter.parse({"state=closing"}, &ss);
a8e16298 93 Session *a = new Session(nullptr);
7c673cae 94 a->set_state(Session::STATE_CLOSING);
a8e16298 95 Session *b = new Session(nullptr);
7c673cae
FG
96 b->set_state(Session::STATE_OPENING);
97
98 ASSERT_TRUE(filter.match(*a, [](client_t c) -> bool {return false;}));
99 ASSERT_FALSE(filter.match(*b, [](client_t c) -> bool {return false;}));
100 a->put();
101 b->put();
102}
103
104TEST(MDSSessionFilter, AuthEquality)
105{
106 SessionFilter filter;
107 std::stringstream ss;
108 filter.parse({"auth_name=rhubarb"}, &ss);
a8e16298 109 Session *a = new Session(nullptr);
7c673cae 110 a->info.auth_name.set_id("rhubarb");
a8e16298 111 Session *b = new Session(nullptr);
7c673cae
FG
112 b->info.auth_name.set_id("custard");
113
114 ASSERT_TRUE(filter.match(*a, [](client_t c) -> bool {return false;}));
115 ASSERT_FALSE(filter.match(*b, [](client_t c) -> bool {return false;}));
116 a->put();
117 b->put();
118}
119
120TEST(MDSSessionFilter, MetadataEquality)
121{
122 SessionFilter filter;
123 std::stringstream ss;
124 int r = filter.parse({"client_metadata.root=/rhubarb"}, &ss);
125 ASSERT_EQ(r, 0);
11fdf7f2 126 client_metadata_t meta;
a8e16298 127 Session *a = new Session(nullptr);
11fdf7f2
TL
128 meta.kv_map = {{"root", "/rhubarb"}};
129 a->set_client_metadata(meta);
a8e16298 130 Session *b = new Session(nullptr);
11fdf7f2
TL
131 meta.kv_map = {{"root", "/custard"}};
132 b->set_client_metadata(meta);
7c673cae
FG
133
134 ASSERT_TRUE(filter.match(*a, [](client_t c) -> bool {return false;}));
135 ASSERT_FALSE(filter.match(*b, [](client_t c) -> bool {return false;}));
136 a->put();
137 b->put();
138}
139
140TEST(MDSSessionFilter, ReconnectingEquality)
141{
142 SessionFilter filter;
143 std::stringstream ss;
144 int r = filter.parse({"reconnecting=true"}, &ss);
145 ASSERT_EQ(r, 0);
a8e16298 146 Session *a = new Session(nullptr);
7c673cae
FG
147
148 ASSERT_TRUE(filter.match(*a, [](client_t c) -> bool {return true;}));
149 ASSERT_FALSE(filter.match(*a, [](client_t c) -> bool {return false;}));
150 a->put();
151}