use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.
the class CollectionFindTest method testCollectionFindStress_002.
/* 64k length key */
@Test
public void testCollectionFindStress_002() throws Exception {
int i = 0, maxrec = 5;
int maxLen = 1024 * 64 - 1;
SqlResult res1 = null;
Session tmpSess = null;
Row r = null;
int defXPackLen = 0;
int defPackLen = 0;
try {
tmpSess = new SessionFactory().getSession(this.baseUrl);
res1 = tmpSess.sql("show variables like 'mysqlx_max_allowed_packet'").execute();
r = res1.next();
defXPackLen = Integer.parseInt(r.getString("Value"));
res1 = tmpSess.sql("show variables like 'max_allowed_packet'").execute();
r = res1.next();
defPackLen = Integer.parseInt(r.getString("Value"));
tmpSess.sql("set Global mysqlx_max_allowed_packet=128*1024*1024 ").execute();
tmpSess.sql("set Global max_allowed_packet=128*1024*1024 ").execute();
String s1 = "";
/* max+1 key length --> Expect error */
s1 = buildString(maxLen + 1, 'q');
DbDoc[] jsonlist = new DbDocImpl[maxrec];
for (i = 0; i < maxrec; i++) {
DbDoc newDoc2 = new DbDocImpl();
newDoc2.add("_id", new JsonString().setValue(String.valueOf(i + 1 + 1000)));
newDoc2.add("F1", new JsonNumber().setValue(String.valueOf(i + 1)));
newDoc2.add(s1, new JsonString().setValue("Data_1" + i));
jsonlist[i] = newDoc2;
newDoc2 = null;
}
assertThrows(XProtocolError.class, "ERROR 3151 \\(22032\\) The JSON object contains a key name that is too long\\.", () -> this.collection.add(jsonlist).execute());
/* With Max Keysize */
s1 = buildString(maxLen - 1, 'q');
for (i = 0; i < maxrec; i++) {
DbDoc newDoc2 = new DbDocImpl();
newDoc2.add("_id", new JsonString().setValue(String.valueOf(i + 1 + 1000)));
newDoc2.add(s1 + "1", new JsonNumber().setValue(String.valueOf(i + 1)));
newDoc2.add(s1 + "2", new JsonString().setValue("Data_1" + i));
// jsonlist[i]=newDoc2;
this.collection.add(newDoc2).execute();
newDoc2 = null;
}
// coll.add(jsonlist).execute();
DocResult docs0 = this.collection.find("$._id= '1001'").fields("$._id as _id, $." + s1 + "1 as " + s1 + "X, $." + s1 + "2 as " + s1 + "Y").execute();
DbDoc doc0 = docs0.next();
assertEquals(String.valueOf(1 + 1000), (((JsonString) doc0.get("_id")).getString()));
} finally {
if (tmpSess != null) {
tmpSess.sql("set Global mysqlx_max_allowed_packet=" + defXPackLen).execute();
tmpSess.sql("set Global max_allowed_packet=" + defPackLen).execute();
tmpSess.close();
}
}
}
use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.
the class CollectionFindTest method testCollectionFindStress_003.
/* Large Data */
@Test
public // @Ignore("Wait for 1M Data issue Fix in Plugin")
void testCollectionFindStress_003() throws Exception {
int i = 0, maxrec = 5;
int maxLen = 1024 * 1024 + 4;
SqlResult res1 = null;
Session tmpSess = null;
Row r = null;
int defPackLen = 0;
int defXPackLen = 0;
try {
tmpSess = new SessionFactory().getSession(this.baseUrl);
res1 = tmpSess.sql("show variables like 'mysqlx_max_allowed_packet'").execute();
r = res1.next();
defXPackLen = Integer.parseInt(r.getString("Value"));
res1 = tmpSess.sql("show variables like 'max_allowed_packet'").execute();
r = res1.next();
defPackLen = Integer.parseInt(r.getString("Value"));
tmpSess.sql("set Global mysqlx_max_allowed_packet=128*1024*1024 ").execute();
tmpSess.sql("set Global max_allowed_packet=128*1024*1024 ").execute();
((SessionImpl) this.session).getSession().getProtocol().setMaxAllowedPacket(128 * 1024 * 1024);
String s1 = "";
/* maxLen Data length */
s1 = buildString(maxLen + 1, 'q');
for (i = 0; i < maxrec; i++) {
DbDoc newDoc2 = new DbDocImpl();
newDoc2.add("_id", new JsonString().setValue(String.valueOf(i + 1 + 1000)));
newDoc2.add("F1", new JsonString().setValue(s1 + i));
newDoc2.add("F2", new JsonString().setValue(s1 + i));
this.collection.add(newDoc2).execute();
newDoc2 = null;
}
DocResult docs0 = this.collection.find("$._id= '1001'").fields("$._id as _id, $.F1 as f1, $.F2 as f2").execute();
DbDoc doc0 = docs0.next();
assertEquals(String.valueOf(1 + 1000), (((JsonString) doc0.get("_id")).getString()));
} finally {
if (tmpSess != null) {
tmpSess.sql("set Global mysqlx_max_allowed_packet=" + defXPackLen).execute();
tmpSess.sql("set Global max_allowed_packet=" + defPackLen).execute();
tmpSess.close();
}
}
}
use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.
the class SecureSessionTest method allowsRsa.
private boolean allowsRsa(Session sess) {
boolean allowsRSA = false;
SqlResult rset = sess.sql("SHOW STATUS LIKE 'Rsa_public_key'").execute();
if (rset.hasNext()) {
String value = rset.fetchOne().getString(1);
allowsRSA = (value != null && value.length() > 0);
}
return allowsRSA;
}
use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.
the class SessionTest method testSessionAttributes_checkSession.
private void testSessionAttributes_checkSession(Session s, Map<String, String> userAttributes) {
Map<String, Integer> matchedCounts = new HashMap<>();
Map<String, String> matchValues = new HashMap<>();
matchValues.put("_platform", Constants.OS_ARCH);
matchValues.put("_os", Constants.OS_NAME + "-" + Constants.OS_VERSION);
matchValues.put("_client_name", Constants.CJ_NAME);
matchValues.put("_client_version", Constants.CJ_VERSION);
matchValues.put("_client_license", Constants.CJ_LICENSE);
matchValues.put("_runtime_version", Constants.JVM_VERSION);
matchValues.put("_runtime_vendor", Constants.JVM_VENDOR);
matchValues.putAll(userAttributes);
SqlResult res = s.sql("SELECT * FROM performance_schema.session_connect_attrs WHERE processlist_id = CONNECTION_ID()").execute();
while (res.hasNext()) {
Row r = res.next();
String key = r.getString(1);
String val = r.getString(2);
assertTrue(matchValues.containsKey(key), "Unexpected connection attribute key: " + key);
Integer cnt = matchedCounts.get(key);
matchedCounts.put(key, cnt == null ? 1 : cnt++);
// when client sends an empty string as an attribute value the NULL value is stored to performance_schema.session_connect_attrs
String expected = matchValues.get(key);
if (expected.equals("")) {
expected = null;
}
assertEquals(expected, val);
}
for (String key : matchValues.keySet()) {
assertTrue(matchedCounts.containsKey(key), "Incorrect number of entries for key \"" + key + "\": 0");
assertTrue(matchedCounts.get(key) == 1, "Incorrect number of entries for key \"" + key + "\": " + matchedCounts.get(key));
}
}
use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.
the class SessionTest method testExecAsyncNegative.
/**
* Few Negative Scenarios
*
* @throws Exception
*/
@Test
public void testExecAsyncNegative() throws Exception {
int i = 0;
SqlResult sqlRes = null;
Row r = null;
try {
assertThrows(ExecutionException.class, ".*Unknown table '" + this.schema.getName() + ".non_existing'.*", () -> {
CompletableFuture<SqlResult> res = this.session.sql("drop table non_existing").executeAsync();
res.get();
return null;
});
assertThrows(ExecutionException.class, ".* BIGINT value is out of range .*", () -> {
CompletableFuture<SqlResult> res = this.session.sql("select 123456*123456722323289").executeAsync();
res.get();
return null;
});
sqlUpdate("drop table if exists testExecAsyncNegative");
sqlUpdate("create table testExecAsyncNegative(a int,b bigint ,c bigint GENERATED ALWAYS AS (b*1000) VIRTUAL COMMENT '1',d bigint GENERATED ALWAYS AS (c*100000) STOred COMMENT '2')");
sqlUpdate("Insert into testExecAsyncNegative (a,b) values(1,100)");
sqlUpdate("create index id on testExecAsyncNegative(d)");
sqlUpdate("create unique index id2 on testExecAsyncNegative(a)");
int NUMBER_OF_QUERIES = 5000;
List<CompletableFuture<SqlResult>> futures = new ArrayList<>();
for (i = 0; i < NUMBER_OF_QUERIES; ++i) {
if (i % 6 == 0) {
futures.add(this.session.sql("replace into testExecAsyncNegative (a,b) values(?,?)").bind(1).bind(1555666000000L).executeAsync());
} else if (i % 6 == 1) {
futures.add(this.session.sql("insert into testExecAsyncNegative (a,b) values (?,?) ON DUPLICATE KEY UPDATE b= ?").bind(1).bind(2).bind(1555666009990L).executeAsync());
} else if (i % 6 == 2) {
futures.add(this.session.sql("alter table testExecAsyncNegative add d point").executeAsync());
} else if (i % 6 == 3) {
futures.add(this.session.sql("insert into testExecAsyncNegative (a,b) values (?,?) ON DUPLICATE KEY UPDATE b=b/?").bind(1).bind(2).bind(0).executeAsync());
} else if (i % 6 == 4) {
futures.add(this.session.sql("SELECT /*+ max_execution_time (100) bad_hint */ SLEEP(0.5)").executeAsync());
} else {
futures.add(this.session.sql("select /*+*/ * from testExecAsyncNegative").executeAsync());
}
}
for (i = 0; i < NUMBER_OF_QUERIES; ++i) {
int i1 = i;
if (i % 6 == 0) {
assertThrows(ExecutionException.class, ".* BIGINT value is out of range .*", () -> futures.get(i1).get());
} else if (i % 6 == 1) {
assertThrows(ExecutionException.class, ".* BIGINT value is out of range .*", () -> futures.get(i1).get());
} else if (i % 6 == 2) {
assertThrows(ExecutionException.class, ".*Duplicate column name 'd'.*", () -> futures.get(i1).get());
} else if (i % 6 == 3) {
assertThrows(ExecutionException.class, ".*Division by 0.*", () -> futures.get(i1).get());
} else {
sqlRes = futures.get(i).get();
r = sqlRes.next();
assertEquals(1, r.getInt(0));
assertFalse(sqlRes.hasNext());
Iterator<Warning> w = sqlRes.getWarnings();
while (w.hasNext()) {
Warning element = w.next();
assertTrue(element.getMessage().contains("Optimizer hint syntax error"));
}
}
}
} finally {
sqlUpdate("drop table if exists testExecAsyncNegative");
}
}
Aggregations