Exemplo n.º 1
0
        protected IRingMasterRequestHandler ConnectToRingMaster()
        {
            SimpleTransport           clientTransport = null;
            IRingMasterRequestHandler ringMaster      = null;
            bool mustDispose = true;

            try
            {
                var configuration = new RingMasterClient.Configuration();
                IRingMasterClientInstrumentation instrumentation = new RingMasterClientInstrumentation();
                clientTransport = new SimpleTransport();
                ringMaster      = new RingMasterClient(configuration, instrumentation, this.protocol, clientTransport, CancellationToken.None);

                clientTransport.Connect(this.serverTransport);
                mustDispose = false;
                return(ringMaster);
            }
            finally
            {
                if (mustDispose)
                {
                    ringMaster.Dispose();
                    clientTransport.Dispose();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the ring master connection.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="timeStreamId">The time stream identifier.</param>
        /// <returns>ring master client connection</returns>
        public static IRingMasterRequestHandler CreateRingMasterTimeStreamRequestHandler(string connectionString, CancellationToken cancellationToken, ulong timeStreamId)
        {
            var configuration = new RingMasterClient.Configuration();
            var ringMaster    = new RingMasterClient(connectionString, configuration, null, cancellationToken);

            return(ringMaster.OpenTimeStream(timeStreamId));
        }
Exemplo n.º 3
0
        public void TestConstructorWithServerSpec()
        {
            var serverSpec = new RingMasterClient.ServerSpec();

            serverSpec.Endpoints                  = new IPEndPoint[] { new IPEndPoint(IPAddress.Loopback, 0) };
            serverSpec.UseSecureConnection        = true;
            serverSpec.ClientCertificate          = GetLocalCertificates(1)[0];
            serverSpec.AcceptedServerCertificates = GetLocalCertificates(1);

            var configuration = new RingMasterClient.Configuration();

            configuration.DefaultTimeout     = Timeout.InfiniteTimeSpan;
            configuration.HeartBeatInterval  = Timeout.InfiniteTimeSpan;
            configuration.RequestQueueLength = int.MaxValue;
            configuration.BufferSize         = int.MaxValue;

            var instrumentation = new RingMasterClientInstrumentation();

            try
            {
                using (var client = new RingMasterClient(serverSpec, configuration, instrumentation, new CancellationToken(true)))
                {
                    client.Sync("/").Wait();
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RingMasterSession" /> class.
 /// </summary>
 /// <param name="serverSpec">Server spec</param>
 /// <param name="configuration">Client configuration</param>
 internal RingMasterSession(
     RingMasterClient.ServerSpec serverSpec,
     RingMasterClient.Configuration configuration)
 {
     this.ServerSpec    = serverSpec;
     this.Configuration = configuration;
     this.Client        = new RingMasterClient(serverSpec, configuration, instrumentation: null, cancellationToken: CancellationToken.None);
 }
Exemplo n.º 5
0
        public void TestDefaultconfiguration()
        {
            var configuration = new RingMasterClient.Configuration();
            var protocol      = new RingMasterCommunicationProtocol();

            using (var clientTransport = new SimpleTransport())
                using (var ringMaster = new RingMasterClient(protocol, clientTransport))
                {
                    Assert.AreEqual((int)configuration.DefaultTimeout.TotalMilliseconds, ringMaster.Timeout);
                }
        }
Exemplo n.º 6
0
        public void TestConstructorWithConnectionStringNoCancellationToken()
        {
            var configuration = new RingMasterClient.Configuration();

            configuration.DefaultTimeout     = Timeout.InfiniteTimeSpan;
            configuration.HeartBeatInterval  = Timeout.InfiniteTimeSpan;
            configuration.RequestQueueLength = int.MaxValue;
            configuration.BufferSize         = int.MaxValue;

            var instrumentation = new RingMasterClientInstrumentation();

            using (var client = new RingMasterClient("127.0.0.1:0", configuration, instrumentation))
            {
            }
        }
Exemplo n.º 7
0
        public void TestNullServerSpec()
        {
            var configuration   = new RingMasterClient.Configuration();
            var instrumentation = new RingMasterClientInstrumentation();

            try
            {
                using (var clientTransport = new SimpleTransport())
                    using (var ringMaster = new RingMasterClient((RingMasterClient.ServerSpec)null, configuration, instrumentation, CancellationToken.None))
                    {
                        Assert.Fail("ArgumentNullException should have been thrown");
                    }
            }
            catch (ArgumentNullException)
            {
            }
        }
Exemplo n.º 8
0
        private async Task <IRingMasterRequestHandler> ConnectToRingMaster(long iteration, CancellationToken cancellationToken)
        {
            using (var serviceDiscovery = new ServiceDiscovery())
            {
                IReadOnlyList <Uri> endpoints = await serviceDiscovery.GetServiceEndpoints(this.ringMasterServiceUri, ServiceEndpointName);

                if (endpoints.Count == 0 || string.IsNullOrEmpty(endpoints[0].Host) || endpoints[0].Port <= 0)
                {
                    return(null);
                }

                var    configuration    = new RingMasterClient.Configuration();
                string connectionString = $"{endpoints[0].Host}:{endpoints[0].Port}";
                RingMasterWatchdogEventSource.Log.ConnectToRingMaster(iteration, connectionString);
                return(new RingMasterClient(connectionString, configuration, null, cancellationToken));
            }
        }
Exemplo n.º 9
0
        public void TestTimeoutConfiguration()
        {
            int timespanInMilliseconds = 4536;
            var configuration          = new RingMasterClient.Configuration()
            {
                DefaultTimeout = TimeSpan.FromMilliseconds(timespanInMilliseconds)
            };
            var protocol = new RingMasterCommunicationProtocol();

            using (var clientTransport = new SimpleTransport())
                using (var ringMaster = new RingMasterClient(configuration, null, protocol, clientTransport, CancellationToken.None))
                {
                    Assert.AreEqual(timespanInMilliseconds, ringMaster.Timeout);

                    ringMaster.Timeout = 10000;

                    Assert.AreEqual(10000, ringMaster.Timeout);
                }
        }
Exemplo n.º 10
0
        protected override void ProcessRecord()
        {
            if (this.ServerSpec == null)
            {
                this.ServerSpec = new RingMasterClient.ServerSpec
                {
                    Endpoints           = SecureTransport.ParseConnectionString(this.ConnectionString),
                    UseSecureConnection = false,
                };
            }

            var configuration = new RingMasterClient.Configuration
            {
                DefaultTimeout     = this.DefaultTimeout,
                HeartBeatInterval  = this.HeartBeatInterval,
                RequestQueueLength = this.RequestQueueLength,
            };

            this.WriteObject(new RingMasterSession(this.ServerSpec, configuration));
        }
Exemplo n.º 11
0
        public void TestEmptyEndpoints()
        {
            var serverSpec      = new RingMasterClient.ServerSpec();
            var configuration   = new RingMasterClient.Configuration();
            var instrumentation = new RingMasterClientInstrumentation();

            try
            {
                serverSpec.Endpoints           = new IPEndPoint[0];
                serverSpec.UseSecureConnection = false;
                using (var clientTransport = new SimpleTransport())
                    using (var ringMaster = new RingMasterClient(serverSpec, configuration, instrumentation, CancellationToken.None))
                    {
                        Assert.Fail("ArgumentException should have been thrown");
                    }
            }
            catch (ArgumentException)
            {
            }
        }
Exemplo n.º 12
0
        private static IRingMasterRequestHandler ConnectToRingMaster(string connectionString, CancellationToken cancellationToken)
        {
            var configuration = new RingMasterClient.Configuration();

            return(new RingMasterClient(connectionString, configuration, null, cancellationToken));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Entry point
        /// </summary>
        /// <param name="args">Arguments provided to the program</param>
        public static void Main(string[] args)
        {
            string testType          = "getdata";
            string ringMasterAddress = "127.0.0.1:99";
            string path = "/Performance";

            var assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var builder      = new ConfigurationBuilder().SetBasePath(Path.GetDirectoryName(assemblyPath)).AddJsonFile("appSettings.json");

            appSettings = builder.Build();

            if (args.Length > 0)
            {
                testType = args[0].ToLower();
            }

            if (args.Length > 1)
            {
                ringMasterAddress = args[1];
            }

            if (args.Length > 2)
            {
                path = args[2];
            }

            bool useSecureConnection = false;

            X509Certificate[] clientCertificates         = null;
            X509Certificate[] acceptedServerCertificates = null;

            if (bool.Parse(appSettings["SSL.UseSSL"]))
            {
                useSecureConnection = true;
                string[] clientCertificateThumbprints = appSettings["SSL.ClientCerts"].Split(new char[] { ';', ',' });
                clientCertificates         = RingMasterClient.GetCertificatesFromThumbPrintOrFileName(clientCertificateThumbprints);
                acceptedServerCertificates = Certificates.GetDecodedCertificates(appSettings["SSL.ServerCerts"]);

                foreach (var certificate in clientCertificates)
                {
                    Trace.TraceInformation($"Client certificate: subject={certificate.Subject} thumbprint={certificate.GetCertHashString()}");
                }

                foreach (var certificate in acceptedServerCertificates)
                {
                    Trace.TraceInformation($"Server certificate: subject={certificate.Subject} thumbprint={certificate.GetCertHashString()}");
                }
            }
            else
            {
                Trace.TraceInformation("Not using SSL");
            }

            var performanceTest = new RingMasterPerformance();

            performanceTest.TestPath                       = path;
            performanceTest.TimeStreamId                   = ulong.Parse(appSettings["TimeStream"]);
            performanceTest.MaxConcurrency                 = int.Parse(appSettings["MaxConcurrency"]);
            performanceTest.MaxDataSize                    = int.Parse(appSettings["MaxDataSize"]);
            performanceTest.MinDataSize                    = int.Parse(appSettings["MinDataSize"]);
            performanceTest.MinChildrenPerNode             = int.Parse(appSettings["MinChildrenPerNode"]);
            performanceTest.MaxChildrenPerNode             = int.Parse(appSettings["MaxChildrenPerNode"]);
            performanceTest.BatchLength                    = int.Parse(appSettings["BatchLength"]);
            performanceTest.MaxAllowedCodePoint            = int.Parse(appSettings["MaxAllowedCodePoint"]);
            performanceTest.MaxGetChildrenEnumerationCount = int.Parse(appSettings["MaxGetChildrenEnumerationCount"]);
            performanceTest.MaxSetOperations               = int.Parse(appSettings["MaxSetOperations"]);
            performanceTest.MaxNodes                       = int.Parse(appSettings["MaxNodes"]);
            performanceTest.TestMaxRunTimeInSeconds        = int.Parse(appSettings["TestMaxRunTimeInSeconds"]);

            int requestTimeout = int.Parse(appSettings["RequestTimeout"]);

            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

            var serverSpec = new RingMasterClient.ServerSpec
            {
                Endpoints           = SecureTransport.ParseConnectionString(ringMasterAddress),
                UseSecureConnection = useSecureConnection,
            };

            if (useSecureConnection)
            {
                serverSpec.ClientCertificate              = clientCertificates[0];
                serverSpec.AcceptedServerCertificates     = acceptedServerCertificates;
                serverSpec.MustCheckCertificateRevocation = false;
                serverSpec.MustCheckCertificateTrustChain = false;
            }

            var clientConfiguration = new RingMasterClient.Configuration
            {
                DefaultTimeout = TimeSpan.FromMilliseconds(requestTimeout),
            };

            var cancellation = new CancellationTokenSource();

            cancellation.CancelAfter(TimeSpan.FromSeconds(performanceTest.TestMaxRunTimeInSeconds));

            try
            {
                using (var client = new RingMasterClient(serverSpec, clientConfiguration, instrumentation: null, watcher: null, cancellationToken: CancellationToken.None))
                    using (var ringMaster = client.OpenTimeStream(performanceTest.TimeStreamId))
                    {
                        if (testType == "setdata")
                        {
                            performanceTest.SetDataPerformanceTest(ringMaster).Wait();
                        }
                        else if (testType == "create")
                        {
                            int numNodes = 500000;

                            if (args.Length > 3)
                            {
                                numNodes = int.Parse(args[3]);
                            }

                            performanceTest.CreatePerformanceTest(ringMaster, numNodes);
                        }
                        else if (testType == "createflat")
                        {
                            int numNodes = 1000000;

                            if (args.Length > 3)
                            {
                                numNodes = int.Parse(args[3]);
                            }

                            performanceTest.CreateFlatPerformanceTest(ringMaster, numNodes);
                        }
                        else if (testType == "getchildren")
                        {
                            int maxChildren = 1000;

                            if (args.Length > 3)
                            {
                                maxChildren = int.Parse(args[3]);
                            }

                            performanceTest.GetChildrenPerformanceTest(ringMaster, maxChildren);
                        }
                        else if (testType == "delete")
                        {
                            performanceTest.DeletePerformanceTest(ringMaster).Wait();
                        }
                        else if (testType == "scheduleddelete")
                        {
                            performanceTest.ScheduledDeletePerformanceTest(ringMaster);
                        }
                        else if (testType == "connect")
                        {
                            int numConnections = 100;

                            if (args.Length > 3)
                            {
                                numConnections = int.Parse(args[3]);
                            }

                            var configuration = new SecureTransport.Configuration
                            {
                                UseSecureConnection          = useSecureConnection,
                                ClientCertificates           = clientCertificates,
                                ServerCertificates           = acceptedServerCertificates,
                                CommunicationProtocolVersion = RingMasterCommunicationProtocol.MaximumSupportedVersion,
                            };

                            IPEndPoint[] endpoints = SecureTransport.ParseConnectionString(ringMasterAddress);

                            performanceTest.ConnectPerformanceTest(configuration, endpoints, numConnections);
                        }
                        else if (testType == "exists")
                        {
                            performanceTest.ExistsPerformanceTest(ringMaster).Wait();
                        }
                        else if (testType == "watchers")
                        {
                            int maxWatchers = 1000;
                            if (args.Length > 3)
                            {
                                maxWatchers = int.Parse(args[3]);
                            }

                            performanceTest.WatcherPerformanceTest(ringMaster, maxWatchers, cancellation).Wait();
                        }
                        else
                        {
                            performanceTest.GetDataPerformanceTest(ringMaster, cancellation).Wait();
                        }
                    }
            }
            catch (OperationCanceledException)
            {
            }
            catch (AggregateException ex)
            {
                if (!ex.Flatten().InnerExceptions.Any(e => e is OperationCanceledException))
                {
                    throw ex;
                }
            }
        }