Skip to content

Commit 1253bdf

Browse files
committed
docs(showcase): add Javadoc and explanatory comments to T3 integration tests
1 parent 37288a8 commit 1253bdf

3 files changed

Lines changed: 134 additions & 0 deletions

File tree

‎java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelT3MetricsExemplar.java‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ void tearDown() {
113113
// F3.1: HTTP M3 metric records T3 span as exemplar
114114
@Test
115115
void testHttpJson_m3ExemplarMatchesT3Span() throws Exception {
116+
// Verifies that for HTTP/JSON, client request duration metrics attach exemplars
117+
// pointing directly to the overall T3 operation span (traceId and spanId match).
116118
ApiTracerFactory compositeTracerFactory = createCompositeTracerFactory();
117119
EchoSettings settings = createEchoSettings(true);
118120
EchoStub stub = createStubWithServiceName(settings, compositeTracerFactory);
@@ -156,6 +158,8 @@ void testHttpJson_m3ExemplarMatchesT3Span() throws Exception {
156158
// F3.2: gRPC M3 metric records T3 span as exemplar
157159
@Test
158160
void testGrpc_m3ExemplarMatchesT3Span() throws Exception {
161+
// Verifies that for gRPC, client request duration metrics attach exemplars
162+
// pointing directly to the overall T3 operation span (traceId and spanId match).
159163
ApiTracerFactory compositeTracerFactory = createCompositeTracerFactory();
160164
EchoSettings settings = createEchoSettings(false);
161165
EchoStub stub = createStubWithServiceName(settings, compositeTracerFactory);
@@ -196,19 +200,37 @@ void testGrpc_m3ExemplarMatchesT3Span() throws Exception {
196200
}
197201
}
198202

203+
/**
204+
* Creates a composite tracer factory combining both OpenTelemetry tracing and metrics factories.
205+
*
206+
* @return the configured {@link CompositeTracerFactory}
207+
*/
199208
private CompositeTracerFactory createCompositeTracerFactory() {
200209
OpenTelemetryTracingFactory tracingFactory = new OpenTelemetryTracingFactory(openTelemetrySdk);
201210
OpenTelemetryMetricsFactory metricsFactory = new OpenTelemetryMetricsFactory(openTelemetrySdk);
202211
return new CompositeTracerFactory(Arrays.asList(tracingFactory, metricsFactory));
203212
}
204213

214+
/**
215+
* Waits until the in-memory span exporter records at least {@code minSpans} completed spans.
216+
*
217+
* @param minSpans the minimum number of spans expected
218+
* @return the list of completed {@link SpanData} items
219+
*/
205220
private List<SpanData> waitAndCollectSpans(int minSpans) {
206221
Awaitility.await()
207222
.atMost(Duration.ofSeconds(5))
208223
.until(() -> spanExporter.getFinishedSpanItems().size() >= minSpans);
209224
return spanExporter.getFinishedSpanItems();
210225
}
211226

227+
/**
228+
* Constructs {@link EchoSettings} configured for the local Showcase test server.
229+
*
230+
* @param isHttpJson {@code true} for HTTP/JSON transport; {@code false} for gRPC transport
231+
* @return the configured {@link EchoSettings}
232+
* @throws Exception if transport provider initialization fails
233+
*/
212234
private EchoSettings createEchoSettings(boolean isHttpJson) throws Exception {
213235
if (isHttpJson) {
214236
return EchoSettings.newHttpJsonBuilder()
@@ -231,6 +253,14 @@ private EchoSettings createEchoSettings(boolean isHttpJson) throws Exception {
231253
}
232254
}
233255

256+
/**
257+
* Instantiates an {@link EchoStub} with custom service name and tracer factory.
258+
*
259+
* @param settings the client settings to base the stub on
260+
* @param tracerFactory the tracer factory to register with the stub
261+
* @return the initialized {@link EchoStub}
262+
* @throws IOException if stub creation fails
263+
*/
234264
private EchoStub createStubWithServiceName(EchoSettings settings, ApiTracerFactory tracerFactory)
235265
throws IOException {
236266
EchoStubSettings.Builder builder =
@@ -239,7 +269,14 @@ private EchoStub createStubWithServiceName(EchoSettings settings, ApiTracerFacto
239269
return new ExtendedEchoStubSettings(builder).createStub();
240270
}
241271

272+
/** Extended {@link EchoStubSettings} that overrides {@link #getServiceName()} for testing. */
242273
private static class ExtendedEchoStubSettings extends EchoStubSettings {
274+
/**
275+
* Constructs settings wrapping the specified builder.
276+
*
277+
* @param builder the settings builder
278+
* @throws IOException if base settings construction fails
279+
*/
243280
protected ExtendedEchoStubSettings(EchoStubSettings.Builder builder) throws IOException {
244281
super(builder);
245282
}

‎java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelT3T4Hierarchy.java‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ void tearDown() {
113113
// F2.1: HTTP T3/T4 retry succeeds (1 T3 span, 2 T4 child spans)
114114
@Test
115115
void testHttpJson_retrySucceeds() throws Exception {
116+
// Verifies HTTP/JSON retry behavior: transient failure on attempt 0 is retried and succeeds on
117+
// attempt 1.
118+
// Asserts:
119+
// 1. Exactly one overall INTERNAL operation span (T3).
120+
// 2. Both attempt spans (T4) have parent_span_id == T3.span_id.
121+
// 3. T3 operation span aggregates the successful status (OK) and 200 HTTP code.
116122
OpenTelemetryTracingFactory tracingFactory = new OpenTelemetryTracingFactory(openTelemetrySdk);
117123

118124
// Sequence: attempt 1 -> UNAVAILABLE, attempt 2 -> OK
@@ -203,6 +209,11 @@ void testHttpJson_retrySucceeds() throws Exception {
203209
// F2.2: HTTP T3/T4 retries exhausted
204210
@Test
205211
void testHttpJson_retriesExhausted() throws Exception {
212+
// Verifies HTTP/JSON behavior when retries are exhausted after repeated failures.
213+
// Asserts:
214+
// 1. Exactly one overall INTERNAL operation span (T3).
215+
// 2. All attempt spans (T4) are linked to the T3 span as parent.
216+
// 3. T3 operation span aggregates ERROR status, 503 HTTP status, and UNAVAILABLE RPC status.
206217
OpenTelemetryTracingFactory tracingFactory = new OpenTelemetryTracingFactory(openTelemetrySdk);
207218

208219
// Sequence: 3 UNAVAILABLE responses
@@ -300,6 +311,12 @@ void testHttpJson_retriesExhausted() throws Exception {
300311
// F2.3: gRPC T3/T4 retry succeeds
301312
@Test
302313
void testGrpc_retrySucceeds() throws Exception {
314+
// Verifies gRPC retry behavior: transient failure on attempt 0 is retried and succeeds on
315+
// attempt 1.
316+
// Asserts:
317+
// 1. Exactly one overall INTERNAL operation span (T3).
318+
// 2. Both attempt spans (T4) have parent_span_id == T3.span_id.
319+
// 3. T3 operation span aggregates the successful status (OK).
303320
OpenTelemetryTracingFactory tracingFactory = new OpenTelemetryTracingFactory(openTelemetrySdk);
304321

305322
// Sequence: attempt 1 -> UNAVAILABLE, attempt 2 -> OK
@@ -378,6 +395,11 @@ void testGrpc_retrySucceeds() throws Exception {
378395
// F2.4: gRPC T3/T4 retries exhausted
379396
@Test
380397
void testGrpc_retriesExhausted() throws Exception {
398+
// Verifies gRPC behavior when retries are exhausted after repeated failures.
399+
// Asserts:
400+
// 1. Exactly one overall INTERNAL operation span (T3).
401+
// 2. All attempt spans (T4) are linked to the T3 span as parent.
402+
// 3. T3 operation span aggregates ERROR status and UNAVAILABLE RPC status.
381403
OpenTelemetryTracingFactory tracingFactory = new OpenTelemetryTracingFactory(openTelemetrySdk);
382404

383405
// Sequence: 3 UNAVAILABLE responses
@@ -466,13 +488,29 @@ void testGrpc_retriesExhausted() throws Exception {
466488
}
467489
}
468490

491+
/**
492+
* Waits until the in-memory span exporter records at least {@code minSpans} completed spans.
493+
*
494+
* @param minSpans the minimum number of spans expected
495+
* @return the list of completed {@link SpanData} items
496+
*/
469497
private List<SpanData> waitAndCollectSpans(int minSpans) {
470498
Awaitility.await()
471499
.atMost(Duration.ofSeconds(5))
472500
.until(() -> spanExporter.getFinishedSpanItems().size() >= minSpans);
473501
return spanExporter.getFinishedSpanItems();
474502
}
475503

504+
/**
505+
* Constructs a {@link SequenceServiceClient} configured with custom retry settings and tracing.
506+
*
507+
* @param isHttpJson {@code true} for HTTP/JSON transport; {@code false} for gRPC transport
508+
* @param tracingFactory the tracer factory to register with the client
509+
* @param retrySettings the custom retry settings to apply to attemptSequence
510+
* @param retryableCodes the set of status codes considered retryable
511+
* @return the configured {@link SequenceServiceClient}
512+
* @throws Exception if client initialization fails
513+
*/
476514
private SequenceServiceClient createSequenceClient(
477515
boolean isHttpJson,
478516
OpenTelemetryTracingFactory tracingFactory,
@@ -514,7 +552,17 @@ private SequenceServiceClient createSequenceClient(
514552
new ExtendedSequenceServiceStubSettings(stubSettingsBuilder).createStub());
515553
}
516554

555+
/**
556+
* Extended {@link SequenceServiceStubSettings} that overrides {@link #getServiceName()} for
557+
* testing.
558+
*/
517559
private static class ExtendedSequenceServiceStubSettings extends SequenceServiceStubSettings {
560+
/**
561+
* Constructs settings wrapping the specified builder.
562+
*
563+
* @param builder the settings builder
564+
* @throws IOException if base settings construction fails
565+
*/
518566
protected ExtendedSequenceServiceStubSettings(SequenceServiceStubSettings.Builder builder)
519567
throws IOException {
520568
super(builder);

‎java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelT3Tracing.java‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ void tearDown() {
9797
// F1.1: HTTP no traces emitted unless enabled.
9898
@Test
9999
void testTracingDisabled_httpjson() throws Exception {
100+
// Verifies that when OpenTelemetry tracing is not configured on the client settings,
101+
// no spans are recorded for HTTP/JSON calls.
100102
EchoSettings settings = createEchoSettings(true);
101103
try (EchoClient client = EchoClient.create(settings)) {
102104
client.echo(EchoRequest.newBuilder().setContent("test-f1-1").build());
@@ -108,6 +110,10 @@ void testTracingDisabled_httpjson() throws Exception {
108110
// F1.2: HTTP T3 success case name and attributes conform to requirements.
109111
@Test
110112
void testT3Success_httpjson() throws Exception {
113+
// Verifies that a successful HTTP/JSON call produces a T3 INTERNAL span with proper
114+
// semantic convention attributes (http rpc.system, server.address, server.port, 200
115+
// http.response.status_code,
116+
// url.template) and UNSET status.
111117
OpenTelemetryTracingFactory tracingFactory = new OpenTelemetryTracingFactory(openTelemetrySdk);
112118
EchoSettings settings = createEchoSettings(true);
113119
EchoStub stub = createStubWithServiceName(settings, tracingFactory);
@@ -170,6 +176,8 @@ void testT3Success_httpjson() throws Exception {
170176
// F1.3: HTTP T3 server failures case name and attributes conform to requirements.
171177
@Test
172178
void testT3ServerFailure_httpjson() throws Exception {
179+
// Verifies that a server-side error on HTTP/JSON produces a T3 INTERNAL span with ERROR status,
180+
// 400 http.response.status_code, and error.type.
173181
OpenTelemetryTracingFactory tracingFactory = new OpenTelemetryTracingFactory(openTelemetrySdk);
174182
EchoSettings settings = createEchoSettings(true);
175183
EchoStub stub = createStubWithServiceName(settings, tracingFactory);
@@ -218,6 +226,9 @@ void testT3ServerFailure_httpjson() throws Exception {
218226
// F1.4: HTTP T3 client failures case name and attributes conform to requirements.
219227
@Test
220228
void testT3ClientFailure_httpjson() throws Exception {
229+
// Verifies that a client-side timeout on HTTP/JSON produces a T3 INTERNAL span with ERROR
230+
// status,
231+
// 504 http.response.status_code, and error.type.
221232
OpenTelemetryTracingFactory tracingFactory = new OpenTelemetryTracingFactory(openTelemetrySdk);
222233
EchoSettings settings = createEchoSettings(true);
223234
// Configure 1000ms timeout for blockCallable
@@ -269,6 +280,8 @@ void testT3ClientFailure_httpjson() throws Exception {
269280
// F1.5: gRPC no traces emitted unless enabled.
270281
@Test
271282
void testTracingDisabled_grpc() throws Exception {
283+
// Verifies that when OpenTelemetry tracing is not configured on the client settings,
284+
// no spans are recorded for gRPC calls.
272285
EchoSettings settings = createEchoSettings(false);
273286
try (EchoClient client = EchoClient.create(settings)) {
274287
client.echo(EchoRequest.newBuilder().setContent("test-f1-5").build());
@@ -280,6 +293,10 @@ void testTracingDisabled_grpc() throws Exception {
280293
// F1.6: gRPC T3 success case name and attributes conform to requirements.
281294
@Test
282295
void testT3Success_grpc() throws Exception {
296+
// Verifies that a successful gRPC call produces a T3 INTERNAL span with proper
297+
// semantic convention attributes (grpc rpc.system, server.address, server.port, OK
298+
// rpc.response.status_code)
299+
// and UNSET status.
283300
OpenTelemetryTracingFactory tracingFactory = new OpenTelemetryTracingFactory(openTelemetrySdk);
284301
EchoSettings settings = createEchoSettings(false);
285302
EchoStub stub = createStubWithServiceName(settings, tracingFactory);
@@ -338,6 +355,8 @@ void testT3Success_grpc() throws Exception {
338355
// F1.7: gRPC T3 server failures case name and attributes conform to requirements.
339356
@Test
340357
void testT3ServerFailure_grpc() throws Exception {
358+
// Verifies that a server-side error on gRPC produces a T3 INTERNAL span with ERROR status,
359+
// INVALID_ARGUMENT rpc.response.status_code, and error.type.
341360
OpenTelemetryTracingFactory tracingFactory = new OpenTelemetryTracingFactory(openTelemetrySdk);
342361
EchoSettings settings = createEchoSettings(false);
343362
EchoStub stub = createStubWithServiceName(settings, tracingFactory);
@@ -387,6 +406,8 @@ void testT3ServerFailure_grpc() throws Exception {
387406
// F1.8: gRPC T3 client failures case name and attributes conform to requirements.
388407
@Test
389408
void testT3ClientFailure_grpc() throws Exception {
409+
// Verifies that a client-side timeout on gRPC produces a T3 INTERNAL span with ERROR status,
410+
// DEADLINE_EXCEEDED rpc.response.status_code, and error.type.
390411
OpenTelemetryTracingFactory tracingFactory = new OpenTelemetryTracingFactory(openTelemetrySdk);
391412
EchoSettings settings = createEchoSettings(false);
392413
// Configure 1000ms timeout for blockCallable
@@ -435,13 +456,26 @@ void testT3ClientFailure_grpc() throws Exception {
435456
}
436457
}
437458

459+
/**
460+
* Waits until the in-memory span exporter records at least {@code minSpans} completed spans.
461+
*
462+
* @param minSpans the minimum number of spans expected
463+
* @return the list of completed {@link SpanData} items
464+
*/
438465
private List<SpanData> waitAndCollectSpans(int minSpans) {
439466
Awaitility.await()
440467
.atMost(Duration.ofSeconds(5))
441468
.until(() -> spanExporter.getFinishedSpanItems().size() >= minSpans);
442469
return spanExporter.getFinishedSpanItems();
443470
}
444471

472+
/**
473+
* Constructs {@link EchoSettings} configured for the local Showcase test server.
474+
*
475+
* @param isHttpJson {@code true} for HTTP/JSON transport; {@code false} for gRPC transport
476+
* @return the configured {@link EchoSettings}
477+
* @throws Exception if transport provider initialization fails
478+
*/
445479
private EchoSettings createEchoSettings(boolean isHttpJson) throws Exception {
446480
if (isHttpJson) {
447481
return EchoSettings.newHttpJsonBuilder()
@@ -464,6 +498,14 @@ private EchoSettings createEchoSettings(boolean isHttpJson) throws Exception {
464498
}
465499
}
466500

501+
/**
502+
* Instantiates an {@link EchoStub} with custom service name and tracer factory.
503+
*
504+
* @param settings the client settings to base the stub on
505+
* @param tracingFactory the tracer factory to register with the stub
506+
* @return the initialized {@link EchoStub}
507+
* @throws IOException if stub creation fails
508+
*/
467509
private EchoStub createStubWithServiceName(
468510
EchoSettings settings, OpenTelemetryTracingFactory tracingFactory) throws IOException {
469511
EchoStubSettings.Builder builder =
@@ -472,7 +514,14 @@ private EchoStub createStubWithServiceName(
472514
return new ExtendedEchoStubSettings(builder).createStub();
473515
}
474516

517+
/** Extended {@link EchoStubSettings} that overrides {@link #getServiceName()} for testing. */
475518
private static class ExtendedEchoStubSettings extends EchoStubSettings {
519+
/**
520+
* Constructs settings wrapping the specified builder.
521+
*
522+
* @param builder the settings builder
523+
* @throws IOException if base settings construction fails
524+
*/
476525
protected ExtendedEchoStubSettings(EchoStubSettings.Builder builder) throws IOException {
477526
super(builder);
478527
}

0 commit comments

Comments
 (0)