From 5ab4ff0a1a88c78e4389f6b6412d3b66f789833c Mon Sep 17 00:00:00 2001
From: Dimitar Dimitrov <30328539+dimitarndimitrov@users.noreply.github.com>
Date: Tue, 7 Jun 2022 18:42:46 +0200
Subject: [PATCH] KREST-4067 Introduce import control to Kafka REST. (#1022)
This change enables Checkstyle's ImportControl module so that
it's easier to detect when a non-public Kafka API is being
used. This is needed as non-public APIs provide much fewer
guarantees, at least in terms of API stability, and can be
source of breakages or subtle behavior changes.
For that purpose, Checkstyle has also been enabled on test
sources and a main Checkstyle config has been added.
- All Checkstyle rules other than ImportControl rules have
been disabled for test sources though, in order to minimize
the scope of this change.
All pre-existing usages of non-public APIs have been
grandfathered (i.e. allowlisted in the ImportControl ruleset).
Subsequent usages of non-public APIs will be much easier to
spot from here on though.
---
checkstyle/checkstyle.xml | 12 ++
checkstyle/import_control.xml | 149 ++++++++++++++++++
checkstyle/suppressions.xml | 46 +++++-
.../kafkarest/KafkaRestConfigTest.java | 15 ++
.../confluent/kafkarest/OpenConfigEntry.java | 15 ++
.../io/confluent/kafkarest/TestUtils.java | 11 +-
.../controllers/AclManagerImplTest.java | 6 +-
.../RecordSerializerFacadeTest.java | 3 +-
.../controllers/SchemaManagerImplTest.java | 21 ++-
.../SchemaRecordSerializerTest.java | 3 +-
.../extension/EnumConverterProviderTest.java | 15 ++
.../integration/AbstractConsumerTest.java | 28 ++--
.../integration/AbstractProducerTest.java | 8 +-
.../integration/ClusterTestHarness.java | 21 +--
.../integration/ConsumerBinaryTest.java | 1 +
.../integration/ConsumerJsonTest.java | 1 +
.../integration/ConsumerTimeoutTest.java | 1 +
.../integration/JsonProducerTest.java | 1 +
.../KafkaRestStartUpIntegrationTest.java | 15 ++
...adataAPITest.java => MetadataApiTest.java} | 5 +-
.../kafkarest/integration/ProducerTest.java | 1 +
.../SchemaRegistrySaslInheritTest.java | 6 +-
.../v2/AvroProduceConsumeTest.java | 15 ++
.../v2/JsonSchemaProduceConsumeTest.java | 15 ++
.../v2/ProtobufProduceConsumeTest.java | 15 ++
.../v2/SchemaProduceConsumeTest.java | 15 ++
.../integration/v2/SeekToTimestampTest.java | 19 ++-
.../v3/AclsResourceIntegrationTest.java | 23 ++-
.../BrokerConfigsResourceIntegrationTest.java | 15 ++
...ClusterConfigsResourceIntegrationTest.java | 15 ++
...AllReassignmentsActionIntegrationTest.java | 15 ++
.../io/confluent/kafkarest/mock/MockTime.java | 1 +
.../resources/ProduceRateLimitersTest.java | 15 ++
.../resources/v2/RootResourceTest.java | 10 +-
.../v2/TopicsResourceAvroProduceTest.java | 4 +-
.../v3/BrokerConfigResourceTest.java | 15 ++
.../v3/GetReassignmentActionTest.java | 15 ++
.../v3/ListAllTopicsConfigsActionTest.java | 2 +-
.../resources/v3/ProduceActionTest.java | 88 +++++------
.../response/CrnFactoryImplTest.java | 15 ++
.../response/StreamingResponseTest.java | 21 ++-
.../kafkarest/testing/KafkaRestFixture.java | 17 +-
.../kafkarest/testing/SslFixture.java | 14 +-
.../unit/DefaultKafkaRestContextTest.java | 15 ++
.../kafkarest/unit/UriUtilsTest.java | 16 +-
.../v2/KafkaConsumerManagerTest.java | 19 ++-
.../io/confluent/kafkarest/v2/LoadTest.java | 1 +
.../confluent/kafkarest/v2/MockConsumer.java | 1 +
pom.xml | 10 ++
49 files changed, 652 insertions(+), 158 deletions(-)
create mode 100644 checkstyle/checkstyle.xml
create mode 100644 checkstyle/import_control.xml
rename kafka-rest/src/test/java/io/confluent/kafkarest/integration/{MetadataAPITest.java => MetadataApiTest.java} (98%)
diff --git a/checkstyle/checkstyle.xml b/checkstyle/checkstyle.xml
new file mode 100644
index 0000000000..1a987cb501
--- /dev/null
+++ b/checkstyle/checkstyle.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/checkstyle/import_control.xml b/checkstyle/import_control.xml
new file mode 100644
index 0000000000..c87c499e4b
--- /dev/null
+++ b/checkstyle/import_control.xml
@@ -0,0 +1,149 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/checkstyle/suppressions.xml b/checkstyle/suppressions.xml
index b31178b238..23c125ebb9 100644
--- a/checkstyle/suppressions.xml
+++ b/checkstyle/suppressions.xml
@@ -10,19 +10,57 @@
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/kafka-rest/src/test/java/io/confluent/kafkarest/KafkaRestConfigTest.java b/kafka-rest/src/test/java/io/confluent/kafkarest/KafkaRestConfigTest.java
index cc537f2c8b..43f21e1a7e 100644
--- a/kafka-rest/src/test/java/io/confluent/kafkarest/KafkaRestConfigTest.java
+++ b/kafka-rest/src/test/java/io/confluent/kafkarest/KafkaRestConfigTest.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2019 Confluent Inc.
+ *
+ * Licensed under the Confluent Community License (the "License"); you may not use
+ * this file except in compliance with the License. You may obtain a copy of the
+ * License at
+ *
+ * http://www.confluent.io/confluent-community-license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
package io.confluent.kafkarest;
import static io.confluent.kafkarest.KafkaRestConfig.METRICS_REPORTER_CLASSES_CONFIG;
diff --git a/kafka-rest/src/test/java/io/confluent/kafkarest/OpenConfigEntry.java b/kafka-rest/src/test/java/io/confluent/kafkarest/OpenConfigEntry.java
index 1656e67bc1..42452713db 100644
--- a/kafka-rest/src/test/java/io/confluent/kafkarest/OpenConfigEntry.java
+++ b/kafka-rest/src/test/java/io/confluent/kafkarest/OpenConfigEntry.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2021 Confluent Inc.
+ *
+ * Licensed under the Confluent Community License (the "License"); you may not use
+ * this file except in compliance with the License. You may obtain a copy of the
+ * License at
+ *
+ * http://www.confluent.io/confluent-community-license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
package io.confluent.kafkarest;
import static java.util.Objects.requireNonNull;
diff --git a/kafka-rest/src/test/java/io/confluent/kafkarest/TestUtils.java b/kafka-rest/src/test/java/io/confluent/kafkarest/TestUtils.java
index 882f40b004..b2ef5d9f40 100644
--- a/kafka-rest/src/test/java/io/confluent/kafkarest/TestUtils.java
+++ b/kafka-rest/src/test/java/io/confluent/kafkarest/TestUtils.java
@@ -12,6 +12,7 @@
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
+
package io.confluent.kafkarest;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -140,7 +141,8 @@ public static JsonNode jsonTree(String jsonData) {
public static void assertPartitionsEqual(List a, List b) {
assertEquals(a.size(), b.size());
for (int i = 0; i < a.size(); i++) {
- PartitionOffset aOffset = a.get(i), bOffset = b.get(i);
+ PartitionOffset aOffset = a.get(i);
+ PartitionOffset bOffset = b.get(i);
assertEquals(aOffset.getPartition(), bOffset.getPartition());
}
}
@@ -150,7 +152,8 @@ public static void assertPartitionOffsetsEqual(List a, List Map