public void TestCloseChannel()
        {
            IChannel cacheServiceChannel = connection.OpenChannel(CacheServiceProtocol.Instance,
                                                                  "CacheServiceProxy", null, null);

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

            ensureCacheRequest.CacheName = CacheName;

            string response = (string)cacheServiceChannel.Request(ensureCacheRequest);
            Uri    uri      = new Uri(response);

            Assert.IsNotNull(uri);

            IChannel namedCacheChannel = connection.AcceptChannel(uri, null, null);

            Assert.IsNotNull(namedCacheChannel);

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

            Assert.AreEqual(channelUri, uri.ToString());

            CloseChannel channelClose = (CloseChannel)connection.GetChannel(0).MessageFactory.CreateMessage(
                CloseChannel.TYPE_ID);

            channelClose.ChannelClose = (Channel)namedCacheChannel;
            connection.GetChannel(0).Send(channelClose);
        }
Exemple #2
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());
        }
        /// <summary>
        /// Create a new <see cref="RemoteNamedCache"/> for the given
        /// <see cref="INamedCache"/> name.
        /// </summary>
        /// <param name="name">
        /// The name of the cache.
        /// </param>
        /// <returns>
        /// A new <b>RemoteNamedCache</b>.
        /// </returns>
        public virtual RemoteNamedCache CreateRemoteNamedCache(string name)
        {
            IChannel           channel    = EnsureChannel();
            IConnection        connection = channel.Connection;
            IMessageFactory    factory    = channel.MessageFactory;
            RemoteNamedCache   cache      = new RemoteNamedCache();
            IPrincipal         principal  = Thread.CurrentPrincipal;
            EnsureCacheRequest request    = (EnsureCacheRequest)factory.CreateMessage(EnsureCacheRequest.TYPE_ID);

            request.CacheName = name;
            Uri uri;

            try
            {
                uri = new Uri((string)channel.Request(request));
            }
            catch (UriFormatException e)
            {
                throw new Exception("error instantiating URI", e);
            }

            cache.CacheName                = name;
            cache.CacheService             = this;
            cache.DeferKeyAssociationCheck = DeferKeyAssociationCheck;
            cache.EventDispatcher          = EnsureEventDispatcher();

            connection.AcceptChannel(uri, cache, principal);

            return(cache);
        }
Exemple #4
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();
        }
        public IChannel GetNamedCacheChannel(IConnection conn)
        {
            IChannel cacheService = conn.OpenChannel(CacheServiceProtocol.Instance,
                                                     "CacheServiceProxy", null, null);
            EnsureCacheRequest ensureCache =
                (EnsureCacheRequest)cacheService.MessageFactory.CreateMessage(EnsureCacheRequest.TYPE_ID);

            ensureCache.CacheName = CacheName;

            string response = (string)cacheService.Request(ensureCache);
            Uri    uri      = new Uri(response);

            return(conn.AcceptChannel(uri, null, null));
        }
Exemple #6
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)
            {
            }
        }