Skip to content
Permalink
Browse files
docs(regen): update sample code to set total timeout, add API client …
…header test
  • Loading branch information
yoshi-automation committed Feb 10, 2020
1 parent 0f77732 commit 8bc23bc3b68a2c3a2a7caa1d9859dfdd1b56c47d
@@ -83,8 +83,12 @@
* <code>
* SubscriptionAdminSettings.Builder subscriptionAdminSettingsBuilder =
* SubscriptionAdminSettings.newBuilder();
* subscriptionAdminSettingsBuilder.createSubscriptionSettings().getRetrySettings().toBuilder()
* .setTotalTimeout(Duration.ofSeconds(30));
* subscriptionAdminSettingsBuilder
* .createSubscriptionSettings()
* .setRetrySettings(
* subscriptionAdminSettingsBuilder.createSubscriptionSettings().getRetrySettings().toBuilder()
* .setTotalTimeout(Duration.ofSeconds(30))
* .build());
* SubscriptionAdminSettings subscriptionAdminSettings = subscriptionAdminSettingsBuilder.build();
* </code>
* </pre>
@@ -72,8 +72,12 @@
* <code>
* TopicAdminSettings.Builder topicAdminSettingsBuilder =
* TopicAdminSettings.newBuilder();
* topicAdminSettingsBuilder.createTopicSettings().getRetrySettings().toBuilder()
* .setTotalTimeout(Duration.ofSeconds(30));
* topicAdminSettingsBuilder
* .createTopicSettings()
* .setRetrySettings(
* topicAdminSettingsBuilder.createTopicSettings().getRetrySettings().toBuilder()
* .setTotalTimeout(Duration.ofSeconds(30))
* .build());
* TopicAdminSettings topicAdminSettings = topicAdminSettingsBuilder.build();
* </code>
* </pre>
@@ -96,8 +96,12 @@
* <code>
* PublisherStubSettings.Builder topicAdminSettingsBuilder =
* PublisherStubSettings.newBuilder();
* topicAdminSettingsBuilder.createTopicSettings().getRetrySettings().toBuilder()
* .setTotalTimeout(Duration.ofSeconds(30));
* topicAdminSettingsBuilder
* .createTopicSettings()
* .setRetrySettings(
* topicAdminSettingsBuilder.createTopicSettings().getRetrySettings().toBuilder()
* .setTotalTimeout(Duration.ofSeconds(30))
* .build());
* PublisherStubSettings topicAdminSettings = topicAdminSettingsBuilder.build();
* </code>
* </pre>
@@ -98,8 +98,12 @@
* <code>
* SubscriberStubSettings.Builder subscriptionAdminSettingsBuilder =
* SubscriberStubSettings.newBuilder();
* subscriptionAdminSettingsBuilder.createSubscriptionSettings().getRetrySettings().toBuilder()
* .setTotalTimeout(Duration.ofSeconds(30));
* subscriptionAdminSettingsBuilder
* .createSubscriptionSettings()
* .setRetrySettings(
* subscriptionAdminSettingsBuilder.createSubscriptionSettings().getRetrySettings().toBuilder()
* .setTotalTimeout(Duration.ofSeconds(30))
* .build());
* SubscriberStubSettings subscriptionAdminSettings = subscriptionAdminSettingsBuilder.build();
* </code>
* </pre>
@@ -38,6 +38,8 @@
import com.google.protobuf.AbstractMessage;
import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;
import com.google.protobuf.FieldMask;
import com.google.protobuf.Timestamp;
import com.google.pubsub.v1.AcknowledgeRequest;
import com.google.pubsub.v1.CreateSnapshotRequest;
import com.google.pubsub.v1.DeleteSnapshotRequest;
@@ -57,11 +59,15 @@
import com.google.pubsub.v1.PullResponse;
import com.google.pubsub.v1.PushConfig;
import com.google.pubsub.v1.ReceivedMessage;
import com.google.pubsub.v1.SeekRequest;
import com.google.pubsub.v1.SeekResponse;
import com.google.pubsub.v1.Snapshot;
import com.google.pubsub.v1.StreamingPullRequest;
import com.google.pubsub.v1.StreamingPullResponse;
import com.google.pubsub.v1.Subscription;
import com.google.pubsub.v1.TopicName;
import com.google.pubsub.v1.UpdateSnapshotRequest;
import com.google.pubsub.v1.UpdateSubscriptionRequest;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import java.io.IOException;
@@ -234,6 +240,77 @@ public void getSubscriptionExceptionTest() throws Exception {
}
}

@Test
@SuppressWarnings("all")
public void updateSubscriptionTest() {
ProjectSubscriptionName name = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
TopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
int ackDeadlineSeconds2 = 921632575;
boolean retainAckedMessages = false;
boolean enableMessageOrdering = true;
Subscription expectedResponse =
Subscription.newBuilder()
.setName(name.toString())
.setTopic(topic.toString())
.setAckDeadlineSeconds(ackDeadlineSeconds2)
.setRetainAckedMessages(retainAckedMessages)
.setEnableMessageOrdering(enableMessageOrdering)
.build();
mockSubscriber.addResponse(expectedResponse);

int ackDeadlineSeconds = 42;
Subscription subscription =
Subscription.newBuilder().setAckDeadlineSeconds(ackDeadlineSeconds).build();
String pathsElement = "ack_deadline_seconds";
List<String> paths = Arrays.asList(pathsElement);
FieldMask updateMask = FieldMask.newBuilder().addAllPaths(paths).build();
UpdateSubscriptionRequest request =
UpdateSubscriptionRequest.newBuilder()
.setSubscription(subscription)
.setUpdateMask(updateMask)
.build();

Subscription actualResponse = client.updateSubscription(request);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateSubscriptionRequest actualRequest = (UpdateSubscriptionRequest) actualRequests.get(0);

Assert.assertEquals(subscription, actualRequest.getSubscription());
Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}

@Test
@SuppressWarnings("all")
public void updateSubscriptionExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSubscriber.addException(exception);

try {
int ackDeadlineSeconds = 42;
Subscription subscription =
Subscription.newBuilder().setAckDeadlineSeconds(ackDeadlineSeconds).build();
String pathsElement = "ack_deadline_seconds";
List<String> paths = Arrays.asList(pathsElement);
FieldMask updateMask = FieldMask.newBuilder().addAllPaths(paths).build();
UpdateSubscriptionRequest request =
UpdateSubscriptionRequest.newBuilder()
.setSubscription(subscription)
.setUpdateMask(updateMask)
.build();

client.updateSubscription(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}

@Test
@SuppressWarnings("all")
public void listSubscriptionsTest() {
@@ -661,6 +738,65 @@ public void createSnapshotExceptionTest() throws Exception {
}
}

@Test
@SuppressWarnings("all")
public void updateSnapshotTest() {
ProjectSnapshotName name = ProjectSnapshotName.of("[PROJECT]", "[SNAPSHOT]");
ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
Snapshot expectedResponse =
Snapshot.newBuilder().setName(name.toString()).setTopic(topic.toString()).build();
mockSubscriber.addResponse(expectedResponse);

long seconds = 123456L;
Timestamp expireTime = Timestamp.newBuilder().setSeconds(seconds).build();
Snapshot snapshot = Snapshot.newBuilder().setExpireTime(expireTime).build();
String pathsElement = "expire_time";
List<String> paths = Arrays.asList(pathsElement);
FieldMask updateMask = FieldMask.newBuilder().addAllPaths(paths).build();
UpdateSnapshotRequest request =
UpdateSnapshotRequest.newBuilder().setSnapshot(snapshot).setUpdateMask(updateMask).build();

Snapshot actualResponse = client.updateSnapshot(request);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateSnapshotRequest actualRequest = (UpdateSnapshotRequest) actualRequests.get(0);

Assert.assertEquals(snapshot, actualRequest.getSnapshot());
Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}

@Test
@SuppressWarnings("all")
public void updateSnapshotExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSubscriber.addException(exception);

try {
long seconds = 123456L;
Timestamp expireTime = Timestamp.newBuilder().setSeconds(seconds).build();
Snapshot snapshot = Snapshot.newBuilder().setExpireTime(expireTime).build();
String pathsElement = "expire_time";
List<String> paths = Arrays.asList(pathsElement);
FieldMask updateMask = FieldMask.newBuilder().addAllPaths(paths).build();
UpdateSnapshotRequest request =
UpdateSnapshotRequest.newBuilder()
.setSnapshot(snapshot)
.setUpdateMask(updateMask)
.build();

client.updateSnapshot(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}

@Test
@SuppressWarnings("all")
public void deleteSnapshotTest() {
@@ -698,6 +834,50 @@ public void deleteSnapshotExceptionTest() throws Exception {
}
}

@Test
@SuppressWarnings("all")
public void seekTest() {
SeekResponse expectedResponse = SeekResponse.newBuilder().build();
mockSubscriber.addResponse(expectedResponse);

ProjectSubscriptionName subscription =
ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
SeekRequest request = SeekRequest.newBuilder().setSubscription(subscription.toString()).build();

SeekResponse actualResponse = client.seek(request);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
SeekRequest actualRequest = (SeekRequest) actualRequests.get(0);

Assert.assertEquals(
subscription, ProjectSubscriptionName.parse(actualRequest.getSubscription()));
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}

@Test
@SuppressWarnings("all")
public void seekExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSubscriber.addException(exception);

try {
ProjectSubscriptionName subscription =
ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
SeekRequest request =
SeekRequest.newBuilder().setSubscription(subscription.toString()).build();

client.seek(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}

@Test
@SuppressWarnings("all")
public void setIamPolicyTest() {
@@ -34,6 +34,7 @@
import com.google.protobuf.AbstractMessage;
import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;
import com.google.protobuf.FieldMask;
import com.google.pubsub.v1.DeleteTopicRequest;
import com.google.pubsub.v1.GetTopicRequest;
import com.google.pubsub.v1.ListTopicSubscriptionsRequest;
@@ -47,6 +48,7 @@
import com.google.pubsub.v1.PublishResponse;
import com.google.pubsub.v1.PubsubMessage;
import com.google.pubsub.v1.Topic;
import com.google.pubsub.v1.UpdateTopicRequest;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import java.io.IOException;
@@ -145,6 +147,54 @@ public void createTopicExceptionTest() throws Exception {
}
}

@Test
@SuppressWarnings("all")
public void updateTopicTest() {
ProjectTopicName name = ProjectTopicName.of("[PROJECT]", "[TOPIC]");
String kmsKeyName = "kmsKeyName2094986649";
Topic expectedResponse =
Topic.newBuilder().setName(name.toString()).setKmsKeyName(kmsKeyName).build();
mockPublisher.addResponse(expectedResponse);

Topic topic = Topic.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
UpdateTopicRequest request =
UpdateTopicRequest.newBuilder().setTopic(topic).setUpdateMask(updateMask).build();

Topic actualResponse = client.updateTopic(request);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockPublisher.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateTopicRequest actualRequest = (UpdateTopicRequest) actualRequests.get(0);

Assert.assertEquals(topic, actualRequest.getTopic());
Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
Assert.assertTrue(
channelProvider.isHeaderSent(
ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}

@Test
@SuppressWarnings("all")
public void updateTopicExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockPublisher.addException(exception);

try {
Topic topic = Topic.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
UpdateTopicRequest request =
UpdateTopicRequest.newBuilder().setTopic(topic).setUpdateMask(updateMask).build();

client.updateTopic(request);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception
}
}

@Test
@SuppressWarnings("all")
public void publishTest() {

0 comments on commit 8bc23bc

Please sign in to comment.