-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add integration tests and fix unit tests
- Loading branch information
Showing
8 changed files
with
267 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
...loud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetadataIT.java
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
...gtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.google.cloud.bigtable.data.v2.it; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static com.google.common.truth.TruthJUnit.assume; | ||
|
||
import com.google.api.core.ApiFuture; | ||
import com.google.api.gax.rpc.NotFoundException; | ||
import com.google.cloud.bigtable.admin.v2.models.Cluster; | ||
import com.google.cloud.bigtable.data.v2.models.Query; | ||
import com.google.cloud.bigtable.data.v2.models.Row; | ||
import com.google.cloud.bigtable.stats.BuiltinViews; | ||
import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv; | ||
import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; | ||
import com.google.common.collect.Lists; | ||
import io.opencensus.stats.Stats; | ||
import io.opencensus.stats.View; | ||
import io.opencensus.stats.ViewData; | ||
import io.opencensus.stats.ViewManager; | ||
import io.opencensus.tags.TagValue; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
public class StreamingMetricsMetadataIT { | ||
@ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); | ||
|
||
@BeforeClass | ||
public static void setUpClass() { | ||
assume() | ||
.withMessage("StreamingMetricsMetadataIT is not supported on Emulator") | ||
.that(testEnvRule.env()) | ||
.isNotInstanceOf(EmulatorEnv.class); | ||
BuiltinViews.registerBigtableBuiltinViews(); | ||
} | ||
|
||
@Test | ||
public void testSuccess() throws Exception { | ||
String prefix = UUID.randomUUID().toString(); | ||
String uniqueKey = prefix + "-read"; | ||
|
||
Query query = Query.create(testEnvRule.env().getTableId()).rowKey(uniqueKey); | ||
ArrayList<Row> rows = Lists.newArrayList(testEnvRule.env().getDataClient().readRows(query)); | ||
|
||
// give opencensus some time to populate view data | ||
Thread.sleep(100); | ||
|
||
ViewManager viewManager = Stats.getViewManager(); | ||
ViewData viewData = | ||
viewManager.getView( | ||
View.Name.create("bigtable.googleapis.com/internal/client/operation_latencies")); | ||
|
||
List<TagValue> tagValues = | ||
viewData.getAggregationMap().entrySet().stream() | ||
.map(Map.Entry::getKey) | ||
.flatMap(x -> x.stream()) | ||
.collect(Collectors.toCollection(ArrayList::new)); | ||
|
||
ApiFuture<List<Cluster>> clustersFuture = | ||
testEnvRule | ||
.env() | ||
.getInstanceAdminClient() | ||
.listClustersAsync(testEnvRule.env().getInstanceId()); | ||
List<Cluster> clusters = clustersFuture.get(1, TimeUnit.MINUTES); | ||
|
||
assertThat(tagValues).contains(TagValue.create(clusters.get(0).getZone())); | ||
assertThat(tagValues).contains(TagValue.create(clusters.get(0).getId())); | ||
} | ||
|
||
@Test | ||
public void testFailure() throws InterruptedException { | ||
String prefix = UUID.randomUUID().toString(); | ||
String uniqueKey = prefix + "-read"; | ||
|
||
Query query = Query.create("non-exist-table"); | ||
try { | ||
Lists.newArrayList(testEnvRule.env().getDataClient().readRows(query)); | ||
} catch (NotFoundException e) { | ||
} | ||
|
||
// give opencensus some time to populate view data | ||
Thread.sleep(100); | ||
|
||
ViewManager viewManager = Stats.getViewManager(); | ||
ViewData viewData = | ||
viewManager.getView( | ||
View.Name.create("bigtable.googleapis.com/internal/client/operation_latencies")); | ||
|
||
List<TagValue> tagValues = | ||
viewData.getAggregationMap().entrySet().stream() | ||
.map(Map.Entry::getKey) | ||
.flatMap(x -> x.stream()) | ||
.collect(Collectors.toCollection(ArrayList::new)); | ||
|
||
assertThat(tagValues).contains(TagValue.create("undefined")); | ||
assertThat(tagValues).contains(TagValue.create("undefined")); | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
...d-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/UnaryMetricsMetadataIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 com.google.cloud.bigtable.data.v2.it; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static com.google.common.truth.TruthJUnit.assume; | ||
|
||
import com.google.api.core.ApiFuture; | ||
import com.google.api.gax.rpc.NotFoundException; | ||
import com.google.cloud.bigtable.admin.v2.models.Cluster; | ||
import com.google.cloud.bigtable.data.v2.models.RowMutation; | ||
import com.google.cloud.bigtable.stats.BuiltinViews; | ||
import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv; | ||
import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; | ||
import io.opencensus.stats.Stats; | ||
import io.opencensus.stats.View; | ||
import io.opencensus.stats.ViewData; | ||
import io.opencensus.stats.ViewManager; | ||
import io.opencensus.tags.TagValue; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
@Ignore | ||
public class UnaryMetricsMetadataIT { | ||
@ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); | ||
|
||
@BeforeClass | ||
public static void setUpClass() { | ||
assume() | ||
.withMessage("UnaryMetricsMetadataIT is not supported on Emulator") | ||
.that(testEnvRule.env()) | ||
.isNotInstanceOf(EmulatorEnv.class); | ||
|
||
BuiltinViews.registerBigtableBuiltinViews(); | ||
} | ||
|
||
@Test | ||
public void testSuccess() throws Exception { | ||
String rowKey = UUID.randomUUID().toString(); | ||
String familyId = testEnvRule.env().getFamilyId(); | ||
|
||
ApiFuture<Void> future = | ||
testEnvRule | ||
.env() | ||
.getDataClient() | ||
.mutateRowCallable() | ||
.futureCall( | ||
RowMutation.create(testEnvRule.env().getTableId(), rowKey) | ||
.setCell(familyId, "q", "myVal")); | ||
|
||
future.get(1, TimeUnit.MINUTES); | ||
|
||
// give opencensus some time to populate view data | ||
Thread.sleep(100); | ||
|
||
ViewManager viewManager = Stats.getViewManager(); | ||
ViewData viewData = | ||
viewManager.getView( | ||
View.Name.create("bigtable.googleapis.com/internal/client/operation_latencies")); | ||
|
||
List<TagValue> tagValues = | ||
viewData.getAggregationMap().entrySet().stream() | ||
.map(Map.Entry::getKey) | ||
.flatMap(x -> x.stream()) | ||
.collect(Collectors.toCollection(ArrayList::new)); | ||
|
||
ApiFuture<List<Cluster>> clustersFuture = | ||
testEnvRule | ||
.env() | ||
.getInstanceAdminClient() | ||
.listClustersAsync(testEnvRule.env().getInstanceId()); | ||
List<Cluster> clusters = clustersFuture.get(1, TimeUnit.MINUTES); | ||
|
||
assertThat(tagValues).contains(TagValue.create(clusters.get(0).getZone())); | ||
assertThat(tagValues).contains(TagValue.create(clusters.get(0).getId())); | ||
} | ||
|
||
@Test | ||
public void testFailure() throws InterruptedException { | ||
String rowKey = UUID.randomUUID().toString(); | ||
String familyId = testEnvRule.env().getFamilyId(); | ||
|
||
try { | ||
testEnvRule | ||
.env() | ||
.getDataClient() | ||
.mutateRowCallable() | ||
.call(RowMutation.create("non-exist-table", rowKey).setCell(familyId, "q", "myVal")); | ||
} catch (NotFoundException e) { | ||
} | ||
|
||
// give opencensus some time to populate view data | ||
Thread.sleep(100); | ||
|
||
ViewManager viewManager = Stats.getViewManager(); | ||
ViewData viewData = | ||
viewManager.getView( | ||
View.Name.create("bigtable.googleapis.com/internal/client/operation_latencies")); | ||
|
||
List<TagValue> tagValues = | ||
viewData.getAggregationMap().entrySet().stream() | ||
.map(Map.Entry::getKey) | ||
.flatMap(x -> x.stream()) | ||
.collect(Collectors.toCollection(ArrayList::new)); | ||
|
||
assertThat(tagValues).contains(TagValue.create("undefined")); | ||
assertThat(tagValues).contains(TagValue.create("undefined")); | ||
} | ||
} |
Oops, something went wrong.