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 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 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(); }