|
28 | 28 | import com.google.api.gax.rpc.UnaryCallable; |
29 | 29 | import com.google.api.gax.rpc.testing.FakeOperationSnapshot; |
30 | 30 | import com.google.bigtable.admin.v2.AuthorizedViewName; |
| 31 | +import com.google.bigtable.admin.v2.AvroSchema; |
31 | 32 | import com.google.bigtable.admin.v2.Backup.State; |
32 | 33 | import com.google.bigtable.admin.v2.BackupInfo; |
33 | 34 | import com.google.bigtable.admin.v2.ChangeStreamConfig; |
@@ -142,6 +143,9 @@ public class BigtableTableAdminClientTests { |
142 | 143 | private static final String TEST_PROTO_SCHEMA_BUNDLE = "proto_schema_bundle.pb"; |
143 | 144 | // Location: `google-cloud-bigtable/src/test/resources/updated_proto_schema_bundle.pb` |
144 | 145 | private static final String TEST_UPDATED_PROTO_SCHEMA_BUNDLE = "updated_proto_schema_bundle.pb"; |
| 146 | + private static final String TEST_AVRO_SCHEMA = "{\"type\": \"record\", \"name\": \"User\"}"; |
| 147 | + private static final String TEST_UPDATED_AVRO_SCHEMA = |
| 148 | + "{\"type\": \"record\", \"name\": \"UpdatedUser\"}"; |
145 | 149 |
|
146 | 150 | private static final String INSTANCE_NAME = NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID); |
147 | 151 | private static final String TABLE_NAME = |
@@ -1594,6 +1598,125 @@ public void testDeleteSchemaBundle() { |
1594 | 1598 | assertThat(wasCalled.get()).isTrue(); |
1595 | 1599 | } |
1596 | 1600 |
|
| 1601 | + @Test |
| 1602 | + public void testCreateSchemaBundleWithAvroSchema() { |
| 1603 | + // Setup |
| 1604 | + Mockito.when(mockStub.createSchemaBundleOperationCallable()) |
| 1605 | + .thenReturn(mockCreateSchemaBundleOperationCallable); |
| 1606 | + |
| 1607 | + com.google.bigtable.admin.v2.CreateSchemaBundleRequest expectedRequest = |
| 1608 | + com.google.bigtable.admin.v2.CreateSchemaBundleRequest.newBuilder() |
| 1609 | + .setParent(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)) |
| 1610 | + .setSchemaBundleId(SCHEMA_BUNDLE_ID) |
| 1611 | + .setSchemaBundle( |
| 1612 | + com.google.bigtable.admin.v2.SchemaBundle.newBuilder() |
| 1613 | + .setAvroSchema(AvroSchema.newBuilder().addJsonSchemas(TEST_AVRO_SCHEMA))) |
| 1614 | + .build(); |
| 1615 | + |
| 1616 | + com.google.bigtable.admin.v2.SchemaBundle expectedResponse = |
| 1617 | + com.google.bigtable.admin.v2.SchemaBundle.newBuilder() |
| 1618 | + .setName( |
| 1619 | + NameUtil.formatSchemaBundleName( |
| 1620 | + PROJECT_ID, INSTANCE_ID, TABLE_ID, SCHEMA_BUNDLE_ID)) |
| 1621 | + .setAvroSchema(AvroSchema.newBuilder().addJsonSchemas(TEST_AVRO_SCHEMA)) |
| 1622 | + .build(); |
| 1623 | + |
| 1624 | + mockOperationResult( |
| 1625 | + mockCreateSchemaBundleOperationCallable, |
| 1626 | + expectedRequest, |
| 1627 | + expectedResponse, |
| 1628 | + CreateSchemaBundleMetadata.newBuilder() |
| 1629 | + .setName(expectedRequest.getSchemaBundle().getName()) |
| 1630 | + .build()); |
| 1631 | + |
| 1632 | + CreateSchemaBundleRequest req = |
| 1633 | + CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setAvroSchema(TEST_AVRO_SCHEMA); |
| 1634 | + |
| 1635 | + // Execute |
| 1636 | + SchemaBundle actualResult = adminClient.createSchemaBundle(req); |
| 1637 | + |
| 1638 | + // Verify |
| 1639 | + assertThat(actualResult).isEqualTo(SchemaBundle.fromProto(expectedResponse)); |
| 1640 | + assertThat(actualResult.getAvroSchema()).containsExactly(TEST_AVRO_SCHEMA); |
| 1641 | + } |
| 1642 | + |
| 1643 | + @Test |
| 1644 | + public void testUpdateSchemaBundleWithAvroSchema() { |
| 1645 | + // Setup |
| 1646 | + Mockito.when(mockStub.updateSchemaBundleOperationCallable()) |
| 1647 | + .thenReturn(mockUpdateSchemaBundleOperationCallable); |
| 1648 | + |
| 1649 | + com.google.bigtable.admin.v2.UpdateSchemaBundleRequest expectedRequest = |
| 1650 | + com.google.bigtable.admin.v2.UpdateSchemaBundleRequest.newBuilder() |
| 1651 | + .setSchemaBundle( |
| 1652 | + com.google.bigtable.admin.v2.SchemaBundle.newBuilder() |
| 1653 | + .setName( |
| 1654 | + NameUtil.formatSchemaBundleName( |
| 1655 | + PROJECT_ID, INSTANCE_ID, TABLE_ID, SCHEMA_BUNDLE_ID)) |
| 1656 | + .setAvroSchema( |
| 1657 | + AvroSchema.newBuilder().addJsonSchemas(TEST_UPDATED_AVRO_SCHEMA))) |
| 1658 | + .setUpdateMask(FieldMask.newBuilder().addPaths("avro_schema")) |
| 1659 | + .build(); |
| 1660 | + |
| 1661 | + com.google.bigtable.admin.v2.SchemaBundle expectedResponse = |
| 1662 | + com.google.bigtable.admin.v2.SchemaBundle.newBuilder() |
| 1663 | + .setName( |
| 1664 | + NameUtil.formatSchemaBundleName( |
| 1665 | + PROJECT_ID, INSTANCE_ID, TABLE_ID, SCHEMA_BUNDLE_ID)) |
| 1666 | + .setAvroSchema(AvroSchema.newBuilder().addJsonSchemas(TEST_UPDATED_AVRO_SCHEMA)) |
| 1667 | + .build(); |
| 1668 | + |
| 1669 | + mockOperationResult( |
| 1670 | + mockUpdateSchemaBundleOperationCallable, |
| 1671 | + expectedRequest, |
| 1672 | + expectedResponse, |
| 1673 | + UpdateSchemaBundleMetadata.newBuilder() |
| 1674 | + .setName(expectedRequest.getSchemaBundle().getName()) |
| 1675 | + .build()); |
| 1676 | + |
| 1677 | + UpdateSchemaBundleRequest req = |
| 1678 | + UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID) |
| 1679 | + .setAvroSchema(TEST_UPDATED_AVRO_SCHEMA); |
| 1680 | + |
| 1681 | + // Execute |
| 1682 | + SchemaBundle actualResult = adminClient.updateSchemaBundle(req); |
| 1683 | + |
| 1684 | + // Verify |
| 1685 | + assertThat(actualResult).isEqualTo(SchemaBundle.fromProto(expectedResponse)); |
| 1686 | + assertThat(actualResult.getAvroSchema()).containsExactly(TEST_UPDATED_AVRO_SCHEMA); |
| 1687 | + } |
| 1688 | + |
| 1689 | + @Test |
| 1690 | + public void testGetSchemaBundleWithAvroSchema() { |
| 1691 | + // Setup |
| 1692 | + Mockito.when(mockStub.getSchemaBundleCallable()).thenReturn(mockGetSchemaBundleCallable); |
| 1693 | + |
| 1694 | + com.google.bigtable.admin.v2.GetSchemaBundleRequest expectedRequest = |
| 1695 | + com.google.bigtable.admin.v2.GetSchemaBundleRequest.newBuilder() |
| 1696 | + .setName( |
| 1697 | + NameUtil.formatSchemaBundleName( |
| 1698 | + PROJECT_ID, INSTANCE_ID, TABLE_ID, SCHEMA_BUNDLE_ID)) |
| 1699 | + .build(); |
| 1700 | + |
| 1701 | + com.google.bigtable.admin.v2.SchemaBundle expectedResponse = |
| 1702 | + com.google.bigtable.admin.v2.SchemaBundle.newBuilder() |
| 1703 | + .setName( |
| 1704 | + NameUtil.formatSchemaBundleName( |
| 1705 | + PROJECT_ID, INSTANCE_ID, TABLE_ID, SCHEMA_BUNDLE_ID)) |
| 1706 | + .setAvroSchema(AvroSchema.newBuilder().addJsonSchemas(TEST_AVRO_SCHEMA)) |
| 1707 | + .build(); |
| 1708 | + |
| 1709 | + Mockito.when(mockGetSchemaBundleCallable.futureCall(expectedRequest)) |
| 1710 | + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); |
| 1711 | + |
| 1712 | + // Execute |
| 1713 | + SchemaBundle actualResult = adminClient.getSchemaBundle(TABLE_ID, SCHEMA_BUNDLE_ID); |
| 1714 | + |
| 1715 | + // Verify |
| 1716 | + assertThat(actualResult).isEqualTo(SchemaBundle.fromProto(expectedResponse)); |
| 1717 | + assertThat(actualResult.getAvroSchema()).containsExactly(TEST_AVRO_SCHEMA); |
| 1718 | + } |
| 1719 | + |
1597 | 1720 | @Test |
1598 | 1721 | public void testGetBackupIamPolicy() { |
1599 | 1722 | // Setup |
|
0 commit comments