Search in sources :

Example 1 with StatementExecuteOkBuilder

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
    }
}
Also used : XMessageBuilder(com.mysql.cj.protocol.x.XMessageBuilder) StatementExecuteOkBuilder(com.mysql.cj.protocol.x.StatementExecuteOkBuilder) XProtocolError(com.mysql.cj.protocol.x.XProtocolError)

Example 2 with StatementExecuteOkBuilder

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;
}
Also used : XMessageBuilder(com.mysql.cj.protocol.x.XMessageBuilder) StatementExecuteOkBuilder(com.mysql.cj.protocol.x.StatementExecuteOkBuilder) XProtocolError(com.mysql.cj.protocol.x.XProtocolError)

Example 3 with StatementExecuteOkBuilder

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);
    }
}
Also used : StatementExecuteOkBuilder(com.mysql.cj.protocol.x.StatementExecuteOkBuilder) ArrayList(java.util.ArrayList) DefaultColumnDefinition(com.mysql.cj.result.DefaultColumnDefinition) ColumnDefinition(com.mysql.cj.protocol.ColumnDefinition) StatementExecuteOk(com.mysql.cj.protocol.x.StatementExecuteOk) RowResult(com.mysql.cj.xdevapi.RowResult) Field(com.mysql.cj.result.Field) DefaultColumnDefinition(com.mysql.cj.result.DefaultColumnDefinition) Row(com.mysql.cj.result.Row) DocFilterParams(com.mysql.cj.xdevapi.DocFilterParams) ProtocolEntity(com.mysql.cj.protocol.ProtocolEntity) Test(org.junit.jupiter.api.Test)

Example 4 with StatementExecuteOkBuilder

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());
}
Also used : XProtocolRowInputStream(com.mysql.cj.protocol.x.XProtocolRowInputStream) StringValueFactory(com.mysql.cj.result.StringValueFactory) StatementExecuteOkBuilder(com.mysql.cj.protocol.x.StatementExecuteOkBuilder) Row(com.mysql.cj.result.Row) ColumnDefinition(com.mysql.cj.protocol.ColumnDefinition) Test(org.junit.jupiter.api.Test)

Example 5 with 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());
}
Also used : XProtocolRowInputStream(com.mysql.cj.protocol.x.XProtocolRowInputStream) StringValueFactory(com.mysql.cj.result.StringValueFactory) StatementExecuteOkBuilder(com.mysql.cj.protocol.x.StatementExecuteOkBuilder) Row(com.mysql.cj.result.Row) ColumnDefinition(com.mysql.cj.protocol.ColumnDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

StatementExecuteOkBuilder (com.mysql.cj.protocol.x.StatementExecuteOkBuilder)54 Test (org.junit.jupiter.api.Test)36 ColumnDefinition (com.mysql.cj.protocol.ColumnDefinition)33 XProtocolRowInputStream (com.mysql.cj.protocol.x.XProtocolRowInputStream)33 Row (com.mysql.cj.result.Row)33 StringValueFactory (com.mysql.cj.result.StringValueFactory)24 DocFilterParams (com.mysql.cj.xdevapi.DocFilterParams)15 ArrayList (java.util.ArrayList)15 XProtocolError (com.mysql.cj.protocol.x.XProtocolError)12 Field (com.mysql.cj.result.Field)12 StatementExecuteOk (com.mysql.cj.protocol.x.StatementExecuteOk)9 XMessageBuilder (com.mysql.cj.protocol.x.XMessageBuilder)9 FilterParams (com.mysql.cj.xdevapi.FilterParams)9 SqlResult (com.mysql.cj.xdevapi.SqlResult)9 SqlResultBuilder (com.mysql.cj.xdevapi.SqlResultBuilder)9 TableFilterParams (com.mysql.cj.xdevapi.TableFilterParams)9 ProtocolEntity (com.mysql.cj.protocol.ProtocolEntity)6 Notice (com.mysql.cj.protocol.x.Notice)6 DefaultColumnDefinition (com.mysql.cj.result.DefaultColumnDefinition)6 MysqlxSession (com.mysql.cj.MysqlxSession)3