[fix]降低RedisCacheProvider对IConfigProvider的依赖,在外部没有注册IConfigProvider时(常见于没有星尘),自动加载本地配置文件。
大石头 编写于 2024-10-31 09:19:20
NewLife.Redis
using NewLife.Caching;
using NewLife.Caching.Clusters;
using NewLife.Log;
using Xunit;

namespace XUnitTest.Clusters;

public class RedisSentinelTests
{
    public FullRedis _redis { get; set; }

    public RedisSentinelTests()
    {
        var config = BasicTest.GetConfig();
#if DEBUG
        config = "server=127.0.0.1:7002,127.0.0.1:7003,127.0.0.1:7004";
#endif

        _redis = new FullRedis();
        _redis.Init(config);
        //_redis.Db = 2;
        _redis.Log = XTrace.Log;

#if DEBUG
        _redis.ClientLog = XTrace.Log;
#endif
    }

#if DEBUG
    [Fact]
#else
    [Fact(Skip = "No Cluster")]
#endif
    public void GetNodes()
    {
        var cluster = new RedisSentinel(_redis);
        cluster.GetNodes();

        var rep = cluster.Replication;
        Assert.NotNull(rep);
        //Assert.Equal("sentinel", rep.Role);
        Assert.NotNull(rep.Masters);

        Assert.NotNull(cluster.Nodes);
        //Assert.Equal(rep.Masters.Length, cluster.Nodes.Length);
        //Assert.Equal(4, cluster.Nodes.Length);
    }
}