use of com.mysql.cj.protocol.x.StatementExecuteOkBuilder in project ABC by RuiPinto96274.
the class InternalXBaseTestCase method dropTempTestCollection.
public void dropTempTestCollection(XProtocol protocol) {
String collName = "protocol_test_collection";
XMessageBuilder messageBuilder = (XMessageBuilder) protocol.getMessageBuilder();
try {
protocol.send(messageBuilder.buildDropCollection(getTestDatabase(), collName), 0);
protocol.readQueryResult(new StatementExecuteOkBuilder());
} catch (XProtocolError err) {
// ignore
}
}
use of com.mysql.cj.protocol.x.StatementExecuteOkBuilder in project ABC by RuiPinto96274.
the class InternalXBaseTestCase method createTempTestCollection.
/**
* Create a temporary collection for testing.
*
* @param protocol
*
* @return the temporary collection name
*/
public String createTempTestCollection(XProtocol protocol) {
String collName = "protocol_test_collection";
XMessageBuilder messageBuilder = (XMessageBuilder) protocol.getMessageBuilder();
try {
protocol.send(messageBuilder.buildDropCollection(getTestDatabase(), collName), 0);
protocol.readQueryResult(new StatementExecuteOkBuilder());
} catch (XProtocolError err) {
// ignore
}
protocol.send(messageBuilder.buildCreateCollection(getTestDatabase(), collName), 0);
protocol.readQueryResult(new StatementExecuteOkBuilder());
return collName;
}
use of com.mysql.cj.protocol.x.StatementExecuteOkBuilder in project ABC by RuiPinto96274.
the class XProtocolAsyncTest method simpleSuccessfulQuery.
@Test
public void simpleSuccessfulQuery() throws Exception {
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());
final ValueHolder<ColumnDefinition> metadataHolder = new ValueHolder<>();
final ValueHolder<ArrayList<Row>> rowHolder = new ValueHolder<>();
rowHolder.accept(new ArrayList<>());
final ValueHolder<StatementExecuteOk> okHolder = new ValueHolder<>();
final ValueHolder<Throwable> excHolder = new ValueHolder<>();
this.protocol.queryAsync(this.messageBuilder.buildFind(new DocFilterParams(getTestDatabase(), collName)), new ResultBuilder<RowResult>() {
private ArrayList<Field> fields = new ArrayList<>();
private ColumnDefinition metadata;
@Override
public boolean addProtocolEntity(ProtocolEntity entity) {
if (entity instanceof Field) {
this.fields.add((Field) entity);
} else if (entity instanceof ColumnDefinition) {
this.metadata = (ColumnDefinition) entity;
metadataHolder.accept(this.metadata);
} else if (entity instanceof Row) {
if (this.metadata == null) {
this.metadata = new DefaultColumnDefinition(this.fields.toArray(new Field[] {}));
metadataHolder.accept(this.metadata);
}
rowHolder.get().add((Row) entity);
} else if (entity instanceof StatementExecuteOk) {
okHolder.accept((StatementExecuteOk) entity);
synchronized (XProtocolAsyncTest.this) {
XProtocolAsyncTest.this.notify();
}
return true;
}
return false;
}
@Override
public RowResult build() {
return null;
}
});
synchronized (this) {
// timeout in case we get stuck
this.wait(5000);
}
assertEquals(1, metadataHolder.get().getFields().length);
assertEquals(1, rowHolder.get().size());
assertNotNull(okHolder.get());
assertNull(excHolder.get());
} finally {
dropTempTestCollection(this.protocol);
}
}
use of com.mysql.cj.protocol.x.StatementExecuteOkBuilder 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.StatementExecuteOkBuilder 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());
}
Aggregations