Commit 3efde9a6 authored by Marc Gravell's avatar Marc Gravell

removed a lot of DebuggingAids.cs

parent 273ee76d
......@@ -285,7 +285,6 @@ public void GetWithExpiryWrongTypeSync()
Assert.Equal("WRONGTYPE Operation against a key holding the wrong kind of value", ex.Message);
}
#if DEBUG
[Fact]
public void TestQuit()
{
......@@ -296,17 +295,19 @@ public void TestQuit()
string key = Guid.NewGuid().ToString();
db.KeyDelete(key, CommandFlags.FireAndForget);
db.StringSet(key, key, flags: CommandFlags.FireAndForget);
GetServer(muxer).Quit(CommandFlags.FireAndForget);
var watch = Stopwatch.StartNew();
GetServer(muxer).Execute("QUIT", null, CommandFlags.FireAndForget);
var watch = System.Diagnostics.Stopwatch.StartNew();
Assert.Throws<RedisConnectionException>(() => db.Ping());
watch.Stop();
Output.WriteLine("Time to notice quit: {0}ms (any order)", watch.ElapsedMilliseconds);
Thread.Sleep(20);
Debug.WriteLine("Pinging...");
System.Threading.Thread.Sleep(20);
System.Diagnostics.Debug.WriteLine("Pinging...");
Assert.Equal(key, (string)db.StringGet(key));
}
}
#if DEBUG
[Fact]
public async Task TestSevered()
{
......
......@@ -163,6 +163,9 @@ public void TestIdentity()
[Fact]
public void IntentionalWrongServer()
{
string StringGet(IServer server, RedisKey key, CommandFlags flags = CommandFlags.None)
=> (string)server.Execute("GET", new object[] { key }, flags);
using (var conn = Create())
{
var endpoints = conn.GetEndPoints();
......@@ -181,8 +184,7 @@ public void IntentionalWrongServer()
Assert.NotNull(rightMasterNode);
Output.WriteLine("Right Master: {0} {1}", rightMasterNode.EndPoint, rightMasterNode.NodeId);
#if DEBUG
string a = conn.GetServer(rightMasterNode.EndPoint).StringGet(db.Database, key);
string a = StringGet(conn.GetServer(rightMasterNode.EndPoint), key);
Assert.Equal(value, a); // right master
var node = config.Nodes.FirstOrDefault(x => !x.IsSlave && x.NodeId != rightMasterNode.NodeId);
......@@ -190,10 +192,10 @@ public void IntentionalWrongServer()
Output.WriteLine("Using Master: {0}", node.EndPoint, node.NodeId);
if (node != null)
{
string b = conn.GetServer(node.EndPoint).StringGet(db.Database, key);
string b = StringGet(conn.GetServer(node.EndPoint), key);
Assert.Equal(value, b); // wrong master, allow redirect
var ex = Assert.Throws<RedisServerException>(() => conn.GetServer(node.EndPoint).StringGet(db.Database, key, CommandFlags.NoRedirect));
var ex = Assert.Throws<RedisServerException>(() => StringGet(conn.GetServer(node.EndPoint), key, CommandFlags.NoRedirect));
Assert.StartsWith($"Key has MOVED from Endpoint {rightMasterNode.EndPoint} and hashslot {slot}", ex.Message);
}
......@@ -201,7 +203,7 @@ public void IntentionalWrongServer()
Assert.NotNull(node);
if (node != null)
{
string d = conn.GetServer(node.EndPoint).StringGet(db.Database, key);
string d = StringGet(conn.GetServer(node.EndPoint), key);
Assert.Equal(value, d); // right slave
}
......@@ -209,13 +211,12 @@ public void IntentionalWrongServer()
Assert.NotNull(node);
if (node != null)
{
string e = conn.GetServer(node.EndPoint).StringGet(db.Database, key);
string e = StringGet(conn.GetServer(node.EndPoint), key);
Assert.Equal(value, e); // wrong slave, allow redirect
var ex = Assert.Throws<RedisServerException>(() => conn.GetServer(node.EndPoint).StringGet(db.Database, key, CommandFlags.NoRedirect));
var ex = Assert.Throws<RedisServerException>(() => StringGet(conn.GetServer(node.EndPoint), key, CommandFlags.NoRedirect));
Assert.StartsWith($"Key has MOVED from Endpoint {rightMasterNode.EndPoint} and hashslot {slot}", ex.Message);
}
#endif
}
}
......@@ -701,13 +702,13 @@ public void MovedProfiling()
var rightMasterNode = config.GetBySlot(Key);
Assert.NotNull(rightMasterNode);
string a = conn.GetServer(rightMasterNode.EndPoint).StringGet(db.Database, Key);
string a = (string)conn.GetServer(rightMasterNode.EndPoint).Execute("GET", Key);
Assert.Equal(Value, a); // right master
var wrongMasterNode = config.Nodes.FirstOrDefault(x => !x.IsSlave && x.NodeId != rightMasterNode.NodeId);
Assert.NotNull(wrongMasterNode);
string b = conn.GetServer(wrongMasterNode.EndPoint).StringGet(db.Database, Key);
string b = (string)conn.GetServer(wrongMasterNode.EndPoint).Execute("GET", Key);
Assert.Equal(Value, b); // wrong master, allow redirect
var msgs = conn.FinishProfiling(profiler.MyContext).ToList();
......
......@@ -82,10 +82,10 @@ public void ClientName()
var conn = muxer.GetDatabase();
conn.Ping();
#if DEBUG
var name = GetAnyMaster(muxer).ClientGetName();
var name = (string)GetAnyMaster(muxer).Execute("CLIENT", "GETNAME");
Assert.Equal("TestRig", name);
#endif
}
}
......@@ -97,10 +97,10 @@ public void DefaultClientName()
Assert.Equal(Environment.MachineName, muxer.ClientName);
var conn = muxer.GetDatabase();
conn.Ping();
#if DEBUG
var name = GetAnyMaster(muxer).ClientGetName();
var name = (string)GetAnyMaster(muxer).Execute("CLIENT", "GETNAME");
Assert.Equal(Environment.MachineName, name);
#endif
}
}
......
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Pipelines;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StackExchange.Redis
{
......@@ -13,95 +8,18 @@ namespace StackExchange.Redis
internal partial class ResultBox
{
internal static long allocations;
public static long GetAllocationCount() => Interlocked.Read(ref allocations);
static partial void OnAllocated() => Interlocked.Increment(ref allocations);
public static long GetAllocationCount() => System.Threading.Interlocked.Read(ref allocations);
static partial void OnAllocated() => System.Threading.Interlocked.Increment(ref allocations);
}
public partial interface IServer
{
/// <summary>
/// Get the value of key. If the key does not exist the special value nil is returned. An error is returned if the value stored at key is not a string, because GET only handles string values.
/// </summary>
/// <param name="db">The database to get <paramref name="key"/> from.</param>
/// <param name="key">The key to get.</param>
/// <param name="flags">The command flags to use.</param>
/// <returns>the value of key, or nil when key does not exist.</returns>
/// <remarks>https://redis.io/commands/get</remarks>
RedisValue StringGet(int db, RedisKey key, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Get the value of key. If the key does not exist the special value nil is returned. An error is returned if the value stored at key is not a string, because GET only handles string values.
/// </summary>
/// <param name="db">The database to get <paramref name="key"/> from.</param>
/// <param name="key">The key to get.</param>
/// <param name="flags">The command flags to use.</param>
/// <returns>the value of key, or nil when key does not exist.</returns>
/// <remarks>https://redis.io/commands/get</remarks>
Task<RedisValue> StringGetAsync(int db, RedisKey key, CommandFlags flags = CommandFlags.None);
/// <summary>
/// Break the connection without mercy or thought
/// </summary>
void SimulateConnectionFailure();
/// <summary>
/// DEBUG SEGFAULT performs an invalid memory access that crashes Redis. It is used to simulate bugs during the development.
/// </summary>
/// <remarks>https://redis.io/commands/debug-segfault</remarks>
void Crash();
/// <summary>
/// CLIENT PAUSE is a connections control command able to suspend all the Redis clients for the specified amount of time (in milliseconds).
/// </summary>
/// <param name="duration">The time span to hang for.</param>
/// <param name="flags">The command flags to use.</param>
/// <remarks>https://redis.io/commands/client-pause</remarks>
void Hang(TimeSpan duration, CommandFlags flags = CommandFlags.None);
}
public partial interface IRedis
{
/// <summary>
/// The CLIENT GETNAME returns the name of the current connection as set by CLIENT SETNAME. Since every new connection starts without an associated name, if no name was assigned a null string is returned.
/// </summary>
/// <param name="flags">The command flags to use.</param>
/// <remarks>https://redis.io/commands/client-getname</remarks>
/// <returns>The connection name, or a null string if no name is set.</returns>
string ClientGetName(CommandFlags flags = CommandFlags.None);
/// <summary>
/// Ask the server to close the connection. The connection is closed as soon as all pending replies have been written to the client.
/// </summary>
/// <param name="flags">The command flags to use.</param>
/// <remarks>https://redis.io/commands/quit</remarks>
void Quit(CommandFlags flags = CommandFlags.None);
}
public partial interface IRedisAsync
{
/// <summary>
/// The CLIENT GETNAME returns the name of the current connection as set by CLIENT SETNAME. Since every new connection starts without an associated name, if no name was assigned a null string is returned.
/// </summary>
/// <param name="flags">The command flags to use.</param>
/// <remarks>https://redis.io/commands/client-getname</remarks>
/// <returns>The connection name, or a null string if no name is set.</returns>
Task<string> ClientGetNameAsync(CommandFlags flags = CommandFlags.None);
}
internal partial class RedisBase
{
string IRedis.ClientGetName(CommandFlags flags)
{
var msg = Message.Create(-1, flags, RedisCommand.CLIENT, RedisLiterals.GETNAME);
return ExecuteSync(msg, ResultProcessor.String);
}
Task<string> IRedisAsync.ClientGetNameAsync(CommandFlags flags)
{
var msg = Message.Create(-1, flags, RedisCommand.CLIENT, RedisLiterals.GETNAME);
return ExecuteAsync(msg, ResultProcessor.String);
}
}
internal partial class ServerEndPoint
{
......@@ -115,18 +33,6 @@ internal void SimulateConnectionFailure()
internal partial class RedisServer
{
void IServer.SimulateConnectionFailure() => server.SimulateConnectionFailure();
void IServer.Crash()
{
// using DB-0 because we also use "DEBUG OBJECT", which is db-centric
var msg = Message.Create(0, CommandFlags.FireAndForget, RedisCommand.DEBUG, RedisLiterals.SEGFAULT);
ExecuteSync(msg, ResultProcessor.DemandOK);
}
void IServer.Hang(TimeSpan duration, CommandFlags flags)
{
var msg = Message.Create(-1, flags, RedisCommand.CLIENT, RedisLiterals.PAUSE, (long)duration.TotalMilliseconds);
ExecuteSync(msg, ResultProcessor.DemandOK);
}
}
public partial class ConnectionMultiplexer
......@@ -188,14 +94,6 @@ public static bool EmulateStaleConnection
get => emulateStaleConnection;
set => emulateStaleConnection = value;
}
partial void DebugEmulateStaleConnection(ref int firstUnansweredWrite)
{
if (emulateStaleConnection)
{
firstUnansweredWrite = Environment.TickCount - 100000;
}
}
}
#endif
......@@ -273,35 +171,8 @@ partial class ConnectionMultiplexer
#endif
#if LOGOUTPUT
partial class ConnectionMultiplexer
{
/// <summary>
/// Dumps a copy of the stream
/// </summary>
public static string EchoPath { get; set; }
}
partial class PhysicalConnection
{
//private Stream echo;
//partial void OnCreateEcho()
//{
// if (!string.IsNullOrEmpty(ConnectionMultiplexer.EchoPath))
// {
// string fullPath = Path.Combine(ConnectionMultiplexer.EchoPath,
// Regex.Replace(physicalName, @"[\-\.\@\#\:]", "_"));
// echo = File.Open(Path.ChangeExtension(fullPath, "txt"), FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
// }
//}
//partial void OnCloseEcho()
//{
// if (echo != null)
// {
// try { echo.Close(); } catch { }
// try { echo.Dispose(); } catch { }
// echo = null;
// }
//}
partial void OnWrapForLogging(ref IDuplexPipe pipe, string name, SocketManager mgr)
{
foreach(var c in Path.GetInvalidFileNameChars())
......
......@@ -835,17 +835,5 @@ public IEnumerable<SortedSetEntry> SortedSetScan(RedisKey key, RedisValue patter
{
return Inner.SortedSetScan(ToInner(key), pattern, pageSize, cursor, pageOffset, flags);
}
#if DEBUG
public string ClientGetName(CommandFlags flags = CommandFlags.None)
{
return Inner.ClientGetName(flags);
}
public void Quit(CommandFlags flags = CommandFlags.None)
{
Inner.Quit(flags);
}
#endif
}
}
......@@ -805,14 +805,6 @@ public void WaitAll(params Task[] tasks)
{
Inner.WaitAll(tasks);
}
#if DEBUG
public Task<string> ClientGetNameAsync(CommandFlags flags = CommandFlags.None)
{
return Inner.ClientGetNameAsync(flags);
}
#endif
protected internal RedisKey ToInner(RedisKey outer)
{
return RedisKey.WithPrefix(Prefix, outer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment