private IDisposable HConsoleForTest() => HConsole.Capture(options => options .ClearAll() .Configure().SetMinLevel() .Configure <HConsoleLoggerProvider>().SetMaxLevel() );
private IDisposable HConsoleForTest() => HConsole.Capture(options => options .ClearAll() .Configure().SetMaxLevel() .Configure(this).SetPrefix("TEST") .Configure <SocketConnectionBase>().SetIndent(8).SetPrefix("SOCKET"));
private IDisposable HConsoleForTest() => HConsole.Capture(options => options .ClearAll() .Set(x => x.Verbose()) .Set(this, x => x.SetPrefix("TEST")) .Set <SocketConnectionBase>(x => x.SetIndent(8).SetPrefix("SOCKET")));
private IDisposable HConsoleForTest() => HConsole.Capture(options => options .ClearAll() .Configure <HConsoleLoggerProvider>().SetPrefix("LOG").SetMaxLevel() .Configure().SetMinLevel().EnableTimeStamp(origin: DateTime.Now) .Configure(this).SetMaxLevel().SetPrefix("TEST") );
public async Task TimeoutsAfterMultipleRetries() { var address = NetworkAddress.Parse("127.0.0.1:11001"); using var _ = HConsole.Capture(consoleOptions => consoleOptions .ClearAll() .Configure().SetMaxLevel() .Configure(this).SetPrefix("TEST") .Configure <AsyncContext>().SetMinLevel() .Configure <SocketConnectionBase>().SetIndent(1).SetLevel(0).SetPrefix("SOCKET")); HConsole.WriteLine(this, "Begin"); HConsole.WriteLine(this, "Start server"); await using var server = new Server(address, async(xsvr, xconn, xmsg) => await HandleAsync(xsvr, xconn, xmsg, async(svr, conn, msg) => { HConsole.WriteLine(svr, "Handle request (wait...)"); await Task.Delay(500).CfAwait(); HConsole.WriteLine(svr, "Respond with error."); var response = ErrorsServerCodec.EncodeResponse(new[] { // make sure the error is retryable new ErrorHolder(RemoteError.RetryableHazelcast, "classname", "message", Enumerable.Empty <StackTraceElement>()) }); //HConsole.WriteLine(svr, "Respond with success."); //var response = ClientPingServerCodec.EncodeResponse(); response.CorrelationId = msg.CorrelationId; await conn.SendAsync(response).CfAwait(); }), LoggerFactory); await server.StartAsync().CfAwait(); HConsole.WriteLine(this, "Start client"); var options = HazelcastOptions.Build(configure: (configuration, options) => { options.Networking.Addresses.Add("127.0.0.1:11001"); options.Messaging.RetryTimeoutSeconds = 3; // default value is 120s }); await using var client = (HazelcastClient) await HazelcastClientFactory.StartNewClientAsync(options); HConsole.WriteLine(this, "Send message"); var message = ClientPingServerCodec.EncodeRequest(); // note: the error only happens *after* the server has responded // we could wait for the response for ever await AssertEx.ThrowsAsync <TaskTimeoutException>(async() => { // server will respond w/ error every 500ms and client will retry // until the 3s retry timeout (options above) is reached await client.Cluster.Messaging.SendAsync(message).CfAwait(); }); await server.StopAsync().CfAwait(); }
private IDisposable HConsoleForTest() => HConsole.Capture(options => options .Configure().SetMaxLevel() .Configure(this).SetPrefix("TEST") .Configure <SocketConnectionBase>().SetIndent(8).SetPrefix("SOCKET").SetLevel(0) .Configure <ClientMessageConnection>().SetMinLevel() .Configure <AsyncContext>().SetMinLevel() .Configure <Partitioner>().SetLevel(1));
private IDisposable HConsoleForTest() => HConsole.Capture(options => options .Set(x => x.Verbose()) .Set(this, x => x.SetPrefix("TEST")) .Set <SocketConnectionBase>(x => x.SetIndent(8).SetPrefix("SOCKET").SetLevel(0)) .Set <ClientMessageConnection>(x => x.Quiet()) .Set <AsyncContext>(x => x.Quiet()) .Set <Partitioner>(x => x.SetLevel(1)));
public void WriteAndClear() { var capture = new ConsoleCapture(); HConsole.WriteAndClear(); Assert.That(HConsole.Text.Length, Is.Zero); HConsole.WriteAndClear(); Assert.That(HConsole.Text.Length, Is.Zero); HConsole.Configure(x => x.Set(xx => xx.Verbose())); HConsole.WriteLine(this, "meh"); Assert.That(HConsole.Text.Length, Is.GreaterThan(0)); using (capture.Output()) { HConsole.WriteAndClear(); } Assert.That(HConsole.Text.Length, Is.Zero); Assert.That(capture.ReadToEnd(), Does.EndWith("meh" + Environment.NewLine)); HConsole.WriteLine(this, "meh"); Assert.That(HConsole.Text.Length, Is.GreaterThan(0)); using (capture.Output()) { HConsole.Clear(); } Assert.That(HConsole.Text.Length, Is.Zero); Assert.That(capture.ReadToEnd().Length, Is.Zero); HConsole.WriteLine(this, "meh"); using (capture.Output()) { using (HConsole.Capture()) { } } Assert.That(HConsole.Text.Length, Is.Zero); Assert.That(capture.ReadToEnd(), Does.EndWith("meh" + Environment.NewLine)); }
public async Task Test() { using var _ = HConsole.Capture(consoleOptions => consoleOptions .ClearAll() .Configure().SetLevel(1).EnableTimeStamp(origin: DateTime.Now) .Configure(this).SetPrefix("TEST") .Configure <AsyncContext>().SetMinLevel() .Configure <SocketConnectionBase>().SetIndent(1).SetLevel(0).SetPrefix("SOCKET")); for (var i = 0; i < RunCount; i++) { HConsole.WriteLine(this, $"-------- RUN #{i} --------"); await Run(); // don't leave anything behind this run! foreach (var member in RcMembers.Values) { await RemoveMember(Guid.Parse(member.Uuid)); } } }
public static async Task Main(string[] args) { var h = new object(); using var _ = HConsole.Capture(options => options .ClearAll() .Set(x => x.SetLevel(1)) .Set(h, x => x.SetPrefix("PROGRAM")) .Set <AsyncContext>(x => x.Quiet()) .Set("Hazelcast.Networking.SocketConnectionBase", x => x.SetIndent(1).SetLevel(0).SetPrefix("SOCKET")) .Set("Hazelcast.Clustering.MemberConnection", x => x.SetLevel(1)) ); var options = new HazelcastOptionsBuilder() .With(args) .With("Logging:LogLevel:Hazelcast", "Debug") .WithHConsoleLogger() .Build(); options.Networking.Addresses.Clear(); options.Networking.Addresses.Add("127.0.0.1:5701"); options.ClusterName = "dev"; var logger = options.LoggerFactory.Service.CreateLogger <Program>(); logger.LogInformation("Begin."); logger.LogInformation("Start client..."); var hz = await HazelcastClientFactory.StartNewClientAsync(options); logger.LogWarning("Wait..."); await Task.Delay(1000); logger.LogWarning("Dispose client..."); await hz.DisposeAsync(); logger.LogWarning("End."); options.LoggerFactory.Service.Dispose(); }
public async Task TestSSLEnabled_DoNotValidateChain_DoNotValidateName_invalidName() { // note: if we let the test timeout (via the [Timeout] attribute) then HConsole // does not log => timeout the StartClientAsync within the test so that the // test fails properly, and HConsole can log. using var _ = HConsole.Capture(consoleOptions => consoleOptions .ClearAll() .Configure().SetMaxLevel() .Configure(this).SetPrefix("TEST") .Configure <AsyncContext>().SetMinLevel() .Configure <SocketConnectionBase>().SetIndent(1).SetLevel(0).SetPrefix("SOCKET") ); await using var client = await StartClientAsync(Resources.Cluster_Ssl_Signed, true, false, false, null, "Invalid Cert Name", null, null).AsTask().CfAwait(TimeSpan.FromSeconds(20)); }
public async Task SchedulerTest() { // this test verifies that the scheduler works as expected using var _ = HConsole.Capture(consoleOptions => consoleOptions .Configure().SetMinLevel() .Configure <DistributedEventScheduler>().SetMaxLevel() .Configure(this).SetMaxLevel().SetPrefix("TEST")); using var loggerFactory = LoggerFactory.Create(builder => builder.AddHConsole()); var logger = loggerFactory.CreateLogger("TEST"); var scheduler = new DistributedEventScheduler(loggerFactory); var pe = new ConcurrentDictionary <int, long>(); var exceptionCount = 0; var concurrentCount = 0; var maxConcurentCount = 0; var concurrentLock = new object(); scheduler.HandlerError += (sender, args) => { Interlocked.Increment(ref exceptionCount); var message = "An event handler has thrown: " + args.Exception.Message; if (args.Message.CorrelationId < 25) { args.Handled = true; message += " (handling)"; } HConsole.WriteLine(this, "WARN: " + message); }; var s = new ClusterSubscription(async(clientMessage, state) => { HConsole.WriteLine(this, $"Handling event for partition: {clientMessage.PartitionId}, sequence: {clientMessage.CorrelationId}"); lock (pe) { // for each partition, events trigger in the right order if (pe.TryGetValue(clientMessage.PartitionId, out var pv)) { Assert.That(clientMessage.CorrelationId, Is.GreaterThan(pv)); } pe[clientMessage.PartitionId] = clientMessage.CorrelationId; } //await Task.Yield(); lock (concurrentLock) concurrentCount++; await Task.Delay(200); lock (concurrentLock) { maxConcurentCount = Math.Max(maxConcurentCount, concurrentCount); concurrentCount--; } if (clientMessage.CorrelationId % 10 == 0) { throw new Exception($"Throwing for partition: {clientMessage.PartitionId} sequence: {clientMessage.CorrelationId}"); } HConsole.WriteLine(this, $"Handled event for partition: {clientMessage.PartitionId} sequence: {clientMessage.CorrelationId}"); }); for (var i = 0; i < 50; i++) { var capture = i; var m = new ClientMessage(new Frame(new byte[64])) { PartitionId = RandomProvider.Random.Next(4), CorrelationId = capture, }; // can add the events Assert.That(scheduler.Add(s, m), Is.True); } // make sure everything is completed // (disposing aborts all queues) await AssertEx.SucceedsEventually(() => { Assert.That(scheduler.Count, Is.EqualTo(0)); }, 8000, 200); // aborts the scheduler & all current queues! await scheduler.DisposeAsync(); // the exceptions have triggered the OnError handler Assert.That(exceptionCount, Is.EqualTo(5)); // the scheduler counts exceptions Assert.That(scheduler.ExceptionCount, Is.EqualTo(5)); Assert.That(scheduler.UnhandledExceptionCount, Is.EqualTo(2)); // cannot add events to disposed event scheduler Assert.That(scheduler.Add(s, new ClientMessage(new Frame(new byte[64]))), Is.False); // some events ran concurrently Console.WriteLine(maxConcurentCount); Assert.That(maxConcurentCount, Is.GreaterThan(1)); // all tasks are gone Assert.That(scheduler.Count, Is.EqualTo(0)); }