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(); } } }
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) { } }
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); } }
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) { } }
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); } }
/// <summary> /// Initializes a new instance of the <see cref="RingMasterClientUnitTest"/> class. /// </summary> public RingMasterClientUnitTest() { this.serverTransport = new SimpleTransport(); this.backend = this.CreateBackend(); this.ringMasterServer = new RingMasterServer(this.protocol, null, this.cancellationTokenSource.Token); this.ringMasterServer.RegisterTransport(this.serverTransport); this.ringMasterServer.OnInitSession = initRequest => { return(new CoreRequestHandler(this.backend, initRequest)); }; foreach (var source in EventSource.GetSources()) { if (source.Guid == this.ringMasterClientEventSourceGuid) { Trace.TraceInformation($"Enabling EventSource {source.Name}"); this.listener.EnableEvents(source, EventLevel.Verbose); } } }
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) { } }