rajeshkumarchandolu commented on code in PR #11852:
URL: https://github.com/apache/ozone/pull/11852#discussion_r4452843598


##########
hadoop-hdds/common/src/test/java/org/apache/hadoop/hdds/tracing/TestSpanCollector.java:
##########
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdds.tracing;
+
+import static io.opentelemetry.api.common.AttributeKey.booleanKey;
+import static io.opentelemetry.api.common.AttributeKey.longKey;
+import static io.opentelemetry.api.common.AttributeKey.stringKey;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import io.opentelemetry.api.GlobalOpenTelemetry;
+import io.opentelemetry.api.common.AttributeKey;
+import io.opentelemetry.api.trace.SpanKind;
+import io.opentelemetry.api.trace.StatusCode;
+import io.opentelemetry.context.Context;
+import io.opentelemetry.sdk.OpenTelemetrySdk;
+import io.opentelemetry.sdk.trace.ReadWriteSpan;
+import io.opentelemetry.sdk.trace.ReadableSpan;
+import io.opentelemetry.sdk.trace.SdkTracerProvider;
+import io.opentelemetry.sdk.trace.SpanProcessor;
+import io.opentelemetry.sdk.trace.data.SpanData;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.stream.Collectors;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+
+/**
+ * {@link SpanProcessor} that collects ended spans in memory, so tests can 
assert on them.
+ */
+public final class TestSpanCollector implements SpanProcessor, AutoCloseable {
+  private final List<ReadableSpan> spans = new CopyOnWriteArrayList<>();
+
+  private TestSpanCollector() {
+  }
+
+  /** Registers a collecting SDK as the global OpenTelemetry and initializes 
Ozone tracing with it. */
+  public static TestSpanCollector install(String serviceName) {
+    TracingUtil.shutdownTracing();
+    GlobalOpenTelemetry.resetForTest();
+    TestSpanCollector collector = new TestSpanCollector();
+    GlobalOpenTelemetry.set(OpenTelemetrySdk.builder()
+        
.setTracerProvider(SdkTracerProvider.builder().addSpanProcessor(collector).build())
+        .build());
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.setBoolean("ozone.tracing.enabled", true);
+    TracingUtil.initTracing(serviceName, conf);
+    return collector;
+  }
+
+  public List<ReadableSpan> getSpans() {
+    return spans;
+  }
+
+  public List<ReadableSpan> named(String name) {
+    return spans.stream().filter(span -> 
span.getName().equals(name)).collect(Collectors.toList());
+  }
+
+  /** Fails unless exactly one ended span is named {@code spanName}. */
+  public void assertSingleSpan(String spanName) {

Review Comment:
   onlyspan is private right and everyone uses it right .so just a public 
assertion helper method with a meaningful thing. 
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to