<commit_before>using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Orleans.MultiCluster;
using Orleans.Runtime;
using Orleans.Runtime.Configuration;
using Orleans.Runtime.MultiClusterNetwork;
using Orleans.TestingHost.Utils;
using TestExtensions;
using Xunit;

namespace Tester.AzureUtils
{
    public class AzureGossipTableTests : AzureStorageBasicTests , IDisposable
    {
        private readonly ILogger logger;

        private Guid globalServiceId; //this should be the same for all clusters. Use this as partition key.
        private SiloAddress siloAddress1;
        private SiloAddress siloAddress2;
        private static readonly TimeSpan Timeout = TimeSpan.FromMinutes(1);
        private AzureTableBasedGossipChannel gossipTable; // This type is internal
        private readonly ILoggerFactory loggerFactory;
        public AzureGossipTableTests()
        {
            this.loggerFactory = TestingUtils.CreateDefaultLoggerFactory($"{this.GetType().Name}.log");
            this.logger = this.loggerFactory.CreateLogger<AzureGossipTableTests>();

            this.globalServiceId = Guid.NewGuid();

            IPAddress ip;
            if (!IPAddress.TryParse("127.0.0.1", out ip))
            {
                this.logger.Error(-1, "Could not parse ip address");
                return;
            }
            IPEndPoint ep1 = new IPEndPoint(ip, 21111);
            this.siloAddress1 = SiloAddress.New(ep1, 0);
            IPEndPoint ep2 = new IPEndPoint(ip, 21112);
            this.siloAddress2 = SiloAddress.New(ep2, 0);

            this.logger.Info("Global ServiceId={0}", this.globalServiceId);
            
            this.gossipTable = new AzureTableBasedGossipChannel(this.loggerFactory);
            var done = this.gossipTable.Initialize(globalServiceId.ToString(), TestDefaultConfiguration.DataConnectionString);
            if (!done.Wait(Timeout))
            {
                throw new TimeoutException("Could not create/read table.");
            }
        }

        public void Dispose()
        {
            this.loggerFactory.Dispose();
        }

        [SkippableFact, TestCategory("Functional"), TestCategory("GeoCluster"), TestCategory("Azure"), TestCategory("Storage")]
        public async Task AzureGossip_ConfigGossip()
        {
            // start clean
            await this.gossipTable.DeleteAllEntries();

            // push empty data
            await this.gossipTable.Publish(new MultiClusterData());

            // push and pull empty data
            var answer = await this.gossipTable.Synchronize(new MultiClusterData());
            Assert.True(answer.IsEmpty);

            var ts1 = new DateTime(year: 2011, month: 1, day: 1);
            var ts2 = new DateTime(year: 2012, month: 2, day: 2);
            var ts3 = new DateTime(year: 2013, month: 3, day: 3);

            var conf1 = new MultiClusterConfiguration(ts1, new string[] { "A" }.ToList(), "comment");
            var conf2 = new MultiClusterConfiguration(ts2, new string[] { "A", "B", "C" }.ToList());
            var conf3 = new MultiClusterConfiguration(ts3, new string[] { }.ToList());

            // push configuration 1
            await this.gossipTable.Publish(new MultiClusterData(conf1));

            // retrieve (by push/pull empty)
            answer = await this.gossipTable.Synchronize(new MultiClusterData());
            Assert.Equal(conf1, answer.Configuration);<commit_msg>Fix AzureGossip_ConfigGossip to use UTC DateTime instead of local. (#6019)<commit_after>using System;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Orleans.MultiCluster;
using Orleans.Runtime;
using Orleans.Runtime.Configuration;
using Orleans.Runtime.MultiClusterNetwork;
using Orleans.TestingHost.Utils;
using TestExtensions;
using Xunit;

namespace Tester.AzureUtils
{
    public class AzureGossipTableTests : AzureStorageBasicTests , IDisposable
    {
        private readonly ILogger logger;

        private Guid globalServiceId; //this should be the same for all clusters. Use this as partition key.
        private SiloAddress siloAddress1;
        private SiloAddress siloAddress2;
        private static readonly TimeSpan Timeout = TimeSpan.FromMinutes(1);
        private AzureTableBasedGossipChannel gossipTable; // This type is internal
        private readonly ILoggerFactory loggerFactory;
        public AzureGossipTableTests()
        {
            this.loggerFactory = TestingUtils.CreateDefaultLoggerFactory($"{this.GetType().Name}.log");
            this.logger = this.loggerFactory.CreateLogger<AzureGossipTableTests>();

            this.globalServiceId = Guid.NewGuid();

            IPAddress ip;
            if (!IPAddress.TryParse("127.0.0.1", out ip))
            {
                this.logger.Error(-1, "Could not parse ip address");
                return;
            }
            IPEndPoint ep1 = new IPEndPoint(ip, 21111);
            this.siloAddress1 = SiloAddress.New(ep1, 0);
            IPEndPoint ep2 = new IPEndPoint(ip, 21112);
            this.siloAddress2 = SiloAddress.New(ep2, 0);

            this.logger.Info("Global ServiceId={0}", this.globalServiceId);
            
            this.gossipTable = new AzureTableBasedGossipChannel(this.loggerFactory);
            var done = this.gossipTable.Initialize(globalServiceId.ToString(), TestDefaultConfiguration.DataConnectionString);
            if (!done.Wait(Timeout))
            {
                throw new TimeoutException("Could not create/read table.");
            }
        }

        public void Dispose()
        {
            this.loggerFactory.Dispose();
        }

        [SkippableFact, TestCategory("Functional"), TestCategory("GeoCluster"), TestCategory("Azure"), TestCategory("Storage")]
        public async Task AzureGossip_ConfigGossip()
        {
            // start clean
            await this.gossipTable.DeleteAllEntries();

            // push empty data
            await this.gossipTable.Publish(new MultiClusterData());

            // push and pull empty data
            var answer = await this.gossipTable.Synchronize(new MultiClusterData());
            Assert.True(answer.IsEmpty);

            var ts1 = new DateTime(year: 2011, month: 1, day: 1, hour: 0, minute: 0, second: 0, kind: DateTimeKind.Utc);
            var ts2 = new DateTime(year: 2012, month: 2, day: 2, hour: 0, minute: 0, second: 0, kind: DateTimeKind.Utc);
            var ts3 = new DateTime(year: 2013, month: 3, day: 3, hour: 0, minute: 0, second: 0, kind: DateTimeKind.Utc);

            var conf1 = new MultiClusterConfiguration(ts1, new string[] { "A" }.ToList(), "comment");
            var conf2 = new MultiClusterConfiguration(ts2, new string[] { "A", "B", "C" }.ToList());
            var conf3 = new MultiClusterConfiguration(ts3, new string[] { }.ToList());

            // push configuration 1
            await this.gossipTable.Publish(new MultiClusterData(conf1));

            // retrieve (by push/pull empty)
            answer = await this.gossipTable.Synchronize(new MultiClusterData());
            Assert.Equal(conf1, answer.Configuration);
{'fraction_non_alphanumeric': 0.10060723157604196, 'fraction_numerical': 0.018078940104885453, 'mean_word_length': 2.5576828669612173, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6717622', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1892, 'n_words': 498}