public void TestReadOnlyNearCacheConfig() { var config = new NearCacheConfig(); var readOnly = config.GetAsReadOnly(); var actions = new Action[] { () => readOnly.SetEvictionPolicy(TestSupport.RandomString()), () => readOnly.SetName(TestSupport.RandomString()), () => readOnly.SetInMemoryFormat(TestSupport.RandomString()), () => readOnly.SetInMemoryFormat(InMemoryFormat.Binary), () => readOnly.SetInvalidateOnChange(true), () => readOnly.SetMaxIdleSeconds(TestSupport.RandomInt()), () => readOnly.SetMaxSize(TestSupport.RandomInt()), () => readOnly.SetTimeToLiveSeconds(TestSupport.RandomInt()) }; foreach (var action in actions) { try { action(); Assert.Fail("The config was not readonly."); } catch (NotSupportedException) { } } }
private void HandleNearCache(XmlNode node) { var name = node.Attributes.GetNamedItem("name").Value; var nearCacheConfig = new NearCacheConfig(name); foreach (XmlNode child in node.ChildNodes) { var nodeName = CleanNodeName(child); switch (nodeName) { case "max-size": nearCacheConfig.SetMaxSize(Convert.ToInt32(GetTextContent(child))); break; case "time-to-live-seconds": nearCacheConfig.SetTimeToLiveSeconds(Convert.ToInt32(GetTextContent(child))); break; case "max-idle-seconds": nearCacheConfig.SetMaxIdleSeconds(Convert.ToInt32(GetTextContent(child))); break; case "eviction-policy": nearCacheConfig.SetEvictionPolicy(GetTextContent(child)); break; case "in-memory-format": InMemoryFormat result; Enum.TryParse(GetTextContent(child), true, out result); nearCacheConfig.SetInMemoryFormat(result); break; case "invalidate-on-change": nearCacheConfig.SetInvalidateOnChange(bool.Parse(GetTextContent(child))); break; } } _clientConfig.AddNearCacheConfig(name, nearCacheConfig); }
public virtual void TestNearCacheConfigWildcard3() { NearCacheConfig nearCacheConfig = new NearCacheConfig().SetName("com.hazelcast.test.*"); ClientConfig config = new ClientConfig(); config.SetConfigPatternMatcher(new MatchingPointConfigPatternMatcher()); config.AddNearCacheConfig(nearCacheConfig); Assert.AreEqual(nearCacheConfig, config.GetNearCacheConfig("com.hazelcast.test.myNearCache")); }
public NearCacheConfig(NearCacheConfig config) { _name = config.GetName(); _evictionPolicy = config.GetEvictionPolicy(); _inMemoryFormat = config.GetInMemoryFormat(); _invalidateOnChange = config.IsInvalidateOnChange(); _maxIdleSeconds = config.GetMaxIdleSeconds(); _maxSize = config.GetMaxSize(); _timeToLiveSeconds = config.GetTimeToLiveSeconds(); }
public virtual void TestMapConfigWildcardMultipleAmbiguousConfigs() { NearCacheConfig nearCacheConfig1 = new NearCacheConfig().SetName("com.hazelcast*"); NearCacheConfig nearCacheConfig2 = new NearCacheConfig().SetName("*com.hazelcast"); ClientConfig config = new ClientConfig(); config.SetConfigPatternMatcher(new MatchingPointConfigPatternMatcher()); config.AddNearCacheConfig(nearCacheConfig1); config.AddNearCacheConfig(nearCacheConfig2); config.GetNearCacheConfig("com.hazelcast"); }
public NearCacheConfig(NearCacheConfig config) { name = config.GetName(); evictionPolicy = config.GetEvictionPolicy(); inMemoryFormat = config.GetInMemoryFormat(); invalidateOnChange = config.IsInvalidateOnChange(); maxIdleSeconds = config.GetMaxIdleSeconds(); maxSize = config.GetMaxSize(); timeToLiveSeconds = config.GetTimeToLiveSeconds(); cacheLocalEntries = config.IsCacheLocalEntries(); }
public virtual void TestDuplicateConfig() { NearCacheConfig nearCacheConfig1 = new NearCacheConfig().SetName("com.hazelcast.*ap"); NearCacheConfig nearCacheConfig2 = new NearCacheConfig().SetName("com.hazelcast*map"); ClientConfig config = new ClientConfig(); config.SetConfigPatternMatcher(new MatchingPointConfigPatternMatcher()); config.AddNearCacheConfig(nearCacheConfig1); config.AddNearCacheConfig(nearCacheConfig2); config.GetNearCacheConfig("com.hazelcast.map"); }
public virtual void TestSpecificNearCacheConfig_whenAsteriskAtTheEnd() { var clientConfig = new ClientConfig(); var genericNearCacheConfig = new NearCacheConfig(); genericNearCacheConfig.SetName("map*"); clientConfig.AddNearCacheConfig(genericNearCacheConfig); var specificNearCacheConfig = new NearCacheConfig(); specificNearCacheConfig.SetName("mapStudent*"); clientConfig.AddNearCacheConfig(specificNearCacheConfig); var mapFoo = clientConfig.GetNearCacheConfig("mapFoo"); var mapStudentFoo = clientConfig.GetNearCacheConfig("mapStudentFoo"); Assert.AreEqual(genericNearCacheConfig, mapFoo); Assert.AreEqual(specificNearCacheConfig, mapStudentFoo); }
public static void Run(string[] args) { Environment.SetEnvironmentVariable("hazelcast.logging.level", "info"); Environment.SetEnvironmentVariable("hazelcast.logging.type", "console"); var config = new ClientConfig(); var nearCacheConfig = new NearCacheConfig(); nearCacheConfig.SetMaxSize(1000) .SetInvalidateOnChange(true) .SetEvictionPolicy("Lru") .SetInMemoryFormat(InMemoryFormat.Binary); config.AddNearCacheConfig("nearcache-map-*", nearCacheConfig); config.GetNetworkConfig().AddAddress("127.0.0.1"); var client = HazelcastClient.NewHazelcastClient(config); var map = client.GetMap<string, string>("nearcache-map-1"); for (var i = 0; i < 1000; i++) { map.Put("key" + i, "value" + i); } var sw = new Stopwatch(); sw.Start(); for (var i = 0; i < 1000; i++) { map.Get("key" + i); } Console.WriteLine("Got values in " + sw.ElapsedMilliseconds + " millis"); sw.Restart(); for (var i = 0; i < 1000; i++) { map.Get("key" + i); } Console.WriteLine("Got cached values in " + sw.ElapsedMilliseconds + " millis"); map.Destroy(); client.Shutdown(); }
private static void HandleNearCache(this NearCacheConfig nearCacheConfig, XmlNode node) { foreach (XmlNode child in node.ChildNodes) { var nodeName = CleanNodeName(child); var textContent = GetTextContent(child); switch (nodeName) { case "max-size": nearCacheConfig.MaxSize = Convert.ToInt32(textContent); break; case "time-to-live-seconds": nearCacheConfig.TimeToLiveSeconds = Convert.ToInt32(textContent); break; case "max-idle-seconds": nearCacheConfig.MaxIdleSeconds = Convert.ToInt32(textContent); break; case "in-memory-format": Enum.TryParse(textContent, true, out InMemoryFormat result); nearCacheConfig.InMemoryFormat = result; break; case "serialize-keys": nearCacheConfig.SerializeKeys = Convert.ToBoolean(textContent); break; case "invalidate-on-change": nearCacheConfig.InvalidateOnChange = Convert.ToBoolean(textContent); break; case "eviction-policy": nearCacheConfig.EvictionPolicy = (EvictionPolicy)Enum.Parse(typeof(EvictionPolicy), textContent, true); break; default: throw new InvalidConfigurationException($"Xml tag:{nodeName} is not supported."); } } }
public virtual ClientConfig AddNearCacheConfig(NearCacheConfig nearCacheConfig) { _nearCacheConfigMap.Add(nearCacheConfig.GetName(), nearCacheConfig); return(this); }
public NearCacheConfigReadOnly(NearCacheConfig config) : base(config) { }
public virtual void TestNearCacheConfigWildcardMatchingPointEndsWith() { NearCacheConfig nearCacheConfig1 = new NearCacheConfig().SetName("*.sub"); NearCacheConfig nearCacheConfig2 = new NearCacheConfig().SetName("*.test.sub"); NearCacheConfig nearCacheConfig3 = new NearCacheConfig().SetName("*.hazelcast.test.sub"); ClientConfig config = new ClientConfig(); config.SetConfigPatternMatcher(new MatchingPointConfigPatternMatcher()); config.AddNearCacheConfig(nearCacheConfig1); config.AddNearCacheConfig(nearCacheConfig2); config.AddNearCacheConfig(nearCacheConfig3); // we should not match any of the configs (endsWith) Assert.AreEqual(null, config.GetNearCacheConfig("com.hazelFast.Fast.sub.myNearCache")); Assert.AreEqual(null, config.GetNearCacheConfig("hazelFast.test.sub.myNearCache")); Assert.AreEqual(null, config.GetNearCacheConfig("test.sub.myNearCache")); }
public virtual void TestNearCacheConfigWithoutWildcard() { NearCacheConfig nearCacheConfig = new NearCacheConfig().SetName("someNearCache"); ClientConfig config = new ClientConfig(); config.SetConfigPatternMatcher(new MatchingPointConfigPatternMatcher()); config.AddNearCacheConfig(nearCacheConfig); Assert.AreEqual(nearCacheConfig, config.GetNearCacheConfig("someNearCache")); // non-matching name Assert.AreNotEqual(nearCacheConfig, config.GetNearCacheConfig("doesNotExist")); // non-matching case Assert.AreNotEqual(nearCacheConfig, config.GetNearCacheConfig("SomeNearCache")); }
public virtual void TestNearCacheConfigWildcardOnlyMultipleConfigs() { NearCacheConfig nearCacheConfig1 = new NearCacheConfig().SetName("*"); NearCacheConfig nearCacheConfig2 = new NearCacheConfig().SetName("com.hazelcast.*"); ClientConfig config = new ClientConfig(); config.SetConfigPatternMatcher(new MatchingPointConfigPatternMatcher()); config.AddNearCacheConfig(nearCacheConfig1); config.AddNearCacheConfig(nearCacheConfig2); // we should get the best matching result Assert.AreEqual(nearCacheConfig2, config.GetNearCacheConfig("com.hazelcast.myNearCache")); }
public virtual ClientConfig AddNearCacheConfig(string mapName, NearCacheConfig nearCacheConfig) { _nearCacheConfigMap.Add(mapName, nearCacheConfig); return(this); }
protected override void ConfigureClient(ClientConfig config) { base.ConfigureClient(config); var nearCacheConfig = new NearCacheConfig().SetInMemoryFormat(InMemoryFormat.Object); config.AddNearCacheConfig("nearCachedMap*", nearCacheConfig); }
public virtual void TestNearCacheConfigWildcardMatchingPointStartsWith() { var nearCacheConfig1 = new NearCacheConfig().SetName("hazelcast.*"); var nearCacheConfig2 = new NearCacheConfig().SetName("hazelcast.test.*"); var nearCacheConfig3 = new NearCacheConfig().SetName("hazelcast.test.sub.*"); var config = new ClientConfig(); config.SetConfigPatternMatcher(new MatchingPointConfigPatternMatcher()); config.AddNearCacheConfig(nearCacheConfig1); config.AddNearCacheConfig(nearCacheConfig2); config.AddNearCacheConfig(nearCacheConfig3); // we should not match any of the configs (startsWith) Assert.AreEqual(null, config.GetNearCacheConfig("com.hazelcast.myNearCache")); Assert.AreEqual(null, config.GetNearCacheConfig("com.hazelcast.test.myNearCache")); Assert.AreEqual(null, config.GetNearCacheConfig("com.hazelcast.test.sub.myNearCache")); }