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) { } }
public void TestNullConfiguration() { var instrumentation = new RingMasterClientInstrumentation(); try { var serverSpec = new RingMasterClient.ServerSpec(); using (var ringMaster = new RingMasterClient(serverSpec, null, instrumentation, CancellationToken.None)) { Assert.Fail("ArgumentNullException should have been thrown"); } } catch (ArgumentNullException) { } var protocol = new RingMasterCommunicationProtocol(); try { using (var clientTransport = new SimpleTransport()) using (var ringMaster = new RingMasterClient(null, instrumentation, protocol, clientTransport, CancellationToken.None)) { Assert.Fail("ArgumentNullException should have been thrown"); } } catch (ArgumentNullException) { } }
/// <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); }
/// <inheritdoc /> protected override void ProcessRecord() { var serverSpec = new RingMasterClient.ServerSpec { Endpoints = SecureTransport.ParseConnectionString(this.ConnectionString), UseSecureConnection = true, MustCheckCertificateRevocation = !this.NoCertificateRevocationCheck.IsPresent, MustCheckCertificateTrustChain = !this.NoTrustChainCheck.IsPresent, CertValidationASubject = this.CertValidationASubject, CertValidationASigningThumbprints = this.CertValidationASigningThumbprints, CertValidationBSubject = this.CertValidationBSubject, CertValidationBSigningThumbprints = this.CertValidationBSigningThumbprints, }; string[] clientCerts = new string[] { this.ClientCertificateThumbprint }; serverSpec.ClientCertificate = SecureTransport.GetCertificatesFromThumbPrintOrFileName(clientCerts)[0]; serverSpec.AcceptedServerCertificates = SecureTransport.GetCertificatesFromThumbPrintOrFileName(this.AcceptedServerCertificateThumbprints); this.WriteObject(serverSpec); }
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) { } }
/// <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; } } }