|
27 | 27 | import com.google.cloud.biglake.v1.IcebergCatalogServiceSettings; |
28 | 28 | import com.google.cloud.biglake.v1.ListIcebergCatalogsRequest; |
29 | 29 | import java.io.IOException; |
| 30 | +import com.google.api.gax.rpc.ApiException; |
| 31 | +import com.google.api.gax.rpc.StatusCode; |
| 32 | +import org.junit.Test; |
30 | 33 |
|
31 | | -public class BiglakeDemo { |
32 | | - public static void main(String[] args) { |
| 34 | +public class BiglakeDemoTest { |
| 35 | + |
| 36 | + @Test |
| 37 | + public void testBiglakeRequests() throws Exception { |
33 | 38 | String projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); |
34 | 39 | if (projectId == null || projectId.isEmpty()) { |
35 | | - System.err.println("Error: GOOGLE_CLOUD_PROJECT environment variable is not defined."); |
36 | | - System.exit(1); |
| 40 | + System.err.println("Warning: GOOGLE_CLOUD_PROJECT environment variable not defined. Skipping demo requests."); |
| 41 | + return; |
37 | 42 | } |
38 | 43 |
|
39 | 44 | System.out.println("Starting BigLake Client library demo execution..."); |
40 | 45 | System.out.println("Target Project ID: " + projectId); |
41 | 46 |
|
42 | 47 | try { |
43 | 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 { |
44 | 58 | runIcebergCatalogDemo(projectId); |
45 | | - } catch (Exception e) { |
46 | | - System.err.println("Demo Execution encountered error:"); |
47 | | - e.printStackTrace(); |
48 | | - System.exit(1); |
| 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 | + } |
49 | 65 | } |
50 | 66 | } |
51 | 67 |
|
52 | | - private static void runHiveMetastoreDemo(String projectId) throws IOException { |
| 68 | + private void runHiveMetastoreDemo(String projectId) throws IOException { |
53 | 69 | System.out.println("\nExecuting Hive Metastore affected requests test..."); |
54 | 70 | HiveMetastoreServiceSettings settings = |
55 | 71 | HiveMetastoreServiceSettings.newHttpJsonBuilder().build(); |
@@ -88,7 +104,7 @@ private static void runHiveMetastoreDemo(String projectId) throws IOException { |
88 | 104 | } |
89 | 105 | } |
90 | 106 |
|
91 | | - private static void runIcebergCatalogDemo(String projectId) throws IOException { |
| 107 | + private void runIcebergCatalogDemo(String projectId) throws IOException { |
92 | 108 | System.out.println("\nExecuting Iceberg Catalog affected requests test..."); |
93 | 109 | IcebergCatalogServiceSettings settings = |
94 | 110 | IcebergCatalogServiceSettings.newHttpJsonBuilder().build(); |
|
0 commit comments