Skip to content

Commit

Permalink
Remote task exec test with listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
mgencur committed Oct 9, 2017
1 parent 1947e2f commit 4c72d9c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/test/cs/Infinispan/HotRod/RemoteEventTest.cs
@@ -1,14 +1,15 @@
using Infinispan.HotRod.Config;
using Infinispan.HotRod.Tests.Util;
using NUnit.Framework;
using System.Collections.Generic;

namespace Infinispan.HotRod.Tests
{
class RemoteEventTest
{
RemoteCacheManager remoteManager;
const string ERRORS_KEY_SUFFIX = ".errors";
const string PROTOBUF_SCRIPT_CACHE_NAME = "___script_cache";
const string SCRIPT_CACHE_NAME = "___script_cache";
static IMarshaller marshaller;

[TestFixtureSetUp]
Expand Down Expand Up @@ -203,6 +204,45 @@ public void FilterEventsTest()
}
}

[Test]
public void TaskExecPutGetWithListener()
{
LoggingEventListener<string> listener = new LoggingEventListener<string>();
IRemoteCache<string, string> testCache = remoteManager.GetCache<string, string>();
IRemoteCache<string, string> scriptCache = remoteManager.GetCache<string, string>(SCRIPT_CACHE_NAME);
Event.ClientListener<string, string> cl = new Event.ClientListener<string, string>();
const string scriptName = "put-get.js";
ScriptUtils.LoadScriptCache(scriptCache, scriptName, scriptName);
try
{
testCache.Clear();
cl.filterFactoryName = "";
cl.converterFactoryName = "";
cl.AddListener(listener.CreatedEventAction);
testCache.AddClientListener(cl, new string[] { }, new string[] { }, null);
AssertNoEvents(listener);
Dictionary<string, string> scriptArgs = new Dictionary<string, string>();
scriptArgs.Add("k", Marshall("mykey"));
scriptArgs.Add("v", Marshall("myvalue"));
byte[] v = testCache.Execute(scriptName, scriptArgs);
Assert.AreEqual("myvalue", marshaller.ObjectFromByteBuffer(v));
AssertOnlyCreated(Marshall("mykey"), listener);
}
finally
{
if (cl.listenerId != null)
{
testCache.RemoveClientListener(cl);
}
}
}

private string Marshall(string v)
{
byte[] bv = marshaller.ObjectToByteBuffer(v);
return System.Text.Encoding.UTF8.GetString(bv);
}

private void AssertNoEvents(LoggingEventListener<string> listener)
{
Assert.AreEqual(0, listener.createdEvents.Count);
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/put-get.js
@@ -0,0 +1,3 @@
// mode=local,language=javascript,parameters=[k,v]
cache.put(k, v)
cache.get(k)

0 comments on commit 4c72d9c

Please sign in to comment.