Skip to content

Commit

Permalink
Merge branch 'main' into python/geodist
Browse files Browse the repository at this point in the history
  • Loading branch information
shohamazon authored Apr 22, 2024
2 parents 38c4d37 + 95b6f2f commit b784b3a
Show file tree
Hide file tree
Showing 22 changed files with 662 additions and 67 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* Python: Added GEOADD command ([#1259](https://github.com/aws/glide-for-redis/pull/1259))
* Python: Added GEODIST command ([#1260](https://github.com/aws/glide-for-redis/pull/1260))
* Python: Added GEOHASH command ([#1281](https://github.com/aws/glide-for-redis/pull/1281))
* Python: Added ZLEXCOUNT command ([#1305](https://github.com/aws/glide-for-redis/pull/1305))
* Python: Added ZREMRANGEBYLEX command ([#1306](https://github.com/aws/glide-for-redis/pull/1306))
* Python: Added LINSERT command ([#1304](https://github.com/aws/glide-for-redis/pull/1304))

#### Fixes
* Python: Fix typing error "‘type’ object is not subscriptable" ([#1203](https://github.com/aws/glide-for-redis/pull/1203))
Expand Down
39 changes: 23 additions & 16 deletions csharp/tests/Integration/GetAndSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

using System.Runtime.InteropServices;

using FluentAssertions;

using Glide;

using static Tests.Integration.IntegrationTestBase;

namespace Tests.Integration;
public class GetAndSet
public class GetAndSet : IClassFixture<IntegrationTestBase>
{
private async Task GetAndSetValues(AsyncClient client, string key, string value)
{
string? setResult = await client.SetAsync(key, value);
Assert.That(setResult, Is.EqualTo("OK"));
string? result = await client.GetAsync(key);
Assert.That(result, Is.EqualTo(value));
_ = (await client.SetAsync(key, value))
.Should()
.Be("OK");
_ = (await client.GetAsync(key))
.Should()
.Be(value);
}

private async Task GetAndSetRandomValues(AsyncClient client)
Expand All @@ -24,14 +28,14 @@ private async Task GetAndSetRandomValues(AsyncClient client)
await GetAndSetValues(client, key, value);
}

[Test]
[Fact]
public async Task GetReturnsLastSet()
{
using AsyncClient client = new("localhost", TestConfiguration.STANDALONE_PORTS[0], false);
await GetAndSetRandomValues(client);
}

[Test]
[Fact]
public async Task GetAndSetCanHandleNonASCIIUnicode()
{
using AsyncClient client = new("localhost", TestConfiguration.STANDALONE_PORTS[0], false);
Expand All @@ -40,15 +44,16 @@ public async Task GetAndSetCanHandleNonASCIIUnicode()
await GetAndSetValues(client, key, value);
}

[Test]
[Fact]
public async Task GetReturnsNull()
{
using AsyncClient client = new("localhost", TestConfiguration.STANDALONE_PORTS[0], false);
string? result = await client.GetAsync(Guid.NewGuid().ToString());
Assert.That(result, Is.EqualTo(null));
_ = (await client.GetAsync(Guid.NewGuid().ToString()))
.Should()
.BeNull();
}

[Test]
[Fact]
public async Task GetReturnsEmptyString()
{
using AsyncClient client = new("localhost", TestConfiguration.STANDALONE_PORTS[0], false);
Expand All @@ -57,13 +62,14 @@ public async Task GetReturnsEmptyString()
await GetAndSetValues(client, key, value);
}

[Test]
[Fact]
public async Task HandleVeryLargeInput()
{
// TODO invesitage and fix
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Assert.Ignore("Flaky on MacOS");
//"Flaky on MacOS"
return;
}
using AsyncClient client = new("localhost", TestConfiguration.STANDALONE_PORTS[0], false);

Expand All @@ -80,7 +86,7 @@ public async Task HandleVeryLargeInput()

// This test is slow and hardly a unit test, but it caught timing and releasing issues in the past,
// so it's being kept.
[Test]
[Fact]
public void ConcurrentOperationsWork()
{
// TODO investigate and fix
Expand All @@ -105,8 +111,9 @@ public void ConcurrentOperationsWork()
}
else
{
string? result = await client.GetAsync(Guid.NewGuid().ToString());
Assert.That(result, Is.EqualTo(null));
_ = (await client.GetAsync(Guid.NewGuid().ToString()))
.Should()
.BeNull();
}
}
}));
Expand Down
54 changes: 28 additions & 26 deletions csharp/tests/Integration/IntegrationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

using System.Diagnostics;

using Xunit.Abstractions;
using Xunit.Sdk;

// Note: All IT should be in the same namespace
namespace Tests.Integration;

[SetUpFixture]
public class IntegrationTestBase
public class IntegrationTestBase : IDisposable
{
internal class TestConfiguration
{
Expand All @@ -15,9 +17,24 @@ internal class TestConfiguration
public static Version REDIS_VERSION { get; internal set; } = new();
}

[OneTimeSetUp]
public void SetUp()
private readonly IMessageSink _diagnosticMessageSink;

public IntegrationTestBase(IMessageSink diagnosticMessageSink)
{
_diagnosticMessageSink = diagnosticMessageSink;
string? projectDir = Directory.GetCurrentDirectory();
while (!(Path.GetFileName(projectDir) == "csharp" || projectDir == null))
{
projectDir = Path.GetDirectoryName(projectDir);
}

if (projectDir == null)
{
throw new FileNotFoundException("Can't detect the project dir. Are you running tests from `csharp` directory?");
}

_scriptDir = Path.Combine(projectDir, "..", "utils");

// Stop all if weren't stopped on previous test run
StopRedis(false);

Expand All @@ -31,34 +48,19 @@ public void SetUp()
// Get redis version
TestConfiguration.REDIS_VERSION = GetRedisVersion();

TestContext.Progress.WriteLine($"Cluster ports = {string.Join(',', TestConfiguration.CLUSTER_PORTS)}");
TestContext.Progress.WriteLine($"Standalone ports = {string.Join(',', TestConfiguration.STANDALONE_PORTS)}");
TestContext.Progress.WriteLine($"Redis version = {TestConfiguration.REDIS_VERSION}");
TestConsoleWriteLine($"Cluster ports = {string.Join(',', TestConfiguration.CLUSTER_PORTS)}");
TestConsoleWriteLine($"Standalone ports = {string.Join(',', TestConfiguration.STANDALONE_PORTS)}");
TestConsoleWriteLine($"Redis version = {TestConfiguration.REDIS_VERSION}");
}

[OneTimeTearDown]
public void TearDown() =>
public void Dispose() =>
// Stop all
StopRedis(true);

private readonly string _scriptDir;

// Nunit requires a public default constructor. These variables would be set in SetUp method.
public IntegrationTestBase()
{
string? projectDir = Directory.GetCurrentDirectory();
while (!(Path.GetFileName(projectDir) == "csharp" || projectDir == null))
{
projectDir = Path.GetDirectoryName(projectDir);
}

if (projectDir == null)
{
throw new FileNotFoundException("Can't detect the project dir. Are you running tests from `csharp` directory?");
}

_scriptDir = Path.Combine(projectDir, "..", "utils");
}
private void TestConsoleWriteLine(string message) =>
_ = _diagnosticMessageSink.OnMessage(new DiagnosticMessage(message));

internal List<uint> StartRedis(bool cluster, bool tls = false, string? name = null)
{
Expand Down Expand Up @@ -92,7 +94,7 @@ private string RunClusterManager(string cmd, bool ignoreExitCode)
string? output = script?.StandardOutput.ReadToEnd();
int? exit_code = script?.ExitCode;

TestContext.Progress.WriteLine($"cluster_manager.py stdout\n====\n{output}\n====\ncluster_manager.py stderr\n====\n{error}\n====\n");
TestConsoleWriteLine($"cluster_manager.py stdout\n====\n{output}\n====\ncluster_manager.py stderr\n====\n{error}\n====\n");

return !ignoreExitCode && exit_code != 0
? throw new ApplicationException($"cluster_manager.py script failed: exit code {exit_code}.")
Expand Down
2 changes: 1 addition & 1 deletion csharp/tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0

global using NUnit.Framework;
global using Xunit;
18 changes: 13 additions & 5 deletions csharp/tests/tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -16,11 +18,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions glide-core/THIRD_PARTY_LICENSES_RUST
Original file line number Diff line number Diff line change
Expand Up @@ -19461,7 +19461,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----

Package: rustls:0.22.3
Package: rustls:0.22.4

The following copyrights and licenses were found in the source code of this package:

Expand Down Expand Up @@ -22894,7 +22894,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----

Package: thiserror:1.0.58
Package: thiserror:1.0.59

The following copyrights and licenses were found in the source code of this package:

Expand Down Expand Up @@ -23123,7 +23123,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----

Package: thiserror-impl:1.0.58
Package: thiserror-impl:1.0.59

The following copyrights and licenses were found in the source code of this package:

Expand Down
5 changes: 4 additions & 1 deletion glide-core/src/client/value_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ pub(crate) fn convert_to_expected_type(
Value::Array(array) => {
let array_of_bools = array
.iter()
.map(|v| Value::Boolean(from_owned_redis_value::<bool>(v.clone()).unwrap()))
.map(|v| {
convert_to_expected_type(v.clone(), Some(ExpectedReturnType::Boolean))
.unwrap()
})
.collect();
Ok(Value::Array(array_of_bools))
}
Expand Down
3 changes: 2 additions & 1 deletion glide-core/src/protobuf/redis_request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ enum RequestType {
LastSave = 120;
GeoAdd = 121;
GeoHash = 122;
GeoDist = 123;
ObjectEncoding = 123;
GeoDist = 124;
}

message Command {
Expand Down
5 changes: 4 additions & 1 deletion glide-core/src/request_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ pub enum RequestType {
LastSave = 120,
GeoAdd = 121,
GeoHash = 122,
GeoDist = 123,
ObjectEncoding = 123,
GeoDist = 124,
}

fn get_two_word_command(first: &str, second: &str) -> Cmd {
Expand Down Expand Up @@ -264,6 +265,7 @@ impl From<::protobuf::EnumOrUnknown<ProtobufRequestType>> for RequestType {
ProtobufRequestType::LastSave => RequestType::LastSave,
ProtobufRequestType::GeoAdd => RequestType::GeoAdd,
ProtobufRequestType::GeoHash => RequestType::GeoHash,
ProtobufRequestType::ObjectEncoding => RequestType::ObjectEncoding,
ProtobufRequestType::GeoDist => RequestType::GeoDist,
}
}
Expand Down Expand Up @@ -394,6 +396,7 @@ impl RequestType {
RequestType::LastSave => Some(cmd("LASTSAVE")),
RequestType::GeoAdd => Some(cmd("GEOADD")),
RequestType::GeoHash => Some(cmd("GEOHASH")),
RequestType::ObjectEncoding => Some(get_two_word_command("OBJECT", "ENCODING")),
RequestType::GeoDist => Some(cmd("GEODIST")),
}
}
Expand Down
7 changes: 7 additions & 0 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static redis_request.RedisRequestOuterClass.RequestType.Lindex;
import static redis_request.RedisRequestOuterClass.RequestType.MGet;
import static redis_request.RedisRequestOuterClass.RequestType.MSet;
import static redis_request.RedisRequestOuterClass.RequestType.ObjectEncoding;
import static redis_request.RedisRequestOuterClass.RequestType.PExpire;
import static redis_request.RedisRequestOuterClass.RequestType.PExpireAt;
import static redis_request.RedisRequestOuterClass.RequestType.PTTL;
Expand Down Expand Up @@ -334,6 +335,12 @@ public CompletableFuture<String> mset(@NonNull Map<String, String> keyValueMap)
return commandManager.submitNewCommand(MSet, args, this::handleStringResponse);
}

@Override
public CompletableFuture<String> objectEncoding(@NonNull String key) {
return commandManager.submitNewCommand(
ObjectEncoding, new String[] {key}, this::handleStringOrNullResponse);
}

@Override
public CompletableFuture<Long> incr(@NonNull String key) {
return commandManager.submitNewCommand(Incr, new String[] {key}, this::handleLongResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,22 @@ CompletableFuture<Boolean> pexpireAt(
* }</pre>
*/
CompletableFuture<String> type(String key);

/**
* Returns the internal encoding for the Redis object stored at <code>key</code>.
*
* @see <a href="https://redis.io/commands/object-encoding/">redis.io</a> for details.
* @param key The <code>key</code> of the object to get the internal encoding of.
* @return If <code>key</code> exists, returns the internal encoding of the object stored at
* <code>key</code> as a <code>String</code>. Otherwise, returns <code>null</code>.
* @example
* <pre>{@code
* String encoding = client.objectEncoding("my_hash").get();
* assert encoding.equals("listpack");
*
* encoding = client.objectEncoding("non_existing_key").get();
* assert encoding.equals(null);
* }</pre>
*/
CompletableFuture<String> objectEncoding(String key);
}
16 changes: 16 additions & 0 deletions java/client/src/main/java/glide/api/models/BaseTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static redis_request.RedisRequestOuterClass.RequestType.Lindex;
import static redis_request.RedisRequestOuterClass.RequestType.MGet;
import static redis_request.RedisRequestOuterClass.RequestType.MSet;
import static redis_request.RedisRequestOuterClass.RequestType.ObjectEncoding;
import static redis_request.RedisRequestOuterClass.RequestType.PExpire;
import static redis_request.RedisRequestOuterClass.RequestType.PExpireAt;
import static redis_request.RedisRequestOuterClass.RequestType.PTTL;
Expand Down Expand Up @@ -2224,6 +2225,21 @@ public T pfmerge(@NonNull String destination, @NonNull String[] sourceKeys) {
return getThis();
}

/**
* Returns the internal encoding for the Redis object stored at <code>key</code>.
*
* @see <a href="https://redis.io/commands/object-encoding/">redis.io</a> for details.
* @param key The <code>key</code> of the object to get the internal encoding of.
* @return Command response - If <code>key</code> exists, returns the internal encoding of the
* object stored at <code>key</code> as a <code>String</code>. Otherwise, return <code>null
* </code>.
*/
public T objectEncoding(@NonNull String key) {
ArgsArray commandArgs = buildArgs(key);
protobufTransaction.addCommands(buildCommand(ObjectEncoding, commandArgs));
return getThis();
}

/** Build protobuf {@link Command} object for given command and arguments. */
protected Command buildCommand(RequestType requestType) {
return buildCommand(requestType, buildArgs());
Expand Down
Loading

0 comments on commit b784b3a

Please sign in to comment.