Skip to content

Commit 690b8d1

Browse files
shacharPashchayim
andcommitted
Initial support for OSS Cluster API (#170)
* delete mock * coverage * fix test * indent * change to var - check * cluster test * add opthin to connect cluster with dotnet test * use key in topk tests * get env vars inside RedisFixture * skip if redis * add skip where needed * Execute broadcast * delete cluster tests * RedisFixture fix * add to contributing * run cluster on CI * wip * fix / * -d * delete restore * return restore * add -RC3 * add RC3 to docker-compose * try define both .net 6 and 7 * Skip if cluster where needed * add names * skip configOnTimeout if cluster * try to fix win tests * tests names +fix win version * fix versions * versions * win verer * wording * change to OSSCluster * isOSSCluster * update skip reason to OSS cluster * general dispose * general dispose for the rest of the disposes --------- Co-authored-by: Chayim <chayim@users.noreply.github.com>
1 parent 61a245d commit 690b8d1

File tree

8 files changed

+274
-0
lines changed

8 files changed

+274
-0
lines changed

.github/cluster.env

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
REDIS_CLUSTER=127.0.0.1:16379
2+
NUM_REDIS_CLUSTER_NODES=6

.github/docker-compose.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
version: "3.8"
3+
services:
4+
5+
redis-stack-7.2.0-RC3:
6+
image: redis/redis-stack-server:7.2.0-RC3
7+
ports: ["6379:6379"]
8+
9+
redis-stack-6.2.6:
10+
image: redis/redis-stack-server:6.2.6-v9
11+
ports: ["6379:6379"]
12+
13+
redis-stack-edge:
14+
image: redis/redis-stack-server:edge
15+
ports: ["6379:6379"]
16+
17+
redis-stack-cluster:
18+
container_name: redis-cluster
19+
build:
20+
context: .
21+
dockerfile: dockers/Dockerfile.cluster
22+
ports:
23+
- 16379:16379
24+
- 16380:16380
25+
- 16381:16381
26+
- 16382:16382
27+
- 16383:16383
28+
- 16384:16384
29+
volumes:
30+
- "./dockers/cluster.redis.conf:/redis.conf:ro"

.github/dockers/Dockerfile.cluster

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM redis/redis-stack-server:edge as rss
2+
3+
COPY dockers/create_cluster.sh /create_cluster.sh
4+
RUN ls -R /opt/redis-stack
5+
RUN chmod a+x /create_cluster.sh
6+
7+
ENTRYPOINT [ "/create_cluster.sh"]

.github/dockers/cluster.redis.conf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
protected-mode no
2+
enable-debug-command yes
3+
loadmodule /opt/redis-stack/lib/redisearch.so
4+
loadmodule /opt/redis-stack/lib/redisgraph.so
5+
loadmodule /opt/redis-stack/lib/redistimeseries.so
6+
loadmodule /opt/redis-stack/lib/rejson.so
7+
loadmodule /opt/redis-stack/lib/redisbloom.so
8+
loadmodule /opt/redis-stack/lib/redisgears.so v8-plugin-path /opt/redis-stack/lib/libredisgears_v8_plugin.so

.github/dockers/create_cluster.sh

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#! /bin/bash
2+
3+
mkdir -p /nodes
4+
touch /nodes/nodemap
5+
if [ -z ${START_PORT} ]; then
6+
START_PORT=16379
7+
fi
8+
if [ -z ${END_PORT} ]; then
9+
END_PORT=16384
10+
fi
11+
if [ ! -z "$3" ]; then
12+
START_PORT=$2
13+
START_PORT=$3
14+
fi
15+
echo "STARTING: ${START_PORT}"
16+
echo "ENDING: ${END_PORT}"
17+
18+
for PORT in `seq ${START_PORT} ${END_PORT}`; do
19+
mkdir -p /nodes/$PORT
20+
if [[ -e /redis.conf ]]; then
21+
cp /redis.conf /nodes/$PORT/redis.conf
22+
else
23+
touch /nodes/$PORT/redis.conf
24+
fi
25+
cat << EOF >> /nodes/$PORT/redis.conf
26+
port ${PORT}
27+
cluster-enabled yes
28+
daemonize yes
29+
logfile /redis.log
30+
dir /nodes/$PORT
31+
EOF
32+
33+
set -x
34+
/opt/redis-stack/bin/redis-server /nodes/$PORT/redis.conf
35+
sleep 1
36+
if [ $? -ne 0 ]; then
37+
echo "Redis failed to start, exiting."
38+
continue
39+
fi
40+
echo 127.0.0.1:$PORT >> /nodes/nodemap
41+
done
42+
if [ -z "${REDIS_PASSWORD}" ]; then
43+
echo yes | /opt/redis-stack/bin/redis-cli --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
44+
else
45+
echo yes | opt/redis-stack/bin/redis-cli -a ${REDIS_PASSWORD} --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
46+
fi
47+
tail -f /redis.log

.github/standalone.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
REDIS=localhost:6379

.github/workflows/reusable.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build and Test
2+
on:
3+
workflow_call:
4+
inputs:
5+
6+
redis_stack_type:
7+
required: true
8+
type: string
9+
10+
dotnet_version:
11+
required: true
12+
type: string
13+
14+
clr_version:
15+
required: true
16+
type: string
17+
18+
dotenv_file:
19+
required: true
20+
type: string
21+
jobs:
22+
23+
build_and_test:
24+
name: Test
25+
runs-on: ubuntu-latest
26+
27+
env:
28+
USER_NAME: ${{ secrets.USER_NAME }}
29+
PASSWORD: ${{ secrets.PASSWORD }}
30+
ENDPOINT: ${{ secrets.ENDPOINT }}
31+
steps:
32+
33+
- uses: actions/checkout@v3
34+
35+
- name: .NET Core 6
36+
uses: actions/setup-dotnet@v2
37+
with:
38+
dotnet-version: '6.0.x'
39+
40+
- name: .NET Core 7
41+
uses: actions/setup-dotnet@v2
42+
with:
43+
dotnet-version: '7.0.x'
44+
45+
- name: run redis-stack-server docker
46+
working-directory: .github
47+
run: docker-compose up -d redis-stack-${{inputs.redis_stack_type}}
48+
49+
- name: set variables in dotenv
50+
uses: c-py/action-dotenv-to-setenv@v2
51+
with:
52+
env-file: ${{inputs.dotenv_file}}
53+
54+
- name: Restore dependencies
55+
run: dotnet restore
56+
- name: Build
57+
run: dotnet build --no-restore /p:ContinuousIntegrationBuild=true
58+
- name: Test
59+
run: |
60+
echo "${{secrets.REDIS_CA_PEM}}" > tests/NRedisStack.Tests/bin/Debug/net6.0/redis_ca.pem
61+
echo "${{secrets.REDIS_USER_CRT}}" > tests/NRedisStack.Tests/bin/Debug/net6.0/redis_user.crt
62+
echo "${{secrets.REDIS_USER_PRIVATE_KEY}}" > tests/NRedisStack.Tests/bin/Debug/net6.0/redis_user_private.key
63+
ls -R
64+
dotnet test -f ${{inputs.clr_version}} --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
65+
- name: Codecov
66+
uses: codecov/codecov-action@v3
67+
with:
68+
token: ${{secrets.CODECOV_TOKEN}}
69+
verbose: true
70+
- name: Build
71+
run: dotnet pack -c Release
72+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using Xunit;
2+
3+
namespace NRedisStack.Tests;
4+
public enum Comparison
5+
{
6+
LessThan,
7+
GreaterThanOrEqual,
8+
}
9+
10+
public enum Is
11+
{
12+
Standalone,
13+
OSSCluster
14+
}
15+
16+
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
17+
public class SkipIfRedisAttribute : FactAttribute
18+
{
19+
private readonly string _targetVersion;
20+
private readonly Comparison _comparison;
21+
private readonly Is? _is = null;
22+
private readonly string DefaultRedisConnectionString = Environment.GetEnvironmentVariable("REDIS") ?? "localhost:6379";
23+
24+
public SkipIfRedisAttribute(
25+
Is _is,
26+
Comparison comparison = Comparison.LessThan,
27+
string targetVersion = "0.0.0")
28+
{
29+
this._is = _is;
30+
_comparison = comparison;
31+
_targetVersion = targetVersion;
32+
}
33+
34+
public SkipIfRedisAttribute(string targetVersion) // defaults to LessThan
35+
{
36+
_comparison = Comparison.LessThan;
37+
_targetVersion = targetVersion;
38+
}
39+
40+
public SkipIfRedisAttribute(Comparison comparison, string targetVersion)
41+
{
42+
_comparison = comparison;
43+
_targetVersion = targetVersion;
44+
}
45+
46+
public override string? Skip
47+
{
48+
get
49+
{
50+
string skipReason = "";
51+
bool skipped = false;
52+
using (RedisFixture redisFixture = new RedisFixture())
53+
{
54+
55+
// Cluster check
56+
if (_is != null)
57+
{
58+
switch (_is)
59+
{
60+
case Is.OSSCluster:
61+
if (redisFixture.isOSSCluster)
62+
{
63+
skipReason = skipReason + " Redis server is OSS cluster.";
64+
skipped = true;
65+
}
66+
break;
67+
68+
case Is.Standalone:
69+
if (!redisFixture.isOSSCluster)
70+
{
71+
skipReason = skipReason + " Redis server is not OSS cluster.";
72+
skipped = true;
73+
}
74+
break;
75+
}
76+
}
77+
// Version check (if Is.Standalone/Is.Cluster is set then )
78+
79+
var serverVersion = redisFixture.Redis.GetServer(redisFixture.Redis.GetEndPoints()[0]).Version;
80+
var targetVersion = new Version(_targetVersion);
81+
int comparisonResult = serverVersion.CompareTo(targetVersion);
82+
83+
switch (_comparison)
84+
{
85+
case Comparison.LessThan:
86+
if (comparisonResult < 0)
87+
{
88+
skipReason = skipReason + $" Redis server version ({serverVersion}) is less than {_targetVersion}.";
89+
skipped = true;
90+
}
91+
break;
92+
case Comparison.GreaterThanOrEqual:
93+
if (comparisonResult >= 0)
94+
{
95+
skipReason = skipReason + $" Redis server version ({serverVersion}) is greater than or equal to {_targetVersion}.";
96+
skipped = true;
97+
}
98+
break;
99+
}
100+
}
101+
102+
if (skipped)
103+
return "Test skipped, because:" + skipReason;
104+
return null;
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)