2727import com .google .cloud .bigtable .admin .v2 .models .CreateInstanceRequest ;
2828import com .google .cloud .bigtable .admin .v2 .models .CreateMaterializedViewRequest ;
2929import com .google .cloud .bigtable .admin .v2 .models .CreateTableRequest ;
30- import com .google .cloud .bigtable .admin .v2 .models .Instance ;
3130import com .google .cloud .bigtable .admin .v2 .models .MaterializedView ;
3231import com .google .cloud .bigtable .admin .v2 .models .StorageType ;
3332import com .google .cloud .bigtable .admin .v2 .models .Table ;
3938import java .io .IOException ;
4039import java .util .List ;
4140import java .util .logging .Logger ;
42- import org .junit .AfterClass ;
41+ import org .junit .After ;
4342import org .junit .Before ;
4443import org .junit .BeforeClass ;
4544import org .junit .ClassRule ;
@@ -55,10 +54,10 @@ public class BigtableMaterializedViewIT {
5554 private static final Logger LOGGER = Logger .getLogger (BigtableMaterializedViewIT .class .getName ());
5655 private static final int [] BACKOFF_DURATION = {2 , 4 , 8 , 16 , 32 , 64 , 128 , 256 , 512 , 1024 };
5756
58- private static BigtableInstanceAdminClient client ;
59- private static BigtableTableAdminClient tableAdminClient ;
60- private static Table testTable ;
61- private static String instanceId = "" ;
57+ private BigtableInstanceAdminClient client ;
58+ private BigtableTableAdminClient tableAdminClient ;
59+ private Table testTable ;
60+ private String instanceId = "" ;
6261
6362 // TODO: Update this test once emulator supports InstanceAdmin operation
6463 // https://github.com/googleapis/google-cloud-go/issues/1069
@@ -68,33 +67,30 @@ public static void validatePlatform() throws IOException {
6867 .withMessage ("BigtableInstanceAdminClient doesn't support on Emulator" )
6968 .that (testEnvRule .env ())
7069 .isNotInstanceOf (EmulatorEnv .class );
71-
72- createInstance ();
7370 }
7471
75- public static void createInstance () throws IOException {
72+ @ Before
73+ public void setUp () throws InterruptedException , IOException {
7674 client = testEnvRule .env ().getInstanceAdminClient ();
7775
78- Instance instance =
79- client .createInstance (
80- CreateInstanceRequest .of (new PrefixGenerator ().newPrefix ())
81- .addCluster ("my-cluster" , "us-east1-c" , 3 , StorageType .SSD ));
82- instanceId = instance .getId ();
76+ instanceId = new PrefixGenerator ().newPrefix ();
77+ client .createInstance (
78+ CreateInstanceRequest .of (instanceId )
79+ .setDisplayName ("BigtableMaterializedViewIT" )
80+ .addCluster (
81+ instanceId + "-c1" , testEnvRule .env ().getPrimaryZone (), 1 , StorageType .SSD ));
8382 tableAdminClient = testEnvRule .env ().getTableAdminClientForInstance (instanceId );
83+
84+ testTable = createTestTable (tableAdminClient );
8485 }
8586
86- @ AfterClass
87- public static void deleteInstance () {
87+ @ After
88+ public void deleteInstance () {
8889 if (!instanceId .isEmpty ()) {
8990 client .deleteInstance (instanceId );
9091 }
9192 }
9293
93- @ Before
94- public void setUp () throws InterruptedException {
95- testTable = createTestTable (tableAdminClient );
96- }
97-
9894 @ Test
9995 public void createMaterializedViewAndGetMaterializedViewTest () {
10096 String materializedViewId = prefixGenerator .newPrefix ();
@@ -209,8 +205,7 @@ private String getQuery() {
209205 + "` GROUP BY _key" ;
210206 }
211207
212- private static Table createTestTable (BigtableTableAdminClient tableAdmin )
213- throws InterruptedException {
208+ private Table createTestTable (BigtableTableAdminClient tableAdmin ) throws InterruptedException {
214209 String tableId = PrefixGenerator .newPrefix ("BigtableMaterializedViewIT#createTestTable" );
215210 Table testTable = tableAdmin .createTable (CreateTableRequest .of (tableId ).addFamily ("cf1" ));
216211
0 commit comments