Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2777,9 +2777,11 @@ project(':connect:runtime') {
testImplementation project(':clients').sourceSets.test.output
testImplementation project(':core')
testImplementation project(':metadata')
testImplementation project(':server-common')
testImplementation project(':core').sourceSets.test.output
testImplementation project(':server-common')
testImplementation project(':connect:test-plugins')
testImplementation project(':server-common').sourceSets.test.output

testImplementation libs.easymock
testImplementation libs.junitJupiterApi
Expand Down Expand Up @@ -2986,6 +2988,7 @@ project(':connect:mirror') {
testImplementation project(':connect:runtime').sourceSets.test.output
testImplementation project(':core')
testImplementation project(':core').sourceSets.test.output
testImplementation project(':server-common').sourceSets.test.output

testRuntimeOnly project(':connect:runtime')
testRuntimeOnly libs.slf4jlog4j
Expand Down
2 changes: 2 additions & 0 deletions checkstyle/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@
<subpackage name="clusters">
<allow pkg="kafka.cluster" />
<allow pkg="kafka.server" />
<allow pkg="kafka.testkit" />
<allow pkg="kafka.zk" />
<allow pkg="kafka.utils" />
<allow class="javax.servlet.http.HttpServletResponse" />
Expand All @@ -574,6 +575,7 @@
<allow pkg="org.eclipse.jetty.util"/>
<!-- for tests -->
<allow pkg="org.apache.kafka.server.util" />
<allow pkg="kafka.server"/>
</subpackage>

<subpackage name="json">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ public void testSingleNodeCluster() throws Exception {
EmbeddedKafkaCluster clusterA = startKafkaCluster("A", 1, brokerProps);
EmbeddedKafkaCluster clusterB = startKafkaCluster("B", 1, brokerProps);

clusterA.start();
clusterB.start();
Comment thread
yashmayya marked this conversation as resolved.
Outdated

try (Admin adminB = clusterB.createAdminClient()) {

// Cluster aliases
Expand Down Expand Up @@ -187,9 +184,6 @@ public void testMultiNodeCluster() throws Exception {
EmbeddedKafkaCluster clusterA = startKafkaCluster("A", 1, brokerProps);
EmbeddedKafkaCluster clusterB = startKafkaCluster("B", 1, brokerProps);

clusterA.start();
clusterB.start();

try (Admin adminB = clusterB.createAdminClient()) {
// Cluster aliases
final String a = "A";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,49 @@
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.config.ConfigResource;
import org.apache.kafka.common.config.TopicConfig;
import org.apache.kafka.common.utils.Exit;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.utils.Time;
import org.apache.kafka.common.utils.Timer;
import org.apache.kafka.common.utils.Utils;
import org.apache.kafka.connect.connector.Connector;
import org.apache.kafka.connect.mirror.Checkpoint;
import org.apache.kafka.connect.mirror.DefaultConfigPropertyFilter;
import org.apache.kafka.connect.mirror.MirrorCheckpointConnector;
import org.apache.kafka.connect.mirror.MirrorClient;
import org.apache.kafka.connect.mirror.MirrorHeartbeatConnector;
import org.apache.kafka.connect.mirror.MirrorMakerConfig;
import org.apache.kafka.connect.mirror.MirrorSourceConnector;
import org.apache.kafka.connect.mirror.MirrorUtils;
import org.apache.kafka.connect.mirror.SourceAndTarget;
import org.apache.kafka.connect.mirror.Checkpoint;
import org.apache.kafka.connect.mirror.MirrorCheckpointConnector;
import org.apache.kafka.connect.mirror.TestUtils;
import org.apache.kafka.connect.runtime.rest.entities.ConnectorOffset;
import org.apache.kafka.connect.runtime.rest.entities.ConnectorOffsets;
import org.apache.kafka.connect.util.clusters.EmbeddedConnectCluster;
import org.apache.kafka.connect.util.clusters.EmbeddedKafkaCluster;
import org.apache.kafka.connect.util.clusters.UngracefulShutdownException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -77,19 +81,12 @@
import java.util.function.LongUnaryOperator;
import java.util.stream.Collectors;

import org.junit.jupiter.api.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.kafka.test.TestUtils.waitForCondition;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Tests MM2 replication and failover/failback logic.
Expand Down Expand Up @@ -429,12 +426,12 @@ public void testReplicationWithEmptyPartition() throws Exception {
try (Consumer<byte[], byte[]> primaryConsumer = primary.kafka().createConsumerAndSubscribeTo(consumerProps, topic)) {
waitForConsumingAllRecords(primaryConsumer, expectedRecords);
}

// one way replication from primary to backup
mm2Props.put(BACKUP_CLUSTER_ALIAS + "->" + PRIMARY_CLUSTER_ALIAS + ".enabled", "false");
mm2Config = new MirrorMakerConfig(mm2Props);
waitUntilMirrorMakerIsRunning(backup, CONNECTOR_LIST, mm2Config, PRIMARY_CLUSTER_ALIAS, BACKUP_CLUSTER_ALIAS);

// sleep few seconds to have MM2 finish replication so that "end" consumer will consume some record
Thread.sleep(TimeUnit.SECONDS.toMillis(3));

Expand All @@ -445,7 +442,7 @@ public void testReplicationWithEmptyPartition() throws Exception {
backupTopic)) {
waitForConsumingAllRecords(backupConsumer, expectedRecords);
}

try (Admin backupClient = backup.kafka().createAdminClient()) {
// retrieve the consumer group offset from backup cluster
Map<TopicPartition, OffsetAndMetadata> remoteOffsets =
Expand Down Expand Up @@ -1093,14 +1090,11 @@ protected Producer<byte[], byte[]> initializeProducer(EmbeddedConnectCluster clu
* @param records Records to send in one parallel batch
*/
protected void produceMessages(Producer<byte[], byte[]> producer, List<ProducerRecord<byte[], byte[]>> records) {
List<Future<RecordMetadata>> futures = new ArrayList<>();
for (ProducerRecord<byte[], byte[]> record : records) {
futures.add(producer.send(record));
}
Timer timer = Time.SYSTEM.timer(RECORD_PRODUCE_DURATION_MS);

try {
for (Future<RecordMetadata> future : futures) {
future.get(timer.remainingMs(), TimeUnit.MILLISECONDS);
for (ProducerRecord<byte[], byte[]> record : records) {
producer.send(record).get(timer.remainingMs(), TimeUnit.MILLISECONDS);
Comment on lines 1096 to 1097

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testReplicationWithEmptyPartition was consistently timing out without this change, although I haven't yet gotten around to debugging why exactly that was the case..

timer.update();
}
} catch (ExecutionException | InterruptedException | TimeoutException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@
*/
package org.apache.kafka.connect.mirror.integration;

import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

import kafka.server.KafkaConfig;
import org.apache.kafka.clients.CommonClientConfigs;
import org.apache.kafka.common.config.SslConfigs;
import org.apache.kafka.common.config.types.Password;
import org.apache.kafka.common.network.Mode;
import org.apache.kafka.test.TestSslUtils;
import org.apache.kafka.test.TestUtils;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;

import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

/**
* Tests MM2 replication with SSL enabled at backup kafka cluster
*/
Expand All @@ -41,25 +40,24 @@ public class MirrorConnectorsIntegrationSSLTest extends MirrorConnectorsIntegrat
public void startClusters() throws Exception {
Map<String, Object> sslConfig = TestSslUtils.createSslConfig(false, true, Mode.SERVER, TestUtils.tempFile(), "testCert");
// enable SSL on backup kafka broker
backupBrokerProps.put(KafkaConfig.ListenersProp(), "SSL://localhost:0");
backupBrokerProps.put(KafkaConfig.InterBrokerListenerNameProp(), "SSL");
backupBrokerProps.put(KafkaConfig.ListenerSecurityProtocolMapProp(), "EXTERNAL:SSL,CONTROLLER:SSL");
backupBrokerProps.putAll(sslConfig);

Properties sslProps = new Properties();
sslProps.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, sslConfig.get(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG));
sslProps.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, ((Password) sslConfig.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG)).value());
sslProps.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SSL");

// set SSL config for kafka connect worker
backupWorkerProps.putAll(sslProps.entrySet().stream().collect(Collectors.toMap(
e -> String.valueOf(e.getKey()), e -> String.valueOf(e.getValue()))));

mm2Props.putAll(sslProps.entrySet().stream().collect(Collectors.toMap(
e -> BACKUP_CLUSTER_ALIAS + "." + e.getKey(), e -> String.valueOf(e.getValue()))));
// set SSL config for producer used by source task in MM2
mm2Props.putAll(sslProps.entrySet().stream().collect(Collectors.toMap(
e -> BACKUP_CLUSTER_ALIAS + ".producer." + e.getKey(), e -> String.valueOf(e.getValue()))));

super.startClusters();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.kafka.connect.mirror.integration;

import kafka.server.KafkaConfig;
import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.NewPartitions;
import org.apache.kafka.common.acl.AccessControlEntry;
Expand Down Expand Up @@ -67,17 +68,18 @@ public class MirrorConnectorsWithCustomForwardingAdminIntegrationTest extends Mi
* enable ACL on brokers.
*/
protected static void enableAclAuthorizer(Properties brokerProps) {
brokerProps.put("authorizer.class.name", "kafka.security.authorizer.AclAuthorizer");
brokerProps.put("sasl.enabled.mechanisms", "PLAIN");
brokerProps.put("sasl.mechanism.inter.broker.protocol", "PLAIN");
brokerProps.put("security.inter.broker.protocol", "SASL_PLAINTEXT");
brokerProps.put("listeners", "SASL_PLAINTEXT://localhost:0");
brokerProps.put("listener.name.sasl_plaintext.plain.sasl.jaas.config",
"org.apache.kafka.common.security.plain.PlainLoginModule required "
+ "username=\"super\" "
+ "password=\"super_pwd\" "
+ "user_connector=\"connector_pwd\" "
+ "user_super=\"super_pwd\";");
brokerProps.put(KafkaConfig.ListenerSecurityProtocolMapProp(), "CONTROLLER:SASL_PLAINTEXT,EXTERNAL:SASL_PLAINTEXT");
brokerProps.put(KafkaConfig.AuthorizerClassNameProp(), "org.apache.kafka.metadata.authorizer.StandardAuthorizer");
brokerProps.put(KafkaConfig.SaslEnabledMechanismsProp(), "PLAIN");
brokerProps.put(KafkaConfig.SaslMechanismInterBrokerProtocolProp(), "PLAIN");
brokerProps.put(KafkaConfig.SaslMechanismControllerProtocolProp(), "PLAIN");
String listenerSaslJaasConfig = "org.apache.kafka.common.security.plain.PlainLoginModule required "
+ "username=\"super\" "
+ "password=\"super_pwd\" "
+ "user_connector=\"connector_pwd\" "
+ "user_super=\"super_pwd\";";
brokerProps.put("listener.name.external.plain.sasl.jaas.config", listenerSaslJaasConfig);
brokerProps.put("listener.name.controller.plain.sasl.jaas.config", listenerSaslJaasConfig);
brokerProps.put("super.users", "User:super");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public class BlockingConnectorTest {

@Before
public void setup() throws Exception {
// build a Connect cluster backed by Kafka and Zk
// build a Connect cluster backed by a Kafka KRaft cluster
connect = new EmbeddedConnectCluster.Builder()
.name("connect-cluster")
.numWorkers(NUM_WORKERS)
Expand All @@ -137,7 +137,7 @@ public void setup() throws Exception {

@After
public void close() {
// stop all Connect, Kafka and Zk threads.
// stop the Connect cluster and its backing Kafka cluster.
connect.stop();
Block.resetBlockLatch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.kafka.connect.integration;

import kafka.server.KafkaConfig;
import org.apache.kafka.connect.runtime.distributed.DistributedConfig;
import org.apache.kafka.connect.storage.StringConverter;
import org.apache.kafka.connect.util.clusters.EmbeddedConnectCluster;
Expand All @@ -30,6 +31,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.ServerSocket;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -89,7 +91,7 @@ public void setup() {
brokerProps = new Properties();
brokerProps.put("auto.create.topics.enable", String.valueOf(false));

// build a Connect cluster backed by Kafka and Zk
// build a Connect cluster backed by a Kafka KRaft cluster
connectBuilder = new EmbeddedConnectCluster.Builder()
.name("connect-cluster")
.numWorkers(NUM_WORKERS)
Expand All @@ -100,7 +102,7 @@ public void setup() {

@After
public void close() {
// stop all Connect, Kafka and Zk threads.
// stop the Connect cluster and its backing Kafka cluster.
connect.stop();
}

Expand Down Expand Up @@ -196,7 +198,20 @@ public void testRestartFailedTask() throws Exception {
public void testBrokerCoordinator() throws Exception {
ConnectorHandle connectorHandle = RuntimeHandles.get().connectorHandle(CONNECTOR_NAME);
workerProps.put(DistributedConfig.SCHEDULED_REBALANCE_MAX_DELAY_MS_CONFIG, String.valueOf(5000));
connect = connectBuilder.workerProps(workerProps).build();
Properties brokerProps = new Properties();

// Find a free port and use it in the Kafka broker's listeners config. We can't use port 0 in the listeners
// config to get a random free port because in this test we want to stop the Kafka broker and then bring it
// back up and listening on the same port in order to verify that the Connect cluster can re-connect to Kafka
// and continue functioning normally. If we were to use port 0 here, the Kafka broker would most likely listen
// on a different random free port the second time it is started. Note that we can only use the static port
// because we have a single broker setup in this test.
int listenerPort;
try (ServerSocket s = new ServerSocket(0)) {
listenerPort = s.getLocalPort();
}
brokerProps.put(KafkaConfig.ListenersProp(), String.format("EXTERNAL://localhost:%d,CONTROLLER://localhost:0", listenerPort));
connect = connectBuilder.workerProps(workerProps).brokerProps(brokerProps).build();
// start the clusters
connect.start();
int numTasks = 4;
Expand All @@ -218,7 +233,7 @@ public void testBrokerCoordinator() throws Exception {
// expect that the connector will be stopped once the coordinator is detected to be down
StartAndStopLatch stopLatch = connectorHandle.expectedStops(1, false);

connect.kafka().stopOnlyKafka();
connect.kafka().stopOnlyBrokers();

connect.assertions().assertExactlyNumWorkersAreUp(NUM_WORKERS,
"Group of workers did not remain the same after broker shutdown");
Expand All @@ -233,7 +248,7 @@ public void testBrokerCoordinator() throws Exception {
stopLatch.await(CONNECTOR_SETUP_DURATION_MS, TimeUnit.MILLISECONDS));

StartAndStopLatch startLatch = connectorHandle.expectedStarts(1, false);
connect.kafka().startOnlyKafkaOnSamePorts();
connect.kafka().restartOnlyBrokers();

// Allow for the kafka brokers to come back online
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private EmbeddedConnectCluster connectClusterWithPolicy(String policy) throws In
Properties exampleBrokerProps = new Properties();
exampleBrokerProps.put("auto.create.topics.enable", "false");

// build a Connect cluster backed by Kafka and Zk
// build a Connect cluster backed by a Kafka KRaft cluster
EmbeddedConnectCluster connect = new EmbeddedConnectCluster.Builder()
.name("connect-cluster")
.numWorkers(NUM_WORKERS)
Expand Down
Loading