@Test public void shouldParseHostStringWithAddressForOneReplicaSet() { sets = ReplicaSets.parse("myReplicaSet/localhost:27017"); assertThat(sets.replicaSetCount()).isEqualTo(1); assertThat(sets.hosts()).isEqualTo("myReplicaSet/localhost:27017"); rs = sets.all().get(0); assertThat(rs.hasReplicaSetName()).isTrue(); assertThat(rs.isStandaloneServer()).isFalse(); assertThat(rs.replicaSetName()).isEqualTo("myReplicaSet"); assertThat(rs.shardName()).isNull(); ServerAddress expected = new ServerAddress("localhost", 27017); assertThat(rs.addresses().size()).isEqualTo(1); assertThat(rs.addresses()).containsOnly(expected); }
private void validateFieldDef(Field expected) { ConfigDef configDef = connector.config(); assertThat(configDef.names()).contains(expected.name()); ConfigDef.ConfigKey key = configDef.configKeys().get(expected.name()); assertThat(key).isNotNull(); assertThat(key.name).isEqualTo(expected.name()); assertThat(key.displayName).isEqualTo(expected.displayName()); assertThat(key.importance).isEqualTo(expected.importance()); assertThat(key.documentation).isEqualTo(expected.description()); assertThat(key.type).isEqualTo(expected.type()); assertThat(key.defaultValue).isEqualTo(expected.defaultValue()); assertThat(key.dependents).isEqualTo(expected.dependents()); assertThat(key.width).isNotNull(); assertThat(key.group).isNotNull(); assertThat(key.orderInGroup).isGreaterThan(0); assertThat(key.validator).isNull(); assertThat(key.recommender).isNull(); } }
protected void assertConfigurationErrors(Config config, io.debezium.config.Field field, int minErrorsInclusive, int maxErrorsInclusive) { ConfigValue value = configValue(config, field.name()); assertThat(value.errorMessages().size()).isGreaterThanOrEqualTo(minErrorsInclusive); assertThat(value.errorMessages().size()).isLessThanOrEqualTo(maxErrorsInclusive); }
@Test public void shouldTruncateStrings() { Configuration config = Configuration.create() .with("column.truncate.to.10.chars", fullyQualifiedNames.toUpperCase()) .build(); mappers = ColumnMappers.create(config); converter = mappers.mappingConverterFor(tableId, column); assertThat(converter).isNotNull(); assertThat(converter.convert("12345678901234567890").toString()).isEqualTo("1234567890"); assertThat(converter.convert("12345678901234567890").toString().length()).isEqualTo(10); assertThat(converter.convert("12345678901").toString()).isEqualTo("1234567890"); assertThat(converter.convert("12345678901").toString().length()).isEqualTo(10); assertThat(converter.convert("1234567890").toString()).isEqualTo("1234567890"); assertThat(converter.convert("1234567890").toString().length()).isEqualTo(10); assertThat(converter.convert("123456789").toString()).isEqualTo("123456789"); assertThat(converter.convert("123456789").toString().length()).isEqualTo(9); assertThat(converter.convert(null)).isNull(); // null values are unaltered }
@Test public void shouldParseCreateTableStatementWithCharacterSetForColumns() { String ddl = "CREATE TABLE t ( col1 VARCHAR(25) CHARACTER SET greek ); "; parser.parse(ddl, tables); assertThat(tables.size()).isEqualTo(1); Table t = tables.forTable(new TableId(null, null, "t")); assertThat(t).isNotNull(); assertThat(t.retrieveColumnNames()).containsExactly("col1"); assertThat(t.primaryKeyColumnNames()).isEmpty(); assertColumn(t, "col1", "VARCHAR", Types.VARCHAR, 25, -1, true, false, false); }
@Test public void shouldReturnOffsetForUnusedReplicaName() { assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false); Map<String, ?> offset = source.lastOffset(REPLICA_SET_NAME); assertThat(offset.get(SourceInfo.TIMESTAMP)).isEqualTo(0); assertThat(offset.get(SourceInfo.ORDER)).isEqualTo(0); assertThat(offset.get(SourceInfo.OPERATION_ID)).isNull(); BsonTimestamp ts = source.lastOffsetTimestamp(REPLICA_SET_NAME); assertThat(ts.getTime()).isEqualTo(0); assertThat(ts.getInc()).isEqualTo(0); Struct struct = source.lastOffsetStruct(REPLICA_SET_NAME,new CollectionId(REPLICA_SET_NAME,"dbA","collectA")); assertThat(struct.getInt32(SourceInfo.TIMESTAMP)).isEqualTo(0); assertThat(struct.getInt32(SourceInfo.ORDER)).isEqualTo(0); assertThat(struct.getInt64(SourceInfo.OPERATION_ID)).isNull(); assertThat(struct.getString(SourceInfo.NAMESPACE)).isEqualTo("dbA.collectA"); assertThat(struct.getString(SourceInfo.REPLICA_SET_NAME)).isEqualTo(REPLICA_SET_NAME); assertThat(struct.getString(SourceInfo.SERVER_NAME)).isEqualTo("serverX"); assertThat(struct.getBoolean(SourceInfo.INITIAL_SYNC)).isNull(); assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false); }
@Test public void shouldParseMultipleStatementsWithFullyQualifiedDatabase() { parser.setCurrentSchema("mydb"); String ddl = "CREATE TABLE other.foo ( " + System.lineSeparator() + " c1 INTEGER NOT NULL, " + System.lineSeparator() + " c2 VARCHAR(22) " + System.lineSeparator() + "); " + System.lineSeparator() + "-- This is a comment" + System.lineSeparator() + "DROP TABLE other.foo;" + System.lineSeparator(); parser.parse(ddl, tables); assertThat(tables.size()).isEqualTo(0); // table created and dropped changes.groupEventsByDatabase((dbName, list) -> { assertThat(dbName).isEqualTo("other"); assertThat(list.size()).isEqualTo(2); assertThat(list.get(0).type()).isEqualTo(EventType.CREATE_TABLE); assertThat(list.get(1).type()).isEqualTo(EventType.DROP_TABLE); }); }
protected void assertCanConnectToJdbc() throws SQLException { AtomicInteger count = new AtomicInteger(); context.getConnectionContext().jdbc().query("SHOW DATABASES", rs -> { while (rs.next()) count.incrementAndGet(); }); assertThat(count.get()).isGreaterThan(0); }
assertThat(actualRecords.topics().size()).isEqualTo(1); assertThat(actualRecords.recordsForTopic(topicName("s1.a")).size()).isEqualTo(1); Assertions.assertThat(flushLsn.size()).isGreaterThanOrEqualTo((recordCount * 3) / 4);
@Test @FixFor("DBZ-474") public void shouldParseCreateTableStatementWithCollate() { String ddl = "CREATE TABLE c1 (pk INT PRIMARY KEY, v1 CHAR(36) NOT NULL COLLATE utf8_unicode_ci);"; parser.parse(ddl, tables); assertThat(tables.size()).isEqualTo(1); Table table = tables.forTable(new TableId(null, null, "c1")); assertThat(table).isNotNull(); assertColumn(table, "v1", "CHAR", Types.CHAR, 36, -1, false, false, false); Column column = table.columnWithName("v1"); assertThat(column.typeUsesCharset()).isTrue(); }
protected void assertRows(WriteRowsEventData eventData, int numRowsInEvent, Serializable... expectedValuesInRows) { assertThat(eventData.getRows().size()).isEqualTo(numRowsInEvent); int valuePosition = 0; for (Serializable[] row : eventData.getRows()) { for (Serializable value : row) { assertThat(value).isEqualTo(expectedValuesInRows[valuePosition++]); } } }
@Test public void shouldParseStatementsWithQuotedIdentifiers() { parser.parse(readFile("ddl/mysql-quoted.ddl"), tables); Testing.print(tables); assertThat(tables.size()).isEqualTo(4); assertThat(listener.total()).isEqualTo(10); assertThat(tables.forTable("connector_test_ro", null, "products")).isNotNull(); assertThat(tables.forTable("connector_test_ro", null, "products_on_hand")).isNotNull(); assertThat(tables.forTable("connector_test_ro", null, "customers")).isNotNull(); assertThat(tables.forTable("connector_test_ro", null, "orders")).isNotNull(); }
@Test public void shouldParseCreateUserTable() { String ddl = "CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(32) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) unsigned DEFAULT 0 NOT NULL, plugin char(64) DEFAULT 'mysql_native_password' NOT NULL, authentication_string TEXT, password_expired ENUM('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, password_last_changed timestamp NULL DEFAULT NULL, password_lifetime smallint unsigned NULL DEFAULT NULL, account_locked ENUM('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges';"; parser.parse(ddl, tables); assertThat(tables.size()).isEqualTo(1); Table foo = tables.forTable(new TableId(null, null, "user")); assertThat(foo).isNotNull(); assertThat(foo.retrieveColumnNames()).contains("Host", "User", "Select_priv"); assertColumn(foo, "Host", "CHAR BINARY", Types.BINARY, 60, -1, false, false, false); parser.parse("DROP TABLE user", tables); assertThat(tables.size()).isEqualTo(0); }
InsertOneOptions insertOptions = new InsertOneOptions().bypassDocumentValidation(true); movies.insertOne(Document.parse("{ \"name\":\"Starter Wars\"}"), insertOptions); assertThat(collection.countDocuments()).isEqualTo(1); FindIterable<Document> movieResults = collection.find(filter); try (MongoCursor<Document> cursor = movieResults.iterator();) { assertThat(cursor.tryNext().getString("name")).isEqualTo("Starter Wars"); assertThat(cursor.tryNext()).isNull(); assertThat(primary.databaseNames()).containsOnly("dbA", "dbB"); assertThat(primary.collections()).containsOnly(new CollectionId(replicaSet.replicaSetName(), "dbA", "moviesA")); assertThat(eventQueue.size()).isGreaterThanOrEqualTo(1);
.using(config) .notifying((records, committer) -> { assertThat(records.size()).isGreaterThanOrEqualTo(NUMBER_OF_LINES); Integer groupCount = records.size() / NUMBER_OF_LINES; assertThat(firstLatch.getCount()).isEqualTo(0); assertThat(allLatch.getCount()).isEqualTo(0);
protected List<Document> loadTestDocuments(String pathOnClasspath) { List<Document> results = new ArrayList<>(); try (InputStream stream = Testing.Files.readResourceAsStream(pathOnClasspath);) { assertThat(stream).isNotNull(); IoUtil.readLines(stream, line -> { Document doc = Document.parse(line); assertThat(doc.size()).isGreaterThan(0); results.add(doc); }); } catch (IOException e) { fail("Unable to find or read file '" + pathOnClasspath + "': " + e.getMessage()); } return results; }
@Test public void hashCodeDiffersForSubclassAttributes() { assertThat(example1.hashCode()).isNotEqualTo(example2.hashCode()); }
@Test public void shouldNotSubdivideOneReplicaSet() { sets = ReplicaSets.parse("rs1/host1:27017,host2:27017"); List<ReplicaSets> divided = new ArrayList<>(); sets.subdivide(1, divided::add); assertThat(divided.size()).isEqualTo(1); assertThat(divided.get(0)).isSameAs(sets); }
protected void assertType( String content, String typeName, int jdbcType, long length, int scale, int[] arrayDims ) { DataType type = parser.parse(text(content), null); assertThat(type).isNotNull(); assertThat(type.jdbcType()).isEqualTo(jdbcType); assertThat(type.name()).isEqualTo(typeName); assertThat(type.length()).isEqualTo(length); assertThat(type.scale()).isEqualTo(scale); assertThat(type.arrayDimensions()).isEqualTo(arrayDims); }
@Test public void shouldParseCreateTableStatementWithSingleGeneratedAndPrimaryKeyColumn() { String ddl = "CREATE TABLE foo ( " + System.lineSeparator() + " c1 INTEGER GENERATED ALWAYS AS IDENTITY NOT NULL PRIMARY KEY, " + System.lineSeparator() + " c2 VARCHAR(22) " + System.lineSeparator() + "); " + System.lineSeparator(); parser.parse(ddl, tables); assertThat(tables.size()).isEqualTo(1); Table foo = tables.forTable(new TableId(null,null,"foo")); assertThat(foo).isNotNull(); assertThat(foo.retrieveColumnNames()).containsExactly("c1","c2"); assertThat(foo.primaryKeyColumnNames()).containsExactly("c1"); assertColumn(foo,"c1","INTEGER",Types.INTEGER,-1,-1,false,true,true); assertColumn(foo,"c2","VARCHAR",Types.VARCHAR,22,-1,true,false,false); }