|
| 1 | +/* |
| 2 | + * Copyright 2022 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.google.cloud.bigtable.data.v2.it; |
| 17 | + |
| 18 | +import static com.google.common.truth.Truth.assertThat; |
| 19 | +import static com.google.common.truth.TruthJUnit.assume; |
| 20 | + |
| 21 | +import com.google.api.core.ApiFuture; |
| 22 | +import com.google.api.gax.rpc.NotFoundException; |
| 23 | +import com.google.cloud.bigtable.admin.v2.models.Cluster; |
| 24 | +import com.google.cloud.bigtable.data.v2.models.RowMutation; |
| 25 | +import com.google.cloud.bigtable.stats.BuiltinViews; |
| 26 | +import com.google.cloud.bigtable.stats.StatsWrapper; |
| 27 | +import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv; |
| 28 | +import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; |
| 29 | +import java.util.List; |
| 30 | +import java.util.UUID; |
| 31 | +import java.util.concurrent.TimeUnit; |
| 32 | +import org.junit.BeforeClass; |
| 33 | +import org.junit.ClassRule; |
| 34 | +import org.junit.Test; |
| 35 | + |
| 36 | +public class UnaryMetricsMetadataIT { |
| 37 | + @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); |
| 38 | + |
| 39 | + @BeforeClass |
| 40 | + public static void setUpClass() { |
| 41 | + assume() |
| 42 | + .withMessage("UnaryMetricsMetadataIT is not supported on Emulator") |
| 43 | + .that(testEnvRule.env()) |
| 44 | + .isNotInstanceOf(EmulatorEnv.class); |
| 45 | + BuiltinViews.registerBigtableBuiltinViews(); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testSuccess() throws Exception { |
| 50 | + String rowKey = UUID.randomUUID().toString(); |
| 51 | + String familyId = testEnvRule.env().getFamilyId(); |
| 52 | + |
| 53 | + ApiFuture<Void> future = |
| 54 | + testEnvRule |
| 55 | + .env() |
| 56 | + .getDataClient() |
| 57 | + .mutateRowCallable() |
| 58 | + .futureCall( |
| 59 | + RowMutation.create(testEnvRule.env().getTableId(), rowKey) |
| 60 | + .setCell(familyId, "q", "myVal")); |
| 61 | + |
| 62 | + future.get(1, TimeUnit.MINUTES); |
| 63 | + |
| 64 | + ApiFuture<List<Cluster>> clustersFuture = |
| 65 | + testEnvRule |
| 66 | + .env() |
| 67 | + .getInstanceAdminClient() |
| 68 | + .listClustersAsync(testEnvRule.env().getInstanceId()); |
| 69 | + List<Cluster> clusters = clustersFuture.get(1, TimeUnit.MINUTES); |
| 70 | + |
| 71 | + // give opencensus some time to populate view data |
| 72 | + Thread.sleep(100); |
| 73 | + |
| 74 | + List<String> tagValueStrings = StatsWrapper.getOperationLatencyViewTagValueStrings(); |
| 75 | + assertThat(tagValueStrings).contains(clusters.get(0).getZone()); |
| 76 | + assertThat(tagValueStrings).contains(clusters.get(0).getId()); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void testFailure() throws InterruptedException { |
| 81 | + String rowKey = UUID.randomUUID().toString(); |
| 82 | + String familyId = testEnvRule.env().getFamilyId(); |
| 83 | + |
| 84 | + try { |
| 85 | + testEnvRule |
| 86 | + .env() |
| 87 | + .getDataClient() |
| 88 | + .mutateRowCallable() |
| 89 | + .call(RowMutation.create("non-exist-table", rowKey).setCell(familyId, "q", "myVal")); |
| 90 | + } catch (NotFoundException e) { |
| 91 | + } |
| 92 | + |
| 93 | + // give opencensus some time to populate view data |
| 94 | + Thread.sleep(100); |
| 95 | + |
| 96 | + List<String> tagValueStrings = StatsWrapper.getOperationLatencyViewTagValueStrings(); |
| 97 | + assertThat(tagValueStrings).contains("undefined"); |
| 98 | + assertThat(tagValueStrings).contains("undefined"); |
| 99 | + } |
| 100 | +} |
0 commit comments