|
18 | 18 | import static com.google.common.truth.Truth.assertThat;
|
19 | 19 |
|
20 | 20 | import com.google.api.gax.core.CredentialsProvider;
|
| 21 | +import com.google.api.gax.retrying.RetrySettings; |
21 | 22 | import com.google.api.gax.rpc.StatusCode.Code;
|
| 23 | +import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStubSettings; |
22 | 24 | import java.io.IOException;
|
| 25 | +import java.lang.reflect.Field; |
| 26 | +import java.lang.reflect.Modifier; |
23 | 27 | import org.junit.Test;
|
24 | 28 | import org.junit.runner.RunWith;
|
25 | 29 | import org.junit.runners.JUnit4;
|
26 | 30 | import org.mockito.Mockito;
|
| 31 | +import org.threeten.bp.Duration; |
27 | 32 |
|
28 | 33 | @RunWith(JUnit4.class)
|
29 | 34 | public class BigtableTableAdminSettingsTest {
|
@@ -97,4 +102,83 @@ public void testStubSettings() throws IOException {
|
97 | 102 | .getRetryableCodes())
|
98 | 103 | .containsExactly(Code.INVALID_ARGUMENT);
|
99 | 104 | }
|
| 105 | + |
| 106 | + static final String[] SETTINGS_LIST = { |
| 107 | + "createTableSettings", |
| 108 | + "createTableFromSnapshotSettings", |
| 109 | + "createTableFromSnapshotOperationSettings", |
| 110 | + "listTablesSettings", |
| 111 | + "getTableSettings", |
| 112 | + "deleteTableSettings", |
| 113 | + "modifyColumnFamiliesSettings", |
| 114 | + "dropRowRangeSettings", |
| 115 | + "generateConsistencyTokenSettings", |
| 116 | + "checkConsistencySettings", |
| 117 | + "getIamPolicySettings", |
| 118 | + "setIamPolicySettings", |
| 119 | + "testIamPermissionsSettings", |
| 120 | + "snapshotTableSettings", |
| 121 | + "snapshotTableOperationSettings", |
| 122 | + "getSnapshotSettings", |
| 123 | + "listSnapshotsSettings", |
| 124 | + "deleteSnapshotSettings", |
| 125 | + "createBackupSettings", |
| 126 | + "createBackupOperationSettings", |
| 127 | + "getBackupSettings", |
| 128 | + "listBackupsSettings", |
| 129 | + "updateBackupSettings", |
| 130 | + "deleteBackupSettings", |
| 131 | + "restoreTableSettings", |
| 132 | + "restoreTableOperationSettings", |
| 133 | + }; |
| 134 | + |
| 135 | + @Test |
| 136 | + public void testToString() throws IOException { |
| 137 | + BigtableTableAdminSettings defaultSettings = |
| 138 | + BigtableTableAdminSettings.newBuilder() |
| 139 | + .setProjectId("our-project-85") |
| 140 | + .setInstanceId("our-instance-06") |
| 141 | + .build(); |
| 142 | + |
| 143 | + checkToString(defaultSettings); |
| 144 | + |
| 145 | + BigtableTableAdminSettings.Builder builder = defaultSettings.toBuilder(); |
| 146 | + BigtableTableAdminStubSettings.Builder stubSettings = |
| 147 | + builder.stubSettings().setEndpoint("example.com:1234"); |
| 148 | + |
| 149 | + stubSettings |
| 150 | + .getBackupSettings() |
| 151 | + .setRetrySettings( |
| 152 | + RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(812)).build()); |
| 153 | + |
| 154 | + BigtableTableAdminSettings settings = builder.build(); |
| 155 | + checkToString(settings); |
| 156 | + assertThat(defaultSettings.toString()).doesNotContain("endpoint=example.com:1234"); |
| 157 | + assertThat(settings.toString()).contains("endpoint=example.com:1234"); |
| 158 | + assertThat(defaultSettings.toString()).doesNotContain("totalTimeout=PT13H32M"); |
| 159 | + assertThat(settings.toString()).contains("totalTimeout=PT13H32M"); |
| 160 | + |
| 161 | + int nonStaticFields = 0; |
| 162 | + for (Field field : BigtableTableAdminStubSettings.class.getDeclaredFields()) { |
| 163 | + if (!Modifier.isStatic(field.getModifiers())) { |
| 164 | + nonStaticFields++; |
| 165 | + } |
| 166 | + } |
| 167 | + // failure will signal about adding a new settings property |
| 168 | + assertThat(SETTINGS_LIST.length).isEqualTo(nonStaticFields); |
| 169 | + } |
| 170 | + |
| 171 | + void checkToString(BigtableTableAdminSettings settings) { |
| 172 | + String projectId = settings.getProjectId(); |
| 173 | + String instanceId = settings.getInstanceId(); |
| 174 | + String toString = settings.toString(); |
| 175 | + assertThat(toString).isEqualTo(settings.toString()); // no variety |
| 176 | + assertThat(toString) |
| 177 | + .startsWith( |
| 178 | + "BigtableTableAdminSettings{projectId=" + projectId + ", instanceId=" + instanceId); |
| 179 | + for (String subSettings : SETTINGS_LIST) { |
| 180 | + assertThat(toString).contains(subSettings + "="); |
| 181 | + } |
| 182 | + assertThat(toString.contains(settings.getStubSettings().toString())); |
| 183 | + } |
100 | 184 | }
|
0 commit comments