Example #1
0
        /// <summary>
        /// Replaces an existing value with a new value.
        /// </summary>
        /// <typeparam name="V">Data type of Value</typeparam>
        /// <typeparam name="K">Data type of Key</typeparam>
        /// <param name="key">key</param>
        /// <param name="val">value</param>
        /// <param name="lifespaninMillis">Lifespan in milliseconds</param>
        /// <param name="maxIdleTimeinMillis">Maximum idle time in milliseconds</param>
        public V replace <V, K>(K key, V val, int lifespaninMillis, int maxIdleTimeinMillis)
        {
            int lifespanSecs    = TimeSpan.FromMilliseconds(lifespaninMillis).Seconds;
            int maxIdleSecs     = TimeSpan.FromMilliseconds(maxIdleTimeinMillis).Seconds;
            ReplaceOperation op = operationsFactory.newReplaceOperation(serializer.serialize(key), serializer.serialize(val), lifespanSecs, maxIdleSecs);

            transport = transportFactory.getTransport();
            try
            {
            }
            finally
            {
                transportFactory.releaseTransport(transport);
            }
            byte[] bytes = (byte[])op.executeOperation(transport);
            return((V)serializer.deserialize(bytes));
        }
        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);
        }
Example #3
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);
        }