|
50 | 50 | import com.google.cloud.bigtable.admin.v2.models.UpdateAppProfileRequest;
|
51 | 51 | import com.google.cloud.bigtable.admin.v2.models.UpdateInstanceRequest;
|
52 | 52 | import com.google.cloud.bigtable.admin.v2.stub.BigtableInstanceAdminStub;
|
| 53 | +import com.google.common.collect.ImmutableList; |
53 | 54 | import com.google.common.collect.Lists;
|
54 | 55 | import com.google.common.io.BaseEncoding;
|
55 | 56 | import com.google.protobuf.ByteString;
|
@@ -617,6 +618,131 @@ public void testCreateAppProfile() {
|
617 | 618 | assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));
|
618 | 619 | }
|
619 | 620 |
|
| 621 | + @Test |
| 622 | + public void testCreateAppProfileAddSingleClusterId() { |
| 623 | + // Setup |
| 624 | + Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); |
| 625 | + |
| 626 | + com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = |
| 627 | + com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() |
| 628 | + .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) |
| 629 | + .setAppProfileId(APP_PROFILE_ID) |
| 630 | + .setAppProfile( |
| 631 | + com.google.bigtable.admin.v2.AppProfile.newBuilder() |
| 632 | + .setDescription("my description") |
| 633 | + .setMultiClusterRoutingUseAny( |
| 634 | + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny |
| 635 | + .newBuilder() |
| 636 | + .addClusterIds("cluster-id-1"))) |
| 637 | + .build(); |
| 638 | + |
| 639 | + com.google.bigtable.admin.v2.AppProfile expectedResponse = |
| 640 | + com.google.bigtable.admin.v2.AppProfile.newBuilder() |
| 641 | + .setName(APP_PROFILE_NAME) |
| 642 | + .setDescription("my description") |
| 643 | + .setMultiClusterRoutingUseAny( |
| 644 | + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() |
| 645 | + .addClusterIds("cluster-id-1")) |
| 646 | + .build(); |
| 647 | + |
| 648 | + Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)) |
| 649 | + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); |
| 650 | + |
| 651 | + // Execute |
| 652 | + AppProfile actualResult = |
| 653 | + adminClient.createAppProfile( |
| 654 | + CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) |
| 655 | + .setDescription("my description") |
| 656 | + .setRoutingPolicy(MultiClusterRoutingPolicy.of("cluster-id-1"))); |
| 657 | + |
| 658 | + // Verify |
| 659 | + assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); |
| 660 | + } |
| 661 | + |
| 662 | + @Test |
| 663 | + public void testCreateAppProfileAddMultipleClusterIds() { |
| 664 | + // Setup |
| 665 | + Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); |
| 666 | + |
| 667 | + com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = |
| 668 | + com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() |
| 669 | + .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) |
| 670 | + .setAppProfileId(APP_PROFILE_ID) |
| 671 | + .setAppProfile( |
| 672 | + com.google.bigtable.admin.v2.AppProfile.newBuilder() |
| 673 | + .setDescription("my description") |
| 674 | + .setMultiClusterRoutingUseAny( |
| 675 | + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny |
| 676 | + .newBuilder() |
| 677 | + .addClusterIds("cluster-id-1") |
| 678 | + .addClusterIds("cluster-id-2"))) |
| 679 | + .build(); |
| 680 | + |
| 681 | + com.google.bigtable.admin.v2.AppProfile expectedResponse = |
| 682 | + com.google.bigtable.admin.v2.AppProfile.newBuilder() |
| 683 | + .setName(APP_PROFILE_NAME) |
| 684 | + .setDescription("my description") |
| 685 | + .setMultiClusterRoutingUseAny( |
| 686 | + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() |
| 687 | + .addClusterIds("cluster-id-1") |
| 688 | + .addClusterIds("cluster-id-2")) |
| 689 | + .build(); |
| 690 | + |
| 691 | + Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)) |
| 692 | + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); |
| 693 | + |
| 694 | + // Execute |
| 695 | + AppProfile actualResult = |
| 696 | + adminClient.createAppProfile( |
| 697 | + CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) |
| 698 | + .setDescription("my description") |
| 699 | + .setRoutingPolicy(MultiClusterRoutingPolicy.of("cluster-id-1", "cluster-id-2"))); |
| 700 | + |
| 701 | + // Verify |
| 702 | + assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); |
| 703 | + } |
| 704 | + |
| 705 | + @Test |
| 706 | + public void testCreateAppProfileAddMultipleClusterIdsWithList() { |
| 707 | + // Setup |
| 708 | + Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable); |
| 709 | + |
| 710 | + com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = |
| 711 | + com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder() |
| 712 | + .setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) |
| 713 | + .setAppProfileId(APP_PROFILE_ID) |
| 714 | + .setAppProfile( |
| 715 | + com.google.bigtable.admin.v2.AppProfile.newBuilder() |
| 716 | + .setDescription("my description") |
| 717 | + .setMultiClusterRoutingUseAny( |
| 718 | + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny |
| 719 | + .newBuilder() |
| 720 | + .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")))) |
| 721 | + .build(); |
| 722 | + |
| 723 | + com.google.bigtable.admin.v2.AppProfile expectedResponse = |
| 724 | + com.google.bigtable.admin.v2.AppProfile.newBuilder() |
| 725 | + .setName(APP_PROFILE_NAME) |
| 726 | + .setDescription("my description") |
| 727 | + .setMultiClusterRoutingUseAny( |
| 728 | + com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder() |
| 729 | + .addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2"))) |
| 730 | + .build(); |
| 731 | + |
| 732 | + Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)) |
| 733 | + .thenReturn(ApiFutures.immediateFuture(expectedResponse)); |
| 734 | + |
| 735 | + // Execute |
| 736 | + AppProfile actualResult = |
| 737 | + adminClient.createAppProfile( |
| 738 | + CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID) |
| 739 | + .setDescription("my description") |
| 740 | + .setRoutingPolicy(MultiClusterRoutingPolicy.of("cluster-id-1", "cluster-id-2"))); |
| 741 | + |
| 742 | + // Verify |
| 743 | + assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse)); |
| 744 | + } |
| 745 | + |
620 | 746 | @Test
|
621 | 747 | public void testGetAppProfile() {
|
622 | 748 | // Setup
|
|
0 commit comments