Exemplo n.º 1
0
        public async Task GetSinkAsync()
        {
            Mock <ConfigServiceV2.ConfigServiceV2Client> mockGrpcClient = new Mock <ConfigServiceV2.ConfigServiceV2Client>(MockBehavior.Strict);
            GetSinkRequest expectedRequest = new GetSinkRequest
            {
                SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")),
            };
            LogSink expectedResponse = new LogSink
            {
                Name = "name3373707",
                DestinationAsResourceName = new BillingName("[BILLING_ACCOUNT]"),
                Filter          = "filter-1274492040",
                WriterIdentity  = "writerIdentity775638794",
                IncludeChildren = true,
            };

            mockGrpcClient.Setup(x => x.GetSinkAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <LogSink>(Task.FromResult(expectedResponse), null, null, null, null));
            ConfigServiceV2Client client   = new ConfigServiceV2ClientImpl(mockGrpcClient.Object, null);
            SinkNameOneof         sinkName = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]"));
            LogSink response = await client.GetSinkAsync(sinkName);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 2
0
        public void UpdateSink3()
        {
            Mock <ConfigServiceV2.ConfigServiceV2Client> mockGrpcClient = new Mock <ConfigServiceV2.ConfigServiceV2Client>(MockBehavior.Strict);
            UpdateSinkRequest request = new UpdateSinkRequest
            {
                SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")),
                Sink = new LogSink(),
            };
            LogSink expectedResponse = new LogSink
            {
                Name = "name3373707",
                DestinationAsResourceName = new BillingName("[BILLING_ACCOUNT]"),
                Filter          = "filter-1274492040",
                WriterIdentity  = "writerIdentity775638794",
                IncludeChildren = true,
            };

            mockGrpcClient.Setup(x => x.UpdateSink(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            ConfigServiceV2Client client = new ConfigServiceV2ClientImpl(mockGrpcClient.Object, null);
            LogSink response             = client.UpdateSink(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 3
0
        // [END logging_delete_log]

        // [START logging_delete_log_sink]
        private void DeleteSink(string sinkId)
        {
            var      sinkClient = ConfigServiceV2Client.Create();
            SinkName sinkName   = new SinkName(s_projectId, sinkId);

            sinkClient.DeleteSink(SinkNameOneof.From(sinkName), _retryAWhile);
            Console.WriteLine($"Deleted {sinkId}.");
        }
 /// <summary>Snippet for GetSink</summary>
 public void GetSink()
 {
     // Snippet: GetSink(SinkNameOneof,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     SinkNameOneof sinkName = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]"));
     // Make the request
     LogSink response = configServiceV2Client.GetSink(sinkName);
     // End snippet
 }
Exemplo n.º 5
0
        // [END list_log_sinks]

        // [START update_log_sink]
        private void UpdateSinkLog(string sinkId, string logId)
        {
            var      sinkClient = ConfigServiceV2Client.Create();
            LogName  logName    = new LogName(s_projectId, logId);
            SinkName sinkName   = new SinkName(s_projectId, sinkId);
            var      sink       = sinkClient.GetSink(SinkNameOneof.From(sinkName), _retryAWhile);

            sink.Filter = $"logName={logName.ToString()}AND severity<=ERROR";
            sinkClient.UpdateSink(SinkNameOneof.From(sinkName), sink, _retryAWhile);
            Console.WriteLine($"Updated {sinkId} to export logs from {logId}.");
        }
 /// <summary>Snippet for UpdateSink</summary>
 public void UpdateSink1()
 {
     // Snippet: UpdateSink(SinkNameOneof,LogSink,FieldMask,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     SinkNameOneof sinkName   = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]"));
     LogSink       sink       = new LogSink();
     FieldMask     updateMask = new FieldMask();
     // Make the request
     LogSink response = configServiceV2Client.UpdateSink(sinkName, sink, updateMask);
     // End snippet
 }
 /// <summary>Snippet for GetSink</summary>
 public void GetSink_RequestObject()
 {
     // Snippet: GetSink(GetSinkRequest,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     GetSinkRequest request = new GetSinkRequest
     {
         SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")),
     };
     // Make the request
     LogSink response = configServiceV2Client.GetSink(request);
     // End snippet
 }
        /// <summary>Snippet for DeleteSinkAsync</summary>
        public async Task DeleteSinkAsync()
        {
            // Snippet: DeleteSinkAsync(SinkNameOneof,CallSettings)
            // Additional: DeleteSinkAsync(SinkNameOneof,CancellationToken)
            // Create client
            ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync();

            // Initialize request argument(s)
            SinkNameOneof sinkName = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]"));
            // Make the request
            await configServiceV2Client.DeleteSinkAsync(sinkName);

            // End snippet
        }
        /// <summary>Snippet for UpdateSinkAsync</summary>
        public async Task UpdateSinkAsync2()
        {
            // Snippet: UpdateSinkAsync(SinkNameOneof,LogSink,CallSettings)
            // Additional: UpdateSinkAsync(SinkNameOneof,LogSink,CancellationToken)
            // Create client
            ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync();

            // Initialize request argument(s)
            SinkNameOneof sinkName = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]"));
            LogSink       sink     = new LogSink();
            // Make the request
            LogSink response = await configServiceV2Client.UpdateSinkAsync(sinkName, sink);

            // End snippet
        }
        /// <summary>Snippet for DeleteSinkAsync</summary>
        public async Task DeleteSinkAsync_RequestObject()
        {
            // Snippet: DeleteSinkAsync(DeleteSinkRequest,CallSettings)
            // Create client
            ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync();

            // Initialize request argument(s)
            DeleteSinkRequest request = new DeleteSinkRequest
            {
                SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")),
            };
            // Make the request
            await configServiceV2Client.DeleteSinkAsync(request);

            // End snippet
        }
Exemplo n.º 11
0
        public async Task DeleteSinkAsync2()
        {
            Mock <ConfigServiceV2.ConfigServiceV2Client> mockGrpcClient = new Mock <ConfigServiceV2.ConfigServiceV2Client>(MockBehavior.Strict);
            DeleteSinkRequest request = new DeleteSinkRequest
            {
                SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")),
            };
            Empty expectedResponse = new Empty();

            mockGrpcClient.Setup(x => x.DeleteSinkAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Empty>(Task.FromResult(expectedResponse), null, null, null, null));
            ConfigServiceV2Client client = new ConfigServiceV2ClientImpl(mockGrpcClient.Object, null);
            await client.DeleteSinkAsync(request);

            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 12
0
        public void DeleteSink2()
        {
            Mock <ConfigServiceV2.ConfigServiceV2Client> mockGrpcClient = new Mock <ConfigServiceV2.ConfigServiceV2Client>(MockBehavior.Strict);
            DeleteSinkRequest request = new DeleteSinkRequest
            {
                SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")),
            };
            Empty expectedResponse = new Empty();

            mockGrpcClient.Setup(x => x.DeleteSink(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            ConfigServiceV2Client client = new ConfigServiceV2ClientImpl(mockGrpcClient.Object, null);

            client.DeleteSink(request);
            mockGrpcClient.VerifyAll();
        }
        /// <summary>Snippet for GetSinkAsync</summary>
        public async Task GetSinkAsync_RequestObject()
        {
            // Snippet: GetSinkAsync(GetSinkRequest,CallSettings)
            // Additional: GetSinkAsync(GetSinkRequest,CancellationToken)
            // Create client
            ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync();

            // Initialize request argument(s)
            GetSinkRequest request = new GetSinkRequest
            {
                SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")),
            };
            // Make the request
            LogSink response = await configServiceV2Client.GetSinkAsync(request);

            // End snippet
        }
        /// <summary>Snippet for UpdateSinkAsync</summary>
        public async Task UpdateSinkAsync_RequestObject()
        {
            // Snippet: UpdateSinkAsync(UpdateSinkRequest,CallSettings)
            // Create client
            ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync();

            // Initialize request argument(s)
            UpdateSinkRequest request = new UpdateSinkRequest
            {
                SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")),
                Sink = new LogSink(),
            };
            // Make the request
            LogSink response = await configServiceV2Client.UpdateSinkAsync(request);

            // End snippet
        }
Exemplo n.º 15
0
            public void TestCreateSink()
            {
                string   sinkId   = "sinkForTestCreateSink";
                string   logId    = "logForTestCreateSink";
                SinkName sinkName = new SinkName(_projectId, sinkId);
                string   message  = "Example log entry.";

                _sinksToDelete.Add(sinkId);
                _logsToDelete.Add(logId);
                // Try creating log with log entry.
                var created1 = Run("create-log-entry", logId, message);

                created1.AssertSucceeded();
                // Try creating sink.
                var created2 = Run("create-sink", sinkId, logId);

                created2.AssertSucceeded();
                var sinkClient = ConfigServiceV2Client.Create();
                var results    = sinkClient.GetSink(SinkNameOneof.From(sinkName));

                // Confirm newly created sink is returned.
                Assert.NotNull(results);
            }
Exemplo n.º 16
0
            public void TestUpdateSink()
            {
                string   sinkId   = "sinkForTestUpdateSink";
                string   logId    = "logForTestUpdateSink";
                string   newLogId = "newlogForTestUpdateSink";
                SinkName sinkName = new SinkName(_projectId, sinkId);
                string   message  = "Example log entry.";

                _sinksToDelete.Add(sinkId);
                _logsToDelete.Add(logId);
                _logsToDelete.Add(newLogId);
                // Try creating logs with log entries.
                Run("create-log-entry", logId, message).AssertSucceeded();
                Run("create-log-entry", newLogId, message).AssertSucceeded();
                Run("create-sink", sinkId, logId).AssertSucceeded();
                // Try updating sink.
                Run("update-sink", sinkId, newLogId).AssertSucceeded();
                // Get sink to confirm that log has been updated.
                var sinkClient = ConfigServiceV2Client.Create();
                var results    = sinkClient.GetSink(SinkNameOneof.From(sinkName));
                var currentLog = results.Filter;

                Assert.Contains(newLogId, currentLog);
            }
Exemplo n.º 17
0
            public void TestDeleteSink()
            {
                string   sinkId   = "sinkForTestDeleteSink";
                string   logId    = "logForTestDeleteSink";
                SinkName sinkName = new SinkName(_projectId, sinkId);
                string   message  = "Example log entry.";

                _logsToDelete.Add(logId);
                // Try creating log with log entry.
                Run("create-log-entry", logId, message).AssertSucceeded();
                // Try creating sink.
                Run("create-sink", sinkId, logId).AssertSucceeded();
                // Try deleting sink.
                Run("delete-sink", sinkId);
                // Get sink to confirm it has been deleted.
                var       sinkClient = ConfigServiceV2Client.Create();
                Exception ex         = Assert.Throws <Grpc.Core.RpcException>(() =>
                                                                              sinkClient.GetSink(SinkNameOneof.From(sinkName)));
            }