File tree Expand file tree Collapse file tree 4 files changed +44
-2
lines changed
google-cloud-bigtable/src/test/java/com/google/cloud/bigtable Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -102,14 +102,14 @@ public static void createClient()
102102 // Setup a prefix to avoid collisions between concurrent test runs
103103 prefix = String .format ("020%d" , System .currentTimeMillis ());
104104
105- tableAdmin = BigtableTableAdminClient . create ( testEnvRule .env ().getProjectId (), targetInstance );
105+ tableAdmin = testEnvRule .env ().getTableAdminClientForInstance ( targetInstance );
106106
107107 testTable =
108108 tableAdmin .createTable (
109109 CreateTableRequest .of (generateId (TEST_TABLE_SUFFIX )).addFamily ("cf1" ));
110110
111111 // Populate test data.
112- dataClient = BigtableDataClient . create ( testEnvRule .env ().getProjectId (), targetInstance );
112+ dataClient = testEnvRule .env ().getDataClientForInstance ( targetInstance );
113113 byte [] rowBytes = new byte [1024 ];
114114 Random random = new Random ();
115115 random .nextBytes (rowBytes );
Original file line number Diff line number Diff line change 2222import com .google .cloud .bigtable .admin .v2 .models .Instance ;
2323import com .google .cloud .bigtable .data .v2 .BigtableDataClient ;
2424import com .google .cloud .bigtable .data .v2 .BigtableDataSettings ;
25+ import java .io .IOException ;
2526import org .threeten .bp .Instant ;
2627import org .threeten .bp .temporal .ChronoUnit ;
2728
@@ -42,8 +43,13 @@ public abstract class AbstractTestEnv {
4243
4344 public abstract BigtableDataClient getDataClient ();
4445
46+ public abstract BigtableDataClient getDataClientForInstance (String instanceId ) throws IOException ;
47+
4548 public abstract BigtableTableAdminClient getTableAdminClient ();
4649
50+ public abstract BigtableTableAdminClient getTableAdminClientForInstance (String instanceId )
51+ throws IOException ;
52+
4753 public abstract BigtableInstanceAdminClient getInstanceAdminClient ();
4854
4955 public abstract BigtableDataSettings getDataClientSettings ();
Original file line number Diff line number Diff line change @@ -152,11 +152,35 @@ public BigtableDataClient getDataClient() {
152152 return dataClient ;
153153 }
154154
155+ @ Override
156+ public BigtableDataClient getDataClientForInstance (String instanceId ) throws IOException {
157+ BigtableDataSettings .Builder settings =
158+ BigtableDataSettings .newBuilder ()
159+ .setProjectId (dataSettings .getProjectId ())
160+ .setInstanceId (instanceId );
161+ settings
162+ .stubSettings ()
163+ .setEndpoint (dataSettings .stubSettings ().getEndpoint ())
164+ .setTransportChannelProvider (dataSettings .stubSettings ().getTransportChannelProvider ());
165+ return BigtableDataClient .create (settings .build ());
166+ }
167+
155168 @ Override
156169 public BigtableTableAdminClient getTableAdminClient () {
157170 return tableAdminClient ;
158171 }
159172
173+ @ Override
174+ public BigtableTableAdminClient getTableAdminClientForInstance (String instanceId )
175+ throws IOException {
176+ BigtableTableAdminSettings .Builder settings =
177+ BigtableTableAdminSettings .newBuilder ()
178+ .setProjectId (tableAdminSettings .getProjectId ())
179+ .setInstanceId (instanceId );
180+ settings .stubSettings ().setEndpoint (tableAdminSettings .stubSettings ().getEndpoint ());
181+ return BigtableTableAdminClient .create (settings .build ());
182+ }
183+
160184 @ Override
161185 public BigtableInstanceAdminClient getInstanceAdminClient () {
162186 return instanceAdminClient ;
Original file line number Diff line number Diff line change 2323import com .google .cloud .bigtable .data .v2 .BigtableDataSettings ;
2424import com .google .cloud .bigtable .emulator .v2 .Emulator ;
2525import com .google .common .base .Strings ;
26+ import java .io .IOException ;
2627import java .nio .file .Paths ;
2728
2829public class EmulatorEnv extends AbstractTestEnv {
@@ -104,11 +105,22 @@ public BigtableDataClient getDataClient() {
104105 return dataClient ;
105106 }
106107
108+ @ Override
109+ public BigtableDataClient getDataClientForInstance (String instanceId ) throws IOException {
110+ throw new UnsupportedOperationException ("Could not create a data client for another instance." );
111+ }
112+
107113 @ Override
108114 public BigtableTableAdminClient getTableAdminClient () {
109115 return tableAdminClient ;
110116 }
111117
118+ @ Override
119+ public BigtableTableAdminClient getTableAdminClientForInstance (String instanceId )
120+ throws IOException {
121+ throw new UnsupportedOperationException ("Could not create a table admin for another instance." );
122+ }
123+
112124 @ Override
113125 public BigtableInstanceAdminClient getInstanceAdminClient () {
114126 throw new UnsupportedOperationException ("InstanceAdminClient is not supported with emulator" );
You can’t perform that action at this time.
0 commit comments