Search in sources :

Example 1 with SqlResult

use of com.mysql.cj.xdevapi.SqlResult 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());
}
Also used : MysqlErrorNumbers(com.mysql.cj.exceptions.MysqlErrorNumbers) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) XProtocolRowInputStream(com.mysql.cj.protocol.x.XProtocolRowInputStream) MysqlType(com.mysql.cj.MysqlType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) BiConsumer(java.util.function.BiConsumer) StreamSupport(java.util.stream.StreamSupport) XServerCapabilities(com.mysql.cj.protocol.x.XServerCapabilities) DocFilterParams(com.mysql.cj.xdevapi.DocFilterParams) SqlResultBuilder(com.mysql.cj.xdevapi.SqlResultBuilder) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StringValueFactory(com.mysql.cj.result.StringValueFactory) UpdateSpec(com.mysql.cj.xdevapi.UpdateSpec) UpdateType(com.mysql.cj.xdevapi.UpdateType) Warning(com.mysql.cj.xdevapi.Warning) Iterator(java.util.Iterator) ColumnDefinition(com.mysql.cj.protocol.ColumnDefinition) XMessageBuilder(com.mysql.cj.protocol.x.XMessageBuilder) Field(com.mysql.cj.result.Field) InsertParams(com.mysql.cj.xdevapi.InsertParams) IOException(java.io.IOException) TableFilterParams(com.mysql.cj.xdevapi.TableFilterParams) WarningImpl(com.mysql.cj.xdevapi.WarningImpl) Collectors(java.util.stream.Collectors) PropertyDefinitions(com.mysql.cj.conf.PropertyDefinitions) StatementExecuteOkBuilder(com.mysql.cj.protocol.x.StatementExecuteOkBuilder) XProtocolError(com.mysql.cj.protocol.x.XProtocolError) Test(org.junit.jupiter.api.Test) SqlResult(com.mysql.cj.xdevapi.SqlResult) Row(com.mysql.cj.result.Row) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) FilterParams(com.mysql.cj.xdevapi.FilterParams) XProtocol(com.mysql.cj.protocol.x.XProtocol) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Warning(com.mysql.cj.xdevapi.Warning) SqlResult(com.mysql.cj.xdevapi.SqlResult) SqlResultBuilder(com.mysql.cj.xdevapi.SqlResultBuilder) WarningImpl(com.mysql.cj.xdevapi.WarningImpl) Test(org.junit.jupiter.api.Test)

Example 2 with SqlResult

use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.

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

Example 3 with SqlResult

use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.

the class XProtocolTest method tableInsert.

@Test
public void tableInsert() {
    assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
    this.protocol.send(this.messageBuilder.buildSqlStatement("drop table if exists tableInsert"), 0);
    this.protocol.readQueryResult(new StatementExecuteOkBuilder());
    this.protocol.send(this.messageBuilder.buildSqlStatement("create table tableInsert (x int, y varchar(20), z decimal(10, 2))"), 0);
    this.protocol.readQueryResult(new StatementExecuteOkBuilder());
    InsertParams insertParams = new InsertParams();
    insertParams.setProjection(new String[] { "z", "x", "y" });
    insertParams.addRow(Arrays.asList("10.2", 40, "some string value"));
    insertParams.addRow(Arrays.asList("10.3", 50, "another string value"));
    this.protocol.send(this.messageBuilder.buildRowInsert(getTestDatabase(), "tableInsert", insertParams), 0);
    SqlResult res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
    assertEquals(2, res.getAffectedItemsCount());
    FilterParams filterParams = new TableFilterParams(getTestDatabase(), "tableInsert");
    filterParams.setOrder("x DESC");
    filterParams.setFields("z, y, x");
    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("10.30", r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
    assertEquals("another string value", r.getValue(1, new StringValueFactory(this.protocol.getPropertySet())));
    assertEquals("50", r.getValue(2, new StringValueFactory(this.protocol.getPropertySet())));
    r = ris.next();
    assertEquals("10.20", r.getValue(0, new StringValueFactory(this.protocol.getPropertySet())));
    assertEquals("some string value", r.getValue(1, new StringValueFactory(this.protocol.getPropertySet())));
    assertEquals("40", r.getValue(2, new StringValueFactory(this.protocol.getPropertySet())));
    this.protocol.readQueryResult(new StatementExecuteOkBuilder());
    this.protocol.send(this.messageBuilder.buildSqlStatement("drop table tableInsert"), 0);
    this.protocol.readQueryResult(new StatementExecuteOkBuilder());
}
Also used : XProtocolRowInputStream(com.mysql.cj.protocol.x.XProtocolRowInputStream) TableFilterParams(com.mysql.cj.xdevapi.TableFilterParams) SqlResult(com.mysql.cj.xdevapi.SqlResult) StatementExecuteOkBuilder(com.mysql.cj.protocol.x.StatementExecuteOkBuilder) SqlResultBuilder(com.mysql.cj.xdevapi.SqlResultBuilder) StringValueFactory(com.mysql.cj.result.StringValueFactory) DocFilterParams(com.mysql.cj.xdevapi.DocFilterParams) TableFilterParams(com.mysql.cj.xdevapi.TableFilterParams) FilterParams(com.mysql.cj.xdevapi.FilterParams) Row(com.mysql.cj.result.Row) InsertParams(com.mysql.cj.xdevapi.InsertParams) ColumnDefinition(com.mysql.cj.protocol.ColumnDefinition) Test(org.junit.jupiter.api.Test)

Example 4 with SqlResult

use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.

the class XProtocolTest method testSqlDml.

/**
 * Test DML that is executed with <i>StmtExecute</i> and does not return a result set.
 */
@Test
public void testSqlDml() {
    assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
    this.protocol.send(this.messageBuilder.buildSqlStatement("drop table if exists mysqlx_sqlDmlTest"), 0);
    assertFalse(this.protocol.hasResults());
    SqlResult res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
    assertEquals(0, res.getAffectedItemsCount());
    this.protocol.send(this.messageBuilder.buildSqlStatement("create table mysqlx_sqlDmlTest (w int primary key auto_increment, x int) auto_increment = 7"), 0);
    assertFalse(this.protocol.hasResults());
    res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
    assertEquals(0, res.getAffectedItemsCount());
    this.protocol.send(this.messageBuilder.buildSqlStatement("insert into mysqlx_sqlDmlTest (x) values (44),(29)"), 0);
    assertFalse(this.protocol.hasResults());
    res = this.protocol.readQueryResult(new SqlResultBuilder(this.protocol.getServerSession().getDefaultTimeZone(), this.protocol.getPropertySet()));
    assertEquals(2, res.getAffectedItemsCount());
    assertEquals(new Long(7), res.getAutoIncrementValue());
    this.protocol.send(this.messageBuilder.buildSqlStatement("drop table mysqlx_sqlDmlTest"), 0);
    assertFalse(this.protocol.hasResults());
    this.protocol.readQueryResult(new StatementExecuteOkBuilder());
}
Also used : SqlResult(com.mysql.cj.xdevapi.SqlResult) SqlResultBuilder(com.mysql.cj.xdevapi.SqlResultBuilder) StatementExecuteOkBuilder(com.mysql.cj.protocol.x.StatementExecuteOkBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with SqlResult

use of com.mysql.cj.xdevapi.SqlResult in project aws-mysql-jdbc by awslabs.

the class SchemaTest method testCreateCollectionWithOptions.

@Test
public void testCreateCollectionWithOptions() {
    String collName1 = "testCreateCollection1";
    String collName2 = "testCreateCollection2";
    dropCollection(collName1);
    dropCollection(collName2);
    String sch1 = "{" + "\"id\":\"http://json-schema.org/geo\",\"$schema\":\"http://json-schema.org/draft-06/schema#\"," + "\"description\":\"A geographical coordinate\",\"type\":\"object\",\"properties\":{\"latitude\":{\"type\":\"number\"}," + "\"longitude\":{\"type\":\"number\"}},\"required\":[\"latitude\",\"longitude\"]}";
    String sch2 = "{\"id\":\"http://json-schema.org/geo\",\"$schema\":\"http://json-schema.org/draft-06/schema#\"," + "\"description\":\"The geographical coordinate\",\"type\":\"object\",\"properties\":{\"latitude\":{\"type\":\"number\"}," + "\"longitude\":{\"type\":\"number\"}},\"required\":[\"latitude\",\"longitude\"]}";
    String sch3 = "{\"id\":\"http://json-schema.org/idx\",\"$schema\":\"http://json-schema.org/draft-06/schema#\"," + "\"type\":\"object\",\"properties\":{\"index\":{\"type\":\"number\"}},\"required\":[\"index\"]}";
    try {
        if (mysqlVersionMeetsMinimum(ServerVersion.parseVersion("8.0.19"))) {
            // TSFR2b.1: Call createCollection with both level and schema options are set. Ensure that given values are set on server.
            Collection coll = // 
            this.schema.createCollection(// 
            collName1, new CreateCollectionOptions().setReuseExisting(false).setValidation(new Validation().setLevel(ValidationLevel.STRICT).setSchema(sch1)));
            SqlResult res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName1 + "`").execute();
            String def = res.next().getString(1);
            assertFalse(def.contains("NOT ENFORCED"));
            assertTrue(def.contains(sch1));
            coll.add("{\"latitude\": 20, \"longitude\": 30}").execute();
            Collection coll1 = // 
            this.schema.createCollection(// 
            collName1, new CreateCollectionOptions().setReuseExisting(true).setValidation(new Validation().setLevel(ValidationLevel.OFF).setSchema(sch1)));
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName1 + "`").execute();
            def = res.next().getString(1);
            assertFalse(def.contains("NOT ENFORCED"));
            assertTrue(def.contains(sch1));
            coll1 = // 
            this.schema.createCollection(// 
            collName1, new CreateCollectionOptions().setReuseExisting(true).setValidation(new Validation().setSchema(sch2)));
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName1 + "`").execute();
            def = res.next().getString(1);
            assertFalse(def.contains("NOT ENFORCED"));
            assertFalse(def.contains(sch2));
            assertTrue(def.contains(sch1));
            coll1 = // 
            this.schema.createCollection(// 
            collName1, new CreateCollectionOptions().setReuseExisting(true).setValidation(new Validation().setLevel(ValidationLevel.STRICT).setSchema(sch1)));
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName1 + "`").execute();
            def = res.next().getString(1);
            assertFalse(def.contains("NOT ENFORCED"));
            assertFalse(def.contains(sch2));
            assertTrue(def.contains(sch1));
            coll1.add("{\"latitude\": 30, \"longitude\": 40}").execute();
            // TSFR6d: Call createCollection(String collectionName) and createCollection(String collectionName, boolean reuseExisting) methods against server implementing WL#12965 and ensure they work as before.
            this.schema.createCollection(collName2);
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName2 + "`").execute();
            def = res.next().getString(1);
            assertTrue(def.contains("NOT ENFORCED"));
            dropCollection(collName2);
            this.schema.createCollection(collName2, new CreateCollectionOptions().setReuseExisting(false));
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName2 + "`").execute();
            def = res.next().getString(1);
            assertTrue(def.contains("NOT ENFORCED"));
            dropCollection(collName2);
            assertEquals(MysqlErrorNumbers.ER_TABLE_EXISTS_ERROR, assertThrows(XProtocolError.class, new Callable<Void>() {

                public Void call() throws Exception {
                    SchemaTest.this.schema.createCollection(collName1);
                    return null;
                }
            }).getErrorCode());
            assertEquals(MysqlErrorNumbers.ER_TABLE_EXISTS_ERROR, assertThrows(XProtocolError.class, new Callable<Void>() {

                public Void call() throws Exception {
                    SchemaTest.this.schema.createCollection(collName1, false);
                    return null;
                }
            }).getErrorCode());
            assertEquals(MysqlErrorNumbers.ER_TABLE_EXISTS_ERROR, assertThrows(XProtocolError.class, new Callable<Void>() {

                public Void call() throws Exception {
                    SchemaTest.this.schema.createCollection(collName1, new CreateCollectionOptions().setReuseExisting(false));
                    return null;
                }
            }).getErrorCode());
            Collection coll2 = this.schema.createCollection(collName1, true);
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName1 + "`").execute();
            def = res.next().getString(1);
            assertFalse(def.contains("NOT ENFORCED"));
            assertTrue(def.contains(sch1));
            coll2 = this.schema.createCollection(collName1, new CreateCollectionOptions().setReuseExisting(true));
            assertEquals(coll, coll2);
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName1 + "`").execute();
            def = res.next().getString(1);
            assertFalse(def.contains("NOT ENFORCED"));
            assertTrue(def.contains(sch1));
            // TSFR2b.2: Call createCollection with only schema option. Ensure the default level value is set on server.
            dropCollection(collName2);
            this.schema.createCollection(collName2, new CreateCollectionOptions().setValidation(new Validation().setSchema(sch1)));
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName2 + "`").execute();
            def = res.next().getString(1);
            if (mysqlVersionMeetsMinimum(ServerVersion.parseVersion("8.0.20"))) {
                // After the Bug#30830962 fix when schema is set and level is omitted xplugin sets it to "strict"
                assertFalse(def.contains("NOT ENFORCED"));
            } else {
                assertTrue(def.contains("NOT ENFORCED"));
            }
            assertTrue(def.contains(sch1));
            // TSFR2b.3: Call createCollection with only level option. Ensure the default schema and the given level are set on server.
            dropCollection(collName2);
            this.schema.createCollection(collName2, new CreateCollectionOptions().setValidation(new Validation().setLevel(ValidationLevel.STRICT)));
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName2 + "`").execute();
            def = res.next().getString(1);
            assertFalse(def.contains("NOT ENFORCED"));
            assertTrue(def.contains("{\"type\":\"object\"}"));
            // TSFR5: Create collection with json schema and level `strict`. Try to insert document which doesn't match this schema, ensure that a server error being raised.
            assertThrows(XProtocolError.class, "ERROR 5180 \\(HY000\\) Document is not valid according to the schema assigned to collection.*", new Callable<Void>() {

                public Void call() throws Exception {
                    coll.add("{\"_id\": 1}").execute();
                    return null;
                }
            });
            // TSFR2a.1: Call modifyCollection with only level option. Ensure it's changed on server.
            this.schema.modifyCollection(collName1, new ModifyCollectionOptions().setValidation(new Validation().setLevel(ValidationLevel.OFF)));
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName1 + "`").execute();
            def = res.next().getString(1);
            assertTrue(def.contains("NOT ENFORCED"));
            assertTrue(def.contains(sch1));
            this.schema.modifyCollection(collName1, new ModifyCollectionOptions().setValidation(new Validation().setLevel(ValidationLevel.STRICT)));
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName1 + "`").execute();
            def = res.next().getString(1);
            assertFalse(def.contains("NOT ENFORCED"));
            assertTrue(def.contains(sch1));
            // TSFR2a.2: Call modifyCollection with only schema option. Ensure it's changed on server.
            // sch2 is compatible with sch1
            this.schema.modifyCollection(collName1, new ModifyCollectionOptions().setValidation(new Validation().setSchema(sch2)));
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName1 + "`").execute();
            def = res.next().getString(1);
            assertFalse(def.contains("NOT ENFORCED"));
            assertFalse(def.contains(sch1));
            assertTrue(def.contains(sch2));
            assertThrows(XProtocolError.class, "ERROR 5180 \\(HY000\\) Document is not valid according to the schema assigned to collection.*", new Callable<Void>() {

                public Void call() throws Exception {
                    SchemaTest.this.schema.modifyCollection(collName1, // sch3 is incompatible with sch1
                    new ModifyCollectionOptions().setValidation(new Validation().setSchema(sch3)));
                    return null;
                }
            });
            // TSFR2a.3: Call modifyCollection with both level and schema options. Ensure they are changed on server.
            this.schema.modifyCollection(collName1, new ModifyCollectionOptions().setValidation(new Validation().setLevel(ValidationLevel.OFF).setSchema(sch3)));
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName1 + "`").execute();
            def = res.next().getString(1);
            assertTrue(def.contains("NOT ENFORCED"));
            assertFalse(def.contains(sch2));
            assertTrue(def.contains(sch3));
            this.schema.modifyCollection(collName1, new ModifyCollectionOptions().setValidation(new Validation().setLevel(ValidationLevel.STRICT).setSchema(sch1)));
            res = this.session.sql("SHOW CREATE TABLE `" + this.schema.getName() + "`.`" + collName1 + "`").execute();
            def = res.next().getString(1);
            assertFalse(def.contains("NOT ENFORCED"));
            assertFalse(def.contains(sch3));
            assertTrue(def.contains(sch1));
            // TSFR2a.4: Call modifyCollection with neither level nor schema options are set. Ensure Connector/J throws the XProtocolError
            assertThrows(XProtocolError.class, "ERROR 5020 \\(HY000\\) Arguments value used under \"validation\" must be an object with at least one field", new Callable<Void>() {

                public Void call() throws Exception {
                    SchemaTest.this.schema.modifyCollection(collName1, null);
                    return null;
                }
            });
            assertThrows(XProtocolError.class, "ERROR 5020 \\(HY000\\) Arguments value used under \"validation\" must be an object with at least one field", new Callable<Void>() {

                public Void call() throws Exception {
                    SchemaTest.this.schema.modifyCollection(collName1, new ModifyCollectionOptions());
                    return null;
                }
            });
            assertThrows(XProtocolError.class, "ERROR 5020 \\(HY000\\) Arguments value used under \"validation\" must be an object with at least one field", new Callable<Void>() {

                public Void call() throws Exception {
                    SchemaTest.this.schema.modifyCollection(collName1, new ModifyCollectionOptions().setValidation(new Validation()));
                    return null;
                }
            });
            // TSFR4: Try to create collection with an invalid json schema. Ensure that a server error being raised.
            assertThrows(XProtocolError.class, "ERROR 5182 \\(HY000\\) JSON validation schema .*", new Callable<Void>() {

                public Void call() throws Exception {
                    SchemaTest.this.schema.createCollection("wrongSchema", new CreateCollectionOptions().setValidation(new Validation().setSchema("{\"id\": \"http://json-schema.org/geo\",\"$schema\":\"http://json-schema.org/draft-06/schema#\"," + // 
                    "\"description\":\"The geographical coordinate\",\"type\":\"object\",\"properties\":{\"latitude\":{" + // wrong type
                    "\"type\":\"blablabla\"" + "}},\"required\":[\"latitude\",\"foo\"]}")));
                    return null;
                }
            });
        } else {
            // for old servers
            // TSFR6b: Call createCollection(collectionName, createCollectionOptions) method against server which doesn't support validation parameter for `create_collection` X Protocol command,
            // eg. MySQL 5.7. Ensure that server responds with error code 5015 and that Connector/J wraps it to WrongArgumentException with message
            // "The server doesn't support the requested operation. Please update the MySQL Server and or Client library".
            assertThrows(WrongArgumentException.class, Messages.getString("Schema.CreateCollection"), new Callable<Void>() {

                public Void call() throws Exception {
                    SchemaTest.this.schema.createCollection(collName1, new CreateCollectionOptions().setValidation(new Validation().setLevel(ValidationLevel.STRICT).setSchema("{\"id\": \"http://json-schema.org/geo\",\"$schema\": \"http://json-schema.org/draft-06/schema#\"," + "\"description\": \"A geographical coordinate\",\"type\": \"object\",\"properties\":" + "{\"latitude\": {\"type\": \"number\"},\"longitude\": {\"type\": \"number\"}}," + "\"required\": [\"latitude\", \"longitude\"]}")));
                    return null;
                }
            });
            // TSFR6c: Call modifyCollection(String collectionName, ModifyCollectionOptions options) method against server which doesn't implement `modify_collection_options` X Protocol command,
            // eg. MySQL 5.7. Ensure that server responds with error code 5157 and that Connector/J wraps it to WrongArgumentException with message
            // "The server doesn't support the requested operation. Please update the MySQL Server and or Client library".
            assertThrows(WrongArgumentException.class, Messages.getString("Schema.CreateCollection"), new Callable<Void>() {

                public Void call() throws Exception {
                    SchemaTest.this.schema.modifyCollection(collName1, new ModifyCollectionOptions().setValidation(new Validation().setLevel(ValidationLevel.OFF)));
                    return null;
                }
            });
        // TSFR6a: Call createCollection(String collectionName) and createCollection(String collectionName, boolean reuseExisting) methods against servers not implementing WL#12965 and ensure they work as before.
        // It's covered by testCreateCollection() test case.
        }
    } finally {
        dropCollection(collName1);
        dropCollection(collName2);
    }
}
Also used : Validation(com.mysql.cj.xdevapi.Schema.Validation) ModifyCollectionOptions(com.mysql.cj.xdevapi.Schema.ModifyCollectionOptions) SqlResult(com.mysql.cj.xdevapi.SqlResult) Collection(com.mysql.cj.xdevapi.Collection) CreateCollectionOptions(com.mysql.cj.xdevapi.Schema.CreateCollectionOptions) WrongArgumentException(com.mysql.cj.exceptions.WrongArgumentException) Test(org.junit.jupiter.api.Test)

Aggregations

SqlResult (com.mysql.cj.xdevapi.SqlResult)39 Test (org.junit.jupiter.api.Test)27 Row (com.mysql.cj.xdevapi.Row)17 JsonString (com.mysql.cj.xdevapi.JsonString)11 Session (com.mysql.cj.xdevapi.Session)8 ExecutionException (java.util.concurrent.ExecutionException)7 WrongArgumentException (com.mysql.cj.exceptions.WrongArgumentException)6 SqlStatement (com.mysql.cj.xdevapi.SqlStatement)6 CoreSession (com.mysql.cj.CoreSession)5 CJCommunicationsException (com.mysql.cj.exceptions.CJCommunicationsException)4 StatementExecuteOkBuilder (com.mysql.cj.protocol.x.StatementExecuteOkBuilder)4 SqlResultBuilder (com.mysql.cj.xdevapi.SqlResultBuilder)4 ArrayList (java.util.ArrayList)4 CJPacketTooBigException (com.mysql.cj.exceptions.CJPacketTooBigException)3 FeatureNotAvailableException (com.mysql.cj.exceptions.FeatureNotAvailableException)3 XProtocolRowInputStream (com.mysql.cj.protocol.x.XProtocolRowInputStream)3 DbDoc (com.mysql.cj.xdevapi.DbDoc)3 DbDocImpl (com.mysql.cj.xdevapi.DbDocImpl)3 DocResult (com.mysql.cj.xdevapi.DocResult)3 SessionFactory (com.mysql.cj.xdevapi.SessionFactory)3