[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 RedisReplicationTests
{
    public FullRedis _redis { get; set; }

    public RedisReplicationTests()
    {
        var config = BasicTest.GetConfig();
#if DEBUG
        config = "server=127.0.0.1:6002,127.0.0.1:6003,127.0.0.1:6004";
#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 RedisReplication(_redis) { SetHostServer = true };
        cluster.GetNodes();

        var rep = cluster.Replication;
        Assert.NotNull(rep);
        Assert.Equal("master", rep.Role);

        Assert.NotNull(rep.Slaves);

        Assert.NotNull(cluster.Nodes);
        Assert.Equal(1 + rep.Slaves.Length, cluster.Nodes.Length);

        var ver = _redis.Version;
        Assert.NotNull(ver);
    }
}