use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method streamingPullTest.
@Test
@SuppressWarnings("all")
public void streamingPullTest() throws Exception {
StreamingPullResponse expectedResponse = StreamingPullResponse.newBuilder().build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
int streamAckDeadlineSeconds = 1875467245;
StreamingPullRequest request = StreamingPullRequest.newBuilder().setSubscriptionWithSubscriptionName(subscription).setStreamAckDeadlineSeconds(streamAckDeadlineSeconds).build();
MockStreamObserver<StreamingPullResponse> responseObserver = new MockStreamObserver<>();
StreamingCallable<StreamingPullRequest, StreamingPullResponse> callable = client.streamingPullCallable();
ApiStreamObserver<StreamingPullRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
requestObserver.onNext(request);
requestObserver.onCompleted();
List<StreamingPullResponse> actualResponses = responseObserver.future().get();
Assert.assertEquals(1, actualResponses.size());
Assert.assertEquals(expectedResponse, actualResponses.get(0));
}
use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method modifyPushConfigTest.
@Test
@SuppressWarnings("all")
public void modifyPushConfigTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
PushConfig pushConfig = PushConfig.newBuilder().build();
client.modifyPushConfig(subscription, pushConfig);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
ModifyPushConfigRequest actualRequest = (ModifyPushConfigRequest) actualRequests.get(0);
Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
Assert.assertEquals(pushConfig, actualRequest.getPushConfig());
}
use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method modifyPushConfigExceptionTest.
@Test
@SuppressWarnings("all")
public void modifyPushConfigExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSubscriber.addException(exception);
try {
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
PushConfig pushConfig = PushConfig.newBuilder().build();
client.modifyPushConfig(subscription, pushConfig);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method getSubscriptionTest.
@Test
@SuppressWarnings("all")
public void getSubscriptionTest() {
SubscriptionName name = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
TopicNameOneof topic = TopicNameOneof.from(TopicName.create("[PROJECT]", "[TOPIC]"));
int ackDeadlineSeconds = 2135351438;
boolean retainAckedMessages = false;
Subscription expectedResponse = Subscription.newBuilder().setNameWithSubscriptionName(name).setTopicWithTopicNameOneof(topic).setAckDeadlineSeconds(ackDeadlineSeconds).setRetainAckedMessages(retainAckedMessages).build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
Subscription actualResponse = client.getSubscription(subscription);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetSubscriptionRequest actualRequest = (GetSubscriptionRequest) actualRequests.get(0);
Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
}
use of com.google.pubsub.v1.SubscriptionName in project java-docs-samples by GoogleCloudPlatform.
the class CreatePullSubscriptionExample method main.
/**
* Create a pull subscription.
*
* @param args topic subscriptionId
* @throws Exception exception thrown if operation is unsuccessful
*/
public static void main(String... args) throws Exception {
// Your Google Cloud Platform project ID
String projectId = ServiceOptions.getDefaultProjectId();
// Your topic ID, eg. "my-topic"
String topicId = args[0];
// Your subscription ID eg. "my-sub"
String subscriptionId = args[1];
ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId);
// Create a new subscription
ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscriptionId);
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
// create a pull subscription with default acknowledgement deadline (= 10 seconds)
Subscription subscription = subscriptionAdminClient.createSubscription(subscriptionName, topicName, PushConfig.getDefaultInstance(), 0);
} catch (ApiException e) {
// example : code = ALREADY_EXISTS(409) implies subscription already exists
System.out.print(e.getStatusCode().getCode());
System.out.print(e.isRetryable());
}
System.out.printf("Subscription %s:%s created.\n", subscriptionName.getProject(), subscriptionName.getSubscription());
}
Aggregations