Search in sources :

Example 6 with XProtocolError

use of com.mysql.cj.protocol.x.XProtocolError in project aws-mysql-jdbc by awslabs.

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 7 with XProtocolError

use of com.mysql.cj.protocol.x.XProtocolError in project aws-mysql-jdbc by awslabs.

the class MysqlxSessionTest method testInterleavedResults.

@Test
public void testInterleavedResults() {
    assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
    XMessageBuilder builder = (XMessageBuilder) this.session.<XMessage>getMessageBuilder();
    String collName = "testInterleavedResults";
    try {
        try {
            this.session.query(builder.buildDropCollection(getTestDatabase(), collName), new UpdateResultBuilder<>());
        } catch (XProtocolError e) {
            if (e.getErrorCode() != MysqlErrorNumbers.ER_BAD_TABLE_ERROR) {
                throw e;
            }
        }
        this.session.query(builder.buildCreateCollection(getTestDatabase(), collName), new UpdateResultBuilder<>());
        List<String> stringDocs = new ArrayList<>();
        stringDocs.add("{'_id':'0'}");
        stringDocs.add("{'_id':'1'}");
        stringDocs.add("{'_id':'2'}");
        stringDocs.add("{'_id':'3'}");
        stringDocs.add("{'_id':'4'}");
        stringDocs = stringDocs.stream().map(s -> s.replaceAll("'", "\"")).collect(Collectors.toList());
        this.session.query(builder.buildDocInsert(getTestDatabase(), collName, stringDocs, false), new UpdateResultBuilder<>());
        FilterParams filterParams = new DocFilterParams(getTestDatabase(), collName);
        filterParams.setOrder("$._id");
        DocResult docs1 = this.session.query(((XMessageBuilder) this.session.<XMessage>getMessageBuilder()).buildFind(filterParams), new StreamingDocResultBuilder(this.session));
        DocResult docs2 = this.session.query(((XMessageBuilder) this.session.<XMessage>getMessageBuilder()).buildFind(filterParams), new StreamingDocResultBuilder(this.session));
        DocResult docs3 = this.session.query(((XMessageBuilder) this.session.<XMessage>getMessageBuilder()).buildFind(filterParams), new StreamingDocResultBuilder(this.session));
        DocResult docs4 = this.session.query(((XMessageBuilder) this.session.<XMessage>getMessageBuilder()).buildFind(filterParams), new StreamingDocResultBuilder(this.session));
        DocResult docs5 = this.session.query(((XMessageBuilder) this.session.<XMessage>getMessageBuilder()).buildFind(filterParams), new StreamingDocResultBuilder(this.session));
        assertTrue(docs5.hasNext());
        assertTrue(docs4.hasNext());
        assertTrue(docs3.hasNext());
        assertTrue(docs2.hasNext());
        assertTrue(docs1.hasNext());
        for (int i = 0; i < 5; ++i) {
            assertEquals("{\n\"_id\" : \"" + i + "\"\n}", docs1.next().toFormattedString());
            assertEquals("{\n\"_id\" : \"" + i + "\"\n}", docs2.next().toFormattedString());
            assertEquals("{\n\"_id\" : \"" + i + "\"\n}", docs3.next().toFormattedString());
            assertEquals("{\n\"_id\" : \"" + i + "\"\n}", docs4.next().toFormattedString());
            assertEquals("{\n\"_id\" : \"" + i + "\"\n}", docs5.next().toFormattedString());
        }
        assertFalse(docs5.hasNext());
        assertFalse(docs4.hasNext());
        assertFalse(docs3.hasNext());
        assertFalse(docs2.hasNext());
        assertFalse(docs1.hasNext());
    // let the session be closed with all of these "open"
    } finally {
        try {
            this.session.query(builder.buildDropCollection(getTestDatabase(), collName), new UpdateResultBuilder<>());
        } catch (XProtocolError e) {
            if (e.getErrorCode() != MysqlErrorNumbers.ER_BAD_TABLE_ERROR) {
                throw e;
            }
        }
    }
}
Also used : XMessageBuilder(com.mysql.cj.protocol.x.XMessageBuilder) XMessage(com.mysql.cj.protocol.x.XMessage) XProtocolError(com.mysql.cj.protocol.x.XProtocolError) DocFilterParams(com.mysql.cj.xdevapi.DocFilterParams) FilterParams(com.mysql.cj.xdevapi.FilterParams) ArrayList(java.util.ArrayList) StreamingDocResultBuilder(com.mysql.cj.xdevapi.StreamingDocResultBuilder) DocResult(com.mysql.cj.xdevapi.DocResult) DocFilterParams(com.mysql.cj.xdevapi.DocFilterParams) Test(org.junit.jupiter.api.Test)

Example 8 with XProtocolError

use of com.mysql.cj.protocol.x.XProtocolError in project aws-mysql-jdbc by awslabs.

the class MysqlxSessionTest method testGetObjects.

@Test
public void testGetObjects() {
    assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
    XMessageBuilder builder = (XMessageBuilder) this.session.<XMessage>getMessageBuilder();
    ValueFactory<String> svf = new StringValueFactory(new DefaultPropertySet());
    String collName = "test_get_objects";
    try {
        this.session.query(builder.buildDropCollection(getTestDatabase(), collName), new UpdateResultBuilder<>());
    } catch (XProtocolError e) {
        if (e.getErrorCode() != MysqlErrorNumbers.ER_BAD_TABLE_ERROR) {
            throw e;
        }
    }
    this.session.query(builder.buildCreateCollection(getTestDatabase(), collName), new UpdateResultBuilder<>());
    Set<String> strTypes = Arrays.stream(new DbObjectType[] { DbObjectType.COLLECTION }).map(DatabaseObject.DbObjectType::toString).collect(Collectors.toSet());
    Predicate<com.mysql.cj.result.Row> rowFiler = r -> (strTypes).contains(r.getValue(1, svf));
    Function<com.mysql.cj.result.Row, String> rowToName = r -> r.getValue(0, svf);
    List<String> collNames = this.session.query(builder.buildListObjects(getTestDatabase(), null), rowFiler, rowToName, Collectors.toList());
    assertTrue(collNames.contains(collName));
    collNames = this.session.query(builder.buildListObjects(getTestDatabase(), "none%"), rowFiler, rowToName, Collectors.toList());
    assertFalse(collNames.contains(collName));
    collNames = this.session.query(builder.buildListObjects(getTestDatabase(), "%get_obj%"), rowFiler, rowToName, Collectors.toList());
    assertTrue(collNames.contains(collName));
    this.session.query(builder.buildDropCollection(getTestDatabase(), collName), new UpdateResultBuilder<>());
}
Also used : MysqlErrorNumbers(com.mysql.cj.exceptions.MysqlErrorNumbers) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) StreamingDocResultBuilder(com.mysql.cj.xdevapi.StreamingDocResultBuilder) Function(java.util.function.Function) MysqlxSession(com.mysql.cj.MysqlxSession) ArrayList(java.util.ArrayList) DatabaseObject(com.mysql.cj.xdevapi.DatabaseObject) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) UpdateResultBuilder(com.mysql.cj.xdevapi.UpdateResultBuilder) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) XMessage(com.mysql.cj.protocol.x.XMessage) DbObjectType(com.mysql.cj.xdevapi.DatabaseObject.DbObjectType) DocFilterParams(com.mysql.cj.xdevapi.DocFilterParams) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StringValueFactory(com.mysql.cj.result.StringValueFactory) DefaultPropertySet(com.mysql.cj.conf.DefaultPropertySet) XMessageBuilder(com.mysql.cj.protocol.x.XMessageBuilder) Predicate(java.util.function.Predicate) Set(java.util.Set) DocResult(com.mysql.cj.xdevapi.DocResult) Collectors(java.util.stream.Collectors) PropertyDefinitions(com.mysql.cj.conf.PropertyDefinitions) XProtocolError(com.mysql.cj.protocol.x.XProtocolError) Test(org.junit.jupiter.api.Test) IntegerValueFactory(com.mysql.cj.result.IntegerValueFactory) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) FilterParams(com.mysql.cj.xdevapi.FilterParams) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ValueFactory(com.mysql.cj.result.ValueFactory) XMessageBuilder(com.mysql.cj.protocol.x.XMessageBuilder) StringValueFactory(com.mysql.cj.result.StringValueFactory) XProtocolError(com.mysql.cj.protocol.x.XProtocolError) DefaultPropertySet(com.mysql.cj.conf.DefaultPropertySet) DatabaseObject(com.mysql.cj.xdevapi.DatabaseObject) Test(org.junit.jupiter.api.Test)

Example 9 with XProtocolError

use of com.mysql.cj.protocol.x.XProtocolError in project aws-mysql-jdbc by awslabs.

the class CollectionFindTest method outOfRange.

/**
 * MYSQLCONNJ-618
 */
@Test
public void outOfRange() {
    try {
        this.collection.add("{\"_id\": \"1\"}").execute();
        DocResult docs = this.collection.find().fields(expr(mysqlVersionMeetsMinimum(ServerVersion.parseVersion("8.0.13")) ? "{'X':cast(pow(2,63) as signed)+1}" : "{'X':1-cast(pow(2,63) as signed)}")).execute();
        // we are getting valid data from xplugin before the error, need this call to force the error
        docs.next();
        fail("Statement should raise an error");
    } catch (XProtocolError err) {
        assertEquals(MysqlErrorNumbers.ER_DATA_OUT_OF_RANGE, err.getErrorCode());
    }
}
Also used : XProtocolError(com.mysql.cj.protocol.x.XProtocolError) DocResult(com.mysql.cj.xdevapi.DocResult) Test(org.junit.jupiter.api.Test)

Example 10 with XProtocolError

use of com.mysql.cj.protocol.x.XProtocolError in project aws-mysql-jdbc by awslabs.

the class AsyncQueryTest method manyFutures.

/**
 * This test addresses the "correlation" of messages to their proper async listeners.
 *
 * @throws Exception
 */
@Test
public void manyFutures() throws Exception {
    // 100000;
    int MANY = 10;
    Collection coll = this.collection;
    List<CompletableFuture<DocResult>> futures = new ArrayList<>();
    for (int i = 0; i < MANY; ++i) {
        // System.out.println("++++ Write " + i + " set " + i % 3 + " +++++");
        if (i % 3 == 0) {
            futures.add(coll.find("F1  like '%Field%-5'").fields("$._id as _id, $.F1 as F1, $.F2 as F2, $.F3 as F3").executeAsync());
        } else if (i % 3 == 1) {
            // Expecting Error
            futures.add(coll.find("NON_EXISTING_FUNCTION()").fields("$._id as _id, $.F1 as F1, $.F2 as F2, $.F3 as F3").executeAsync());
        } else {
            futures.add(coll.find("F3 = ?").bind(106).executeAsync());
        }
    }
    DocResult docs;
    for (int i = 0; i < MANY; ++i) {
        // System.out.println("++++ Read " + i + " set " + i % 3 + " +++++");
        if (i % 3 == 0) {
            // Expect Success and check F1  is like  %Field%-5
            System.out.println("\nExpect Success and check F1  is like  %Field%-5");
            docs = futures.get(i).get();
            assertFalse(docs.hasNext());
            System.out.println(docs.fetchOne());
        } else if (i % 3 == 1) {
            try {
                // Expecting Error FUNCTION test.NON_EXISTING_FUNCTION does not exist
                docs = futures.get(i).get();
                fail("Expected error");
            } catch (ExecutionException ex) {
                XProtocolError err = (XProtocolError) ex.getCause();
                assertEquals(MysqlErrorNumbers.ER_SP_DOES_NOT_EXIST, err.getErrorCode());
            }
        } else {
            // Expect Success and check F3 is 106
            System.out.println("\nExpect Success and check F3 is 106");
            docs = futures.get(i).get();
            assertFalse(docs.hasNext());
            System.out.println(docs.fetchOne());
        }
    }
    System.out.println("Done.");
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) XProtocolError(com.mysql.cj.protocol.x.XProtocolError) ArrayList(java.util.ArrayList) Collection(com.mysql.cj.xdevapi.Collection) ExecutionException(java.util.concurrent.ExecutionException) DocResult(com.mysql.cj.xdevapi.DocResult) Test(org.junit.jupiter.api.Test)

Aggregations

XProtocolError (com.mysql.cj.protocol.x.XProtocolError)15 Test (org.junit.jupiter.api.Test)12 XMessageBuilder (com.mysql.cj.protocol.x.XMessageBuilder)6 DocResult (com.mysql.cj.xdevapi.DocResult)6 StatementExecuteOkBuilder (com.mysql.cj.protocol.x.StatementExecuteOkBuilder)4 JsonString (com.mysql.cj.xdevapi.JsonString)4 ArrayList (java.util.ArrayList)4 ExecutionException (java.util.concurrent.ExecutionException)4 Collection (com.mysql.cj.xdevapi.Collection)3 List (java.util.List)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)3 ServerVersion (com.mysql.cj.ServerVersion)2 MysqlErrorNumbers (com.mysql.cj.exceptions.MysqlErrorNumbers)2 WrongArgumentException (com.mysql.cj.exceptions.WrongArgumentException)2 XMessage (com.mysql.cj.protocol.x.XMessage)2 DbDoc (com.mysql.cj.xdevapi.DbDoc)2 DbDocImpl (com.mysql.cj.xdevapi.DbDocImpl)2