Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions test/Garnet.test.cluster/ClusterConfigTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
Expand All @@ -10,6 +9,7 @@
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using StackExchange.Redis;

namespace Garnet.test.cluster
{
Expand Down Expand Up @@ -79,21 +79,16 @@ public void ClusterForgetAfterNodeRestartTest()
var nodesResult = context.clusterTestUtils.ClusterNodes(0);
Assert.That(nodesResult.Nodes.Count == nbInstances);

try
{
var server = context.clusterTestUtils.GetServer(context.endpoints[0].ToIPEndPoint());
var args = new List<object>() {
var server = context.clusterTestUtils.GetServer(context.endpoints[0].ToIPEndPoint());
var args = new List<object>() {
"forget",
Encoding.ASCII.GetBytes("1ip23j89123no"),
Encoding.ASCII.GetBytes("0")
};
var result = (string)server.Execute("cluster", args);
Assert.Fail("Cluster forget call shouldn't have succeeded for an invalid node id.");
}
catch (Exception ex)
{
Assert.That(ex.Message == "ERR I don't know about node 1ip23j89123no.");
}
var ex = Assert.Throws<RedisServerException>(() => server.Execute("cluster", args),
"Cluster forget call shouldn't have succeeded for an invalid node id.");

Assert.That(ex.Message == "ERR I don't know about node 1ip23j89123no.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a better debugging experience, please use Assert.That(ex.Message, Is.EqualTo(<message>));. Otherwise it'll give a generic error, something like "Expected True but was False" rather than "Expected message was "abcd" but got "efgh"".


nodesResult = context.clusterTestUtils.ClusterNodes(0);
Assert.That(nodesResult.Nodes.Count == nbInstances, "No node should've been removed from the cluster after an invalid id was passed.");
Expand Down
152 changes: 45 additions & 107 deletions test/Garnet.test.cluster/RedirectTests/ClusterSlotVerificationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,33 +283,19 @@ public void ClusterCLUSTERDOWNTest()

void SERedisClusterDown(BaseCommand command)
{
try
{
AssertSlotsNotAssigned(requestNodeIndex);
_ = context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest());
}
catch (Exception ex)
{
ClassicAssert.AreEqual("CLUSTERDOWN Hash slot not served", ex.Message, command.Command);
return;
}
Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}");
AssertSlotsNotAssigned(requestNodeIndex);
var ex = Assert.Throws<RedisServerException>(() => context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest()),
$"Should not reach here. Command: {command.Command} \n{ClusterState()}");
ClassicAssert.AreEqual("CLUSTERDOWN Hash slot not served", ex.Message, command.Command);
}

void GarnetClientSessionClusterDown(BaseCommand command)
{
var client = context.clusterTestUtils.GetGarnetClientSession(requestNodeIndex);
try
{
AssertSlotsNotAssigned(requestNodeIndex);
_ = client.ExecuteAsync(command.GetSingleSlotRequestWithCommand).GetAwaiter().GetResult();
}
catch (Exception ex)
{
ClassicAssert.AreEqual("CLUSTERDOWN Hash slot not served", ex.Message, command.Command);
return;
}
Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}");
AssertSlotsNotAssigned(requestNodeIndex);
var ex = Assert.Throws<Exception>(() => client.ExecuteAsync(command.GetSingleSlotRequestWithCommand).GetAwaiter().GetResult(),
$"Should not reach here. Command: {command.Command} \n{ClusterState()}");
ClassicAssert.AreEqual("CLUSTERDOWN Hash slot not served", ex.Message, command.Command);
}
}
}
Expand Down Expand Up @@ -391,33 +377,19 @@ void SERedisCrossslotTest(BaseCommand command)
{
if (!command.IsArrayCommand)
return;
try
{
_ = context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetCrossSlotRequest());
}
catch (Exception ex)
{
ClassicAssert.AreEqual("CROSSSLOT Keys in request do not hash to the same slot", ex.Message, command.Command);
return;
}
Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}");
var ex = Assert.Throws<RedisServerException>(() => context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetCrossSlotRequest()),
$"Should not reach here. Command: {command.Command} \n{ClusterState()}");
ClassicAssert.AreEqual("CROSSSLOT Keys in request do not hash to the same slot", ex.Message, command.Command);
}

void GarnetClientSessionCrossslotTest(BaseCommand command)
{
if (!command.IsArrayCommand)
return;
var client = context.clusterTestUtils.GetGarnetClientSession(requestNodeIndex);
try
{
client.ExecuteAsync(command.GetCrossslotRequestWithCommand).GetAwaiter().GetResult();
}
catch (Exception ex)
{
ClassicAssert.AreEqual("CROSSSLOT Keys in request do not hash to the same slot", ex.Message, command.Command);
return;
}
Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}");
var ex = Assert.Throws<Exception>(() => client.ExecuteAsync(command.GetCrossslotRequestWithCommand).GetAwaiter().GetResult(),
$"Should not reach here. Command: {command.Command} \n{ClusterState()}");
ClassicAssert.AreEqual("CROSSSLOT Keys in request do not hash to the same slot", ex.Message, command.Command);
}
}
}
Expand All @@ -442,40 +414,26 @@ public void ClusterMOVEDTest()

void SERedisMOVEDTest(BaseCommand command)
{
try
{
context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest(), CommandFlags.NoRedirect);
}
catch (Exception ex)
{
ClassicAssert.IsTrue(ex.Message.StartsWith("Key has MOVED"), command.Command);
var tokens = ex.Message.Split(' ');
ClassicAssert.IsTrue(tokens.Length > 10 && tokens[2].Equals("MOVED"), command.Command);

var _address = tokens[5].Split(':')[0];
var _port = int.Parse(tokens[5].Split(':')[1]);
var _slot = int.Parse(tokens[8]);
ClassicAssert.AreEqual(address, _address, command.Command);
ClassicAssert.AreEqual(port, _port, command.Command);
ClassicAssert.AreEqual(command.GetSlot, _slot, command.Command);
return;
}
Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}");
var ex = Assert.Throws<RedisServerException>(() => context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest(), CommandFlags.NoRedirect),
$"Should not reach here. Command: {command.Command} \n{ClusterState()}");
ClassicAssert.IsTrue(ex.Message.StartsWith("Key has MOVED"), command.Command);
var tokens = ex.Message.Split(' ');
ClassicAssert.IsTrue(tokens.Length > 10 && tokens[2].Equals("MOVED"), command.Command);

var _address = tokens[5].Split(':')[0];
var _port = int.Parse(tokens[5].Split(':')[1]);
var _slot = int.Parse(tokens[8]);
ClassicAssert.AreEqual(address, _address, command.Command);
ClassicAssert.AreEqual(port, _port, command.Command);
ClassicAssert.AreEqual(command.GetSlot, _slot, command.Command);
}

void GarnetClientSessionMOVEDTest(BaseCommand command)
{
var client = context.clusterTestUtils.GetGarnetClientSession(requestNodeIndex);
try
{
client.ExecuteAsync(command.GetSingleSlotRequestWithCommand).GetAwaiter().GetResult();
}
catch (Exception ex)
{
ClassicAssert.AreEqual($"MOVED {command.GetSlot} {address}:{port}", ex.Message, command.Command);
return;
}
Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}");
var ex = Assert.Throws<Exception>(() => client.ExecuteAsync(command.GetSingleSlotRequestWithCommand).GetAwaiter().GetResult(),
$"Should not reach here. Command: {command.Command} \n{ClusterState()}");
ClassicAssert.AreEqual($"MOVED {command.GetSlot} {address}:{port}", ex.Message, command.Command);
}
}
}
Expand Down Expand Up @@ -518,40 +476,25 @@ public void ClusterASKTest()

void SERedisASKTest(BaseCommand command)
{
RedisResult result = default;
try
{
result = context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest(), CommandFlags.NoRedirect);
}
catch (Exception ex)
{
var tokens = ex.Message.Split(' ');
ClassicAssert.IsTrue(tokens.Length > 10 && tokens[0].Equals("Endpoint"), command.Command + " => " + ex.Message);

var _address = tokens[1].Split(':')[0];
var _port = int.Parse(tokens[1].Split(':')[1]);
var _slot = int.Parse(tokens[4]);
ClassicAssert.AreEqual(address, _address, command.Command);
ClassicAssert.AreEqual(port, _port, command.Command);
ClassicAssert.AreEqual(command.GetSlot, _slot, command.Command);
return;
}
Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}");
var ex = Assert.Throws<RedisConnectionException>(() => context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest(), CommandFlags.NoRedirect),
$"Should not reach here. Command: {command.Command} \n{ClusterState()}");
var tokens = ex.Message.Split(' ');
ClassicAssert.IsTrue(tokens.Length > 10 && tokens[0].Equals("Endpoint"), command.Command + " => " + ex.Message);

var _address = tokens[1].Split(':')[0];
var _port = int.Parse(tokens[1].Split(':')[1]);
var _slot = int.Parse(tokens[4]);
ClassicAssert.AreEqual(address, _address, command.Command);
ClassicAssert.AreEqual(port, _port, command.Command);
ClassicAssert.AreEqual(command.GetSlot, _slot, command.Command);
}

void GarnetClientSessionASKTest(BaseCommand command)
{
var client = context.clusterTestUtils.GetGarnetClientSession(requestNodeIndex);
try
{
_ = client.ExecuteAsync(command.GetSingleSlotRequestWithCommand).GetAwaiter().GetResult();
}
catch (Exception ex)
{
ClassicAssert.AreEqual($"ASK {command.GetSlot} {address}:{port}", ex.Message, command.Command);
return;
}
Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}");
var ex = Assert.Throws<Exception>(() => client.ExecuteAsync(command.GetSingleSlotRequestWithCommand).GetAwaiter().GetResult(),
$"Should not reach here. Command: {command.Command} \n{ClusterState()}");
ClassicAssert.AreEqual($"ASK {command.GetSlot} {address}:{port}", ex.Message, command.Command);
}
}
}
Expand Down Expand Up @@ -591,12 +534,9 @@ void SERedisTRYAGAINTest(BaseCommand command)
ConfigureSlotForMigration();
try
{
_ = context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest(), CommandFlags.NoRedirect);
}
catch (Exception ex)
{
var ex = Assert.Throws<RedisServerException>(() => context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest(), CommandFlags.NoRedirect),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there are still a couple of try/catch blocks in this method?

$"Should not reach here. Command: {command.Command} \n{ClusterState()}");
ClassicAssert.AreEqual("TRYAGAIN Multiple keys request during rehashing of slot", ex.Message, command.Command, $"\n{ClusterState()}");
return;
}
finally
{
Expand All @@ -611,8 +551,6 @@ void SERedisTRYAGAINTest(BaseCommand command)
Assert.Fail($"Failed executing cleanup. Command: {command.Command} \n{ClusterState()}");
}
}

Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}");
}
}
}
Expand Down
Loading