public void Start_throws_if_already_started()
        {
            var server = new CacheServer();
            var endpoint = Utils.GetEndpoint();

            server.Start(endpoint);

            Assert.Throws<InvalidOperationException>(() =>
            {
                server.Start(endpoint);
            });
        }
        public void CacheServer_should_start_and_stop()
        {
            var server = new CacheServer();

            server.Start(Utils.GetEndpoint());
            server.Stop();
        }
Esempio n. 3
0
 static void Main(string[] args)
 {
     var server = new CacheServer();
     server.Start("tcp://*:4632");
     Console.WriteLine("MemCache server has started");
     Console.WriteLine("Press Enter to stop");
     Console.ReadLine();
 }
        public void Client_should_connect_to_server()
        {
            var endPoint = Utils.GetEndpoint();

            var server = new CacheServer();
            server.Start(endPoint);

            var client = new CacheClient();
            client.Connect(new ConnectionInfo { EndPoint = endPoint });
        }
        public async void First_client_set_and_second_client_get_the_same_value()
        {
            var endPoint = Utils.GetEndpoint();

            var server = new CacheServer();
            server.Start(endPoint);

            var client1 = new CacheClient();
            client1.Connect(new ConnectionInfo { EndPoint = endPoint });
            await client1.Set("key", "value");

            var client2 = new CacheClient();
            client2.Connect(new ConnectionInfo { EndPoint = endPoint });

            Assert.Equal("value", await client2.Get("key"));
        }
        public async void Set_and_Get_complex_type()
        {
            var endPoint = Utils.GetEndpoint();

            var server = new CacheServer();
            server.Start(endPoint);

            var client = new CacheClient();
            client.Connect(new ConnectionInfo { EndPoint = endPoint });

            var date = DateTime.Now;
            var value1 = new Foo { Int = 123, Str = "string", Bar = new Bar { Date = date } };
            var value2 = new Foo { Int = 123, Str = "string", Bar = new Bar { Date = date } };

            await client.Set("key", value1);
            
            Assert.Equal(value2, await client.Get("key"));
        }
        public async void Set_and_Get_primitive_types()
        {
            var endPoint = Utils.GetEndpoint();

            var server = new CacheServer();
            server.Start(endPoint);

            var client = new CacheClient();
            client.Connect(new ConnectionInfo { EndPoint = endPoint });

            var values = new object[] {34, "abc", true, new DateTime(2020, 10, 20, 1, 2, 3), Int64.MinValue};
            for (int i = 0; i < values.Length; i++)
            {
                await client.Set(values[i].ToString(), values[i]);
            }

            for (int i = 0; i < values.Length; i++)
            {
                Assert.Equal(values[i], await client.Get(values[i].ToString()));
            }
        }