Example #1
0
        public void TestEnsureCacheRequest()
        {
            IConnection conn = initiator.EnsureConnection();

            IChannel cacheServiceChannel = conn.OpenChannel(CacheServiceProtocol.Instance,
                                                            "CacheServiceProxy", null, null);
            EnsureCacheRequest ensureCacheRequest =
                (EnsureCacheRequest)cacheServiceChannel.MessageFactory.CreateMessage(EnsureCacheRequest.TYPE_ID);

            ensureCacheRequest.CacheName = CacheName;

            IResponse ensureCacheResponse = cacheServiceChannel.Send(ensureCacheRequest).WaitForResponse(-1);

            Assert.IsInstanceOf(typeof(EnsureCacheRequest), ensureCacheRequest);
            Assert.AreEqual(EnsureCacheRequest.TYPE_ID, ensureCacheRequest.TypeId);
            Assert.IsInstanceOf(typeof(CacheServiceResponse), ensureCacheResponse);
            Assert.IsFalse(ensureCacheResponse.IsFailure);
            Assert.IsNotNull(ensureCacheResponse.Result);
            Assert.AreEqual(ensureCacheResponse.RequestId, ensureCacheRequest.Id);
            Assert.AreEqual(0, ensureCacheResponse.TypeId);

            String response = (String)ensureCacheResponse.Result;
            Uri    uri      = new Uri(response);

            Assert.IsNotNull(uri);

            IChannel namedCacheChannel = conn.AcceptChannel(uri, null, new GenericPrincipal(new GenericIdentity("test"), null));

            Assert.IsNotNull(namedCacheChannel);

            string channelUri = "channel:" + namedCacheChannel.Id + "#NamedCacheProtocol";

            Assert.AreEqual(channelUri, uri.ToString());
        }
Example #2
0
        public void TestEnsureCacheRequestException()
        {
            IConnection conn = initiator.EnsureConnection();

            Channel cacheServiceChannel = (Channel)conn.OpenChannel(CacheServiceProtocol.Instance,
                                                                    "CacheServiceProxy", null, null);

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

            ensureCacheRequest.CacheName = null;
            Assert.AreEqual(EnsureCacheRequest.TYPE_ID, ensureCacheRequest.TypeId);
            Assert.IsInstanceOf(typeof(EnsureCacheRequest), ensureCacheRequest);
            Assert.AreEqual(EnsureCacheRequest.TYPE_ID, ensureCacheRequest.TypeId);

            IStatus ensureCacheStatus = cacheServiceChannel.Send(ensureCacheRequest);

            try
            {
                ensureCacheStatus.WaitForResponse(-1);
            }
            catch (PortableException)
            {
                Assert.IsNotNull(ensureCacheStatus);
            }
        }
Example #3
0
        public void TestDestroyCacheRequest()
        {
            IConnection conn = initiator.EnsureConnection();

            Channel cacheServiceChannel = (Channel)conn.OpenChannel(CacheServiceProtocol.Instance,
                                                                    "CacheServiceProxy", null, null);
            EnsureCacheRequest ensureCacheRequest =
                (EnsureCacheRequest)cacheServiceChannel.MessageFactory.CreateMessage(EnsureCacheRequest.TYPE_ID);

            ensureCacheRequest.CacheName = CacheNameTemp;

            String  response          = (String)cacheServiceChannel.Request(ensureCacheRequest);
            Uri     uri               = new Uri(response);
            Channel namedCacheChannel = (Channel)conn.AcceptChannel(uri, null, null);

            Assert.IsTrue(namedCacheChannel.IsOpen);
            DestroyCacheRequest destroyCacheRequest =
                (DestroyCacheRequest)cacheServiceChannel.MessageFactory.CreateMessage(DestroyCacheRequest.TYPE_ID);

            destroyCacheRequest.CacheName = CacheNameTemp;

            IResponse destroyCacheResponse = cacheServiceChannel.Send(destroyCacheRequest).WaitForResponse(-1);

            Assert.IsInstanceOf(typeof(DestroyCacheRequest), destroyCacheRequest);
            Assert.AreEqual(DestroyCacheRequest.TYPE_ID, destroyCacheRequest.TypeId);
            Assert.IsInstanceOf(typeof(CacheServiceResponse), destroyCacheResponse);
            Assert.IsFalse(destroyCacheResponse.IsFailure);
            Assert.AreEqual(destroyCacheResponse.RequestId, destroyCacheRequest.Id);
            Assert.AreEqual(0, destroyCacheResponse.TypeId);
            Assert.IsTrue((bool)destroyCacheResponse.Result);

            PutRequest putRequest =
                (PutRequest)namedCacheChannel.MessageFactory.CreateMessage(PutRequest.TYPE_ID);

            putRequest.Key              = "ivan";
            putRequest.Value            = "3";
            putRequest.IsReturnRequired = true;

            try
            {
                namedCacheChannel.Send(putRequest).WaitForResponse(-1);
            }
            catch (PortableException)
            {
            }
        }
Example #4
0
        public void TestEnsureCacheRequestSerDeser()
        {
            IConnection conn = initiator.EnsureConnection();

            IChannel cacheServiceChannel = conn.OpenChannel(CacheServiceProtocol.Instance,
                                                            "CacheServiceProxy", null, null);
            EnsureCacheRequest ensureCacheRequest =
                (EnsureCacheRequest)cacheServiceChannel.MessageFactory.CreateMessage(EnsureCacheRequest.TYPE_ID);

            ensureCacheRequest.CacheName = CacheName;

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

            codec.Encode(cacheServiceChannel, ensureCacheRequest, new DataWriter(stream));
            stream.Position = 0;
            EnsureCacheRequest result = (EnsureCacheRequest)codec.Decode(cacheServiceChannel, new DataReader(stream));

            stream.Close();
            Assert.AreEqual(ensureCacheRequest.CacheName, result.CacheName);
        }