Skip to content

Commit

Permalink
Merge branch 'main' into pr/1525
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Craver committed Aug 26, 2020
2 parents 26eb3c7 + 2fd5b79 commit be109fd
Show file tree
Hide file tree
Showing 63 changed files with 377 additions and 390 deletions.
16 changes: 8 additions & 8 deletions src/StackExchange.Redis/ConfigurationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ private static class OptionKeys
{
public static int ParseInt32(string key, string value, int minValue = int.MinValue, int maxValue = int.MaxValue)
{
if (!Format.TryParseInt32(value, out int tmp)) throw new ArgumentOutOfRangeException("Keyword '" + key + "' requires an integer value");
if (tmp < minValue) throw new ArgumentOutOfRangeException("Keyword '" + key + "' has a minimum value of " + minValue);
if (tmp > maxValue) throw new ArgumentOutOfRangeException("Keyword '" + key + "' has a maximum value of " + maxValue);
if (!Format.TryParseInt32(value, out int tmp)) throw new ArgumentOutOfRangeException(key, $"Keyword '{key}' requires an integer value; the value '{value}' is not recognised.");
if (tmp < minValue) throw new ArgumentOutOfRangeException(key, $"Keyword '{key}' has a minimum value of '{minValue}'; the value '{tmp}' is not permitted.");
if (tmp > maxValue) throw new ArgumentOutOfRangeException(key, $"Keyword '{key}' has a maximum value of '{maxValue}'; the value '{tmp}' is not permitted.");
return tmp;
}

internal static bool ParseBoolean(string key, string value)
{
if (!Format.TryParseBoolean(value, out bool tmp)) throw new ArgumentOutOfRangeException("Keyword '" + key + "' requires a boolean value");
if (!Format.TryParseBoolean(value, out bool tmp)) throw new ArgumentOutOfRangeException(key, $"Keyword '{key}' requires a boolean value; the value '{value}' is not recognised.");
return tmp;
}

internal static Version ParseVersion(string key, string value)
{
if (!System.Version.TryParse(value, out Version tmp)) throw new ArgumentOutOfRangeException("Keyword '" + key + "' requires a version value");
if (!System.Version.TryParse(value, out Version tmp)) throw new ArgumentOutOfRangeException(key, $"Keyword '{key}' requires a version value; the value '{value}' is not recognised.");
return tmp;
}

internal static Proxy ParseProxy(string key, string value)
{
if (!Enum.TryParse(value, true, out Proxy tmp)) throw new ArgumentOutOfRangeException("Keyword '" + key + "' requires a proxy value");
if (!Enum.TryParse(value, true, out Proxy tmp)) throw new ArgumentOutOfRangeException(key, $"Keyword '{key}' requires a proxy value; the value '{value}' is not recognised.");
return tmp;
}

Expand All @@ -53,14 +53,14 @@ internal static SslProtocols ParseSslProtocols(string key, string value)
//Flags expect commas as separators, but we need to use '|' since commas are already used in the connection string to mean something else
value = value?.Replace("|", ",");

if (!Enum.TryParse(value, true, out SslProtocols tmp)) throw new ArgumentOutOfRangeException("Keyword '" + key + "' requires an SslProtocol value (multiple values separated by '|').");
if (!Enum.TryParse(value, true, out SslProtocols tmp)) throw new ArgumentOutOfRangeException(key, $"Keyword '{key}' requires an SslProtocol value (multiple values separated by '|'); the value '{value}' is not recognised.");

return tmp;
}

internal static void Unknown(string key)
{
throw new ArgumentException("Keyword '" + key + "' is not supported");
throw new ArgumentException($"Keyword '{key}' is not supported.", key);
}

internal const string
Expand Down
2 changes: 1 addition & 1 deletion src/StackExchange.Redis/ConnectionMultiplexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,7 @@ internal async Task<bool> ReconfigureAsync(bool first, bool reconfigureAll, LogP
{
ServerSelectionStrategy.ServerType = ServerType.Sentinel;
}
else
else if (standaloneCount > 0)
{
ServerSelectionStrategy.ServerType = ServerType.Standalone;
}
Expand Down
9 changes: 2 additions & 7 deletions src/StackExchange.Redis/ResultProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,8 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
endPoints.Add(Format.ParseEndPoint(ip, port));
}
}
break;
SetResult(message, endPoints.ToArray());
return true;

case ResultType.SimpleString:
//We don't want to blow up if the master is not found
Expand All @@ -2066,12 +2067,6 @@ protected override bool SetResultCore(PhysicalConnection connection, Message mes
break;
}

if (endPoints.Count > 0)
{
SetResult(message, endPoints.ToArray());
return true;
}

return false;
}
}
Expand Down
2 changes: 0 additions & 2 deletions tests/BasicTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.InProcess;
using BenchmarkDotNet.Validators;
using StackExchange.Redis;

Expand Down Expand Up @@ -42,7 +41,6 @@ protected override Job Configure(Job j)
=> j.WithLaunchCount(1)
.WithWarmupCount(1)
.WithIterationCount(5);
public SlowConfig() { }
}
/// <summary>
/// The tests
Expand Down
6 changes: 3 additions & 3 deletions tests/NRediSearch.Test/ClientTests/AggregationBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public AggregationBuilderTests(ITestOutputHelper output) : base(output)
[Fact]
public void TestAggregations()
{
/**
/*
127.0.0.1:6379> FT.CREATE test_index SCHEMA name TEXT SORTABLE count NUMERIC SORTABLE
OK
127.0.0.1:6379> FT.ADD test_index data1 1.0 FIELDS name abc count 10
Expand Down Expand Up @@ -63,7 +63,7 @@ public void TestAggregations()
[Fact]
public void TestApplyAndFilterAggregations()
{
/**
/*
127.0.0.1:6379> FT.CREATE test_index SCHEMA name TEXT SORTABLE subj1 NUMERIC SORTABLE subj2 NUMERIC SORTABLE
OK
127.0.0.1:6379> FT.ADD test_index data1 1.0 FIELDS name abc subj1 20 subj2 70
Expand Down Expand Up @@ -115,7 +115,7 @@ public void TestApplyAndFilterAggregations()
[Fact]
public void TestCursor()
{
/**
/*
127.0.0.1:6379> FT.CREATE test_index SCHEMA name TEXT SORTABLE count NUMERIC SORTABLE
OK
127.0.0.1:6379> FT.ADD test_index data1 1.0 FIELDS name abc count 10
Expand Down
2 changes: 1 addition & 1 deletion tests/NRediSearch.Test/ClientTests/AggregationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public AggregationTest(ITestOutputHelper output) : base(output) { }
[Obsolete]
public void TestAggregations()
{
/**
/*
127.0.0.1:6379> FT.CREATE test_index SCHEMA name TEXT SORTABLE count NUMERIC SORTABLE
OK
127.0.0.1:6379> FT.ADD test_index data1 1.0 FIELDS name abc count 10
Expand Down
8 changes: 4 additions & 4 deletions tests/NRediSearch.Test/ClientTests/ClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void TestQueryFlags()
{
Assert.StartsWith("doc", d.Id);
Assert.True(d.Score != 1.0);
Assert.StartsWith("hello world", (string)d["title"]);
Assert.StartsWith("hello world", d["title"]);
}

q = new Query("hello").SetNoContent();
Expand Down Expand Up @@ -616,8 +616,8 @@ public void TestAddSuggestionGetSuggestion()
Suggestion suggestion = Suggestion.Builder.String("ANOTHER_WORD").Score(1).Build();
Suggestion noMatch = Suggestion.Builder.String("_WORD MISSED").Score(1).Build();

Assert.True(cl.AddSuggestion(suggestion, false) > 0, $"{suggestion.ToString()} should of inserted at least 1");
Assert.True(cl.AddSuggestion(noMatch, false) > 0, $"{noMatch.ToString()} should of inserted at least 1");
Assert.True(cl.AddSuggestion(suggestion, false) > 0, $"{suggestion} should of inserted at least 1");
Assert.True(cl.AddSuggestion(noMatch, false) > 0, $"{noMatch} should of inserted at least 1");

// test that with a partial part of that string will have the entire word returned SuggestionOptions.builder().build()
Assert.Single(cl.GetSuggestions(suggestion.String.Substring(0, 3), SuggestionOptions.Builder.Fuzzy().Build()));
Expand All @@ -634,7 +634,7 @@ public void TestAddSuggestionGetSuggestionPayloadScores()
Client cl = GetClient();

Suggestion suggestion = Suggestion.Builder.String("COUNT_ME TOO").Payload("PAYLOADS ROCK ").Score(0.2).Build();
Assert.True(cl.AddSuggestion(suggestion, false) > 0, $"{suggestion.ToString()} insert should of at least returned 1");
Assert.True(cl.AddSuggestion(suggestion, false) > 0, $"{suggestion} insert should of at least returned 1");
Assert.True(cl.AddSuggestion(suggestion.ToBuilder().String("COUNT").Payload("My PAYLOAD is better").Build(), false) > 1, "Count single added should return more than 1");
Assert.True(cl.AddSuggestion(suggestion.ToBuilder().String("COUNT_ANOTHER").Score(1).Payload(null).Build(), false) > 1, "Count single added should return more than 1");

Expand Down
29 changes: 14 additions & 15 deletions tests/NRediSearch.Test/ExampleUsage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using StackExchange.Redis;
using Xunit;
Expand All @@ -17,7 +16,7 @@ public void BasicUsage()
{
var client = GetClient();

try { client.DropIndex(); } catch { } // reset DB
try { client.DropIndex(); } catch { /* Intentionally ignored */ } // reset DB

// Defining a schema for an index and creating it:
var sc = new Schema()
Expand All @@ -35,8 +34,8 @@ public void BasicUsage()
// TODO: Convert to Skip
if (ex.Message == "ERR unknown command 'FT.CREATE'")
{
Console.WriteLine(ex.Message);
Console.WriteLine("Module not installed, aborting");
Output.WriteLine(ex.Message);
Output.WriteLine("Module not installed, aborting");
}
throw;
}
Expand Down Expand Up @@ -73,8 +72,8 @@ public void BasicUsage()
Assert.True(item.HasProperty("price"));
Assert.False(item.HasProperty("blap"));

Assert.Equal("hello world", (string)item["title"]);
Assert.Equal("lorem ipsum", (string)item["body"]);
Assert.Equal("hello world", item["title"]);
Assert.Equal("lorem ipsum", item["body"]);
Assert.Equal(1337, (int)item["price"]);
}

Expand All @@ -83,13 +82,13 @@ public void BasicScoringUsage()
{
var client = GetClient();

try { client.DropIndex(); } catch { } // reset DB
try { client.DropIndex(); } catch { /* Intentionally ignored */ } // reset DB

CreateSchema(client);

var term = "petit*";

var query = new NRediSearch.Query(term);
var query = new Query(term);
query.Limit(0, 10);
query.WithScores = true;

Expand All @@ -108,13 +107,13 @@ public void BasicScoringUsageWithExplainScore()
{
var client = GetClient();

try { client.DropIndex(); } catch { } // reset DB
try { client.DropIndex(); } catch { /* Intentionally ignored */ } // reset DB

CreateSchema(client);

var term = "petit*";

var query = new NRediSearch.Query(term);
var query = new Query(term);
query.Limit(0, 10);
query.WithScores = true;
query.Scoring = "TFIDF";
Expand All @@ -138,13 +137,13 @@ public void BasicScoringUsageWithExplainScoreDifferentScorer()
{
var client = GetClient();

try { client.DropIndex(); } catch { } // reset DB
try { client.DropIndex(); } catch { /* Intentionally ignored */ } // reset DB

CreateSchema(client);

var term = "petit*";

var query = new NRediSearch.Query(term);
var query = new Query(term);
query.Limit(0, 10);
query.WithScores = true;
query.Scoring = "TFIDF.DOCNORM";
Expand All @@ -165,7 +164,7 @@ public void BasicScoringUsageWithExplainScoreDifferentScorer()

private void CreateSchema(Client client)
{
var schema = new NRediSearch.Schema();
var schema = new Schema();

schema
.AddSortableTextField("title")
Expand All @@ -176,7 +175,7 @@ private void CreateSchema(Client client)

client.CreateIndex(schema, new ConfiguredIndexOptions());

var doc = new NRediSearch.Document("1");
var doc = new Document("1");

doc
.Set("title", "Le Petit Prince")
Expand Down
3 changes: 1 addition & 2 deletions tests/NRediSearch.Test/RediSearchTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using StackExchange.Redis;
using StackExchange.Redis.Tests;
Expand Down Expand Up @@ -75,7 +74,7 @@ protected bool Reset(Client client)
}
}

private static bool instanceMissing = false;
private static bool instanceMissing;

internal static ConnectionMultiplexer GetWithFT(ITestOutputHelper output)
{
Expand Down
7 changes: 3 additions & 4 deletions tests/StackExchange.Redis.Tests/AggresssiveTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -31,7 +30,6 @@ public async Task ParallelTransactionsWithConditions()
for (int i = 0; i < tasks.Length; i++)
{
var scopedDb = muxers[i % Muxers].GetDatabase();
var rand = new Random(i);
tasks[i] = Task.Run(async () =>
{
for (int j = 0; j < PerThread; j++)
Expand Down Expand Up @@ -67,7 +65,8 @@ public async Task ParallelTransactionsWithConditions()
{
for (int i = 0; i < muxers.Length; i++)
{
try { muxers[i]?.Dispose(); } catch { }
try { muxers[i]?.Dispose(); }
catch { /* Don't care */ }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/StackExchange.Redis.Tests/AsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task AsyncTimeoutIsNoticed()
var ms = Stopwatch.StartNew();
var ex = await Assert.ThrowsAsync<RedisTimeoutException>(async () =>
{
var actual = await db.StringGetAsync(key).ForAwait(); // but *subsequent* operations are paused
await db.StringGetAsync(key).ForAwait(); // but *subsequent* operations are paused
ms.Stop();
Writer.WriteLine($"Unexpectedly succeeded after {ms.ElapsedMilliseconds}ms");
}).ForAwait();
Expand Down
Loading

0 comments on commit be109fd

Please sign in to comment.