Beispiel #1
0
        public void TestNamedCacheException()
        {
            TcpInitiator initiator    = GetInitiator();
            IConnection  conn         = initiator.EnsureConnection();
            IChannel     cacheService = conn.OpenChannel(CacheServiceProtocol.Instance,
                                                         "CacheServiceProxy", null, null);

            EnsureCacheRequest ensureCacheRequest =
                (EnsureCacheRequest)cacheService.MessageFactory.CreateMessage(EnsureCacheRequest.TYPE_ID);

            ensureCacheRequest.CacheName = CacheNameTemp;

            string   response   = (string)cacheService.Request(ensureCacheRequest);
            Uri      uri        = new Uri(response);
            IChannel namedCache = conn.AcceptChannel(uri, null, null);

            string[]    keys      = { "Ana Cikic", "Goran Milosavljevic", "Ivan Cikic" };
            string[]    values    = { "10.0.0.120", "10.0.0.180", "10.0.0.125" };
            IDictionary addresses = new Hashtable();

            addresses.Add(convToBinary.Convert(keys[0]), convToBinary.Convert(values[0]));
            addresses.Add(convToBinary.Convert(keys[1]), convToBinary.Convert(values[1]));
            addresses.Add(convToBinary.Convert(keys[2]), convToBinary.Convert(values[2]));

            PutAllRequest putAllRequest =
                (PutAllRequest)namedCache.MessageFactory.CreateMessage(PutAllRequest.TYPE_ID);

            putAllRequest.Map = addresses;
            namedCache.Request(putAllRequest);

            DestroyCacheRequest destroyCacheRequest =
                (DestroyCacheRequest)cacheService.MessageFactory.CreateMessage(DestroyCacheRequest.TYPE_ID);

            destroyCacheRequest.CacheName = CacheNameTemp;
            cacheService.Request(destroyCacheRequest);

            GetAllRequest getAllRequest =
                (GetAllRequest)namedCache.MessageFactory.CreateMessage(GetAllRequest.TYPE_ID);
            ArrayList names = new ArrayList();

            names.Add(convToBinary.Convert(keys[1]));
            names.Add(convToBinary.Convert(keys[2]));
            getAllRequest.Keys = names;

            try
            {
                namedCache.Send(getAllRequest).WaitForResponse(-1);
            }
            catch (PortableException)
            {
            }

            conn.Close();
            initiator.Stop();
        }
Beispiel #2
0
        public void TestGetAndPutAllRequest()
        {
            TcpInitiator initiator         = GetInitiator();
            IConnection  conn              = initiator.EnsureConnection();
            IChannel     namedCacheChannel = GetNamedCacheChannel(conn);

            string[] keys   = { "Ana Cikic", "Goran Milosavljevic", "Ivan Cikic" };
            string[] values = { "10.0.0.120", "10.0.0.180", "10.0.0.125" };

            IDictionary addresses = new Hashtable();

            addresses.Add(convToBinary.Convert(keys[0]), convToBinary.Convert(values[0]));
            addresses.Add(convToBinary.Convert(keys[1]), convToBinary.Convert(values[1]));
            addresses.Add(convToBinary.Convert(keys[2]), convToBinary.Convert(values[2]));

            PutAllRequest putAllRequest =
                (PutAllRequest)namedCacheChannel.MessageFactory.CreateMessage(PutAllRequest.TYPE_ID);

            putAllRequest.Map = addresses;

            Stream stream = new MemoryStream();
            Codec  codec  = new Codec();

            codec.Encode(namedCacheChannel, putAllRequest, new DataWriter(stream));
            stream.Position = 0;
            PutAllRequest result = (PutAllRequest)codec.Decode(namedCacheChannel, new DataReader(stream));

            Assert.AreEqual(3, result.Map.Count);
            Assert.AreEqual(addresses[keys[0]], result.Map[keys[0]]);
            Assert.AreEqual(addresses[keys[1]], result.Map[keys[1]]);
            Assert.AreEqual(addresses[keys[2]], result.Map[keys[2]]);

            IResponse putAllResponse = namedCacheChannel.Send(putAllRequest).WaitForResponse(-1);

            Assert.IsInstanceOf(typeof(NamedCacheResponse), putAllResponse);
            Assert.AreEqual(putAllRequest.Id, putAllResponse.RequestId);
            Assert.IsNull(putAllResponse.Result);
            Assert.IsFalse(putAllResponse.IsFailure);

            GetAllRequest getAllRequest =
                (GetAllRequest)namedCacheChannel.MessageFactory.CreateMessage(GetAllRequest.TYPE_ID);

            ArrayList names = new ArrayList();

            names.Add(convToBinary.Convert(keys[1]));
            names.Add(convToBinary.Convert(keys[2]));
            getAllRequest.Keys = names;

            IResponse getAllResponse = namedCacheChannel.Send(getAllRequest).WaitForResponse(-1);

            Assert.IsInstanceOf(typeof(NamedCacheResponse), getAllResponse);
            Assert.IsFalse(getAllResponse.IsFailure);
            Assert.AreEqual(getAllResponse.RequestId, getAllRequest.Id);
            Assert.AreEqual(0, getAllResponse.TypeId);
            Assert.IsInstanceOf(typeof(IDictionary), getAllResponse.Result);

            IDictionary resultDict = new Hashtable((IDictionary)getAllResponse.Result);

            Assert.AreEqual(addresses[keys[1]], resultDict[keys[1]]);
            Assert.AreEqual(addresses[keys[2]], resultDict[keys[2]]);

            conn.Close();
            initiator.Stop();
        }