use of com.mysql.cj.xdevapi.Warning in project aws-mysql-jdbc by awslabs.
the class XProtocolTest method testWarnings.
@Test
public void testWarnings() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
this.protocol.send(this.messageBuilder.buildSqlStatement("explain select 1"), 0);
this.protocol.readMetadata();
this.protocol.drainRows();
SqlResult res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
Iterable<Warning> iterable = () -> res.getWarnings();
List<Warning> warnings = StreamSupport.stream(iterable.spliterator(), false).map(w -> new WarningImpl(w)).collect(Collectors.toList());
assertEquals(1, warnings.size());
Warning w = warnings.get(0);
assertEquals(1, w.getLevel());
assertEquals(1003, w.getCode());
// this message format might change over time and have to be loosened up
assertEquals("/* select#1 */ select 1 AS `1`", w.getMessage());
}
use of com.mysql.cj.xdevapi.Warning in project aws-mysql-jdbc by awslabs.
the class SessionTest method testBug97269.
/**
* Test fix for Bug#97269 (30438500), POSSIBLE BUG IN COM.MYSQL.CJ.XDEVAPI.STREAMINGDOCRESULTBUILDER.
*
* @throws Exception
*/
@Test
public void testBug97269() throws Exception {
Session sess = null;
try {
String message1 = "W1";
String message2 = "W2";
// create notice message buffers
Frame.Builder notice1 = Frame.newBuilder().setScope(Frame.Scope.LOCAL).setType(Frame.Type.WARNING_VALUE).setPayload(com.mysql.cj.x.protobuf.MysqlxNotice.Warning.newBuilder().setCode(MysqlErrorNumbers.ER_BAD_DB_ERROR).setMsg(message1).build().toByteString());
Frame.Builder notice2 = Frame.newBuilder().setScope(Frame.Scope.GLOBAL).setType(Frame.Type.WARNING_VALUE).setPayload(com.mysql.cj.x.protobuf.MysqlxNotice.Warning.newBuilder().setCode(MysqlErrorNumbers.ER_BAD_DB_ERROR).setMsg(message2).build().toByteString());
byte[] notice1Bytes = makeNoticeBytes(notice1.build());
byte[] notice2Bytes = makeNoticeBytes(notice2.build());
int size = notice1Bytes.length + notice2Bytes.length;
byte[] noticesBytes = new byte[size];
System.arraycopy(notice1Bytes, 0, noticesBytes, 0, notice1Bytes.length);
System.arraycopy(notice2Bytes, 0, noticesBytes, notice1Bytes.length, notice2Bytes.length);
InjectedSocketFactory.flushAllStaticData();
String url = this.baseUrl + (this.baseUrl.contains("?") ? "" : "?") + makeParam(PropertyKey.socketFactory, InjectedSocketFactory.class.getName(), !this.baseUrl.contains("?") || this.baseUrl.endsWith("?")) + makeParam(PropertyKey.xdevapiSslMode, XdevapiSslMode.DISABLED.toString()) + makeParam(PropertyKey.xdevapiCompression, Compression.DISABLED.toString()) + // to allow injection between result rows
makeParam(PropertyKey.useReadAheadInput, "false");
sess = this.fact.getSession(url);
SocketFactory sf = ((SessionImpl) sess).getSession().getProtocol().getSocketConnection().getSocketFactory();
assertTrue(InjectedSocketFactory.class.isAssignableFrom(sf.getClass()));
Collection collection = sess.getDefaultSchema().createCollection("testBug97269");
collection.add("{\"_id\":\"the_id\",\"g\":1}").execute();
// StreamingDocResultBuilder
InjectedSocketFactory.injectedBuffer = noticesBytes;
DocResult docs = collection.find().fields("$._id as _id, $.g as g, 1 + 1 as q").execute();
DbDoc doc = docs.next();
assertEquals("the_id", ((JsonString) doc.get("_id")).getString());
assertEquals(new Integer(1), ((JsonNumber) doc.get("g")).getInteger());
assertEquals(new Integer(2), ((JsonNumber) doc.get("q")).getInteger());
int cnt = 0;
for (Iterator<Warning> warn = docs.getWarnings(); warn.hasNext(); ) {
Warning w = warn.next();
if (w.getMessage().equals(message1) || w.getMessage().equals(message2)) {
cnt++;
}
}
assertEquals(2, cnt);
InjectedSocketFactory.flushAllStaticData();
InjectedSocketFactory.injectedBuffer = noticesBytes;
SqlResult rs1 = sess.sql("select 1").execute();
assertEquals(1, rs1.fetchOne().getInt(0));
cnt = 0;
for (Iterator<Warning> warn = rs1.getWarnings(); warn.hasNext(); ) {
Warning w = warn.next();
if (w.getMessage().equals(message1) || w.getMessage().equals(message2)) {
cnt++;
}
}
assertEquals(2, cnt);
} finally {
InjectedSocketFactory.flushAllStaticData();
dropCollection("testBug97269");
if (sess != null) {
sess.close();
}
}
}
use of com.mysql.cj.xdevapi.Warning in project aws-mysql-jdbc by awslabs.
the class CollectionFindTest method testGetWarningsFromCollection.
/**
* Checks getWarningsCount and getWarnings APIs
*
* @throws Exception
*/
@Test
public void testGetWarningsFromCollection() throws Exception {
assumeTrue(mysqlVersionMeetsMinimum(ServerVersion.parseVersion("8.0.0")), "MySQL 8.0+ is required to run this test.");
String collname = "coll1";
Collection coll = null;
Warning w = null;
DocResult docs = null;
int i = 0;
try {
this.session.sql("set max_error_count=20000").execute();
dropCollection(collname);
coll = this.schema.createCollection(collname, true);
for (i = 1; i <= 10; i++) {
if (i % 2 == 0) {
coll.add("{\"X\":" + i + ",\"Y\":" + (i + 1000) + "}").execute();
} else {
coll.add("{\"X\":0,\"Y\":0}").execute();
}
}
docs = coll.find().fields("1/$.X as col1,1/$.Y as col2").execute();
assertEquals(10, docs.getWarningsCount());
i = 0;
for (Iterator<Warning> warn = docs.getWarnings(); warn.hasNext(); ) {
w = warn.next();
assertEquals("Division by 0", w.getMessage());
assertEquals(2, w.getLevel());
assertEquals(1365, w.getCode());
i++;
}
this.schema.dropCollection(collname);
coll = this.schema.createCollection(collname, true);
coll.add("{\"X\":1}").execute();
String s = "";
for (i = 1; i <= 10000; i++) {
if (i > 1) {
s = s + ",";
}
if (i % 2 == 0) {
s = s + "1/$.X as col" + i;
} else {
s = s + "$.X/0 as col1" + i;
}
}
docs = coll.find().fields(s).execute();
assertEquals(5000, docs.getWarningsCount());
i = 0;
for (Iterator<Warning> warn = docs.getWarnings(); warn.hasNext(); ) {
w = warn.next();
assertEquals("Division by 0", w.getMessage());
assertEquals(2, w.getLevel());
assertEquals(1365, w.getCode());
i++;
}
this.schema.dropCollection(collname);
} finally {
if (this.session != null) {
this.session.close();
}
}
}
use of com.mysql.cj.xdevapi.Warning in project aws-mysql-jdbc by awslabs.
the class ResultTest method testForceBuffering.
@Test
public void testForceBuffering() {
try {
sqlUpdate("drop table if exists testx");
sqlUpdate("create table testx (x int)");
sqlUpdate("insert into testx values (1), (2), (3)");
Table table = this.schema.getTable("testx");
RowResult rows = table.select("x/0 as bad_x").execute();
// get warnings IMMEDIATELY
assertEquals(3, rows.getWarningsCount());
Iterator<Warning> warnings = rows.getWarnings();
assertEquals(1365, warnings.next().getCode());
assertEquals(1365, warnings.next().getCode());
assertEquals(1365, warnings.next().getCode());
Row r = rows.next();
assertEquals(null, r.getString("bad_x"));
r = rows.next();
assertEquals(null, r.getString("bad_x"));
r = rows.next();
assertEquals(null, r.getString("bad_x"));
assertThrows(NoSuchElementException.class, () -> rows.next());
} finally {
sqlUpdate("drop table if exists testx");
}
}
use of com.mysql.cj.xdevapi.Warning 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