Exemple #1
0
        public void TestContainsKeyRequest()
        {
            TcpInitiator initiator         = GetInitiator();
            IConnection  conn              = initiator.EnsureConnection();
            IChannel     namedCacheChannel = GetNamedCacheChannel(conn);
            string       key   = "testContainsKeyKey";
            string       value = "testContainsKeyValue";

            ClearRequest clearRequest =
                (ClearRequest)namedCacheChannel.MessageFactory.CreateMessage(ClearRequest.TYPE_ID);
            IResponse clearResponse = namedCacheChannel.Send(clearRequest).WaitForResponse(-1);

            Assert.IsFalse(clearResponse.IsFailure);

            ContainsKeyRequest containsKeyRequest =
                (ContainsKeyRequest)namedCacheChannel.MessageFactory.CreateMessage(ContainsKeyRequest.TYPE_ID);

            containsKeyRequest.Key = convToBinary.Convert(key);
            IResponse containsKeyResponse = namedCacheChannel.Send(containsKeyRequest).WaitForResponse(-1);

            Assert.AreEqual(containsKeyRequest.TypeId, ContainsKeyRequest.TYPE_ID);
            Assert.AreEqual(containsKeyResponse.TypeId, NamedCacheResponse.TYPE_ID);
            Assert.IsInstanceOf(typeof(NamedCacheResponse), containsKeyResponse);
            Assert.IsFalse(containsKeyResponse.IsFailure);
            Assert.AreEqual(containsKeyResponse.RequestId, containsKeyRequest.Id);
            Assert.IsInstanceOf(typeof(bool), containsKeyResponse.Result);
            Assert.IsFalse((bool)containsKeyResponse.Result);

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

            putRequest.Key   = convToBinary.Convert(key);
            putRequest.Value = convToBinary.Convert(value);
            namedCacheChannel.Request(putRequest);

            containsKeyRequest     = (ContainsKeyRequest)namedCacheChannel.MessageFactory.CreateMessage(ContainsKeyRequest.TYPE_ID);
            containsKeyRequest.Key = convToBinary.Convert(key);
            containsKeyResponse    = namedCacheChannel.Send(containsKeyRequest).WaitForResponse(-1);

            Assert.AreEqual(containsKeyRequest.TypeId, ContainsKeyRequest.TYPE_ID);
            Assert.AreEqual(containsKeyResponse.TypeId, NamedCacheResponse.TYPE_ID);
            Assert.IsInstanceOf(typeof(NamedCacheResponse), containsKeyResponse);
            Assert.IsFalse(containsKeyResponse.IsFailure);
            Assert.AreEqual(containsKeyResponse.RequestId, containsKeyRequest.Id);
            Assert.IsInstanceOf(typeof(bool), containsKeyResponse.Result);
            Assert.IsTrue((bool)containsKeyResponse.Result);

            conn.Close();
            initiator.Stop();
        }
Exemple #2
0
        public void TestRemoveRequest()
        {
            TcpInitiator initiator         = GetInitiator();
            IConnection  conn              = initiator.EnsureConnection();
            IChannel     namedCacheChannel = GetNamedCacheChannel(conn);
            string       key   = "testRemoveKey";
            string       value = "testRemoveValue";

            ClearRequest clearRequest =
                (ClearRequest)namedCacheChannel.MessageFactory.CreateMessage(ClearRequest.TYPE_ID);
            IResponse clearResponse = namedCacheChannel.Send(clearRequest).WaitForResponse(-1);

            Assert.IsFalse(clearResponse.IsFailure);

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

            putRequest.Key              = convToBinary.Convert(key);
            putRequest.Value            = convToBinary.Convert(value);
            putRequest.IsReturnRequired = true;
            IResponse putResponse = namedCacheChannel.Send(putRequest).WaitForResponse(-1);

            Assert.IsFalse(putResponse.IsFailure);
            Assert.IsNull(convFromBinary.Convert(putResponse.Result));

            ContainsKeyRequest containsKeyRequest =
                (ContainsKeyRequest)namedCacheChannel.MessageFactory.CreateMessage(ContainsKeyRequest.TYPE_ID);

            containsKeyRequest.Key = convToBinary.Convert(key);
            IResponse containsKeyResponse = namedCacheChannel.Send(containsKeyRequest).WaitForResponse(-1);

            Assert.IsFalse(containsKeyResponse.IsFailure);
            Assert.IsTrue((bool)containsKeyResponse.Result);

            RemoveRequest removeRequest = (RemoveRequest)namedCacheChannel.MessageFactory.CreateMessage(RemoveRequest.TYPE_ID);

            removeRequest.Key = convToBinary.Convert(key);
            removeRequest.IsReturnRequired = true;
            IResponse removeResponse = namedCacheChannel.Send(removeRequest).WaitForResponse(-1);

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

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

            Assert.AreEqual(result.IsReturnRequired, removeRequest.IsReturnRequired);
            Assert.AreEqual(result.Key, removeRequest.Key);

            Assert.AreEqual(removeRequest.TypeId, RemoveRequest.TYPE_ID);
            Assert.IsInstanceOf(typeof(NamedCacheResponse), removeResponse);
            Assert.AreEqual(removeResponse.TypeId, NamedCacheResponse.TYPE_ID);
            Assert.AreEqual(removeRequest.Id, removeResponse.RequestId);
            Assert.IsFalse(removeResponse.IsFailure);
            if (removeRequest.IsReturnRequired)
            {
                Assert.AreEqual(removeResponse.Result, convToBinary.Convert(value));
            }

            containsKeyRequest     = (ContainsKeyRequest)namedCacheChannel.MessageFactory.CreateMessage(ContainsKeyRequest.TYPE_ID);
            containsKeyRequest.Key = convToBinary.Convert(key);
            containsKeyResponse    = namedCacheChannel.Send(containsKeyRequest).WaitForResponse(-1);
            Assert.IsFalse(containsKeyResponse.IsFailure);
            Assert.IsFalse((bool)containsKeyResponse.Result);

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