Пример #1
0
        private static EtlInMemoryProducer CreateEtlInMemoryProducerWithFastAndSlowConsumerForTest(
            string logDirectory,
            ITraceFileEventReaderFactory traceFileEventReaderFactory)
        {
            var mockDiskSpaceManager        = TestUtility.MockRepository.Create <DiskSpaceManager>();
            var etlInMemoryProducerSettings = new EtlInMemoryProducerSettings(
                true,
                TimeSpan.FromSeconds(1),
                TimeSpan.FromDays(3000),
                WinFabricEtlType.DefaultEtl,
                logDirectory,
                TestUtility.TestEtlFilePatterns,
                true);

            var configReader = TestUtility.MockRepository.Create <IEtlInMemoryProducerConfigReader>();

            configReader.Setup(c => c.GetSettings()).Returns(etlInMemoryProducerSettings);

            var mockTraceEventSourceFactory = TestUtility.MockRepository.Create <ITraceEventSourceFactory>();

            mockTraceEventSourceFactory
            .Setup(tsf => tsf.CreateTraceEventSource(It.IsAny <EventTask>()))
            .Returns(new ErrorAndWarningFreeTraceEventSource());

            var configStore = TestUtility.MockRepository.Create <IConfigStore>();

            configStore
            .Setup(cs => cs.ReadUnencryptedString("Diagnostics", "MaxDiskQuotaInMB"))
            .Returns("100");
            configStore
            .Setup(cs => cs.ReadUnencryptedString("Diagnostics", "DiskFullSafetySpaceInMB"))
            .Returns("0");
            Utility.InitializeConfigStore(configStore.Object);

            var mockConfigReaderFactory = TestUtility.MockRepository.Create <IEtlInMemoryProducerConfigReaderFactory>();

            mockConfigReaderFactory.Setup(f => f.CreateEtlInMemoryProducerConfigReader(It.IsAny <FabricEvents.ExtensionsEvents>(), It.IsAny <string>()))
            .Returns(configReader.Object);

            var fastDcaInMemoryConsumer = CreateEtlToInMemoryBufferWriter(logDirectory, false);
            var slowDcaInMemoryConsumer = CreateEtlToInMemoryBufferWriter(logDirectory, true);

            var fastEtlToInMemoryBufferWriter = new EtlToInMemoryBufferWriter(
                mockTraceEventSourceFactory.Object,
                LogSourceId,
                TestNodeId,
                TestUtility.GetActualOutputFolderPath(logDirectory),
                true,
                fastDcaInMemoryConsumer);

            var slowEtlToInMemoryBufferWriter = new EtlToInMemoryBufferWriter(
                mockTraceEventSourceFactory.Object,
                LogSourceId,
                TestNodeId,
                TestUtility.GetActualOutputFolderPath(logDirectory),
                true,
                slowDcaInMemoryConsumer);

            var initParam = new ProducerInitializationParameters
            {
                ConsumerSinks = new[] { fastEtlToInMemoryBufferWriter, slowEtlToInMemoryBufferWriter }
            };

            return(new EtlInMemoryProducer(
                       mockDiskSpaceManager.Object,
                       mockConfigReaderFactory.Object,
                       traceFileEventReaderFactory,
                       mockTraceEventSourceFactory.Object,
                       initParam));
        }
Пример #2
0
        private static EtlInMemoryProducer CreateEtlInMemoryProducerWithMDSConsumer(string logDirectory, ITraceFileEventReaderFactory traceFileEventReaderFactory)
        {
            var mockDiskSpaceManager        = TestUtility.MockRepository.Create <DiskSpaceManager>();
            var etlInMemoryProducerSettings = new EtlInMemoryProducerSettings(
                true,
                TimeSpan.FromSeconds(1),
                TimeSpan.FromDays(3000),
                WinFabricEtlType.DefaultEtl,
                logDirectory,
                TestEtlFilePatterns,
                true);

            var configReader = TestUtility.MockRepository.Create <IEtlInMemoryProducerConfigReader>();

            configReader.Setup(c => c.GetSettings()).Returns(etlInMemoryProducerSettings);

            var mockTraceEventSourceFactory = TestUtility.MockRepository.Create <ITraceEventSourceFactory>();

            mockTraceEventSourceFactory
            .Setup(tsf => tsf.CreateTraceEventSource(It.IsAny <EventTask>()))
            .Returns(new ErrorAndWarningFreeTraceEventSource());

            var configStore = TestUtility.MockRepository.Create <IConfigStore>();

            configStore
            .Setup(cs => cs.ReadUnencryptedString("Diagnostics", "MaxDiskQuotaInMB"))
            .Returns("100");
            configStore
            .Setup(cs => cs.ReadUnencryptedString("Diagnostics", "DiskFullSafetySpaceInMB"))
            .Returns("0");
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, MdsFileProducerConstants.EnabledParamName))
            .Returns("true");
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, MdsFileProducerConstants.DirectoryParamName))
            .Returns(logDirectory);
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, MdsFileProducerConstants.TableParamName))
            .Returns(TableName);
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, MdsFileProducerConstants.TablePriorityParamName))
            .Returns(MdsFileProducerConstants.DefaultTablePriority);
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, MdsFileProducerConstants.DiskQuotaParamName))
            .Returns(MdsFileProducerConstants.DefaultDiskQuotaInMB.ToString());
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, MdsFileProducerConstants.BookmarkBatchSizeParamName))
            .Returns(MdsFileProducerConstants.DefaultBookmarkBatchSize.ToString());
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, MdsFileProducerConstants.DataDeletionAgeParamName))
            .Returns(MdsFileProducerConstants.DefaultDataDeletionAge.TotalDays.ToString());
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, MdsFileProducerConstants.TestDataDeletionAgeParamName))
            .Returns(MdsFileProducerConstants.DefaultDataDeletionAge.TotalDays.ToString());
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, MdsFileProducerConstants.LogFilterParamName))
            .Returns(LogFilter);

            Utility.InitializeConfigStore(configStore.Object);

            var mockConfigReaderFactory = TestUtility.MockRepository.Create <IEtlInMemoryProducerConfigReaderFactory>();

            mockConfigReaderFactory.Setup(f => f.CreateEtlInMemoryProducerConfigReader(It.IsAny <FabricEvents.ExtensionsEvents>(), It.IsAny <string>()))
            .Returns(configReader.Object);

            // Create the MDS consumer
            ConfigReader.AddAppConfig(Utility.WindowsFabricApplicationInstanceId, null);
            var consumerInitParam = new ConsumerInitializationParameters(
                Utility.WindowsFabricApplicationInstanceId,
                TestConfigSectionName,
                TestFabricNodeId,
                TestFabricNodeName,
                Utility.LogDirectory,
                Utility.DcaWorkFolder,
                new DiskSpaceManager());

            var mdsFileProducer           = new MdsFileProducer(consumerInitParam);
            var etlToInMemoryBufferWriter = mdsFileProducer.GetDataSink();

            var producerInitParam = new ProducerInitializationParameters
            {
                ConsumerSinks = new[] { etlToInMemoryBufferWriter }
            };

            // Create the in-memory producer
            return(new EtlInMemoryProducer(
                       mockDiskSpaceManager.Object,
                       mockConfigReaderFactory.Object,
                       traceFileEventReaderFactory,
                       mockTraceEventSourceFactory.Object,
                       producerInitParam));
        }
        private static void CreateEtlInMemoryProducerWithAzureBlobConsumer(
            string logDirectory,
            ITraceFileEventReaderFactory traceFileEventReaderFactory,
            out EtlInMemoryProducer etlInMemoryProducer,
            out string containerName,
            out StorageAccountFactory storageAccountFactory,
            AccessCondition uploadStreamAccessCondition = null,
            AccessCondition uploadFileAccessCondition   = null)
        {
            var mockDiskSpaceManager        = TestUtility.MockRepository.Create <DiskSpaceManager>();
            var etlInMemoryProducerSettings = new EtlInMemoryProducerSettings(
                true,
                TimeSpan.FromSeconds(1),
                TimeSpan.FromDays(3000),
                WinFabricEtlType.DefaultEtl,
                logDirectory,
                TestEtlFilePatterns,
                true);

            var configReader = TestUtility.MockRepository.Create <IEtlInMemoryProducerConfigReader>();

            configReader.Setup(c => c.GetSettings()).Returns(etlInMemoryProducerSettings);

            var mockTraceEventSourceFactory = TestUtility.MockRepository.Create <ITraceEventSourceFactory>();

            mockTraceEventSourceFactory
            .Setup(tsf => tsf.CreateTraceEventSource(It.IsAny <EventTask>()))
            .Returns(new ErrorAndWarningFreeTraceEventSource());

            var configStore = TestUtility.MockRepository.Create <IConfigStore>();

            configStore
            .Setup(cs => cs.ReadUnencryptedString("Diagnostics", "MaxDiskQuotaInMB"))
            .Returns("100");
            configStore
            .Setup(cs => cs.ReadUnencryptedString("Diagnostics", "DiskFullSafetySpaceInMB"))
            .Returns("0");
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, AzureConstants.EnabledParamName))
            .Returns("true");

            containerName = string.Format("{0}-{1}", "fabriclogs", Guid.NewGuid());
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, AzureConstants.ContainerParamName))
            .Returns(containerName);

            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, AzureConstants.FileSyncIntervalParamName))
            .Returns("0.25");
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, AzureConstants.DataDeletionAgeParamName))
            .Returns("1");
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, AzureConstants.TestDataDeletionAgeParamName))
            .Returns("0");
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, AzureConstants.LogFilterParamName))
            .Returns("*.*:4");
            configStore
            .Setup(cs => cs.ReadUnencryptedString(TestConfigSectionName, AzureConstants.DeploymentId))
            .Returns(AzureConstants.DefaultDeploymentId);

            var accountKey              = GetTestStorageAccountKey();
            var isEncrypted             = false;
            var storageConnectionString = string.Format(@"xstore:DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", AccountName, accountKey);

            configStore
            .Setup(cs => cs.ReadString(TestConfigSectionName, AzureConstants.ConnectionStringParamName, out isEncrypted))
            .Returns(storageConnectionString);

            Utility.InitializeConfigStore(configStore.Object);

            var mockConfigReaderFactory = TestUtility.MockRepository.Create <IEtlInMemoryProducerConfigReaderFactory>();

            mockConfigReaderFactory.Setup(f => f.CreateEtlInMemoryProducerConfigReader(It.IsAny <FabricEvents.ExtensionsEvents>(), It.IsAny <string>()))
            .Returns(configReader.Object);

            // Create the Azure Blob Uploader consumer
            ConfigReader.AddAppConfig(Utility.WindowsFabricApplicationInstanceId, null);
            var consumerInitParam = new ConsumerInitializationParameters(
                Utility.WindowsFabricApplicationInstanceId,
                TestConfigSectionName,
                TestFabricNodeId,
                TestFabricNodeName,
                Utility.LogDirectory,
                Utility.DcaWorkFolder,
                new DiskSpaceManager());

            // Save storage connection for clean up
            var azureUtility = new AzureUtility(new FabricEvents.ExtensionsEvents(FabricEvents.Tasks.FabricDCA), TraceType);

            storageAccountFactory = azureUtility.GetStorageAccountFactory(
                new ConfigReader(consumerInitParam.ApplicationInstanceId),
                TestConfigSectionName,
                AzureConstants.ConnectionStringParamName);

            var azureBlobConsumer         = new AzureBlobEtwUploader(consumerInitParam, uploadStreamAccessCondition, uploadFileAccessCondition);
            var etlToInMemoryBufferWriter = azureBlobConsumer.GetDataSink();

            var producerInitParam = new ProducerInitializationParameters
            {
                ConsumerSinks = new[] { etlToInMemoryBufferWriter }
            };

            // Create the in-memory producer
            etlInMemoryProducer = new EtlInMemoryProducer(
                mockDiskSpaceManager.Object,
                mockConfigReaderFactory.Object,
                traceFileEventReaderFactory,
                mockTraceEventSourceFactory.Object,
                producerInitParam);
        }