2121import com .google .cloud .biglake .hive .v1beta .HiveMetastoreServiceClient ;
2222import com .google .cloud .biglake .hive .v1beta .HiveMetastoreServiceSettings ;
2323import com .google .cloud .biglake .hive .v1beta .ListHiveCatalogsRequest ;
24- import com .google .cloud .biglake .v1 .CreateIcebergCatalogRequest ;
25- import com .google .cloud .biglake .v1 .IcebergCatalog ;
26- import com .google .cloud .biglake .v1 .IcebergCatalogServiceClient ;
27- import com .google .cloud .biglake .v1 .IcebergCatalogServiceSettings ;
28- import com .google .cloud .biglake .v1 .ListIcebergCatalogsRequest ;
2924import java .io .IOException ;
30- import com .google .api .gax .rpc .ApiException ;
31- import com .google .api .gax .rpc .StatusCode ;
3225import org .junit .Test ;
3326
3427public class BiglakeDemoTest {
@@ -37,32 +30,16 @@ public class BiglakeDemoTest {
3730 public void testBiglakeRequests () throws Exception {
3831 String projectId = System .getenv ("GOOGLE_CLOUD_PROJECT" );
3932 if (projectId == null || projectId .isEmpty ()) {
40- System .err .println ("Warning: GOOGLE_CLOUD_PROJECT environment variable not defined. Skipping demo requests." );
33+ System .err .println (
34+ "Warning: GOOGLE_CLOUD_PROJECT environment variable not defined. Skipping demo requests." );
4135 return ;
4236 }
4337
4438 System .out .println ("Starting BigLake Client library demo execution..." );
4539 System .out .println ("Target Project ID: " + projectId );
4640
47- try {
48- runHiveMetastoreDemo (projectId );
49- } catch (ApiException e ) {
50- if (e .getStatusCode ().getCode () == StatusCode .Code .UNIMPLEMENTED || e .getStatusCode ().getCode () == StatusCode .Code .PERMISSION_DENIED ) {
51- System .out .println ("Target API returned expected status: " + e .getStatusCode ().getCode () + " (" + e .getMessage () + ")" );
52- } else {
53- throw e ;
54- }
55- }
56-
57- try {
58- runIcebergCatalogDemo (projectId );
59- } catch (ApiException e ) {
60- if (e .getStatusCode ().getCode () == StatusCode .Code .UNIMPLEMENTED || e .getStatusCode ().getCode () == StatusCode .Code .PERMISSION_DENIED ) {
61- System .out .println ("Target API returned expected status: " + e .getStatusCode ().getCode () + " (" + e .getMessage () + ")" );
62- } else {
63- throw e ;
64- }
65- }
41+ runHiveMetastoreDemo (projectId );
42+ runIcebergCatalogDemo (projectId );
6643 }
6744
6845 private void runHiveMetastoreDemo (String projectId ) throws IOException {
@@ -72,18 +49,16 @@ private void runHiveMetastoreDemo(String projectId) throws IOException {
7249
7350 try (HiveMetastoreServiceClient client = HiveMetastoreServiceClient .create (settings )) {
7451 String parent = String .format ("projects/%s" , projectId );
75-
52+
7653 // Call ListHiveCatalogsRequest verifying corrected query parameters
7754 System .out .println ("Requesting ListHiveCatalogs..." );
7855 ListHiveCatalogsRequest listRequest =
79- ListHiveCatalogsRequest .newBuilder ()
80- .setParent (parent )
81- .setPageSize (10 )
82- .build ();
83-
84- client .listHiveCatalogs (listRequest ).iterateAll ().forEach (
85- catalog -> System .out .println (" -> Found Catalog: " + catalog .getName ())
86- );
56+ ListHiveCatalogsRequest .newBuilder ().setParent (parent ).setPageSize (10 ).build ();
57+
58+ client
59+ .listHiveCatalogs (listRequest )
60+ .iterateAll ()
61+ .forEach (catalog -> System .out .println (" -> Found Catalog: " + catalog .getName ()));
8762
8863 // Call CreateHiveCatalogRequest verifying query parameter primary_location serialization
8964 System .out .println ("Requesting CreateHiveCatalog (dry-run / testing)..." );
@@ -95,12 +70,8 @@ private void runHiveMetastoreDemo(String projectId) throws IOException {
9570 .setHiveCatalog (HiveCatalog .newBuilder ().build ())
9671 .build ();
9772
98- try {
99- HiveCatalog response = client .createHiveCatalog (createRequest );
100- System .out .println (" -> Successfully Created Catalog: " + response .getName ());
101- } catch (Exception e ) {
102- System .out .println (" -> Create catalog call failed: " + e .getMessage ());
103- }
73+ HiveCatalog response = client .createHiveCatalog (createRequest );
74+ System .out .println (" -> Successfully Created Catalog: " + response .getName ());
10475 }
10576 }
10677
@@ -115,14 +86,13 @@ private void runIcebergCatalogDemo(String projectId) throws IOException {
11586 // Call ListIcebergCatalogsRequest verifying corrected query parameters
11687 System .out .println ("Requesting ListIcebergCatalogs..." );
11788 ListIcebergCatalogsRequest listRequest =
118- ListIcebergCatalogsRequest .newBuilder ()
119- .setParent (parent )
120- .setPageSize (10 )
121- .build ();
89+ ListIcebergCatalogsRequest .newBuilder ().setParent (parent ).setPageSize (10 ).build ();
12290
123- client .listIcebergCatalogs (listRequest ).iterateAll ().forEach (
124- catalog -> System .out .println (" -> Found Iceberg Catalog: " + catalog .getName ())
125- );
91+ client
92+ .listIcebergCatalogs (listRequest )
93+ .iterateAll ()
94+ .forEach (
95+ catalog -> System .out .println (" -> Found Iceberg Catalog: " + catalog .getName ()));
12696
12797 // Call CreateIcebergCatalogRequest verifying corrected parameter
12898 System .out .println ("Requesting CreateIcebergCatalog..." );
@@ -133,12 +103,8 @@ private void runIcebergCatalogDemo(String projectId) throws IOException {
133103 .setIcebergCatalog (IcebergCatalog .newBuilder ().build ())
134104 .build ();
135105
136- try {
137- IcebergCatalog response = client .createIcebergCatalog (createRequest );
138- System .out .println (" -> Successfully Created Iceberg Catalog: " + response .getName ());
139- } catch (Exception e ) {
140- System .out .println (" -> Create iceberg call failed: " + e .getMessage ());
141- }
106+ IcebergCatalog response = client .createIcebergCatalog (createRequest );
107+ System .out .println (" -> Successfully Created Iceberg Catalog: " + response .getName ());
142108 }
143109 }
144110}
0 commit comments