Exemplo n.º 1
0
        /// <summary>
        /// This is the Sample Application that uses the Infinispan .NET client library.
        /// </summary>
        /// <param name="args">string</param>
        static void Main(string[] args)
        {
            //Create new Configuration, overriding the setting in the App.config file.
            ClientConfig conf= new ClientConfig("127.0.0.1",11222,"default",0,false);
            //Here we are using a custom Serializer
            Serializer s= new DefaultSerializer();
            //Create a new RemoteCacheManager
            RemoteCacheManager manager = new RemoteCacheManager(conf, s);
            //Get hold of a cache from the remote cache manager
            RemoteCache cache = manager.getCache();

            //First Check Whether the cache exists
            Console.WriteLine("Ping Result : "+cache.ping());
            //Put a new value "germanium" with key "key 1" into cache
            cache.put<String, String>("key 1", "germanium", 0, 0);
            //Get the value of entry with key "key 1"
            Console.WriteLine("key 1 value : "+cache.get<String>("key 1"));
            //Put if absent is used to add entries if they are not existing in the cache
            cache.putIfAbsent<String, String>("key 1", "trinitrotoluene", 0, 0);
            cache.putIfAbsent<String, String>("key 2", "formaldehyde", 0, 0);
            Console.WriteLine("key 1 value after PutIfAbsent: " + cache.get<String>("key 1"));
            Console.WriteLine("Key 2 value after PutIfAbsent: " + cache.get<String>("key 2"));
            //Replace an existing value with a new one.
               // cache.replace<String, String>("key 1", "fluoride",0,0);
            Console.WriteLine("key 1 value after replace: " + cache.get<String>("key 1"));
            //Check whether a particular key exists
            Console.WriteLine("key 1 is exist ?: " + cache.containsKey("key 1"));
            //Remove a particular entry from the cache
               // cache.remove<String>("key 1");
            Console.WriteLine("key 1 is exist after remove?: " + cache.containsKey("key 1"));

            Console.ReadLine();
        }
Exemplo n.º 2
0
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec codec = new Codec();
            Serializer s = new DefaultSerializer();

            byte[] key = UTF8Encoding.UTF8.GetBytes("key10");

            RemoveOperation target = new RemoveOperation(codec, key, null, 0, null);
            Transport transport = trans;
            byte[] expected = null;
            byte[] actual;
            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
        public void executeOperationTest()
        {
            Transport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec codec = new Codec();
            Serializer s = new DefaultSerializer();
            Serializer s2 = new DefaultSerializer();

            //byte[] key = s.serialize("11");
            byte[] key = s.serialize("key15");
            //byte[] key=UTF8Encoding.UTF8.GetBytes("key10");
            byte[] val = s.serialize("hexachlorocyclohexane777");//UTF8Encoding.UTF8.GetBytes("hexachlorocyclohexane777");
            PutOperation target = new PutOperation(codec, key, null, 0, null, val, 0, 0); // TODO: Initialize to an appropriate value
            Transport transport = trans;

            byte[] expected = null; // TODO: Initialize to an appropriate value
            byte[] actual;
            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 4
0
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec codec = new Codec();
            Serializer s = new DefaultSerializer();

            // byte[] key = s.serialize("11");

            byte[] key = s.serialize("key10");
            //byte[] key= UTF8Encoding.UTF8.GetBytes("key10");

            GetOperation target = new GetOperation(codec, key, null, 0, null);
            Transport transport = trans;
            string expected = "hexachlorocyclohexane 777";
            byte[] actual;
            actual = target.executeOperation(transport);
            string res = (string)(s.deserialize(actual));

            Assert.AreEqual(expected, res);
        }
Exemplo n.º 5
0
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec codec = new Codec();
            Serializer s = new DefaultSerializer();
            byte[] key = s.serialize("key10");
            byte[] value = s.serialize("trinitrotoluene");

            byte[] cacheName = null;
            int topologyId = 0;
            Flag[] flags = null;

            int lifespan = 0;
            int maxIdle = 0;
            ReplaceOperation target = new ReplaceOperation(codec, key, cacheName, topologyId, flags, value, lifespan, maxIdle);
            Transport transport = trans;
            byte[] expected = null;
            byte[] actual;
            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual);
        }