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 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 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); }
public void PutIfAbsentTest() { String key1 = UniqueKey.NextKey(); String key2 = UniqueKey.NextKey(); cache.Put(key1, "carbon0"); cache.PutIfAbsent(key1, "carbon1"); cache.PutIfAbsent(key2, "carbon2"); Assert.AreEqual("carbon0", cache.Get(key1)); Assert.AreEqual("carbon2", cache.Get(key2)); }
private void TestPut(IRemoteCache <string, string> testCache) { string k1 = "key13"; string v1 = "boron"; testCache.Put(k1, v1); Assert.AreEqual(v1, testCache.Get(k1)); }
protected void TestPutIfAbsent(IRemoteCache <string, string> cache) { cache.Remove(K1); Assert.IsNull(cache.PutIfAbsent(K1, V1)); //this should not change the value cache.PutIfAbsent(K1, V2); Assert.AreEqual(V1, cache.Get(K1)); }
public void FailoverTest() { Assert.IsNull(cache1.Put("k1", "v1")); Assert.AreEqual("v1", cache1.Get("k1"), "Expected v1 from cache1"); Assert.AreEqual("v1", cache2.Get("k1"), "Expected v1 from cache2"); XSiteTestSuite.server1.ShutDownHotrodServer(); //client1 should failover Assert.AreEqual("v1", cache1.Get("k1"), "Expected v1 from cache1 after failover"); Assert.AreEqual("v1", cache2.Get("k1"), "Expected v1 from cache2 after failover"); XSiteTestSuite.server1.StartHotRodServer(); manager1.SwitchToDefaultCluster(); //client1 should get null as state transfer is not enabled Assert.IsNull(cache1.Get("k1")); Assert.IsNull(cache1.Put("k2", "v2")); Assert.AreEqual("v2", cache1.Get("k2")); //double check client2 Assert.AreEqual("v1", cache2.Get("k1"), "Expected v1 from cache2 after starting LON back again"); }
protected void TestPutIfAbsentAsync(IRemoteCache <string, string> cache) { cache.Remove(K1); Task <string> result = cache.PutIfAbsentAsync(K1, V1); Assert.IsNull(result.Result); //this should not change the value result = cache.PutIfAbsentAsync(K1, V2); Assert.AreEqual(V1, cache.Get(K1)); }
public void PutAsyncTest() { InitializeRemoteCacheManager(true); IRemoteCache <string, string> testCache = remoteManager.GetCache <string, string>("default"); Task <string> result = testCache.PutAsync("kasync", "vasync"); Assert.AreEqual(null, result.Result); Assert.IsTrue(result.IsCompleted); Assert.Null(result.Exception); Assert.AreEqual("vasync", testCache.Get("kasync")); }
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 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); }
void checkIsNearWithRetry(IRemoteCache <string, string> cache, string key) { ServerStatistics stats0 = cache.Stats(); ServerStatistics stats1 = null; for (var i = 0; i < 10; i++) { cache.Get(key); stats1 = cache.Stats(); if (stats0.GetIntStatistic("nearHits") + 1 == stats1.GetIntStatistic("nearHits")) { break; } System.Threading.Thread.Sleep(200); } Assert.AreEqual(stats0.GetIntStatistic("nearHits") + 1, stats1.GetIntStatistic("nearHits")); }
static void Main() { // Create a configuration for a locally-running server ConfigurationBuilder builder = new ConfigurationBuilder(); Configuration conf = builder.AddServers("127.0.0.1:11222").Build(); // Initialize the remote cache manager RemoteCacheManager remoteManager = new RemoteCacheManager(conf); // Connect to the server remoteManager.Start(); // Store a value IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>(); cache.Put("key", "value"); // Retrieve the value and print it out Console.WriteLine("key = {0}", cache.Get("key")); // Stop the cache manager and release all resources remoteManager.Stop(); }
static void addMemo(IRemoteCache <int, Person> cache) { int id = readInt("Enter person id: "); Person p = cache.Get(id); if (p == null) { Console.Error.WriteLine("Person not found"); return; } Console.WriteLine(p.ToString()); String text = readString("Enter memo text: "); var m = new Person.Types.Memo(); m.Text = text; p.Memo.Add(m); cache.Put(id, p); }
private static void NewMethod(IRemoteCache <string, string> cache, string key, string val) { var count = 0; while (true) { ++count; if (count % 1000 == 0) { System.Console.Write("." + count + " " + System.Threading.Thread.CurrentThread); } cache.Put(key + count, val + count); if (count % 1000 == 0) { System.Console.WriteLine("+" + count); } System.Threading.Thread.Sleep(10); cache.Get(key); System.Threading.Thread.Sleep(10); } }
private static void addPhone(IRemoteCache <int, Person> cache) { int id = readInt("Enter person id: "); Person p = cache.Get(id); if (p == null) { Console.Error.WriteLine("Person not found"); return; } Console.WriteLine(p.ToString()); var pn = new Person.Types.PhoneNumber(); pn.Number = readString("Enter phone number: "); try { pn.Type = (Person.Types.PhoneType)Enum.Parse(typeof(Person.Types.PhoneType), readString("Enter phone type: ")); p.Phone.Add(pn); cache.Put(id, p); } catch { } }
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); } } }
private static void removePhone(IRemoteCache <int, Person> cache) { int id = readInt("Enter person id: "); Person p = cache.Get(id); if (p == null) { Console.Error.WriteLine("Person not found"); return; } Console.WriteLine(p.ToString()); int phone_index = readInt("Enter phone index: "); if ((phone_index < 0) || (phone_index >= p.Phone.Count)) { Console.Error.WriteLine("Phone index '" + phone_index + "' is out of range."); return; } p.Phone.RemoveAt(phone_index); cache.Put(id, p); }
public void GetTest() { String key = UniqueKey.NextKey(); Assert.IsNull(cache.Get(key)); cache.Put(key, "carbon"); Assert.AreEqual("carbon", cache.Get(key)); }
protected void TestPutReplaceWithFlag(IRemoteCache <string, string> cache) { cache.Put(K1, V1); Assert.AreEqual(V1, cache.WithFlags(Flags.FORCE_RETURN_VALUE).Replace(K1, V2)); Assert.AreEqual(V2, cache.Get(K1)); }
protected void TestPutGet(IRemoteCache <string, string> cache) { cache.Put(K1, V1); Assert.AreEqual(V1, cache.Get(K1)); }
protected void TestGetNonExistent(IRemoteCache <string, string> cache) { Assert.IsNull(cache.Get(NON_EXISTENT_KEY)); }
public void JBossCacheDefaultJbossMediaTypeTest() { transcodingCache.Put("k1", "value1"); Assert.AreEqual("value1", transcodingCache.Get("k1")); }
public void RawCacheDefaultJbossMediaTypeTest() { cache.Put("k1", "value1"); Assert.AreEqual("value1", cache.Get("k1")); }