Skip to content

Commit 8f1c487

Browse files
committed
WL #12150 Connection compression. Unit test fixes.
1 parent 5014619 commit 8f1c487

File tree

2 files changed

+59
-22
lines changed

2 files changed

+59
-22
lines changed

devapi/tests/session-t.cc

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class Sess : public mysqlx::test::Xplugin
133133

134134
};
135135

136+
136137
void check_compress(mysqlx::Session &sess)
137138
{
138139
{
@@ -148,15 +149,28 @@ void check_compress(mysqlx::Session &sess)
148149
query.append("'");
149150

150151
SqlResult res = sess.sql(query).execute();
151-
Row row;
152-
while ((row = res.fetchOne()))
152+
153+
auto test_row = [](const std::string &data, const std::string &row)
153154
{
154-
cout << "Uncompressed data: " << row[0] << endl;
155-
}
155+
size_t len = data.length();
156+
for (int i = 0; i < 5000; ++i)
157+
if(row.substr(i*len,len) != data)
158+
FAIL() << "Data differs at position" << 5*len;
159+
};
160+
161+
Row row;
162+
163+
EXPECT_TRUE(row = res.fetchOne());
164+
test_row("Test ", row[0].get<std::string>());
165+
166+
EXPECT_TRUE(row = res.fetchOne());
167+
test_row("0123 ", row[0].get<std::string>());
168+
169+
cout << "Data is correct" << endl;
156170
}
157171

158172
{
159-
SqlResult res = sess.sql("SHOW STATUS LIKE 'Mysqlx%compress%'").execute();
173+
SqlResult res = sess.sql("SHOW STATUS LIKE 'Mysqlx_bytes%compress%'").execute();
160174
Row row;
161175
int actual_row_count = 0;
162176
while((row = res.fetchOne()))
@@ -165,7 +179,7 @@ void check_compress(mysqlx::Session &sess)
165179
++actual_row_count;
166180
EXPECT_TRUE(std::stol((std::string)row[1], nullptr, 0) > 0);
167181
}
168-
cout << "Status rows fetched: " << actual_row_count;
182+
cout << "Status rows fetched: " << actual_row_count << endl;
169183
EXPECT_TRUE(actual_row_count > 0);
170184
}
171185
};
@@ -282,7 +296,7 @@ TEST_F(Sess, tls_ver_ciphers)
282296
mysqlx::Session sess(str.str());
283297

284298
EXPECT_TRUE(0 < versions.count(check_var(sess, "Mysqlx_ssl_version")));
285-
EXPECT_NO_THROW(suites_map.at(check_var(sess, "Mysqlx_ssl_cipher")));
299+
EXPECT_NO_THROW((void)suites_map.at(check_var(sess, "Mysqlx_ssl_cipher")));
286300

287301

288302
// Negative: invalid or not accepted ciphers
@@ -378,7 +392,7 @@ TEST_F(Sess, tls_ver_ciphers)
378392
mysqlx::Session sess(opt);
379393

380394
EXPECT_TRUE(0 < versions.count(check_var(sess, "Mysqlx_ssl_version")));
381-
EXPECT_NO_THROW(suites_map.at(check_var(sess, "Mysqlx_ssl_cipher")));
395+
EXPECT_NO_THROW((void)suites_map.at(check_var(sess, "Mysqlx_ssl_cipher")));
382396
}
383397

384398
// Negative: invalid or not accepted ciphers

xapi/tests/xapi-t.cc

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,36 @@ void check_compress(mysqlx_session_t *sess)
5252
mysqlx_result_t *res;
5353
mysqlx_row_t *row;
5454

55-
CRUD_CHECK(res = mysqlx_sql(sess, query.c_str(), strlen(query.c_str())), sess);
56-
57-
while ((row = mysqlx_row_fetch_one(res)) != NULL)
55+
auto test_row = [](const std::string &data, const std::string &row)
5856
{
59-
char *buf = new char[65536];
60-
size_t buf_len = 65536;
61-
memset(buf, 0, buf_len);
62-
EXPECT_EQ(RESULT_OK, mysqlx_get_bytes(row, 0, 0, buf, &buf_len));
63-
printf("Uncompressed data: %s\n", buf);
64-
delete[] buf;
65-
}
57+
size_t len = data.length();
58+
for (int i = 0; i < 5000; ++i)
59+
if (row.substr(i * len, len) != data)
60+
FAIL() << "Data differs at position" << 5 * len;
61+
};
62+
63+
CRUD_CHECK(res = mysqlx_sql(sess, query.c_str(), query.length()), sess);
64+
65+
char *buf = new char[65536];
66+
size_t buf_len;
67+
68+
buf_len = 65536;
69+
memset(buf, 0, buf_len);
70+
EXPECT_NE(nullptr, row = mysqlx_row_fetch_one(res));
71+
EXPECT_EQ(RESULT_OK, mysqlx_get_bytes(row, 0, 0, buf, &buf_len));
72+
test_row("Test ", buf);
73+
74+
buf_len = 65536;
75+
memset(buf, 0, buf_len);
76+
EXPECT_NE(nullptr, row = mysqlx_row_fetch_one(res));
77+
EXPECT_EQ(RESULT_OK, mysqlx_get_bytes(row, 0, 0, buf, &buf_len));
78+
test_row("0123 ", buf);
79+
80+
delete[] buf;
6681

67-
const char *query2 = (const char*)"SHOW STATUS LIKE 'Mysqlx%compress%'";
82+
cout << "Data is correct" << endl;
83+
84+
const char *query2 = (const char*)"SHOW STATUS LIKE 'Mysqlx_bytes%compress%'";
6885
CRUD_CHECK(res = mysqlx_sql(sess, query2, strlen(query2)), sess);
6986
int actual_row_count = 0;
7087
while ((row = mysqlx_row_fetch_one(res)) != NULL)
@@ -81,12 +98,15 @@ void check_compress(mysqlx_session_t *sess)
8198
++actual_row_count;
8299

83100
printf("%s : %s\n", buf1, buf2);
101+
EXPECT_TRUE(std::stol((std::string)buf2, nullptr, 0) > 0);
84102
}
85103
printf("Status rows fetched: %i \n", actual_row_count);
86104
EXPECT_TRUE(actual_row_count > 0);
87105
};
88106

89-
int check_compress2(mysqlx_session_t* m_sess) {
107+
108+
int check_compress2(mysqlx_session_t* m_sess)
109+
{
90110
mysqlx_result_t* res = NULL;
91111
mysqlx_schema_t* schema;
92112
mysqlx_collection_t* collection;
@@ -114,12 +134,13 @@ int check_compress2(mysqlx_session_t* m_sess) {
114134
printf("\nInsert Success\n");
115135

116136
return retVal;
117-
118137
}
119138

120139

121140
TEST_F(xapi, compression_test)
122141
{
142+
SKIP_IF_NO_XPLUGIN
143+
123144
mysqlx_error_t *error;
124145
mysqlx_session_t *sess;
125146
mysqlx_session_options_t *opt;
@@ -179,6 +200,8 @@ TEST_F(xapi, compression_test)
179200

180201
TEST_F(xapi, compression_test_doc)
181202
{
203+
SKIP_IF_NO_XPLUGIN
204+
182205
mysqlx_session_t* sess = NULL;
183206
mysqlx_error_t *error = NULL;
184207
std::string uri = get_basic_uri() + "?compression=PREFERRED";
@@ -2725,7 +2748,7 @@ TEST_F(xapi, tls_ver_ciphers)
27252748
size_t sz = sizeof(buf);
27262749
mysqlx_get_bytes(row, 1, 0, buf, &sz);
27272750
printf("Mysqlx_ssl_cipher=%s\n", buf);
2728-
EXPECT_NO_THROW(suites_map.at(buf));
2751+
EXPECT_NO_THROW((void)suites_map.at(buf));
27292752
}
27302753

27312754
mysqlx_free_options(opt);

0 commit comments

Comments
 (0)