public IIgnite StartIgniteClient() { try { if (_IGNITE_CLIENT == null) { Ignition.ClientMode = true; // Connect to the cluster. // _IGNITE_CLIENT = Ignition.Start("C:\\Users\bizruntime-86\\source\\client-config.xml"); _IGNITE_CLIENT = Ignition.TryGetIgnite("TextQueryTestNode"); if (_IGNITE_CLIENT == null) { _IGNITE_CLIENT = Ignition.Start(GetIgniteConfiguration()); } //_IGNITE_CLIENT = Ignition.Start(Directory.GetCurrentDirectory()+ "\\client-config.xml");//GetIgniteConfiguration()); } } catch (Exception ex) { throw; } return(_IGNITE_CLIENT); }
public void TestConfigurationAndStartup() { Environment.SetEnvironmentVariable("IGNITE_NATIVE_TEST_CLASSPATH", "true"); Assert.IsNull(Ignition.TryGetIgnite()); // Test default config (picks up app.config section). CheckCacheAndStop("myGrid1", IgniteDbConfiguration.DefaultCacheNamePrefix, new IgniteDbConfiguration()); // Specific config section. CheckCacheAndStop("myGrid2", "cacheName2", new IgniteDbConfiguration("igniteConfiguration2", "cacheName2", null)); // Specific config section, nonexistent cache. CheckCacheAndStop("myGrid2", "newCache", new IgniteDbConfiguration("igniteConfiguration2", "newCache", null)); // In-code configuration. CheckCacheAndStop("myGrid3", "myCache", new IgniteDbConfiguration(new IgniteConfiguration(TestUtils.GetTestConfiguration()) { IgniteInstanceName = "myGrid3" }, new CacheConfiguration("myCache_metadata") { CacheMode = CacheMode.Replicated, AtomicityMode = CacheAtomicityMode.Transactional }, new CacheConfiguration("myCache_data") { CacheMode = CacheMode.Replicated }, null), CacheMode.Replicated); // Existing instance. var ignite = Ignition.Start(TestUtils.GetTestConfiguration()); CheckCacheAndStop(null, "123", new IgniteDbConfiguration(ignite, new CacheConfiguration("123_metadata") { Backups = 1, AtomicityMode = CacheAtomicityMode.Transactional }, new CacheConfiguration("123_data"), null)); // Non-tx meta cache. var ex = Assert.Throws <IgniteException>(() => CheckCacheAndStop(null, "123", new IgniteDbConfiguration(TestUtils.GetTestConfiguration(), new CacheConfiguration("123_metadata"), new CacheConfiguration("123_data"), null))); Assert.AreEqual("EntityFramework meta cache should be Transactional.", ex.Message); // Same cache names. var ex2 = Assert.Throws <ArgumentException>(() => CheckCacheAndStop(null, "abc", new IgniteDbConfiguration(TestUtils.GetTestConfiguration(), new CacheConfiguration("abc"), new CacheConfiguration("abc"), null))); Assert.IsTrue(ex2.Message.Contains("Meta and Data cache can't have the same name.")); }
public IgniteSerializationBenchmark() { var ignite = Ignition.TryGetIgnite() ?? Ignition.Start(GetIgniteConfiguration()); var marsh = ignite.GetType() .GetField("_marsh", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(ignite); var marshalMethod = marsh.GetType().GetMethods() .Single(x => x.Name == "Marshal" && x.GetParameters().Length == 1).MakeGenericMethod(typeof(object)); _serialize = (Func <object, byte[]>)Delegate.CreateDelegate(typeof(Func <object, byte[]>), marsh, marshalMethod); var binaryMode = ignite.GetType().Assembly.GetType("Apache.Ignite.Core.Impl.Binary.BinaryMode"); var unmarshalMethod = marsh.GetType() .GetMethod("Unmarshal", new[] { typeof(byte[]), binaryMode }) .MakeGenericMethod(typeof(object)); _deserialize = (Func <byte[], int, object>) Delegate.CreateDelegate(typeof(Func <byte[], int, object>), marsh, unmarshalMethod); }
public void TestTwoServers() { var cfg1 = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { SpringConfigUrl = @"Config/ssl.xml" }; var cfg2 = new IgniteConfiguration(TestUtils.GetTestConfiguration(name: "grid2")) { SslContextFactory = GetSslContextFactory() }; var grid1 = Ignition.Start(cfg1); Assert.AreEqual("grid1", grid1.Name); Assert.AreSame(grid1, Ignition.GetIgnite()); Assert.AreSame(grid1, Ignition.GetAll().Single()); var grid2 = Ignition.Start(cfg2); Assert.AreEqual("grid2", grid2.Name); Assert.Throws <IgniteException>(() => Ignition.GetIgnite()); Assert.AreSame(grid1, Ignition.GetIgnite("grid1")); Assert.AreSame(grid1, Ignition.TryGetIgnite("grid1")); Assert.AreSame(grid2, Ignition.GetIgnite("grid2")); Assert.AreSame(grid2, Ignition.TryGetIgnite("grid2")); Assert.AreEqual(new[] { grid1, grid2 }, Ignition.GetAll().OrderBy(x => x.Name).ToArray()); Assert.AreEqual(2, grid1.GetCluster().GetNodes().Count); Assert.AreEqual(2, grid2.GetCluster().GetNodes().Count); }
/// <summary> /// Checks that specified cache exists and stops all Ignite instances. /// </summary> // ReSharper disable once UnusedParameter.Local private static void CheckCacheAndStop(string gridName, string cacheName, IgniteDbConfiguration cfg, CacheMode cacheMode = CacheMode.Partitioned) { try { Assert.IsNotNull(cfg); var ignite = Ignition.TryGetIgnite(gridName); Assert.IsNotNull(ignite); var metaCache = ignite.GetCache <object, object>(cacheName + "_metadata"); Assert.IsNotNull(metaCache); Assert.AreEqual(cacheMode, metaCache.GetConfiguration().CacheMode); if (cacheMode == CacheMode.Partitioned) { Assert.AreEqual(1, metaCache.GetConfiguration().Backups); } var dataCache = ignite.GetCache <object, object>(cacheName + "_data"); Assert.IsNotNull(dataCache); Assert.AreEqual(cacheMode, dataCache.GetConfiguration().CacheMode); if (cacheMode == CacheMode.Partitioned) { Assert.AreEqual(0, dataCache.GetConfiguration().Backups); } } finally { Ignition.StopAll(true); } }
public static void Run() { var ignite = Ignition.TryGetIgnite() ?? Ignition.StartFromApplicationConfiguration(); Console.WriteLine(); Console.WriteLine(">>> Cache query example started."); var employeeCache = ignite.GetOrCreateCache <int, Employee>( new CacheConfiguration(EmployeeCacheName, typeof(Employee))); var employeeCacheColocated = ignite.GetOrCreateCache <AffinityKey, Employee>( new CacheConfiguration(EmployeeCacheNameColocated, typeof(Employee))); var organizationCache = ignite.GetOrCreateCache <int, Organization>( new CacheConfiguration(OrganizationCacheName, new QueryEntity(typeof(int), typeof(Organization)))); // Populate cache with sample data entries. PopulateCache(employeeCache); PopulateCache(employeeCacheColocated); PopulateCache(organizationCache); // Run SQL query example. SqlQueryExample(employeeCache); // Run SQL query with join example. SqlJoinQueryExample(employeeCacheColocated); // Run SQL query with distributed join example. SqlDistributedJoinQueryExample(employeeCache); // Run SQL fields query example. SqlFieldsQueryExample(employeeCache); }
public IgniteLinqBenchmark() { var ignite = Ignition.TryGetIgnite() ?? Ignition.Start(new IgniteConfiguration { BinaryConfiguration = new BinaryConfiguration(typeof(SqlPerson)), CacheConfiguration = new[] { new CacheConfiguration("persons", new QueryEntity(typeof(SqlPerson))) } }); _cache = ignite.GetCache <int, SqlPerson>("persons"); _cache.PutAll(Enumerable.Range(0, PersonCount) .ToDictionary(x => x, x => new SqlPerson { Id = x, Age = x * 2 })); // Prepare queries. _sqlQuery = new SqlFieldsQuery("select Age from SqlPerson where (SqlPerson.Id < ?)", SelectCount); var persons = _cache.AsCacheQueryable(); _linq = persons.Where(x => x.Value.Id < SelectCount).Select(x => x.Value.Age); _compiledLinq = CompiledQuery.Compile(() => persons .Where(x => x.Value.Id < SelectCount).Select(x => x.Value.Age)); }
public void TestStartGetStop() { var grid1 = Ignition.Start(TestUtils.GetTestConfiguration(name: "grid1")); Assert.AreEqual("grid1", grid1.Name); Assert.AreSame(grid1, Ignition.GetIgnite()); Assert.AreSame(grid1, Ignition.GetAll().Single()); var grid2 = Ignition.Start(TestUtils.GetTestConfiguration(name: "grid2")); Assert.AreEqual("grid2", grid2.Name); Assert.Throws <IgniteException>(() => Ignition.GetIgnite()); var grid3 = Ignition.Start(TestUtils.GetTestConfiguration()); Assert.IsNull(grid3.Name); Assert.AreSame(grid1, Ignition.GetIgnite("grid1")); Assert.AreSame(grid1, Ignition.TryGetIgnite("grid1")); Assert.AreSame(grid2, Ignition.GetIgnite("grid2")); Assert.AreSame(grid2, Ignition.TryGetIgnite("grid2")); Assert.AreSame(grid3, Ignition.GetIgnite(null)); Assert.AreSame(grid3, Ignition.GetIgnite()); Assert.AreSame(grid3, Ignition.TryGetIgnite(null)); Assert.AreSame(grid3, Ignition.TryGetIgnite()); Assert.AreEqual(new[] { grid3, grid1, grid2 }, Ignition.GetAll().OrderBy(x => x.Name).ToArray()); Assert.Throws <IgniteException>(() => Ignition.GetIgnite("invalid_name")); Assert.IsNull(Ignition.TryGetIgnite("invalid_name")); Assert.IsTrue(Ignition.Stop("grid1", true)); Assert.Throws <IgniteException>(() => Ignition.GetIgnite("grid1")); grid2.Dispose(); Assert.Throws <IgniteException>(() => Ignition.GetIgnite("grid2")); grid3.Dispose(); Assert.Throws <IgniteException>(() => Ignition.GetIgnite("grid3")); // Restart. Ignition.Start(TestUtils.GetTestConfiguration(name: "grid1")); Ignition.Start(TestUtils.GetTestConfiguration(name: "grid2")); Ignition.Start(TestUtils.GetTestConfiguration()); foreach (var gridName in new [] { "grid1", "grid2", null }) { Assert.IsNotNull(Ignition.GetIgnite(gridName)); } Ignition.StopAll(true); foreach (var gridName in new [] { "grid1", "grid2", null }) { Assert.Throws <IgniteException>(() => Ignition.GetIgnite(gridName)); } }
/// <summary> /// Checks the enum value serialization. /// </summary> private static void CheckValue <T>(T val, bool isBinaryEnum = true) { var marsh = GetMarshaller(); var ignite = Ignition.TryGetIgnite(); var bytes = marsh.Marshal(val); var res = marsh.Unmarshal <T>(bytes); var binRes = marsh.Unmarshal <IBinaryObject>(bytes, BinaryMode.ForceBinary); Assert.AreEqual(val, res); Assert.AreEqual(val, binRes.Deserialize <T>()); if (isBinaryEnum) { Assert.AreEqual(TypeCaster <int> .Cast(val), binRes.EnumValue); if (ignite != null) { Assert.AreEqual(string.Format("{0} [typeId={1}, enumValue={2}, enumValueName={3}]", typeof(T).FullName, binRes.GetBinaryType().TypeId, binRes.EnumValue, val), binRes.ToString()); var expectedEnumNames = Enum.GetValues(typeof(T)).OfType <T>().Select(x => x.ToString()).ToList(); var actualEnumNames = binRes.GetBinaryType().GetEnumValues().Select(v => v.EnumName).ToList(); CollectionAssert.AreEquivalent(expectedEnumNames, actualEnumNames); } else { Assert.AreEqual(string.Format("BinaryEnum [typeId={0}, enumValue={1}]", BinaryUtils.GetStringHashCodeLowerCase(typeof(T).FullName), binRes.EnumValue), binRes.ToString()); } } else { Assert.AreEqual(val, binRes.GetField <T>("value__")); } // Check array. CheckSerializeDeserialize(new[] { val, val }); // Check caching. if (ignite != null) { var cache = ignite.GetOrCreateCache <int, T>(typeof(T).FullName); var binCache = cache.WithKeepBinary <int, IBinaryObject>(); cache[1] = val; res = cache[1]; binRes = binCache[1]; Assert.AreEqual(val, res); Assert.AreEqual(val, binRes.Deserialize <T>()); var arrCache = ignite.GetOrCreateCache <int, T[]>(typeof(T[]).FullName); arrCache[1] = new[] { val, val }; Assert.AreEqual(new[] { val, val }, arrCache[1]); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { //Environment.SetEnvironmentVariable("IGNITE_HOME", @"C:\IGNITE_HOME"); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); FirstValues.GeoPointCacheName = ("GeoPointCache" + DateTime.Now).Replace(" ", "").Replace("/", "").Replace(":", ""); FirstValues.ZoneCacheName = ("ZoneCache" + DateTime.Now).Replace(" ", "").Replace("/", "").Replace(":", ""); FirstValues.DeviceCacheName = ("DeviceCache" + DateTime.Now).Replace(" ", "").Replace("/", "").Replace(":", ""); FirstValues.VehicleCacheName = ("VehicleCache" + DateTime.Now).Replace(" ", "").Replace("/", "").Replace(":", ""); FirstValues.IgniteInstanceName = ("ignite-node" + DateTime.Now).Replace(" ", "").Replace("/", "").Replace(":", ""); var cfg = new IgniteConfiguration { JvmDllPath = @"C:\Program Files\Java\jdk-11.0.1\bin\server\jvm.dll", IsActiveOnStart = true, ClientMode = false, IgniteInstanceName = "Test",// FirstValues.IgniteInstanceName, WorkDirectory = @"C:\IGNITE_HOME\workspace", GridName = Guid.NewGuid().ToString(), DataStorageConfiguration = new DataStorageConfiguration() { DefaultDataRegionConfiguration = new DataRegionConfiguration() { PersistenceEnabled = true, Name = "inMemoryRegion", //CheckpointPageBufferSize = 1024, }, WriteThrottlingEnabled = true }, BinaryConfiguration = new BinaryConfiguration() { CompactFooter = false, KeepDeserialized = true } }; cfg = FirstValues.cacheConfigAll(cfg); cfg = FirstValues.setupDiscoveryConfig(cfg); Environment.SetEnvironmentVariable("IGNITE_H2_DEBUG_CONSOLE", "true"); var ignite = Ignition.TryGetIgnite() ?? Ignition.Start(cfg); ignite.GetCluster().SetActive(true); ignite.SetActive(true); var nodes = ignite.GetCluster().ForServers().GetNodes(); ignite.GetCluster().SetBaselineTopology(nodes); DatabaseInitializer.InitializeEfDb(); DatabaseInitializer.Initializer(ignite); }
/// <summary> /// Contains initialisation routines for the whole Product Service. /// </summary> /// <param name="serviceCollection"></param> /// <returns></returns> public async static Task Init(IServiceCollection serviceCollection) { IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", false, true) // read settings from the JSON file .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() // and the environment variables .Build(); // Configure Apache Ignite var igniteConfig = new IgniteConfiguration { // Setup an Ingite node discovery mechanism for the K8s environment // Logger = new IgniteLog4NetLogger(), JvmOptions = new List <string>() { "-Djava.net.preferIPv4Stack=true", "-Xms512m", "-Xmx512m", "-DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true", "-DIGNITE_QUIET=false" }, UserAttributes = new Dictionary <string, object>() { { "service", Program.SERVICE_NAME } } }; Console.WriteLine("KUBERNETES configuration is active."); Console.WriteLine(); Console.WriteLine("Directories in the working directory:"); foreach (var dir in System.IO.Directory.GetDirectories(AppContext.BaseDirectory)) { Console.WriteLine(dir); } Console.WriteLine(); Console.WriteLine("Files in the working directory:"); foreach (var file in System.IO.Directory.GetFiles(AppContext.BaseDirectory)) { Console.WriteLine(file); } Console.WriteLine(); igniteConfig.SpringConfigUrl = "./kubernetes.config"; igniteConfig.JvmClasspath = string.Join(";", System.IO.Directory.GetFiles( System.IO.Path.Combine(AppContext.BaseDirectory, "libs"), "*.jar")); System.Globalization.CultureInfo.CurrentCulture = new System.Globalization.CultureInfo("en-GB"); // Set up dependencies serviceCollection .AddSingleton(sp => Ignition.TryGetIgnite() ?? Ignition.Start(igniteConfig)); var serviceProvider = serviceCollection.BuildServiceProvider(); var ignite = serviceProvider.GetService <IIgnite>(); }
/// <summary> /// Gets the marshaller. /// </summary> private static Marshaller GetMarshaller() { var ignite = Ignition.TryGetIgnite(); return(ignite != null ? ((Ignite)ignite).Marshaller : new Marshaller(null) { CompactFooter = false }); }
/// <summary> /// Starts Ignite from application configuration. /// </summary> private static IIgnite StartFromApplicationConfiguration(string sectionName, string gridName) { IgniteConfiguration config; if (!string.IsNullOrEmpty(sectionName)) { var section = ConfigurationManager.GetSection(sectionName) as IgniteConfigurationSection; if (section == null) { throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture, "Could not find {0} with name '{1}'", typeof(IgniteConfigurationSection).Name, sectionName)); } config = section.IgniteConfiguration; if (config == null) { throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture, "{0} with name '{1}' is defined in <configSections>, but not present in configuration.", typeof(IgniteConfigurationSection).Name, sectionName)); } } else { config = new IgniteConfiguration { IgniteInstanceName = gridName } }; // Check if already started. var ignite = Ignition.TryGetIgnite(config.IgniteInstanceName); if (ignite != null) { return(ignite); } // Start. if (string.IsNullOrWhiteSpace(config.IgniteHome)) { // IgniteHome not set by user: populate from default directory. config = new IgniteConfiguration(config) { IgniteHome = IgniteWebUtils.GetWebIgniteHome() }; } return(Ignition.Start(config)); } }
public void Invoke() { Console.WriteLine($"Loading cache {Type.Name}"); var ignite = Ignition.TryGetIgnite("timtest"); ReflectionHelper.GetOrCreateCache(ignite, Type); var sw = Stopwatch.StartNew(); //var cache = ignite.GetCache<object, object>(Type.Name); //cache.LoadCache(null); var cache = ReflectionHelper.GetCache(ignite, Type); ReflectionHelper.LoadCache(cache); Console.WriteLine($"{ReflectionHelper.GetCacheSize(cache)} {Type.Name}s loaded in {sw.Elapsed} in PID {Process.GetCurrentProcess().Id}"); }
/// <summary> /// Runs the example. /// </summary> public static void Run() { var ignite = Ignition.TryGetIgnite() ?? Ignition.StartFromApplicationConfiguration(); Console.WriteLine(); Console.WriteLine(">>> Cache put-get example started."); // Clean up caches on all nodes before run. ignite.GetOrCreateCache <object, object>(CacheName).Clear(); PutGet(ignite); PutGetBinary(ignite); PutGetAsync(ignite).Wait(); }
static void Main(string[] args) { var store = Ignition.TryGetIgnite() ?? Ignition.Start(IgniteProvider.GetDefaultIgniteConfiguration()); while (true) { var ln = Console.ReadLine(); if (!string.IsNullOrEmpty(ln) && ln.Trim().Equals("c", StringComparison.InvariantCultureIgnoreCase)) { return; } } }
public IgniteLogic() { var cfg = new IgniteConfiguration() { }; _instance = Ignition.TryGetIgnite() ?? Ignition.Start(); var cache = _instance.CreateCache <int, Test3>("ab"); var retcur = cache.Query(new SqlQuery(typeof(Test3), "")); var itemlist = retcur.GetAll().Select(p => p.Value); }
public void TestStartUniqueName() { var cfg = TestUtils.GetTestConfiguration(); cfg.AutoGenerateIgniteInstanceName = true; Ignition.Start(cfg); Assert.IsNotNull(Ignition.GetIgnite()); Assert.IsNotNull(Ignition.TryGetIgnite()); Ignition.Start(cfg); Assert.Throws <IgniteException>(() => Ignition.GetIgnite()); Assert.IsNull(Ignition.TryGetIgnite()); Assert.AreEqual(2, Ignition.GetAll().Count); }
public string Invoke() { IIgnite ignite = Ignition.TryGetIgnite("TRex"); if (ignite != null) { ICache <string, MyCacheClass> cache = ignite.GetCache <string, MyCacheClass>("TestCache"); MyCacheClass c = cache.Get(s); return("Affinity: " + c.name); } else { Console.WriteLine("Unable to get Ignite instance with Ignition.TryGetIgnite()"); return("Affinity: <Error: No Ignite>"); } //return "Affinity: " + Ignition.TryGetIgnite().GetCache<String, MyCacheClass>("TestCache").Get(s).name; }
public void TestTwoServers() { var cfg1 = new IgniteConfiguration { SpringConfigUrl = @"config/start-test-grid1-ssl.xml", JvmOptions = TestUtils.TestJavaOptions(), JvmClasspath = TestUtils.CreateTestClasspath(), }; var cfg2 = new IgniteConfiguration { SpringConfigUrl = @"config/start-test-grid2.xml", JvmOptions = TestUtils.TestJavaOptions(), JvmClasspath = TestUtils.CreateTestClasspath(), SslContextFactory = GetSslContextFactory() }; var grid1 = Ignition.Start(cfg1); Assert.AreEqual("grid1", grid1.Name); Assert.AreSame(grid1, Ignition.GetIgnite()); Assert.AreSame(grid1, Ignition.GetAll().Single()); var grid2 = Ignition.Start(cfg2); Assert.AreEqual("grid2", grid2.Name); Assert.Throws <IgniteException>(() => Ignition.GetIgnite()); Assert.AreSame(grid1, Ignition.GetIgnite("grid1")); Assert.AreSame(grid1, Ignition.TryGetIgnite("grid1")); Assert.AreSame(grid2, Ignition.GetIgnite("grid2")); Assert.AreSame(grid2, Ignition.TryGetIgnite("grid2")); Assert.AreEqual(new[] { grid1, grid2 }, Ignition.GetAll().OrderBy(x => x.Name).ToArray()); Assert.AreEqual(2, grid1.GetCluster().GetNodes().Count); Assert.AreEqual(2, grid2.GetCluster().GetNodes().Count); Ignition.StopAll(true); }
/// <summary> /// Serializes and deserializes a value. /// </summary> private static void CheckSerializeDeserialize <T>(T val, bool cacheOnly = false) { if (!cacheOnly) { var marsh = GetMarshaller(); var res = marsh.Unmarshal <T>(marsh.Marshal(val)); Assert.AreEqual(val, res); } var ignite = Ignition.TryGetIgnite(); if (ignite != null) { var cache = ignite.GetOrCreateCache <int, T>(typeof(T).FullName); cache.Put(1, val); var res = cache.Get(1); Assert.AreEqual(val, res); } }
private static void AddDIEntries() { DIBuilder.Continue() .Add(x => x.AddSingleton <IActivatePersistentGridServer, ActivatePersistentGridServer>()) .Add(x => x.AddSingleton <Func <string, IgniteConfiguration, IIgnite> >(factory => (gridName, cfg) => Ignition.TryGetIgnite(gridName) ?? (cfg == null ? null : Ignition.Start(cfg)))) .Add(x => x.AddSingleton <ITRexGridFactory, TRexGridFactory>()); }
/// <summary> /// Gets the Ignite instance. /// </summary> private static IIgnite GetOrStartIgnite(IgniteConfiguration cfg) { cfg = cfg ?? new IgniteConfiguration(); return(Ignition.TryGetIgnite(cfg.IgniteInstanceName) ?? Ignition.Start(cfg)); }
public void TestStartGetStop() { var cfgs = new List <string> { "config\\start-test-grid1.xml", "config\\start-test-grid2.xml", "config\\start-test-grid3.xml" }; var cfg = new IgniteConfiguration { SpringConfigUrl = cfgs[0], JvmOptions = TestUtils.TestJavaOptions(), JvmClasspath = TestUtils.CreateTestClasspath() }; var grid1 = Ignition.Start(cfg); Assert.AreEqual("grid1", grid1.Name); Assert.AreSame(grid1, Ignition.GetIgnite()); Assert.AreSame(grid1, Ignition.GetAll().Single()); cfg.SpringConfigUrl = cfgs[1]; var grid2 = Ignition.Start(cfg); Assert.AreEqual("grid2", grid2.Name); Assert.Throws <IgniteException>(() => Ignition.GetIgnite()); cfg.SpringConfigUrl = cfgs[2]; var grid3 = Ignition.Start(cfg); Assert.IsNull(grid3.Name); Assert.AreSame(grid1, Ignition.GetIgnite("grid1")); Assert.AreSame(grid1, Ignition.TryGetIgnite("grid1")); Assert.AreSame(grid2, Ignition.GetIgnite("grid2")); Assert.AreSame(grid2, Ignition.TryGetIgnite("grid2")); Assert.AreSame(grid3, Ignition.GetIgnite(null)); Assert.AreSame(grid3, Ignition.GetIgnite()); Assert.AreSame(grid3, Ignition.TryGetIgnite(null)); Assert.AreSame(grid3, Ignition.TryGetIgnite()); Assert.AreEqual(new[] { grid3, grid1, grid2 }, Ignition.GetAll().OrderBy(x => x.Name).ToArray()); Assert.Throws <IgniteException>(() => Ignition.GetIgnite("invalid_name")); Assert.IsNull(Ignition.TryGetIgnite("invalid_name")); Assert.IsTrue(Ignition.Stop("grid1", true)); Assert.Throws <IgniteException>(() => Ignition.GetIgnite("grid1")); grid2.Dispose(); Assert.Throws <IgniteException>(() => Ignition.GetIgnite("grid2")); grid3.Dispose(); Assert.Throws <IgniteException>(() => Ignition.GetIgnite("grid3")); foreach (var cfgName in cfgs) { cfg.SpringConfigUrl = cfgName; cfg.JvmOptions = TestUtils.TestJavaOptions(); Ignition.Start(cfg); } foreach (var gridName in new List <string> { "grid1", "grid2", null }) { Assert.IsNotNull(Ignition.GetIgnite(gridName)); } Ignition.StopAll(true); foreach (var gridName in new List <string> { "grid1", "grid2", null }) { Assert.Throws <IgniteException>(() => Ignition.GetIgnite(gridName)); } }