15 #include <boost/scoped_ptr.hpp>
17 #include <gtest/gtest.h>
29 using namespace apache::hive::service::cli::thrift;
30 using namespace apache::thrift;
31 using namespace impala;
42 TEST(SessionTest, TestExpiry) {
43 FLAGS_idle_session_timeout = 1;
50 ImpaladMetricKeys::NUM_SESSIONS_EXPIRED);
51 DCHECK(expired_metric != NULL);
54 ImpaladMetricKeys::IMPALA_SERVER_NUM_OPEN_BEESWAX_SESSIONS);
57 ImpaladMetricKeys::IMPALA_SERVER_NUM_OPEN_HS2_SESSIONS);
58 EXPECT_EQ(expired_metric->value(), 0L);
59 EXPECT_EQ(beeswax_session_metric->value(), 0L);
61 scoped_ptr<ThriftClient<ImpalaServiceClient> > beeswax_clients[5];
62 scoped_ptr<ThriftClient<ImpalaHiveServer2ServiceClient> > hs2_clients[5];
65 for (
int i = 0; i < 5; ++i) {
67 "localhost", FLAGS_beeswax_port));
68 EXPECT_TRUE(beeswax_clients[i]->Open().ok());
71 "localhost", FLAGS_beeswax_port + 1));
72 EXPECT_TRUE(hs2_clients[i]->Open().ok());
73 TOpenSessionResp response;
74 TOpenSessionReq request;
75 hs2_clients[i]->iface()->OpenSession(response, request);
79 while (expired_metric->value() != 10 &&
UnixMillis() - start < 5000) {
83 ASSERT_EQ(expired_metric->value(), 10L) <<
"Sessions did not expire within 5s";
84 ASSERT_EQ(beeswax_session_metric->value(), 5L)
85 <<
"Beeswax sessions unexpectedly closed after expiration";
86 ASSERT_EQ(hs2_session_metric->value(), 5L)
87 <<
"HiveServer2 sessions unexpectedly closed after expiration";
89 TPingImpalaServiceResp resp;
90 ASSERT_THROW({beeswax_clients[0]->iface()->PingImpalaService(resp);}, TException)
91 <<
"Ping succeeded even after session expired";
94 int main(
int argc,
char** argv) {
97 ::testing::InitGoogleTest(&argc, argv);
98 return RUN_ALL_TESTS();
TEST(SessionTest, TestExpiry)
class SimpleMetric< int64_t, TMetricKind::COUNTER > IntCounter
void InitCommonRuntime(int argc, char **argv, bool init_jvm, TestInfo::Mode m=TestInfo::NON_TEST)
DECLARE_int32(idle_session_timeout)
void SleepForMs(const int64_t duration_ms)
Sleeps the current thread for at least duration_ms milliseconds.
M * FindMetricForTesting(const std::string &key)
Used for testing only.
#define EXIT_IF_ERROR(stmt)
Status StartWithClientServers(int beeswax_port, int hs2_port, bool use_statestore)
int main(int argc, char **argv)