Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit b474d3b

Browse files
committed
test fix
1 parent 7d50f13 commit b474d3b

3 files changed

Lines changed: 47 additions & 18 deletions

File tree

google-cloud-spanner/clirr-ignored-differences.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,4 +1062,34 @@
10621062
<className>com/google/cloud/spanner/connection/Connection</className>
10631063
<method>java.lang.Object getConnectionPropertyValue(com.google.cloud.spanner.connection.ConnectionProperty)</method>
10641064
</difference>
1065+
<!-- (Remove since these methods has no usage. CompositeTracer interface is annotated as internal API) -->
1066+
<difference>
1067+
<differenceType>7002</differenceType>
1068+
<className>com/google/cloud/spanner/CompositeTracer</className>
1069+
<method>void recordAFELatency(java.lang.Long)</method>
1070+
</difference>
1071+
<difference>
1072+
<differenceType>7002</differenceType>
1073+
<className>com/google/cloud/spanner/CompositeTracer</className>
1074+
<method>void recordAFELatency(java.lang.Float)</method>
1075+
</difference>
1076+
<difference>
1077+
<differenceType>7002</differenceType>
1078+
<className>com/google/cloud/spanner/CompositeTracer</className>
1079+
<method>void recordAfeHeaderMissingCount(java.lang.Long)</method>
1080+
</difference>
1081+
<difference>
1082+
<differenceType>7002</differenceType>
1083+
<className>com/google/cloud/spanner/CompositeTracer</className>
1084+
<method>void recordGFELatency(java.lang.Long)</method>
1085+
</difference>
1086+
<difference>
1087+
<differenceType>7002</differenceType>
1088+
<className>com/google/cloud/spanner/CompositeTracer</className>
1089+
<method>void recordGFELatency(java.lang.Float)</method>
1090+
</difference><difference>
1091+
<differenceType>7002</differenceType>
1092+
<className>com/google/cloud/spanner/CompositeTracer</className>
1093+
<method>void recordGfeHeaderMissingCount(java.lang.Long)</method>
1094+
</difference>
10651095
</differences>

google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GfeLatencyTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package com.google.cloud.spanner.spi.v1;
1818

1919
import static com.google.cloud.spanner.DisableDefaultMtlsProvider.disableDefaultMtlsProvider;
20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNotNull;
20+
import static org.junit.Assert.*;
2221

2322
import com.google.auth.oauth2.AccessToken;
2423
import com.google.auth.oauth2.OAuth2Credentials;
@@ -55,10 +54,7 @@
5554
import java.util.Random;
5655
import java.util.concurrent.TimeUnit;
5756
import java.util.concurrent.atomic.AtomicInteger;
58-
import org.junit.After;
59-
import org.junit.AfterClass;
60-
import org.junit.BeforeClass;
61-
import org.junit.Test;
57+
import org.junit.*;
6258
import org.junit.runner.RunWith;
6359
import org.junit.runners.JUnit4;
6460

@@ -259,7 +255,7 @@ public void testGfeMissingHeaderCountExecuteStreamingSql() throws InterruptedExc
259255
SpannerRpcViews.SPANNER_GFE_HEADER_MISSING_COUNT_VIEW,
260256
"google.spanner.v1.Spanner/ExecuteStreamingSql",
261257
true);
262-
assertEquals(1, count1);
258+
assertTrue(count1 >= 1);
263259
}
264260

265261
@Test
@@ -270,7 +266,7 @@ public void testGfeMissingHeaderExecuteSql() throws InterruptedException {
270266
long count =
271267
getMetric(
272268
SpannerRpcViews.SPANNER_GFE_HEADER_MISSING_COUNT_VIEW,
273-
"google.spanner.v1.Spanner/ExecuteSql",
269+
"google.spanner.v1.Spanner/Commit",
274270
false);
275271
assertEquals(0, count);
276272

@@ -280,7 +276,7 @@ public void testGfeMissingHeaderExecuteSql() throws InterruptedException {
280276
long count1 =
281277
getMetric(
282278
SpannerRpcViews.SPANNER_GFE_HEADER_MISSING_COUNT_VIEW,
283-
"google.spanner.v1.Spanner/ExecuteSql",
279+
"google.spanner.v1.Spanner/Commit",
284280
true);
285281
assertEquals(1, count1);
286282
}

google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/SpannerRpcMetricsTest.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@
5050
import java.util.Random;
5151
import java.util.concurrent.atomic.AtomicInteger;
5252
import java.util.stream.Collectors;
53-
import org.junit.After;
54-
import org.junit.AfterClass;
55-
import org.junit.BeforeClass;
56-
import org.junit.Test;
53+
import org.junit.*;
5754
import org.junit.runner.RunWith;
5855
import org.junit.runners.JUnit4;
5956

@@ -73,6 +70,7 @@ public class SpannerRpcMetricsTest {
7370
private static DatabaseClient databaseClientNoHeader;
7471
private static String instanceId = "fake-instance";
7572
private static String databaseId = "fake-database";
73+
private static String noHeaderdatabaseId = "fake-database-1";
7674
private static String projectId = "fake-project";
7775
private static AtomicInteger fakeServerTiming = new AtomicInteger(new Random().nextInt(1000) + 1);
7876
private static final Statement SELECT1AND2 =
@@ -183,7 +181,7 @@ public void sendHeaders(Metadata headers) {
183181
createSpannerOptions(addressNoHeader, serverNoHeader).getService();
184182
databaseClientNoHeader =
185183
spannerNoHeaderNoOpenTelemetry.getDatabaseClient(
186-
DatabaseId.of(projectId, instanceId, databaseId));
184+
DatabaseId.of(projectId, instanceId, noHeaderdatabaseId));
187185
}
188186

189187
@AfterClass
@@ -228,7 +226,8 @@ public void testGfeMissingHeaderExecuteSqlWithGlobalOpenTelemetry() throws Inter
228226
long count =
229227
getHeaderLatencyMetric(
230228
getMetricData("spanner/gfe_header_missing_count", inMemoryMetricReaderInjected),
231-
"google.spanner.v1.Spanner/ExecuteSql");
229+
"google.spanner.v1.Spanner/Commit",
230+
databaseId);
232231
assertEquals(0, count);
233232

234233
databaseClientNoHeader
@@ -237,7 +236,8 @@ public void testGfeMissingHeaderExecuteSqlWithGlobalOpenTelemetry() throws Inter
237236
long count1 =
238237
getHeaderLatencyMetric(
239238
getMetricData("spanner/gfe_header_missing_count", inMemoryMetricReader),
240-
"google.spanner.v1.Spanner/ExecuteSql");
239+
"google.spanner.v1.Spanner/Commit",
240+
noHeaderdatabaseId);
241241
assertEquals(1, count1);
242242
}
243243

@@ -273,9 +273,12 @@ private static SpannerOptions createSpannerOptions(InetSocketAddress address, Se
273273
.build();
274274
}
275275

276-
private long getHeaderLatencyMetric(MetricData metricData, String methodName) {
276+
private long getHeaderLatencyMetric(MetricData metricData, String methodName, String databaseId) {
277277
return metricData.getLongSumData().getPoints().stream()
278-
.filter(x -> x.getAttributes().asMap().containsValue(methodName))
278+
.filter(
279+
x ->
280+
x.getAttributes().asMap().containsValue(methodName)
281+
&& x.getAttributes().asMap().containsValue(databaseId))
279282
.findFirst()
280283
.get()
281284
.getValue();

0 commit comments

Comments
 (0)