Skip to content

Commit e4dc787

Browse files
committed
wip: removing the unwanted variables and functions from test codes.
1 parent f9466ed commit e4dc787

File tree

2 files changed

+20
-64
lines changed

2 files changed

+20
-64
lines changed

instrumentation/kafka/kafka-connect-2.6/testing/src/test/java/io/opentelemetry/instrumentation/kafkaconnect/v2_6/MongoKafkaConnectSinkTaskTest.java

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.mongodb.client.MongoCollection;
2020
import com.mongodb.client.MongoDatabase;
2121
import io.restassured.http.ContentType;
22-
import java.io.File;
2322
import java.io.IOException;
2423
import java.net.ServerSocket;
2524
import java.time.Duration;
@@ -61,7 +60,7 @@
6160

6261
@Testcontainers
6362
// Suppressing warnings for test dependencies and deprecated Testcontainers API
64-
@SuppressWarnings({"rawtypes", "unchecked", "deprecation", "unused"})
63+
@SuppressWarnings({"deprecation"})
6564
class MongoKafkaConnectSinkTaskTest {
6665

6766
private static final Logger logger = LoggerFactory.getLogger(MongoKafkaConnectSinkTaskTest.class);
@@ -105,7 +104,6 @@ class MongoKafkaConnectSinkTaskTest {
105104
private static MongoDBContainer mongoDB;
106105
private static int kafkaExposedPort;
107106

108-
private static AdminClient adminClient;
109107

110108
// Static methods
111109

@@ -209,7 +207,6 @@ public static void setup() throws IOException {
209207
throw new IllegalStateException(
210208
"Agent path not found. Make sure the shadowJar task is configured correctly.");
211209
}
212-
File agentFile = new File(agentPath);
213210

214211
kafkaConnect =
215212
new GenericContainer<>("confluentinc/cp-kafka-connect:" + CONFLUENT_VERSION)
@@ -679,14 +676,7 @@ private static void deleteConnectorIfExists() {
679676

680677
@AfterAll
681678
public static void cleanup() {
682-
// Close AdminClient first to release Kafka connections
683-
if (adminClient != null) {
684-
try {
685-
adminClient.close();
686-
} catch (RuntimeException e) {
687-
logger.error("Error closing AdminClient: " + e.getMessage());
688-
}
689-
}
679+
// AdminClient connections are managed locally in methods
690680

691681
// Stop all containers in reverse order of startup to ensure clean shutdown
692682
if (kafkaConnect != null) {
@@ -747,7 +737,6 @@ private static TracingData deserializeAndExtractSpans(String tracesJson, String
747737
assertThat(rootNode.isArray()).as("Traces JSON should be an array").isTrue();
748738

749739
// Extract all spans and organize by type
750-
SpanInfo kafkaProducerSpan = null;
751740
SpanInfo kafkaConnectConsumerSpan = null;
752741
SpanInfo databaseSpan = null;
753742
SpanLinkInfo extractedSpanLink = null;
@@ -790,16 +779,11 @@ private static TracingData deserializeAndExtractSpans(String tracesJson, String
790779
String spanKind = spanNode.get("kind") != null ? spanNode.get("kind").asText() : "";
791780

792781
// Identify spans in our end-to-end flow
793-
if (scopeName.contains("kafka-clients")
794-
&& spanName.contains(expectedTopicName)
795-
&& spanKind.equals("SPAN_KIND_PRODUCER")) {
796-
kafkaProducerSpan =
797-
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind, scopeName);
798-
} else if (scopeName.contains(KAFKA_CONNECT_SCOPE)
782+
if (scopeName.contains(KAFKA_CONNECT_SCOPE)
799783
&& spanName.contains(expectedTopicName)
800784
&& spanKind.equals("SPAN_KIND_CONSUMER")) {
801785
kafkaConnectConsumerSpan =
802-
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind, scopeName);
786+
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind);
803787

804788
// Extract span link information for verification
805789
JsonNode linksArray = spanNode.get("links");
@@ -809,21 +793,20 @@ private static TracingData deserializeAndExtractSpans(String tracesJson, String
809793
firstLink.get("traceId") != null ? firstLink.get("traceId").asText() : "";
810794
String linkedSpanId =
811795
firstLink.get("spanId") != null ? firstLink.get("spanId").asText() : "";
812-
int flags = firstLink.get("flags") != null ? firstLink.get("flags").asInt() : 0;
813796

814-
extractedSpanLink = new SpanLinkInfo(linkedTraceId, linkedSpanId, flags);
797+
extractedSpanLink = new SpanLinkInfo(linkedTraceId, linkedSpanId);
815798
}
816799
} else if (scopeName.contains("mongo") && spanName.contains("testdb.person")) {
817800
databaseSpan =
818-
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind, scopeName);
801+
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind);
819802
}
820803
}
821804
}
822805
}
823806
}
824807

825808
return new TracingData(
826-
kafkaProducerSpan, kafkaConnectConsumerSpan, databaseSpan, extractedSpanLink);
809+
kafkaConnectConsumerSpan, databaseSpan, extractedSpanLink);
827810
}
828811

829812
/** Deserialize traces JSON and extract span information for multi-topic scenarios */
@@ -889,7 +872,7 @@ private static MultiTopicTracingData deserializeAndExtractMultiTopicSpans(
889872

890873
if (containsExpectedTopics) {
891874
kafkaConnectConsumerSpan =
892-
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind, scopeName);
875+
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind);
893876

894877
// Extract span link information for verification
895878
JsonNode linksArray = spanNode.get("links");
@@ -899,14 +882,13 @@ private static MultiTopicTracingData deserializeAndExtractMultiTopicSpans(
899882
firstLink.get("traceId") != null ? firstLink.get("traceId").asText() : "";
900883
String linkedSpanId =
901884
firstLink.get("spanId") != null ? firstLink.get("spanId").asText() : "";
902-
int flags = firstLink.get("flags") != null ? firstLink.get("flags").asInt() : 0;
903885

904-
extractedSpanLink = new SpanLinkInfo(linkedTraceId, linkedSpanId, flags);
886+
extractedSpanLink = new SpanLinkInfo(linkedTraceId, linkedSpanId);
905887
}
906888
}
907889
} else if (scopeName.contains("mongo") && spanName.contains("testdb.person")) {
908890
databaseSpan =
909-
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind, scopeName);
891+
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind);
910892
}
911893
}
912894
}
@@ -932,17 +914,14 @@ private static class MultiTopicTracingData {
932914

933915
/** Helper class to hold all extracted tracing data */
934916
private static class TracingData {
935-
final SpanInfo kafkaProducerSpan;
936917
final SpanInfo kafkaConnectConsumerSpan;
937918
final SpanInfo databaseSpan;
938919
final SpanLinkInfo extractedSpanLink;
939920

940921
TracingData(
941-
SpanInfo kafkaProducerSpan,
942922
SpanInfo kafkaConnectConsumerSpan,
943923
SpanInfo databaseSpan,
944924
SpanLinkInfo extractedSpanLink) {
945-
this.kafkaProducerSpan = kafkaProducerSpan;
946925
this.kafkaConnectConsumerSpan = kafkaConnectConsumerSpan;
947926
this.databaseSpan = databaseSpan;
948927
this.extractedSpanLink = extractedSpanLink;
@@ -953,12 +932,10 @@ private static class TracingData {
953932
private static class SpanLinkInfo {
954933
final String linkedTraceId;
955934
final String linkedSpanId;
956-
final int flags;
957935

958-
SpanLinkInfo(String linkedTraceId, String linkedSpanId, int flags) {
936+
SpanLinkInfo(String linkedTraceId, String linkedSpanId) {
959937
this.linkedTraceId = linkedTraceId;
960938
this.linkedSpanId = linkedSpanId;
961-
this.flags = flags;
962939
}
963940
}
964941

@@ -969,21 +946,18 @@ private static class SpanInfo {
969946
final String spanId;
970947
final String parentSpanId;
971948
final String kind;
972-
final String scope;
973949

974950
SpanInfo(
975951
String name,
976952
String traceId,
977953
String spanId,
978954
String parentSpanId,
979-
String kind,
980-
String scope) {
955+
String kind) {
981956
this.name = name;
982957
this.traceId = traceId;
983958
this.spanId = spanId;
984959
this.parentSpanId = parentSpanId;
985960
this.kind = kind;
986-
this.scope = scope;
987961
}
988962
}
989963
}

instrumentation/kafka/kafka-connect-2.6/testing/src/test/java/io/opentelemetry/instrumentation/kafkaconnect/v2_6/PostgresKafkaConnectSinkTaskTest.java

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
@Testcontainers
6363
// Suppressing warnings for test dependencies and deprecated Testcontainers API
64-
@SuppressWarnings({"deprecation", "unused"})
64+
@SuppressWarnings({"deprecation"})
6565
class PostgresKafkaConnectSinkTaskTest {
6666

6767
private static final Logger logger =
@@ -230,7 +230,6 @@ public static void setup() throws IOException {
230230
throw new IllegalStateException(
231231
"Agent path not found. Make sure the shadowJar task is configured correctly.");
232232
}
233-
File agentFile = new File(agentPath);
234233

235234
kafkaConnect =
236235
new GenericContainer<>("confluentinc/cp-kafka-connect:" + CONFLUENT_VERSION)
@@ -616,7 +615,6 @@ private static TracingData deserializeAndExtractSpans(String tracesJson, String
616615
assertThat(rootNode.isArray()).as("Traces JSON should be an array").isTrue();
617616

618617
// Extract all spans and organize by type
619-
SpanInfo kafkaProducerSpan = null;
620618
SpanInfo kafkaConnectConsumerSpan = null;
621619
SpanInfo databaseSpan = null;
622620
SpanLinkInfo extractedSpanLink = null;
@@ -659,16 +657,11 @@ private static TracingData deserializeAndExtractSpans(String tracesJson, String
659657
String spanKind = spanNode.get("kind") != null ? spanNode.get("kind").asText() : "";
660658

661659
// Identify spans in our end-to-end flow
662-
if (scopeName.contains("kafka-clients")
663-
&& spanName.contains(expectedTopicName)
664-
&& spanKind.equals("SPAN_KIND_PRODUCER")) {
665-
kafkaProducerSpan =
666-
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind, scopeName);
667-
} else if (scopeName.contains("kafka-connect")
660+
if (scopeName.contains("kafka-connect")
668661
&& spanName.contains(expectedTopicName)
669662
&& spanKind.equals("SPAN_KIND_CONSUMER")) {
670663
kafkaConnectConsumerSpan =
671-
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind, scopeName);
664+
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind);
672665

673666
// Extract span link information for verification
674667
JsonNode linksArray = spanNode.get("links");
@@ -678,9 +671,8 @@ private static TracingData deserializeAndExtractSpans(String tracesJson, String
678671
firstLink.get("traceId") != null ? firstLink.get("traceId").asText() : "";
679672
String linkedSpanId =
680673
firstLink.get("spanId") != null ? firstLink.get("spanId").asText() : "";
681-
int flags = firstLink.get("flags") != null ? firstLink.get("flags").asInt() : 0;
682674

683-
extractedSpanLink = new SpanLinkInfo(linkedTraceId, linkedSpanId, flags);
675+
extractedSpanLink = new SpanLinkInfo(linkedTraceId, linkedSpanId);
684676
}
685677
} else if (scopeName.contains("jdbc")
686678
&& (spanName.contains("INSERT")
@@ -689,30 +681,27 @@ private static TracingData deserializeAndExtractSpans(String tracesJson, String
689681
|| spanName.contains("SELECT")
690682
|| spanName.contains(DB_TABLE_PERSON))) {
691683
databaseSpan =
692-
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind, scopeName);
684+
new SpanInfo(spanName, traceId, spanId, parentSpanId, spanKind);
693685
}
694686
}
695687
}
696688
}
697689
}
698690

699691
return new TracingData(
700-
kafkaProducerSpan, kafkaConnectConsumerSpan, databaseSpan, extractedSpanLink);
692+
kafkaConnectConsumerSpan, databaseSpan, extractedSpanLink);
701693
}
702694

703695
// Helper class to hold all tracing data
704696
private static class TracingData {
705-
final SpanInfo kafkaProducerSpan;
706697
final SpanInfo kafkaConnectConsumerSpan;
707698
final SpanInfo databaseSpan;
708699
final SpanLinkInfo extractedSpanLink;
709700

710701
TracingData(
711-
SpanInfo kafkaProducerSpan,
712702
SpanInfo kafkaConnectConsumerSpan,
713703
SpanInfo databaseSpan,
714704
SpanLinkInfo extractedSpanLink) {
715-
this.kafkaProducerSpan = kafkaProducerSpan;
716705
this.kafkaConnectConsumerSpan = kafkaConnectConsumerSpan;
717706
this.databaseSpan = databaseSpan;
718707
this.extractedSpanLink = extractedSpanLink;
@@ -721,39 +710,32 @@ private static class TracingData {
721710

722711
// Helper class to hold span information
723712
private static class SpanInfo {
724-
final String name;
725713
final String traceId;
726714
final String spanId;
727715
final String parentSpanId;
728716
final String kind;
729-
final String scope;
730717

731718
SpanInfo(
732719
String name,
733720
String traceId,
734721
String spanId,
735722
String parentSpanId,
736-
String kind,
737-
String scope) {
738-
this.name = name;
723+
String kind) {
739724
this.traceId = traceId;
740725
this.spanId = spanId;
741726
this.parentSpanId = parentSpanId;
742727
this.kind = kind;
743-
this.scope = scope;
744728
}
745729
}
746730

747731
// Helper class to hold span link information
748732
private static class SpanLinkInfo {
749733
final String linkedTraceId;
750734
final String linkedSpanId;
751-
final int flags;
752735

753-
SpanLinkInfo(String linkedTraceId, String linkedSpanId, int flags) {
736+
SpanLinkInfo(String linkedTraceId, String linkedSpanId) {
754737
this.linkedTraceId = linkedTraceId;
755738
this.linkedSpanId = linkedSpanId;
756-
this.flags = flags;
757739
}
758740
}
759741
}

0 commit comments

Comments
 (0)