Exemple #1
0
        public static IKronosClient CreateClient(string configFilePath)
        {
            string configContent = File.ReadAllText(configFilePath);

            KronosConfig config = JsonConvert.DeserializeObject <KronosConfig>(configContent);

            return(new KronosClient(config));
        }
Exemple #2
0
        public async Task Delete_CallsSendToServerAsync()
        {
            var connectionMock = Substitute.For <IConnection>();

            connectionMock.SendAsync(Arg.Any <DeleteRequest>())
            .Returns(SerializationUtils.Serialize(true));

            KronosConfig  config = LoadTestConfiguration();
            IKronosClient client = new KronosClient(config, endpoint => connectionMock);

            await client.DeleteAsync("key");

            await connectionMock.Received(1).SendAsync(Arg.Any <DeleteRequest>());
        }
Exemple #3
0
        private static IKronosClient CreateInternal(string domain, string ip, int port)
        {
            var config = new KronosConfig
            {
                ClusterConfig = new ClusterConfig
                {
                    Servers = new[] { new ServerConfig {
                                          Domain = domain, Ip = ip, Port = port
                                      } }
                }
            };

            return(new KronosClient(config));
        }
Exemple #4
0
        public async Task Get_DoestNotReturnObject()
        {
            byte[] serverResponse = SerializationUtils.Serialize(RequestStatusCode.NotFound);
            var    connectionMock = Substitute.For <IConnection>();

            connectionMock.SendAsync(Arg.Any <GetRequest>())
            .Returns(SerializationUtils.Serialize(serverResponse));

            KronosConfig  config = LoadTestConfiguration();
            IKronosClient client = new KronosClient(config, endpoint => connectionMock);

            byte[] response = await client.GetAsync("key");

            Assert.Null(response);
            await connectionMock.Received(1).SendAsync(Arg.Any <GetRequest>());
        }
Exemple #5
0
        public async Task Count_ReturnsNumberOfElementsInStorage()
        {
            int countPerServer = 5;
            var connectionMock = Substitute.For <IConnection>();

            connectionMock.SendAsync(Arg.Any <CountRequest>())
            .Returns(SerializationUtils.Serialize(countPerServer));

            KronosConfig  config      = LoadTestConfiguration();
            int           serverCount = config.ClusterConfig.Servers.Length;
            IKronosClient client      = new KronosClient(config, endpoint => connectionMock);

            int sum = await client.CountAsync();

            Assert.Equal(sum, countPerServer * serverCount);
            await connectionMock.Received(serverCount).SendAsync(Arg.Any <CountRequest>());
        }
Exemple #6
0
        public async Task Contains_ReturnsTrueIfElementExistsInStorage()
        {
            bool   expected       = true;
            string key            = "lorem ipsum";
            var    connectionMock = Substitute.For <IConnection>();

            connectionMock.SendAsync(Arg.Any <ContainsRequest>())
            .Returns(SerializationUtils.Serialize(expected));

            KronosConfig  config = LoadTestConfiguration();
            IKronosClient client = new KronosClient(config, endpoint => connectionMock);

            bool exists = await client.ContainsAsync(key);

            Assert.Equal(expected, exists);
            await connectionMock.Received(1).SendAsync(Arg.Any <ContainsRequest>());
        }
Exemple #7
0
        public async Task Insert_InsertsObjectToStorage()
        {
            string key = "key";

            byte[]   package    = Encoding.UTF8.GetBytes("package");
            DateTime expiryDate = DateTime.Today.AddDays(1);

            var connectionMock = Substitute.For <IConnection>();

            connectionMock.SendAsync(Arg.Any <IRequest>())
            .Returns(SerializationUtils.Serialize(true));

            KronosConfig  config = LoadTestConfiguration();
            IKronosClient client = new KronosClient(config, endpoint => connectionMock);
            await client.InsertAsync(key, package, expiryDate);

            await connectionMock.Received(1).SendAsync(Arg.Any <InsertRequest>());
        }
Exemple #8
0
        public async Task Get_ReturnsObject()
        {
            const string word = "lorem ipsum";

            byte[] package = SerializationUtils.Serialize(word);

            var connectionMock = Substitute.For <IConnection>();

            connectionMock.SendAsync(Arg.Any <GetRequest>())
            .Returns(SerializationUtils.Serialize(package));

            KronosConfig  config = LoadTestConfiguration();
            IKronosClient client = new KronosClient(config, endpoint => connectionMock);

            byte[] response = await client.GetAsync("key");

            string responseString = SerializationUtils.Deserialize <string>(response);

            Assert.Equal(responseString, word);
            await connectionMock.Received(1).SendAsync(Arg.Any <GetRequest>());
        }
Exemple #9
0
        private static IKronosClient CreateInternal(string domain, string ip, int port, string login, string password)
        {
            var config = new KronosConfig
            {
                ClusterConfig = new ClusterConfig
                {
                    Servers = new[]
                    {
                        new ServerConfig
                        {
                            Domain      = domain,
                            Ip          = ip,
                            Port        = port,
                            Credentials = new AuthConfig {
                                Login = login, Password = password
                            }
                        }
                    }
                }
            };

            return(new KronosClient(config));
        }
Exemple #10
0
 internal KronosClient(KronosConfig config, Func <IPEndPoint, IConnection> connectionResolver)
 {
     _serverProvider     = new ServerProvider(config.ClusterConfig);
     _connectionResolver = connectionResolver;
 }
Exemple #11
0
 public KronosClient(KronosConfig config) : this(config, endpoint => new Connection(endpoint))
 {
 }
Exemple #12
0
 public KronosClient(KronosConfig config)
 {
     _serverProvider = new ServerProvider(config.ClusterConfig);
 }