<commit_before>﻿//#define USE_GENERICS
//#define DELETE_AFTER_TEST

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
using Orleans;
using Orleans.Providers.Streams.AzureQueue;
using Orleans.Runtime;
using Orleans.Runtime.Configuration;
using Orleans.TestingHost;
using UnitTests.GrainInterfaces;
using UnitTests.Grains;
using UnitTests.StreamingTests;
using UnitTests.Tester;
using Xunit;
using Xunit.Abstractions;

// ReSharper disable ConvertToConstant.Local
// ReSharper disable CheckNamespace

namespace UnitTests.Streaming.Reliability
{
    public class StreamReliabilityTests : HostedTestClusterPerTest
    {
        private readonly ITestOutputHelper output;
        public const string SMS_STREAM_PROVIDER_NAME = "SMSProvider";
        public const string AZURE_QUEUE_STREAM_PROVIDER_NAME = StreamTestsConstants.AZURE_QUEUE_STREAM_PROVIDER_NAME;

        private Guid _streamId;
        private string _streamProviderName;
#if DELETE_AFTER_TEST
        private HashSet<IStreamReliabilityTestGrain> _usedGrains; 
#endif

        private static readonly Guid serviceId = Guid.NewGuid();
        private static readonly TestingSiloOptions siloRunOptions = new TestingSiloOptions
        {
            SiloConfigFile = new FileInfo("Config_AzureStreamProviders.xml"),
            LivenessType = GlobalConfiguration.LivenessProviderType.AzureTable,
            DataConnectionString = StorageTestConstants.DataConnectionString,
            AdjustConfig = config => { config.Globals.ServiceId = serviceId; }
        };

        private static readonly TestingClientOptions clientRunOptions = new TestingClientOptions
        {
            ClientConfigFile = new FileInfo("ClientConfig_AzureStreamProviders.xml")
        };

        private readonly int numExpectedSilos = siloRunOptions.StartSecondary ? 2 : 1;

        public override TestingSiloHost CreateSiloHost()
        {
            return new TestingSiloHost(siloRunOptions, clientRunOptions);
        }
        
        public StreamReliabilityTests(ITestOutputHelper output)
        {
            this.output = output;
            CheckSilosRunning("Initially", numExpectedSilos);
#if DELETE_AFTER_TEST
            _usedGrains = new HashSet<IStreamReliabilityTestGrain>(); 
#endif
        }

        public override void Dispose()
        {
#if DELETE_AFTER_TEST
            List<Task> promises = new List<Task>();
            foreach (var g in _usedGrains)
            {
                promises.Add(g.ClearGrain());
            }
            Task.WhenAll(promises).Wait();
#endif
            var deploymentId = HostedCluster.DeploymentId;
            base.Dispose();
            if (_streamProviderName != null && _streamProviderName.Equals(AZURE_QUEUE_STREAM_PROVIDER_NAME))
            {
                AzureQueueStreamProviderUtils.DeleteAllUsedAzureQueues(_streamProviderName, deploymentId, StorageTestConstants.DataConnectionString).Wait();
            }
        }
<commit_msg>Avoid reusing same ServiceId between clusters<commit_after>﻿//#define USE_GENERICS
//#define DELETE_AFTER_TEST

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Assert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
using Orleans;
using Orleans.Providers.Streams.AzureQueue;
using Orleans.Runtime;
using Orleans.Runtime.Configuration;
using Orleans.TestingHost;
using UnitTests.GrainInterfaces;
using UnitTests.Grains;
using UnitTests.StreamingTests;
using UnitTests.Tester;
using Xunit;
using Xunit.Abstractions;

// ReSharper disable ConvertToConstant.Local
// ReSharper disable CheckNamespace

namespace UnitTests.Streaming.Reliability
{
    public class StreamReliabilityTests : HostedTestClusterPerTest
    {
        private readonly ITestOutputHelper output;
        public const string SMS_STREAM_PROVIDER_NAME = "SMSProvider";
        public const string AZURE_QUEUE_STREAM_PROVIDER_NAME = StreamTestsConstants.AZURE_QUEUE_STREAM_PROVIDER_NAME;

        private Guid _streamId;
        private string _streamProviderName;
        private int numExpectedSilos;
#if DELETE_AFTER_TEST
        private HashSet<IStreamReliabilityTestGrain> _usedGrains; 
#endif

        public override TestingSiloHost CreateSiloHost()
        {
            Guid serviceId = Guid.NewGuid();
            var siloRunOptions = new TestingSiloOptions
            {
                StartSecondary = true,
                SiloConfigFile = new FileInfo("Config_AzureStreamProviders.xml"),
                LivenessType = GlobalConfiguration.LivenessProviderType.AzureTable,
                DataConnectionString = StorageTestConstants.DataConnectionString,
                AdjustConfig = config => { config.Globals.ServiceId = serviceId; }
            };
            var clientRunOptions = new TestingClientOptions
            {
                ClientConfigFile = new FileInfo("ClientConfig_AzureStreamProviders.xml")
            };
            this.numExpectedSilos = siloRunOptions.StartSecondary ? 2 : 1;
            return new TestingSiloHost(siloRunOptions, clientRunOptions);
        }
        
        public StreamReliabilityTests(ITestOutputHelper output)
        {
            this.output = output;
            CheckSilosRunning("Initially", numExpectedSilos);
#if DELETE_AFTER_TEST
            _usedGrains = new HashSet<IStreamReliabilityTestGrain>(); 
#endif
        }

        public override void Dispose()
        {
#if DELETE_AFTER_TEST
            List<Task> promises = new List<Task>();
            foreach (var g in _usedGrains)
            {
                promises.Add(g.ClearGrain());
            }
            Task.WhenAll(promises).Wait();
#endif
            var deploymentId = HostedCluster.DeploymentId;
            base.Dispose();
            if (_streamProviderName != null && _streamProviderName.Equals(AZURE_QUEUE_STREAM_PROVIDER_NAME))
            {
                AzureQueueStreamProviderUtils.DeleteAllUsedAzureQueues(_streamProviderName, deploymentId, StorageTestConstants.DataConnectionString).Wait();
            }
        }

{'fraction_non_alphanumeric': 0.06884406019852705, 'fraction_numerical': 0.0006404098623118795, 'mean_word_length': 3.01994851994852, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4822075', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1633, 'n_words': 338}