/** * Set the database identifier. This is typically called once upon initialization. * * @param logicalId the logical identifier for the database; may not be null */ public void setServerName(String logicalId) { this.serverName = logicalId; sourcePartition = Collect.hashMapOf(SERVER_PARTITION_KEY, serverName); }
@SuppressWarnings("unchecked") public static <T> Set<T> unmodifiableSet(T... values) { return unmodifiableSet(arrayListOf(values)); }
protected Map<String, Object> server(String serverName) { return Collect.linkMapOf("server", serverName); }
@Before public void beforeEach() throws Exception { source = Collect.hashMapOf("server", "my-server"); setLogPosition(0); topicName = "schema-changes-topic"; File dataDir = Testing.Files.createTestingDirectory("history_cluster"); Testing.Files.delete(dataDir); // Configure the extra properties to kafka = new KafkaCluster().usingDirectory(dataDir) .deleteDataPriorToStartup(true) .deleteDataUponShutdown(true) .addBrokers(1) .withKafkaConfiguration(Collect.propertiesOf("auto.create.topics.enable", "false")) .startup(); history = new KafkaDatabaseHistory(); }
@Override public Set<String> keys() { return Collect.unmodifiableSet(newToOld.keySet()); }
/** * Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single * string value into multiple values. * * @param key the key for the configuration property * @param regex the delimiting regular expression * @return the list of string values; null only if there is no such key-value pair in the configuration * @see String#split(String) */ default List<String> getStrings(String key, String regex) { String value = getString(key); if (value == null) return null; return Collect.arrayListOf(value.split(regex)); }
@Override public Set<String> keys() { return Collect.unmodifiableSet(Configuration.this.keys().stream() .filter(k -> k != null) .filter(matcher) .collect(Collectors.toSet())); }
protected void appendLinesToSource(int numberOfLines) throws IOException { CharSequence[] lines = new CharSequence[numberOfLines]; for (int i = 0; i != numberOfLines; ++i) { lines[i] = generateLine(linesAdded + i + 1); } java.nio.file.Files.write(inputFile.toPath(), Collect.arrayListOf(lines), UTF8, StandardOpenOption.APPEND); linesAdded += numberOfLines; }
/** * Get the Kafka Connect detail about the source "partition" for the given database in the replica set. If the database is * not known, this method records the new partition. * * @param replicaSetName the name of the replica set name for which the partition is to be obtained; may not be null * @return the source partition information; never null */ public Map<String, String> partition(String replicaSetName) { if (replicaSetName == null) throw new IllegalArgumentException("Replica set name may not be null"); return sourcePartitionsByReplicaSetName.computeIfAbsent(replicaSetName, rsName -> { return Collect.hashMapOf(SERVER_ID_KEY, serverName, REPLICA_SET_NAME, rsName); }); }
/** * Get the set of {@link TableId}s for which there is a {@link Schema}. * * @return the immutable set of table identifiers; never null */ public Set<TableId> tableIds() { return lock.read(() -> Collect.unmodifiableSet(tablesByTableId.ids())); }
@SuppressWarnings("unchecked") public static <T> Set<T> unmodifiableSet(T... values) { return unmodifiableSet(arrayListOf(values)); }
historyConsumer.subscribe(Collect.arrayListOf(topicName));
protected Map<String, Object> position(String filename, long position, int entry) { return Collect.linkMapOf("file", filename, "position", position, "entry", entry); }
protected Map<String, String> vars(String var1, String val1) { return Collect.hashMapOf(var1, val1); }
private SqlTypeMapper(Connection db, TypeInfo typeInfo) throws SQLException { this.typeInfo = typeInfo; this.preloadedSqlTypes = Collect.unmodifiableSet(typeInfo.getPGTypeNamesWithSQLTypes()); this.sqlTypesByPgTypeNames = getSqlTypes(db, typeInfo); }
@Test public void shouldFilterServerUuids() { String gtidStr = "036d85a9-64e5-11e6-9b48-42010af0000c:1-2," + "7145bf69-d1ca-11e5-a588-0242ac110004:1-3200," + "7c1de3f2-3fd2-11e6-9cdc-42010af000bc:1-41"; Collection<String> keepers = Collect.arrayListOf("036d85a9-64e5-11e6-9b48-42010af0000c", "7c1de3f2-3fd2-11e6-9cdc-42010af000bc", "wont-be-found"); GtidSet original = new GtidSet(gtidStr); assertThat(original.forServerWithId("036d85a9-64e5-11e6-9b48-42010af0000c")).isNotNull(); assertThat(original.forServerWithId("7c1de3f2-3fd2-11e6-9cdc-42010af000bc")).isNotNull(); assertThat(original.forServerWithId("7145bf69-d1ca-11e5-a588-0242ac110004")).isNotNull(); GtidSet filtered = original.retainAll(keepers::contains); List<String> actualUuids = filtered.getUUIDSets().stream().map(UUIDSet::getUUID).collect(Collectors.toList()); assertThat(keepers.containsAll(actualUuids)).isTrue(); assertThat(filtered.forServerWithId("7145bf69-d1ca-11e5-a588-0242ac110004")).isNull(); }
@Test public void canSerializeAndDeserializeHistoryRecord() throws Exception { Map<String,Object> source = Collect.linkMapOf("server", "abc"); Map<String,Object> position = Collect.linkMapOf("file", "x.log", "positionInt", 100, "positionLong", Long.MAX_VALUE, "entry", 1); String databaseName = "db"; String schemaName = "myschema";
protected void setLogPosition(int index) { this.position = Collect.hashMapOf("filename", "my-txn-file.log", "position", index); }
@Test(expected=UnsupportedOperationException.class) public void unmodifiableSetForIteratorShouldRaiseExceptionUponModification() { Set<Integer> values = Collect.unmodifiableSet(Arrays.asList(1, 2, 3, 42).iterator()); values.remove(1); } }
/** * Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single * string value into multiple values. * * @param key the key for the configuration property * @param regex the delimiting regular expression * @return the list of string values; null only if there is no such key-value pair in the configuration * @see String#split(String) */ default List<String> getStrings(String key, String regex) { String value = getString(key); if (value == null) return null; return Collect.arrayListOf(value.split(regex)); }