use of com.mysql.cj.protocol.x.XProtocolRowInputStream in project ABC by RuiPinto96274.
the class XProtocolTest method testResultSet.
/**
* This is a development method that will print a detailed result set for any command sent.
*/
@Test
public void testResultSet() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
// begin "send" stage, change this as necessary
this.protocol.send(this.messageBuilder.buildListNotices(), 0);
// this will read the metadata and result and print all data
ColumnDefinition metadata = this.protocol.readMetadata();
Arrays.stream(metadata.getFields()).forEach(f -> {
System.err.println("***************** field ****************");
System.err.println("Field: " + f.getColumnLabel());
System.err.println("Type: " + f.getMysqlTypeId());
System.err.println("Encoding: " + f.getEncoding());
});
Iterator<Row> ris = new XProtocolRowInputStream(metadata, this.protocol, null);
ris.forEachRemaining(r -> {
System.err.println("***************** row ****************");
for (int i = 0; i < metadata.getFields().length; ++i) {
System.err.println(metadata.getFields()[i].getColumnLabel() + ": " + r.getValue(i, new StringValueFactory(this.protocol.getPropertySet())));
}
});
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
}
use of com.mysql.cj.protocol.x.XProtocolRowInputStream in project ABC by RuiPinto96274.
the class XProtocolTest method testAnotherBasicSqlQuery.
@Test
public void testAnotherBasicSqlQuery() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
this.protocol.send(this.messageBuilder.buildSqlStatement("select 'x' as a_string, 42 as a_long, 7.6 as a_decimal union select 'y' as a_string, 11 as a_long, .1111 as a_decimal"), 0);
assertTrue(this.protocol.hasResults());
ColumnDefinition metadata = this.protocol.readMetadata();
assertEquals(3, metadata.getFields().length);
assertEquals("a_string", metadata.getFields()[0].getColumnLabel());
assertEquals("a_long", metadata.getFields()[1].getColumnLabel());
assertEquals("a_decimal", metadata.getFields()[2].getColumnLabel());
assertEquals(MysqlType.FIELD_TYPE_VARCHAR, metadata.getFields()[0].getMysqlTypeId());
assertEquals(MysqlType.FIELD_TYPE_LONGLONG, metadata.getFields()[1].getMysqlTypeId());
assertEquals(MysqlType.FIELD_TYPE_NEWDECIMAL, metadata.getFields()[2].getMysqlTypeId());
Iterator<Row> rowInputStream = new XProtocolRowInputStream(metadata, this.protocol, null);
// first row
Row r = rowInputStream.next();
String value = r.getValue(0, new StringValueFactory(this.protocol.getPropertySet()));
assertEquals("x", value);
value = r.getValue(1, new StringValueFactory(this.protocol.getPropertySet()));
assertEquals("42", value);
value = r.getValue(2, new StringValueFactory(this.protocol.getPropertySet()));
// TODO: zeroes ok here??? scale is adjusted to 4 due to ".1111" value in RS? not happening in decimal test down below
assertEquals("7.6000", value);
// second row
assertTrue(rowInputStream.hasNext());
r = rowInputStream.next();
value = r.getValue(0, new StringValueFactory(this.protocol.getPropertySet()));
assertEquals("y", value);
value = r.getValue(1, new StringValueFactory(this.protocol.getPropertySet()));
assertEquals("11", value);
value = r.getValue(2, new StringValueFactory(this.protocol.getPropertySet()));
assertEquals("0.1111", value);
assertFalse(rowInputStream.hasNext());
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
}
use of com.mysql.cj.protocol.x.XProtocolRowInputStream in project ABC by RuiPinto96274.
the class XProtocolTest method testDocUpdate.
@Test
public void testDocUpdate() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
try {
String collName = createTempTestCollection(this.protocol);
String json = "{'_id': '85983efc2a9a11e5b345feff819cdc9f', 'testVal': '1', 'insertedBy': 'Jess'}".replaceAll("'", "\"");
this.protocol.send(this.messageBuilder.buildDocInsert(getTestDatabase(), collName, Arrays.asList(new String[] { json }), false), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
List<UpdateSpec> updates = new ArrayList<>();
updates.add(new UpdateSpec(UpdateType.ITEM_SET, "$.a").setValue("lemon"));
updates.add(new UpdateSpec(UpdateType.ITEM_REMOVE, "$.insertedBy"));
this.protocol.send(this.messageBuilder.buildDocUpdate(new DocFilterParams(getTestDatabase(), collName), updates), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
// verify
this.protocol.send(this.messageBuilder.buildFind(new DocFilterParams(getTestDatabase(), collName)), 0);
ColumnDefinition metadata = this.protocol.readMetadata();
Iterator<Row> ris = new XProtocolRowInputStream(metadata, this.protocol, null);
Row r = ris.next();
assertEquals("{\"a\": \"lemon\", \"_id\": \"85983efc2a9a11e5b345feff819cdc9f\", \"testVal\": \"1\"}", r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
} finally {
dropTempTestCollection(this.protocol);
}
}
use of com.mysql.cj.protocol.x.XProtocolRowInputStream in project ABC by RuiPinto96274.
the class XProtocolTest method testEnableDisableNotices.
@Test
public void testEnableDisableNotices() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
// TODO currently only "warnings" are allowed to be disabled
this.protocol.send(this.messageBuilder.buildDisableNotices("warnings"), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
this.protocol.send(this.messageBuilder.buildSqlStatement("select CAST('abc' as CHAR(1))"), 0);
new XProtocolRowInputStream(this.protocol.readMetadata(), this.protocol, null).next();
SqlResult res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
assertEquals(0, res.getWarningsCount());
// "produced_message" are already enabled, they're used here to check that multiple parameters are sent correctly
this.protocol.send(this.messageBuilder.buildEnableNotices("produced_message", "warnings"), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
this.protocol.send(this.messageBuilder.buildSqlStatement("select CAST('abc' as CHAR(1))"), 0);
new XProtocolRowInputStream(this.protocol.readMetadata(), this.protocol, null).next();
res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
assertEquals(1, res.getWarningsCount());
}
use of com.mysql.cj.protocol.x.XProtocolRowInputStream in project JavaSegundasQuintas by ecteruel.
the class XProtocolTest method testMultiInsert.
@Test
public void testMultiInsert() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
try {
String collName = createTempTestCollection(this.protocol);
List<String> stringDocs = new ArrayList<>();
stringDocs.add("{'a': 'A', 'a1': 'A1', '_id': 'a'}");
stringDocs.add("{'b': 'B', 'b2': 'B2', '_id': 'b'}");
stringDocs.add("{'c': 'C', 'c3': 'C3', '_id': 'c'}");
stringDocs = stringDocs.stream().map(s -> s.replaceAll("'", "\"")).collect(Collectors.toList());
this.protocol.send(this.messageBuilder.buildDocInsert(getTestDatabase(), collName, stringDocs, false), 0);
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
FilterParams filterParams = new DocFilterParams(getTestDatabase(), collName);
filterParams.setOrder("_id");
this.protocol.send(this.messageBuilder.buildFind(filterParams), 0);
ColumnDefinition metadata = this.protocol.readMetadata();
Iterator<Row> ris = new XProtocolRowInputStream(metadata, this.protocol, null);
Row r = ris.next();
assertEquals(stringDocs.get(0), r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
r = ris.next();
assertEquals(stringDocs.get(1), r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
r = ris.next();
assertEquals(stringDocs.get(2), r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
this.protocol.readQueryResult(new StatementExecuteOkBuilder());
} finally {
dropTempTestCollection(this.protocol);
}
}
Aggregations