public void ProjectionBasicContQueryTest() { int joined = 0, updated = 0, leaved = 0; object[] uT = null, lT = null; try { IRemoteCache <int, User> userCache = remoteManager.GetCache <int, User>(NAMED_CACHE); userCache.Clear(); Semaphore s = new Semaphore(0, 1); QueryRequest qr = new QueryRequest(); qr.QueryString = "select id, name from sample_bank_account.User"; Event.ContinuousQueryListener <int, object[]> cql = new Event.ContinuousQueryListener <int, object[]>(qr.QueryString); cql.JoiningCallback = (int k, object[] v) => { joined++; }; cql.UpdatedCallback = (int k, object[] v) => { uT = v; updated++; }; cql.LeavingCallback = (int k, object[] v) => { lT = v; leaved++; s.Release(); }; userCache.AddContinuousQueryListener(cql); User u1 = CreateUser1(userCache); User u2 = CreateUser2(userCache); userCache.Put(1, u1); userCache.Put(2, u2); u1.Name = "Jerry"; u1.Surname = "Mouse"; userCache.Put(1, u1); userCache.Remove(2); s.WaitOne(10000); userCache.RemoveContinuousQueryListener(cql); userCache.Clear(); remoteManager.Stop(); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } Assert.AreEqual(2, joined); Assert.AreEqual(1, updated); Assert.AreEqual(1, leaved); Assert.AreEqual(uT, new object[] { 1, "Jerry" }); Assert.AreEqual(lT, new object[] { 2, "Spider" }); }
public void ReadRollbackOnNotExistent() { InitializeRemoteCacheManager(true); IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>("non_xa", true); var txManager = remoteManager.GetTransactionManager(); string k1 = "key13"; string v1 = "boron"; string rv1; cache.Clear(); try { txManager.Begin(); cache.Put(k1, v1); // Check the correct value from the tx context rv1 = cache.Get(k1); Assert.AreEqual(rv1, v1); } finally { txManager.Rollback(); } // Check the correct value from remote cache rv1 = cache.Get(k1); Assert.IsNull(rv1); }
public void ReadCommitted() { InitializeRemoteCacheManager(true); IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>("non_xa", true); var txManager = remoteManager.GetTransactionManager(); string k1 = "key13"; string v1 = "boron"; string rv1; cache.Clear(); try { txManager.Begin(); cache.Put(k1, v1); // Check the correct value from the tx context rv1 = cache.Get(k1); Assert.AreEqual(rv1, v1); txManager.Commit(); } catch (Exception ex) { // try to release the tx resources txManager.Rollback(); throw ex; } // Check the correct value from remote cache rv1 = cache.Get(k1); Assert.AreEqual(rv1, v1); }
protected void TestPutClear(IRemoteCache <string, string> cache) { cache.Put(K1, V1); cache.Put(K2, V2); cache.Clear(); Assert.IsTrue(cache.IsEmpty()); }
public void CustomEventsTest() { LoggingEventListener <string> listener = new LoggingEventListener <string>(); IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>(); Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>(); try { cache.Clear(); cl.filterFactoryName = ""; cl.converterFactoryName = ""; cl.converterFactoryName = "to-string-converter-factory"; cl.AddListener(listener.CreatedEventAction); cl.AddListener(listener.ModifiedEventAction); cl.AddListener(listener.RemovedEventAction); cl.AddListener(listener.ExpiredEventAction); cl.AddListener(listener.CustomEventAction); cache.AddClientListener(cl, new string[] { }, new string[] { }, null); cache.Put("key1", "value1"); AssertOnlyCustom("custom event: key1 value1", listener); } finally { if (cl.listenerId != null) { cache.RemoveClientListener(cl); } } }
public void PutAndReadWithNonTxCache() { InitializeRemoteCacheManager(true); InitializeNonTxRemoteCacheManager(true); IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>("non_xa", true); IRemoteCache <string, string> nonTxCache = nonTxRemoteManager.GetCache <string, string>("non_xa", true); var txManager = remoteManager.GetTransactionManager(); string k1 = "key13"; string v1 = "boron"; string rv1; cache.Clear(); try { txManager.Begin(); string oldv1 = nonTxCache.Put(k1, v1); // Check the correct value from the tx context rv1 = nonTxCache.Get(k1); Assert.AreEqual(rv1, v1); rv1 = cache.Remove(k1); rv1 = cache.Get(k1); Assert.IsNull(rv1); } finally { txManager.Rollback(); } rv1 = nonTxCache.Get(k1); Assert.AreEqual(rv1, v1); }
public void RemoteMapReduceWithStreamsTest() { ConfigurationBuilder conf = new ConfigurationBuilder(); conf.AddServer().Host("127.0.0.1").Port(11222); conf.ConnectionTimeout(90000).SocketTimeout(6000); marshaller = new JBasicMarshaller(); conf.Marshaller(marshaller); remoteManager = new RemoteCacheManager(conf.Build(), true); IRemoteCache <string, string> scriptCache = remoteManager.GetCache <string, string>(PROTOBUF_SCRIPT_CACHE_NAME); IRemoteCache <string, string> testCache = remoteManager.GetCache <string, string>(); try { const string scriptName = "wordCountStream.js"; ScriptUtils.LoadTestCache(testCache, "macbeth.txt"); ScriptUtils.LoadScriptCache(scriptCache, scriptName, scriptName); Dictionary <string, object> scriptArgs = new Dictionary <string, object>(); var result = (System.Int64)testCache.Execute(scriptName, scriptArgs); const int expectedMacbethCount = 287; Assert.AreEqual(expectedMacbethCount, result); } finally { testCache.Clear(); } }
public void IncludeCurrentStateEventTest() { LoggingEventListener <string> listener = new LoggingEventListener <string>(); IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>(); Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>(); try { cache.Clear(); cache.Put("key1", "value1"); cl.filterFactoryName = ""; cl.converterFactoryName = ""; cl.includeCurrentState = true; cl.AddListener(listener.CreatedEventAction); AssertNoEvents(listener); cache.AddClientListener(cl, new string[] { }, new string[] { }, null); AssertOnlyCreated("key1", listener); } finally { if (cl.listenerId != null) { cache.RemoveClientListener(cl); } } }
public void BeforeClass() { ConfigurationBuilder conf = new ConfigurationBuilder(); conf.AddServer().Host("127.0.0.1").Port(11222); conf.ConnectionTimeout(90000).SocketTimeout(6000); conf.Marshaller(new BasicTypesProtoStreamMarshaller()); remoteManager = new RemoteCacheManager(conf.Build(), true); IRemoteCache <String, String> metadataCache = remoteManager.GetCache <String, String>(PROTOBUF_METADATA_CACHE_NAME); metadataCache.Clear(); metadataCache.Put("sample_bank_account/bank.proto", File.ReadAllText("proto2/bank.proto")); if (metadataCache.ContainsKey(ERRORS_KEY_SUFFIX)) { Assert.Fail("fail: error in registering .proto model"); } IRemoteCache <int, User> userCache = remoteManager.GetCache <int, User>(NAMED_CACHE); userCache.Clear(); PutUsers(userCache); IRemoteCache <int, Account> accountCache = remoteManager.GetCache <int, Account>(NAMED_CACHE); PutAccounts(accountCache); IRemoteCache <int, Transaction> transactionCache = remoteManager.GetCache <int, Transaction>(NAMED_CACHE); PutTransactions(transactionCache); }
public void ClearTest() { String key1 = UniqueKey.NextKey(); String key2 = UniqueKey.NextKey(); cache.Put(key1, "hydrogen"); cache.Put(key2, "helium"); Assert.IsFalse(cache.IsEmpty()); cache.Clear(); Assert.IsNull(cache.Get(key1)); Assert.IsNull(cache.Get(key2)); Assert.AreEqual(0, cache.Size()); Assert.IsTrue(cache.IsEmpty()); }
public void GetAllTest() { String key1 = UniqueKey.NextKey(); String key2 = UniqueKey.NextKey(); cache.Clear(); Assert.IsNull(cache.Get(key1)); Assert.IsNull(cache.Get(key2)); cache.Put(key1, "carbon"); cache.Put(key2, "oxygen"); ISet <String> keySet = new HashSet <String>(); keySet.Add(key1); keySet.Add(key2); IDictionary <String, String> d = cache.GetAll(keySet); Assert.AreEqual(d[key1], cache.Get(key1)); Assert.AreEqual(d[key2], cache.Get(key2)); Assert.AreEqual(d[key1], "carbon"); Assert.AreEqual(d[key2], "oxygen"); }
static void Main(string[] args) { RemoteCacheManager remoteManager; const string ERRORS_KEY_SUFFIX = ".errors"; const string PROTOBUF_METADATA_CACHE_NAME = "___protobuf_metadata"; ConfigurationBuilder builder = new ConfigurationBuilder(); builder.AddServer() .Host(args.Length > 1 ? args[0] : "127.0.0.1") .Port(args.Length > 2 ? int.Parse(args[1]) : 11222); builder.Marshaller(new BasicTypesProtoStreamMarshaller()); remoteManager = new RemoteCacheManager(builder.Build(), true); IRemoteCache <String, String> metadataCache = remoteManager.GetCache <String, String>(PROTOBUF_METADATA_CACHE_NAME); IRemoteCache <int, Person> testCache = remoteManager.GetCache <int, Person>("namedCache"); // Installing the entities model into the Infinispan __protobuf_metadata cache metadataCache.Put("sample_person/person.proto", File.ReadAllText("../../resources/proto2/person.proto")); // Console.WriteLine(File.ReadAllText("../../resources/proto2/person.proto")); if (metadataCache.ContainsKey(ERRORS_KEY_SUFFIX)) { Console.WriteLine("fail: error in registering .proto model"); Environment.Exit(-1); } testCache.Clear(); // Fill the application cache putPersons(testCache); // Run a query QueryRequest qr = new QueryRequest(); qr.JpqlString = "from quickstart.Person where surname like '%ou%'"; QueryResponse result = testCache.Query(qr); List <Person> listOfUsers = new List <Person>(); unwrapResults(result, listOfUsers); Console.WriteLine("There are " + listOfUsers.Count + " Users:"); foreach (Person user in listOfUsers) { Console.WriteLine(user.ToString()); System.Threading.Thread.Sleep(1000); } System.Threading.Thread.Sleep(5000); }
public void EntityBasicContQueryTest() { int joined = 0, updated = 0, leaved = 0; try { IRemoteCache <int, User> userCache = remoteManager.GetCache <int, User>(NAMED_CACHE); userCache.Clear(); Semaphore s = new Semaphore(0, 1); QueryRequest qr = new QueryRequest(); // JpqlString will be deprecated please use QueryString // qr.JpqlString = "from sample_bank_account.User"; qr.QueryString = "from sample_bank_account.User"; Event.ContinuousQueryListener <int, User> cql = new Event.ContinuousQueryListener <int, User>(qr.QueryString); cql.JoiningCallback = (int k, User v) => { joined++; }; cql.LeavingCallback = (int k, User v) => { leaved++; s.Release(); }; cql.UpdatedCallback = (int k, User v) => { updated++; }; userCache.AddContinuousQueryListener(cql); User u = CreateUser1(userCache); userCache.Put(1, u); u.Name = "Jerry"; u.Surname = "Mouse"; userCache.Put(1, u); userCache.Remove(1); s.WaitOne(10000); userCache.RemoveContinuousQueryListener(cql); userCache.Clear(); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } Assert.AreEqual(1, joined); Assert.AreEqual(1, updated); Assert.AreEqual(1, leaved); }
public void ConditionalEventsTest() { LoggingEventListener <string> listener = new LoggingEventListener <string>(); IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>(); Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>(); try { cache.Clear(); cl.filterFactoryName = ""; cl.converterFactoryName = ""; cl.AddListener(listener.CreatedEventAction); cl.AddListener(listener.ModifiedEventAction); cl.AddListener(listener.RemovedEventAction); cl.AddListener(listener.ExpiredEventAction); cl.AddListener(listener.CustomEventAction); cache.AddClientListener(cl, new string[] { }, new string[] { }, null); AssertNoEvents(listener); cache.PutIfAbsent("key1", "value1"); AssertOnlyCreated("key1", listener); cache.PutIfAbsent("key1", "value1again"); AssertNoEvents(listener); cache.Replace("key1", "modified"); AssertOnlyModified("key1", listener); cache.ReplaceWithVersion("key1", "modified", 0); AssertNoEvents(listener); IVersionedValue <string> versioned = cache.GetVersioned("key1"); //TODO: this needs conversion from long to ulong (is it a bug?) cache.ReplaceWithVersion("key1", "modified", versioned.GetVersion()); AssertOnlyModified("key1", listener); cache.RemoveWithVersion("key1", 0); AssertNoEvents(listener); versioned = cache.GetVersioned("key1"); cache.RemoveWithVersion("key1", versioned.GetVersion()); AssertOnlyRemoved("key1", listener); } finally { if (cl.listenerId != null) { cache.RemoveClientListener(cl); } } }
public void FilterEventsTest() { LoggingEventListener <string> listener = new LoggingEventListener <string>(); IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>(); Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>(); try { cache.Clear(); cl.filterFactoryName = "string-is-equal-filter-factory"; cl.converterFactoryName = ""; cl.AddListener(listener.CreatedEventAction); cl.AddListener(listener.ModifiedEventAction); cl.AddListener(listener.RemovedEventAction); cl.AddListener(listener.ExpiredEventAction); cl.AddListener(listener.CustomEventAction); cache.AddClientListener(cl, new string[] { "wantedkeyprefix" }, new string[] { }, null); AssertNoEvents(listener); cache.Put("key1", "value1"); cache.Put("wantedkeyprefix_key1", "value2"); //only one received; one is ignored AssertOnlyCreated("wantedkeyprefix_key1", listener); AssertNoEvents(listener); cache.Replace("key1", "modified"); cache.Replace("wantedkeyprefix_key1", "modified"); AssertOnlyModified("wantedkeyprefix_key1", listener); AssertNoEvents(listener); cache.Remove("key1"); cache.Remove("wantedkeyprefix_key1"); AssertOnlyRemoved("wantedkeyprefix_key1", listener); AssertNoEvents(listener); } finally { if (cl.listenerId != null) { cache.RemoveClientListener(cl); } } }
public void RemoteTaskEmptyArgsTest() { // Register on the server a js routine that takes 3 sec to return a value string scriptName = "script.js"; string script = "// mode=local,language=javascript\n " + "var cache = cacheManager.getCache(\"default\");\n" + "cache.put(\"argsKey1\", \"argValue1\");\n" + "cache.get(\"argsKey1\");\n"; IRemoteCache <string, string> scriptCache = remoteManager.GetCache <string, string>(PROTOBUF_SCRIPT_CACHE_NAME, new JBasicMarshaller()); IRemoteCache <string, long> testCache = remoteManager.GetCache <string, long>(); try { scriptCache.Put(scriptName, script); string ret1 = (string)testCache.Execute(scriptName); Assert.AreEqual("argValue1", ret1); } finally { testCache.Clear(); } }
public void ConflictsAndFail() { InitializeRemoteCacheManager(true); InitializeNonTxRemoteCacheManager(true); IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>("non_xa", true); IRemoteCache <string, string> nonTxCache = nonTxRemoteManager.GetCache <string, string>("non_xa", true); var txManager = remoteManager.GetTransactionManager(); string k1 = "key13"; string v1 = "boron"; string k2 = "key14"; string v2 = "helium"; string vx = "calcium"; cache.Clear(); try { txManager.Begin(); string oldv1 = cache.Put(k1, v1); string oldv2 = cache.Put(k2, v2); // Check the correct value from the tx context string rv1 = nonTxCache.Put(k1, vx); Assert.IsNull(rv1); Assert.Throws <Infinispan.HotRod.Exceptions.HotRodClientRollbackException>(() => { txManager.Commit(); }); } catch (Exception ex) { // try to release the tx resources txManager.Rollback(); throw ex; } Assert.AreEqual(cache.Get(k1), vx); Assert.IsNull(cache.Get(k2)); }
public void BasicEventsTest() { LoggingEventListener <string> listener = new LoggingEventListener <string>(); IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>(); Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>(); try { cache.Clear(); cl.filterFactoryName = ""; cl.converterFactoryName = ""; cl.AddListener(listener.CreatedEventAction); cl.AddListener(listener.ModifiedEventAction); cl.AddListener(listener.RemovedEventAction); cl.AddListener(listener.ExpiredEventAction); cl.AddListener(listener.CustomEventAction); cache.AddClientListener(cl, new string[] { }, new string[] { }, null); AssertNoEvents(listener); cache.Put("key1", "value1"); AssertOnlyCreated("key1", listener); cache.Put("key1", "value1bis"); AssertOnlyModified("key1", listener); cache.Remove("key1"); AssertOnlyRemoved("key1", listener); cache.Put("key1", "value1", 100, TimeUnit.MILLISECONDS); AssertOnlyCreated("key1", listener); TimeUtils.WaitFor(() => { return(cache.Get("key1") == null); }); AssertOnlyExpired("key1", listener); } finally { if (cl.listenerId != null) { cache.RemoveClientListener(cl); } } }
public void RepeatableGetForTxClient() { InitializeRemoteCacheManager(true); InitializeNonTxRemoteCacheManager(true); IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>("non_xa", true); IRemoteCache <string, string> nonTxCache = nonTxRemoteManager.GetCache <string, string>("non_xa", true); var txManager = remoteManager.GetTransactionManager(); string k1 = "key13"; string v1 = "boron"; string v2 = "helium"; string rv1; cache.Clear(); try { txManager.Begin(); string oldv1 = nonTxCache.Put(k1, v1); // Check the correct value from the tx context rv1 = cache.Get(k1); Assert.AreEqual(rv1, v1); // This goes to the server oldv1 = nonTxCache.Put(k1, v2); // But this values comes from the tx context rv1 = cache.Get(k1); Assert.AreEqual(rv1, v1); cache.Remove(k1); rv1 = cache.Get(k1); Assert.IsNull(rv1); } finally { txManager.Rollback(); } rv1 = nonTxCache.Get(k1); Assert.AreEqual(rv1, v2); }
/* * public void BeforeClass() * { * IRemoteCache<int, User> userCache = remoteManager.GetCache<int, User>(NAMED_CACHE); * userCache.Clear(); * PutUsers(userCache); * IRemoteCache<int, Account> accountCache = remoteManager.GetCache<int, Account>(NAMED_CACHE); * PutAccounts(accountCache); * IRemoteCache<int, Transaction> transactionCache = remoteManager.GetCache<int, Transaction>(NAMED_CACHE); * PutTransactions(transactionCache); */ static void Main() { // Create a configuration for a locally-running server ConfigurationBuilder conf = new ConfigurationBuilder(); conf.AddServer().Host("127.0.0.1").Port(11222); conf.ConnectionTimeout(90000).SocketTimeout(6000); conf.Marshaller(new BasicTypesProtoStreamMarshaller()); RemoteCacheManager remoteManager = new RemoteCacheManager(conf.Build(), true); IRemoteCache <String, String> metadataCache = remoteManager.GetCache <String, String>(PROTOBUF_METADATA_CACHE_NAME); metadataCache.Put("quickstart/addressbook.proto", File.ReadAllText("addressbook.proto")); if (metadataCache.ContainsKey(ERRORS_KEY_SUFFIX)) { Console.WriteLine("fail: error in registering .proto model"); Environment.Exit(-1); } IRemoteCache <int, Person> cache = remoteManager.GetCache <int, Person>(NAMED_CACHE); bool quit = false; displayActions(); while (!quit) { int action = readAction(); switch (action) { case 1: putPerson(cache); break; case 2: removePerson(cache); break; case 3: addPhone(cache); break; case 4: removePhone(cache); break; case 5: queryPersonByName(cache); break; case 6: queryPersonByPhone(cache); break; case 7: addMemo(cache); break; case 8: fullTextOnMemo(cache); break; case 9: projectAllNames(cache); break; case 10: countByDepartment(cache); break; case 11: printAll(cache); break; case 12: cache.Clear(); Console.WriteLine("Cache cleared"); break; case 13: quit = true; Console.WriteLine("Bye!"); break; case 0: displayActions(); break; default: Console.Error.WriteLine("Invalid action: " + action); break; } } remoteManager.Stop(); }