Skip to content

Commit 36e4b4b

Browse files
author
Sharanya S
committed
Added Algorithm mismatch test to session-t.cc and xapi-t.cc
1 parent 6e7c098 commit 36e4b4b

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

devapi/tests/session-t.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,10 @@ TEST_F(Sess, compression_algorithms)
30783078
{"ZSTD_STREAM", "ZsTd","zStD_sTReaM","lz4","DEFLATE"},
30793079
};
30803080

3081+
//Reading the value of mysqlx_compression_algorithms at the beginning
3082+
SqlResult res = sql("SHOW GLOBAL VARIABLES LIKE 'mysqlx_compression_algorithms';");
3083+
Row row = res.fetchOne();
3084+
std::string Val = row[1].get<std::string>();
30813085

30823086
//By Default, it should use ZTSD compression
30833087

@@ -3383,6 +3387,29 @@ TEST_F(Sess, compression_algorithms)
33833387
Error);
33843388
}
33853389

3390+
//In these cases, algorithm set on the server side is different from the algorithms in connection
3391+
//and compression is REQUIRED, an error should be thrown
3392+
3393+
{
3394+
std::string query ="Set global mysqlx_compression_algorithms="+d.expected+";";
3395+
sql(query);
3396+
std::list<string> algorithms = {d.second,d.third};
3397+
EXPECT_THROW(
3398+
mysqlx::Session(SessionOption::HOST, get_host(),
3399+
SessionOption::PORT, get_port(),
3400+
SessionOption::USER, get_user(),
3401+
SessionOption::PWD, get_password(),
3402+
SessionOption::COMPRESSION, CompressionMode::REQUIRED,
3403+
SessionOption::COMPRESSION_ALGORITHMS, algorithms),
3404+
Error);
3405+
}
3406+
3407+
EXPECT_THROW(mysqlx::Session(uri + "compression=required&compression-algorithms=["+ d.second + "," + d.third +"]"), Error);
3408+
3409+
//Restoring to the original value of mysqlx_compression_algorithms
3410+
std::string query ="Set global mysqlx_compression_algorithms='"+Val+"';";
3411+
sql(query);
3412+
33863413
std::cout << d.expected << ": " <<
33873414
std::chrono::duration_cast<std::chrono::milliseconds>(
33883415
std::chrono::system_clock::now() - start_time).count() << "ms" <<std::endl;

xapi/tests/xapi-t.cc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,6 +3003,14 @@ TEST_F(xapi, compression_algorithms)
30033003
{"ZSTD_STREAM", "ZsTd","zStD_sTReaM","lz4","DEFLATE"},
30043004
};
30053005

3006+
//Reading the value of mysqlx_compression_algorithms at the beginning
3007+
mysqlx_result_t *res = exec_sql("SHOW GLOBAL VARIABLES LIKE 'mysqlx_compression_algorithms';");
3008+
mysqlx_row_t *row=mysqlx_row_fetch_one(res);
3009+
char buffer[50];
3010+
size_t buflen = sizeof(buffer);
3011+
mysqlx_get_bytes(row, 1, 0, buffer, &buflen);
3012+
std::string var_value=buffer;
3013+
mysqlx_result_free(res);
30063014

30073015
//By Default, it should use ZTSD compression
30083016

@@ -3344,6 +3352,31 @@ TEST_F(xapi, compression_algorithms)
33443352
EXPECT_EQ(nullptr, mysqlx_get_session_from_options(opt, &error));
33453353
mysqlx_free(opt);
33463354

3355+
//In these cases, algorithm set on the server side is different from the algorithms in connection
3356+
//and compression is REQUIRED, no session should be created
3357+
3358+
std::string qry = "Set global mysqlx_compression_algorithms=" + d.expected + ";";
3359+
exec_sql(qry.c_str());
3360+
tmp = std::string(d.second) + "," + d.third;
3361+
3362+
opt = mysqlx_session_options_new();
3363+
EXPECT_EQ(RESULT_OK, mysqlx_session_option_set(opt,
3364+
OPT_HOST(get_host()),
3365+
OPT_PORT(get_port()),
3366+
OPT_USER(get_user()),
3367+
OPT_PWD(get_password()),
3368+
OPT_COMPRESSION(MYSQLX_COMPRESSION_REQUIRED),
3369+
OPT_COMPRESSION_ALGORITHMS(tmp.c_str()),
3370+
PARAM_END));
3371+
EXPECT_EQ(nullptr, mysqlx_get_session_from_options(opt, & error));
3372+
mysqlx_free(opt);
3373+
3374+
tmp = uri + "compression=required&compression-algorithms=[" + d.second + "," + d.third + "]";
3375+
EXPECT_EQ(nullptr, mysqlx_get_session_from_url(tmp.c_str(), & error));
3376+
3377+
//Restoring to the original value of mysqlx_compression_algorithms
3378+
qry ="Set global mysqlx_compression_algorithms='"+var_value+"';";
3379+
exec_sql(qry.c_str());
33473380

33483381
std::cout << d.expected << ": " <<
33493382
std::chrono::duration_cast<std::chrono::milliseconds>(

0 commit comments

Comments
 (0)