Skip to content

Commit 6920311

Browse files
committed
test(datastore): parameterize metrics IT to use both gRPC and HTTP transports
1 parent c9f5e00 commit 6920311

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

java-datastore/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ITDatastoreBuiltInAndCustomMetrics.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
import io.opentelemetry.sdk.metrics.data.MetricData;
3030
import io.opentelemetry.sdk.metrics.data.PointData;
3131
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
32+
import java.util.Arrays;
3233
import java.util.Collection;
3334
import java.util.Optional;
3435
import org.junit.After;
3536
import org.junit.Before;
3637
import org.junit.Test;
3738
import org.junit.runner.RunWith;
38-
import org.junit.runners.JUnit4;
39+
import org.junit.runners.Parameterized;
3940

4041
/**
4142
* Integration test that verifies both the default built-in Cloud Monitoring export path and a
@@ -82,14 +83,25 @@
8283
*
8384
* <p>Data may take up to 60 seconds (one periodic flush interval) to appear.
8485
*/
85-
@RunWith(JUnit4.class)
86+
@RunWith(Parameterized.class)
8687
@SuppressWarnings("checkstyle:abbreviationaswordinname")
8788
public class ITDatastoreBuiltInAndCustomMetrics {
8889

8990
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
9091
private static final String DATABASE_ID =
9192
System.getenv().getOrDefault("DATASTORE_DATABASE_ID", "");
9293

94+
private final boolean useGrpc;
95+
96+
public ITDatastoreBuiltInAndCustomMetrics(boolean useGrpc) {
97+
this.useGrpc = useGrpc;
98+
}
99+
100+
@Parameterized.Parameters(name = "useGrpc: {0}")
101+
public static Iterable<Object[]> data() {
102+
return Arrays.asList(new Object[][] {{true}, {false}});
103+
}
104+
93105
/**
94106
* Delta temporality is used so that each {@link InMemoryMetricReader#collectAllMetrics()} call
95107
* returns only the new data points recorded since the last collection, and automatically resets
@@ -122,7 +134,7 @@ public void setUp() {
122134
//
123135
// The resulting DatastoreMetricsRecorder will be a CompositeDatastoreMetricsRecorder that
124136
// fans out all recording calls to both backends simultaneously.
125-
DatastoreOptions options =
137+
DatastoreOptions.Builder builder =
126138
DatastoreOptions.newBuilder()
127139
.setProjectId(PROJECT_ID)
128140
.setDatabaseId(DATABASE_ID)
@@ -131,9 +143,15 @@ public void setUp() {
131143
.setMetricsEnabled(true)
132144
.setOpenTelemetry(customOtel)
133145
.setExportBuiltinMetricsToGoogleCloudMonitoring(true)
134-
.build())
135-
.build();
136-
datastore = options.getService();
146+
.build());
147+
148+
if (useGrpc) {
149+
builder.setTransportOptions(DatastoreOptions.getDefaultGrpcTransportOptions());
150+
} else {
151+
builder.setTransportOptions(DatastoreOptions.getDefaultHttpTransportOptions());
152+
}
153+
154+
datastore = builder.build().getService();
137155

138156
// Drain any metrics emitted during client initialisation so test assertions only capture
139157
// data from the operations performed within the test method itself.

0 commit comments

Comments
 (0)