public async void PublishBinaryMessages() { string randomName = _pubsubFixture.RandomName(); string topicId = $"testTopicForProtoBinaryMessageCreation{randomName}"; string subscriptionId = $"testSubscriptionForProtoBinaryMessageCreation{randomName}"; string schemaId = $"testSchemaForProtoBinaryMessageCreation{randomName}"; var schema = _pubsubFixture.CreateProtoSchema(schemaId); _pubsubFixture.CreateTopicWithSchema(topicId, schema.Name.ToString(), Encoding.Binary); _pubsubFixture.CreateSubscription(topicId, subscriptionId); List <Utilities.State> messageTexts = new List <Utilities.State> { new Utilities.State { Name = "New York", PostAbbr = "NY" }, new Utilities.State { Name = "Pennsylvania", PostAbbr = "PA" } }; var output = await _publishProtoMessagesAsyncSample.PublishProtoMessagesAsync(_pubsubFixture.ProjectId, topicId, messageTexts); Assert.Equal(messageTexts.Count, output); // Pull the Message to confirm it is valid var result = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, false); Assert.True(result > 0); }
public async Task PublishBinaryMessages() { string randomName = _pubsubFixture.RandomName(); string topicId = $"testTopicAvroBinaryMessageCreation{randomName}"; string subscriptionId = $"testSubscriptionAvroBinaryMessageCreation{randomName}"; string schemaId = $"testSchemaAvroBinaryMessageCreation{randomName}"; var schema = _pubsubFixture.CreateAvroSchema(schemaId); _pubsubFixture.CreateTopicWithSchema(topicId, schema.Name.ToString(), Encoding.Binary); _pubsubFixture.CreateSubscription(topicId, subscriptionId); List <AvroUtilities.State> messageTexts = new List <AvroUtilities.State> { new AvroUtilities.State { name = "New York", post_abbr = "NY" }, new AvroUtilities.State { name = "Pennsylvania", post_abbr = "PA" } }; var output = await _publishAvroMessagesAsyncSample.PublishAvroMessagesAsync(_pubsubFixture.ProjectId, topicId, messageTexts); Assert.Equal(messageTexts.Count, output); // Pull the Message to confirm it is valid await _pubsubFixture.Pull.Eventually(async() => { var result = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, false); Assert.True(result > 0); }); }
public async void PullAvroBinaryMessagesAsync() { string randomName = _pubsubFixture.RandomName(); string topicId = $"testTopicForAvroBinaryMessageAck{randomName}"; string subscriptionId = $"testSubscriptionForAvroBinaryMessageAck{randomName}"; string schemaId = $"testSchemaForAvroMessageBinaryAck{randomName}"; var schema = _pubsubFixture.CreateAvroSchema(schemaId); _pubsubFixture.CreateTopicWithSchema(topicId, schema.Name.ToString(), Encoding.Binary); _pubsubFixture.CreateSubscription(topicId, subscriptionId); await _publishAvroMessagesAsyncSample.PublishAvroMessagesAsync(_pubsubFixture.ProjectId, topicId, new AvroUtilities.State[] { new AvroUtilities.State { name = "New York", post_abbr = "NY" } }); await _pubsubFixture.Pull.Eventually(async() => { // Pull and acknowledge the messages var result = await _pullAvroMessagesAsyncSample.PullAvroMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true); Assert.Equal(1, result); }); //Pull the Message to confirm it's gone after it's acknowledged var result = await _pullAvroMessagesAsyncSample.PullAvroMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true); Assert.Equal(0, result); }
public async Task PullMessagesWithFlowControlAsync() { string topicId = $"testTopicForMessageWithFlowControlAck{_pubsubFixture.RandomName()}"; _pubsubFixture.CreateTopic(topicId); // For this sample in particular, we need to retry the sbscription creation, the message publishing etc. // That's because this sample is configuring the ack deadline of the subscriber, which will be extended // automatically. While Pub/Sub has sent a message to a subscriber it will avoid sending it to another subscriber // of the same subscription until the ack deadline has expired. Since we are renewing the ack deadline, it won't // expire (soon) and if the message is sent but not acked, then Pub/Sub won't attempt to send the message // to a different susbcriber even if we keep retrying, as it is waiting for the ack deadline to expire, which we // keep extending. await _pubsubFixture.Pull.Eventually(async() => { string subscriptionId = $"testSubscriptionForMessageWithFlowControlAck{_pubsubFixture.RandomName()}"; _pubsubFixture.CreateSubscription(topicId, subscriptionId); var message = _pubsubFixture.RandomName(); await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, new string[] { message }); // Pull and acknowledge the messages var result = await _pullMessagesCustomAsyncSample.PullMessagesWithFlowControlAsync(_pubsubFixture.ProjectId, subscriptionId, true); Assert.Equal(1, result); //Pull the Message to confirm it's gone after it's acknowledged result = await _pullMessagesCustomAsyncSample.PullMessagesWithFlowControlAsync(_pubsubFixture.ProjectId, subscriptionId, true); Assert.Equal(0, result); }); }
public async void PullProtoBinaryMessagesAsync() { string randomName = _pubsubFixture.RandomName(); string topicId = $"testTopicForProtoBinaryMessageAck{randomName}"; string subscriptionId = $"testSubscriptionForProtoBinaryMessageAck{randomName}"; string schemaId = $"testSchemaForProtoBinaryMessageAck{randomName}"; var schema = _pubsubFixture.CreateProtoSchema(schemaId); _pubsubFixture.CreateTopicWithSchema(topicId, schema.Name.ToString(), Encoding.Binary); _pubsubFixture.CreateSubscription(topicId, subscriptionId); await _publishProtoMessagesAsyncSample.PublishProtoMessagesAsync(_pubsubFixture.ProjectId, topicId, new Utilities.State[] { new Utilities.State { Name = "New York", PostAbbr = "NY" } }); // Pull and acknowledge the messages var result = await _pullProtoMessagesAsyncSample.PullProtoMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true); Assert.Equal(1, result); //Pull the Message to confirm it's gone after it's acknowledged result = await _pullProtoMessagesAsyncSample.PullProtoMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true); Assert.True(result == 0); }
public void TestListSubscriptions() { string topicId = "testTopicForListingSubscriptions" + _pubsubFixture.RandomName(); string subscriptionId = "testSubscriptionForListingSubscriptions" + _pubsubFixture.RandomName(); _pubsubFixture.CreateTopic(topicId); _pubsubFixture.CreateSubscription(topicId, subscriptionId); var subscriptions = _listSubscriptionsSample.ListSubscriptions(_pubsubFixture.ProjectId); Assert.Contains(subscriptions.Select(s => s.SubscriptionName.SubscriptionId), c => c.Contains(subscriptionId)); }
public void CreateTopicWithSchema() { string schemaId = "testSchemaForTopicCreationWithSchema" + _pubsubFixture.RandomName(); var schema = _pubsubFixture.CreateAvroSchema(schemaId); string topicId = "testTopicForTopicCreationWithSchema" + _pubsubFixture.RandomName(); var newlyCreatedTopic = _createTopicWithSchemaSample.CreateTopicWithSchema(_pubsubFixture.ProjectId, topicId, schema.Name, Encoding.Json); _pubsubFixture.TempTopicIds.Add(topicId); var topic = _pubsubFixture.GetTopic(topicId); Assert.Equal(newlyCreatedTopic, topic); }
public void CreateSubscription() { string topicId = "testTopicForSubscriptionCreation" + _pubsubFixture.RandomName(); string subscriptionId = "testSubscriptionForSubscriptionCreation" + _pubsubFixture.RandomName(); _pubsubFixture.CreateTopic(topicId); var newlyCreatedSubscription = _createSubscriptionSample.CreateSubscription(_pubsubFixture.ProjectId, topicId, subscriptionId); _pubsubFixture.TempSubscriptionIds.Add(subscriptionId); var subscription = _pubsubFixture.GetSubscription(subscriptionId); Assert.Equal(newlyCreatedSubscription, subscription); }
public void TestDeleteSubscription() { string topicId = "testTopicForDeleteSubscription" + _pubsubFixture.RandomName(); string subscriptionId = "testSubscriptionForDeleteSubscription" + _pubsubFixture.RandomName(); _pubsubFixture.CreateTopic(topicId); _pubsubFixture.CreateSubscription(topicId, subscriptionId); _deleteSubscriptionSample.DeleteSubscription(_pubsubFixture.ProjectId, subscriptionId); Exception e = Assert.Throws <Grpc.Core.RpcException>(() => _pubsubFixture.GetSubscription(subscriptionId)); _pubsubFixture.TempSubscriptionIds.Remove(subscriptionId); // We already deleted it. }
public async void PullMessagesWithCustomAttributesAsync() { string randomName = _pubsubFixture.RandomName(); string topicId = $"testTopicForMessagesWithPullCustomAttributesAsync{randomName}"; string subscriptionId = $"testSubscriptionMessagesPullWithCustomAttributesAsync{randomName}"; string message = _pubsubFixture.RandomName(); _pubsubFixture.CreateTopic(topicId); _pubsubFixture.CreateSubscription(topicId, subscriptionId); await _publishMessageWithCustomAttributesAsyncSample.PublishMessageWithCustomAttributesAsync(_pubsubFixture.ProjectId, topicId, message); var messages = await _pullMessagesWithCustomAttributesAsyncSample.PullMessagesWithCustomAttributesAsync(_pubsubFixture.ProjectId, subscriptionId, true); Assert.Contains(messages, m => m.Attributes.Keys.Contains("year") && m.Attributes.Values.Contains("2020")); }
public void CreateAvroSchema() { string schemaId = "testAvroSchemaForSchemaCreation" + _pubsubFixture.RandomName(); var newlyCreatedSchema = _createAvroSchemaSample.CreateAvroSchema(_pubsubFixture.ProjectId, schemaId, _pubsubFixture.AvroSchemaFile); _pubsubFixture.TempSchemaIds.Add(schemaId); var schema = _pubsubFixture.GetSchema(schemaId); Assert.Equal(newlyCreatedSchema, schema); }
public void TestListSchemas() { string schemaId = "testSchemaForListSchemas" + _pubsubFixture.RandomName(); _pubsubFixture.CreateProtoSchema(schemaId); var schemas = _listSchemasSample.ListSchemas(_pubsubFixture.ProjectId); Assert.Contains(schemas.Select(s => s.SchemaName.SchemaId), c => c.Contains(schemaId)); }
public void CreateTopic() { string topicId = "testTopicForTopicCreation" + _pubsubFixture.RandomName(); var newlyCreatedTopic = _createTopicSample.CreateTopic(_pubsubFixture.ProjectId, topicId); _pubsubFixture.TempTopicIds.Add(topicId); var topic = _pubsubFixture.GetTopic(topicId); Assert.Equal(newlyCreatedTopic, topic); }
public void GetTopicIamPolicy() { string topicId = "testTopicForGetTopicIamPolicy" + _pubsubFixture.RandomName(); _pubsubFixture.CreateTopic(topicId); var policy = _getTopicIamPolicySample.GetTopicIamPolicy(_pubsubFixture.ProjectId, topicId); Assert.NotNull(policy); }
public void ListTopics() { string topicId = "testTopicForListingTopics" + _pubsubFixture.RandomName(); _pubsubFixture.CreateTopic(topicId); var listProjectTopicsOutput = _listProjectTopicsSample.ListProjectTopics(_pubsubFixture.ProjectId); Assert.Contains(listProjectTopicsOutput, c => c.TopicName.TopicId.Contains(topicId)); }
public void DeleteTopic() { string topicId = "testTopicForDeleteTopic" + _pubsubFixture.RandomName(); _pubsubFixture.CreateTopic(topicId); _deleteTopicSample.DeleteTopic(_pubsubFixture.ProjectId, topicId); Exception ex = Assert.Throws <Grpc.Core.RpcException>(() => _pubsubFixture.GetTopic(topicId)); _pubsubFixture.TempTopicIds.Remove(topicId); // We already deleted it. }
public void DeleteSchema() { string schemaId = "testSchemaForDeleteSchema" + _pubsubFixture.RandomName(); _pubsubFixture.CreateAvroSchema(schemaId); _deleteSchemaSample.DeleteSchema(_pubsubFixture.ProjectId, schemaId); Exception ex = Assert.Throws <Grpc.Core.RpcException>(() => _pubsubFixture.GetSchema(schemaId)); _pubsubFixture.TempSchemaIds.Remove(schemaId); // We already deleted it. }
public void GetSchema() { string schemaId = "testSchemaForGetSchema" + _pubsubFixture.RandomName(); _pubsubFixture.CreateAvroSchema(schemaId); _pubsubFixture.GetSchema(schemaId); var receivedSchema = _getSchemaSample.GetSchema(_pubsubFixture.ProjectId, schemaId); var schema = _pubsubFixture.GetSchema(schemaId); Assert.Equal(receivedSchema, schema); }
public async void PublishMessage() { string topicId = "testTopicForMessageCreation" + _pubsubFixture.RandomName(); string subscriptionId = "testSubscriptionForMessageCreation" + _pubsubFixture.RandomName(); _pubsubFixture.CreateTopic(topicId); _pubsubFixture.CreateSubscription(topicId, subscriptionId); List <string> messageTexts = new List <string> { "Hello World!", "Good day.", "Bye bye." }; var output = await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, messageTexts); Assert.Equal(messageTexts.Count, output); // Pull the Message to confirm it is valid var result = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, false); Assert.True(result > 0); }
public void GetSubscriptionPolicy() { string topicId = "testTopicGetSubscriptionIamPolicy" + _pubsubFixture.RandomName(); string subscriptionId = "testSubscriptionGetSubscriptionIamPolicy"; _pubsubFixture.CreateTopic(topicId); _pubsubFixture.CreateSubscription(topicId, subscriptionId); var policy = _getSubscriptionIamPolicySample.GetSubscriptionIamPolicy(_pubsubFixture.ProjectId, subscriptionId); Assert.NotNull(policy); }
public async void PullMessagesSync() { string topicId = "testTopicForMessageSyncAck" + _pubsubFixture.RandomName(); string subscriptionId = "testSubscriptionForMessageSyncAck" + _pubsubFixture.RandomName(); var message = _pubsubFixture.RandomName(); _pubsubFixture.CreateTopic(topicId); _pubsubFixture.CreateSubscription(topicId, subscriptionId); await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, new string[] { message }); // Pull and acknowledge the messages var result = _pullMessagesSyncSample.PullMessagesSync(_pubsubFixture.ProjectId, subscriptionId, true); // sometimes UNAVAILABLE response from service. Assert.True(result <= 1); //Pull the Message to confirm it's gone after it's acknowledged result = _pullMessagesSyncSample.PullMessagesSync(_pubsubFixture.ProjectId, subscriptionId, true); Assert.True(result <= 1); }
public async void AcknowledgeMessageWithFlowControl() { string topicId = "testTopicForMessageWithFlowControlAck" + _pubsubFixture.RandomName(); string subscriptionId = "testSubscriptionForMessageWithFlowControlAck" + _pubsubFixture.RandomName(); var message = _pubsubFixture.RandomName(); _pubsubFixture.CreateTopic(topicId); _pubsubFixture.CreateSubscription(topicId, subscriptionId); await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, new string[] { message }); // Pull and acknowledge the messages var result = await _pullMessagesCustomAsyncSample.PullMessagesWithFlowControlAsync(_pubsubFixture.ProjectId, subscriptionId, true); Assert.Equal(1, result); //Pull the Message to confirm it's gone after it's acknowledged result = await _pullMessagesCustomAsyncSample.PullMessagesWithFlowControlAsync(_pubsubFixture.ProjectId, subscriptionId, true); Assert.True(result == 0); }
public void CreateSubscriptionWithDeadLetterPolicy() { string randomName = _pubsubFixture.RandomName(); string topicId = $"testTopicForCreateSubscriptionWithDeadLetterPolicy{randomName}"; string subscriptionId = $"testSubscriptionForCreateSubscriptionWithDeadLetterPolicy{randomName}"; _pubsubFixture.CreateTopic(topicId); _createSubscriptionWithDeadLetterPolicySample.CreateSubscriptionWithDeadLetterPolicy(_pubsubFixture.ProjectId, subscriptionId, topicId, _pubsubFixture.DeadLetterTopic); _pubsubFixture.TempSubscriptionIds.Add(subscriptionId); var subscription = _pubsubFixture.GetSubscription(subscriptionId); Assert.Equal(10, subscription.DeadLetterPolicy.MaxDeliveryAttempts); }
public void CreateSubscriptionWithOrdering() { string randomName = _pubsubFixture.RandomName(); string topicId = $"testTopicForCreateSubscriptionWithOrdering{randomName}"; string subscriptionId = $"testSubscriptionForCreateSubscriptionWithOrdering{randomName}"; _pubsubFixture.CreateTopic(topicId); _createSubscriptionWithOrderingSample.CreateSubscriptionWithOrdering(_pubsubFixture.ProjectId, subscriptionId, topicId); _pubsubFixture.TempSubscriptionIds.Add(subscriptionId); var subscription = _pubsubFixture.GetSubscription(subscriptionId); Assert.True(subscription.EnableMessageOrdering); }
public void SetTopicIamPolicy() { string topicId = "testTopicForSetTopicIamPolicy" + _pubsubFixture.RandomName(); string testRoleValueToConfirm = "pubsub.editor"; string testMemberValueToConfirm = "group:[email protected]"; _pubsubFixture.CreateTopic(topicId); var policy = _setTopicIamPolicySample.SetTopicIamPolicy(_pubsubFixture.ProjectId, topicId, testRoleValueToConfirm, testMemberValueToConfirm); Assert.Equal($"roles/{testRoleValueToConfirm}", policy.Bindings[0].Role); Assert.Contains(policy.Bindings[0].Members, c => c.Contains(testMemberValueToConfirm)); }
public async void PullMessagesAsyncWithDeliveryAttempts() { string randomName = _pubsubFixture.RandomName(); string topicId = $"testTopicForDeadLetterPolicyMessageSyncAck{randomName}"; string subscriptionId = $"testSubscriptionDeadLetterPolicyForMessageSyncAck{randomName}"; var message = _pubsubFixture.RandomName(); _pubsubFixture.CreateTopic(topicId); _createSubscriptionWithDeadLetterPolicySample.CreateSubscriptionWithDeadLetterPolicy( _pubsubFixture.ProjectId, subscriptionId, topicId, _pubsubFixture.DeadLetterTopic); _pubsubFixture.TempSubscriptionIds.Add(subscriptionId); await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, new List <string> { message }); // Pull and acknowledge the messages var deliveryAttempt = await _pullMessagesAsyncWithDeliveryAttemptsSample.PullMessagesAsyncWithDeliveryAttempts(_pubsubFixture.ProjectId, subscriptionId, true); Assert.True(deliveryAttempt > 0); }
public async Task WithEmulatorAsync() { string randomName = _pubsubFixture.RandomName(); string topicId = $"testTopicForMessageCreation{randomName}"; string subscriptionId = $"testSubscriptionForMessageCreation{randomName}"; _pubsubFixture.TempTopicIds.Add(topicId); _pubsubFixture.TempSubscriptionIds.Add(subscriptionId); // We just test that the method finishes without error. // Note that we don't set the PUBSUB_EMULATOR_HOST so, this really executes against production, // but that's fine. await _emulatorSupportSample.WithEmulatorAsync(_pubsubFixture.ProjectId, topicId, subscriptionId); }
public void TopicIamPolicyPermissions() { string topicId = "testTopicForTestTopicIamPolicy" + _pubsubFixture.RandomName(); string testRoleValueToConfirm = "pubsub.editor"; string testMemberValueToConfirm = "group:[email protected]"; _pubsubFixture.CreateTopic(topicId); _setTopicIamPolicySample.SetTopicIamPolicy(_pubsubFixture.ProjectId, topicId, testRoleValueToConfirm, testMemberValueToConfirm); var response = _testTopicIamPermissionsSample.TestTopicIamPermissions(_pubsubFixture.ProjectId, topicId); Assert.NotEmpty(response.ToString()); }
public async Task PullMessagesAsync() { string randomName = _pubsubFixture.RandomName(); string topicId = $"testTopicForMessageAck{randomName}"; string subscriptionId = $"testSubscriptionForMessageAck{randomName}"; var message = _pubsubFixture.RandomName(); _pubsubFixture.CreateTopic(topicId); _pubsubFixture.CreateSubscription(topicId, subscriptionId); await _publishMessagesAsyncSample.PublishMessagesAsync(_pubsubFixture.ProjectId, topicId, new string[] { message }); await _pubsubFixture.Pull.Eventually(async() => { // Pull and acknowledge the messages var result = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true); Assert.Equal(1, result); }); //Pull the Message to confirm it's gone after it's acknowledged var result = await _pullMessagesAsyncSample.PullMessagesAsync(_pubsubFixture.ProjectId, subscriptionId, true); Assert.Equal(0, result); }
public void TestDetachSubscription() { string randomName = _pubsubFixture.RandomName(); string topicId = $"testTopicForDetachSubscription{randomName}"; string subscriptionId = $"testSubscriptionForDetachSubscription{randomName}"; _pubsubFixture.CreateTopic(topicId); _pubsubFixture.CreateSubscription(topicId, subscriptionId); _detachSubscriptionSample.DetachSubscription(_pubsubFixture.ProjectId, subscriptionId); var subscription = _pubsubFixture.GetSubscription(subscriptionId); Assert.True(subscription.Detached); }