public void TestSizeRequest() { TcpInitiator initiator = GetInitiator(); IConnection conn = initiator.EnsureConnection(); IChannel namedCacheChannel = GetNamedCacheChannel(conn); ClearRequest clearRequest = (ClearRequest)namedCacheChannel.MessageFactory.CreateMessage(ClearRequest.TYPE_ID); IResponse clearResponse = namedCacheChannel.Send(clearRequest).WaitForResponse(-1); Assert.AreEqual(clearRequest.TypeId, ClearRequest.TYPE_ID); Assert.IsInstanceOf(typeof(NamedCacheResponse), clearResponse); Assert.AreEqual(clearResponse.TypeId, NamedCacheResponse.TYPE_ID); Assert.AreEqual(clearResponse.RequestId, clearRequest.Id); Assert.IsFalse(clearResponse.IsFailure); SizeRequest sizeRequestBefore = (SizeRequest)namedCacheChannel.MessageFactory.CreateMessage(SizeRequest.TYPE_ID); IResponse sizeResponseBefore = namedCacheChannel.Send(sizeRequestBefore).WaitForResponse(-1); Assert.IsInstanceOf(typeof(NamedCacheResponse), sizeResponseBefore); Assert.IsFalse(sizeResponseBefore.IsFailure); Assert.AreEqual(sizeResponseBefore.RequestId, sizeRequestBefore.Id); Assert.AreEqual(0, sizeResponseBefore.TypeId); Assert.IsInstanceOf(typeof(Int32), sizeResponseBefore.Result); int before = (int)sizeResponseBefore.Result; Assert.AreEqual(0, before); PutRequest putRequest = (PutRequest)namedCacheChannel.MessageFactory.CreateMessage(PutRequest.TYPE_ID); putRequest.Key = convToBinary.Convert("newKey"); putRequest.Value = convToBinary.Convert("newValue"); namedCacheChannel.Request(putRequest); SizeRequest sizeRequest = (SizeRequest)namedCacheChannel.MessageFactory.CreateMessage(SizeRequest.TYPE_ID); IResponse sizeResponse = namedCacheChannel.Send(sizeRequest).WaitForResponse(-1); Assert.IsFalse(sizeResponse.IsFailure); Assert.AreEqual(sizeResponse.RequestId, sizeRequest.Id); Assert.AreEqual(0, sizeResponse.TypeId); Assert.IsInstanceOf(typeof(Int32), sizeResponse.Result); int after = (int)sizeResponse.Result; Assert.AreEqual(1, after); conn.Close(); initiator.Stop(); }
public void TestContainsValueRequest() { TcpInitiator initiator = GetInitiator(); IConnection conn = initiator.EnsureConnection(); IChannel namedCacheChannel = GetNamedCacheChannel(conn); string key = "testContainsValueKey"; string value = "testContainsValueValue"; ClearRequest clearRequest = (ClearRequest)namedCacheChannel.MessageFactory.CreateMessage(ClearRequest.TYPE_ID); IResponse clearResponse = namedCacheChannel.Send(clearRequest).WaitForResponse(-1); Assert.IsFalse(clearResponse.IsFailure); ContainsValueRequest containsValueRequest = (ContainsValueRequest)namedCacheChannel.MessageFactory.CreateMessage(ContainsValueRequest.TYPE_ID); containsValueRequest.Value = convToBinary.Convert(value); IResponse containsValueResponse = namedCacheChannel.Send(containsValueRequest).WaitForResponse(-1); Assert.AreEqual(containsValueRequest.TypeId, ContainsValueRequest.TYPE_ID); Assert.AreEqual(containsValueResponse.TypeId, NamedCacheResponse.TYPE_ID); Assert.IsInstanceOf(typeof(NamedCacheResponse), containsValueResponse); Assert.IsFalse(containsValueResponse.IsFailure); Assert.AreEqual(containsValueResponse.RequestId, containsValueRequest.Id); Assert.IsInstanceOf(typeof(bool), containsValueResponse.Result); Assert.IsFalse((bool)containsValueResponse.Result); PutRequest putRequest = (PutRequest)namedCacheChannel.MessageFactory.CreateMessage(PutRequest.TYPE_ID); putRequest.Key = convToBinary.Convert(key); putRequest.Value = convToBinary.Convert(value); namedCacheChannel.Request(putRequest); containsValueRequest = (ContainsValueRequest)namedCacheChannel.MessageFactory.CreateMessage(ContainsValueRequest.TYPE_ID); containsValueRequest.Value = convToBinary.Convert(value); containsValueResponse = namedCacheChannel.Send(containsValueRequest).WaitForResponse(-1); Assert.AreEqual(containsValueRequest.TypeId, ContainsValueRequest.TYPE_ID); Assert.AreEqual(containsValueResponse.TypeId, NamedCacheResponse.TYPE_ID); Assert.IsInstanceOf(typeof(NamedCacheResponse), containsValueResponse); Assert.IsFalse(containsValueResponse.IsFailure); Assert.AreEqual(containsValueResponse.RequestId, containsValueRequest.Id); Assert.IsInstanceOf(typeof(bool), containsValueResponse.Result); Assert.IsTrue((bool)containsValueResponse.Result); conn.Close(); initiator.Stop(); }
public void TestContainsAllAndRemoveAllRequest() { 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])); ArrayList list = new ArrayList(); list.Add(convToBinary.Convert(keys[0])); list.Add(convToBinary.Convert(keys[2])); ClearRequest clearRequest = (ClearRequest)namedCacheChannel.MessageFactory.CreateMessage(ClearRequest.TYPE_ID); IResponse clearResponse = namedCacheChannel.Send(clearRequest).WaitForResponse(-1); Assert.IsFalse(clearResponse.IsFailure); PutAllRequest putAllRequest = (PutAllRequest)namedCacheChannel.MessageFactory.CreateMessage(PutAllRequest.TYPE_ID); putAllRequest.Map = addresses; IResponse putAllResponse = namedCacheChannel.Send(putAllRequest).WaitForResponse(-1); Assert.IsFalse(putAllResponse.IsFailure); ContainsAllRequest containsAllRequest = (ContainsAllRequest)namedCacheChannel.MessageFactory.CreateMessage(ContainsAllRequest.TYPE_ID); list.Add(convToBinary.Convert("dummy")); containsAllRequest.Keys = list; IResponse containsAllResponse = namedCacheChannel.Send(containsAllRequest).WaitForResponse(-1); Assert.AreEqual(containsAllRequest.TypeId, ContainsAllRequest.TYPE_ID); Assert.IsInstanceOf(typeof(NamedCacheResponse), containsAllResponse); Assert.AreEqual(containsAllResponse.TypeId, NamedCacheResponse.TYPE_ID); Assert.AreEqual(containsAllRequest.Id, containsAllResponse.RequestId); Assert.IsFalse(containsAllResponse.IsFailure); Assert.IsInstanceOf(typeof(bool), containsAllResponse.Result); Assert.IsFalse((bool)containsAllResponse.Result); containsAllRequest = (ContainsAllRequest)namedCacheChannel.MessageFactory.CreateMessage(ContainsAllRequest.TYPE_ID); list.Remove(convToBinary.Convert("dummy")); containsAllRequest.Keys = list; containsAllResponse = namedCacheChannel.Send(containsAllRequest).WaitForResponse(-1); Assert.IsFalse(containsAllResponse.IsFailure); Assert.IsTrue((bool)containsAllResponse.Result); RemoveAllRequest removeAllRequest = (RemoveAllRequest)namedCacheChannel.MessageFactory.CreateMessage(RemoveAllRequest.TYPE_ID); removeAllRequest.Keys = list; IResponse removeAllResponse = namedCacheChannel.Send(removeAllRequest).WaitForResponse(-1); Assert.AreEqual(removeAllRequest.TypeId, RemoveAllRequest.TYPE_ID); Assert.IsInstanceOf(typeof(NamedCacheResponse), removeAllResponse); Assert.AreEqual(removeAllResponse.TypeId, NamedCacheResponse.TYPE_ID); Assert.AreEqual(removeAllRequest.Id, removeAllResponse.RequestId); Assert.IsFalse(removeAllResponse.IsFailure); Assert.IsInstanceOf(typeof(bool), removeAllResponse.Result); Assert.IsTrue((bool)removeAllResponse.Result); conn.Close(); initiator.Stop(); }
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(); }