public void StopGrids() { for (int i = 0; i < GridCnt; i++) { Ignition.Stop("grid-" + i, true); } }
public void TestBaselineTopology() { var cfg1 = new IgniteConfiguration(GetPersistentConfiguration()) { ConsistentId = "node1" }; var cfg2 = new IgniteConfiguration(GetPersistentConfiguration()) { ConsistentId = "node2", IgniteInstanceName = "2" }; using (var ignite = Ignition.Start(cfg1)) { // Start and stop to bump topology version. Ignition.Start(cfg2); Ignition.Stop(cfg2.IgniteInstanceName, true); var cluster = ignite.GetCluster(); Assert.AreEqual(3, cluster.TopologyVersion); // Can not set baseline while inactive. var ex = Assert.Throws <IgniteException>(() => cluster.SetBaselineTopology(2)); Assert.AreEqual("Changing BaselineTopology on inactive cluster is not allowed.", ex.Message); // Set with version. cluster.SetActive(true); cluster.SetBaselineTopology(2); var res = cluster.GetBaselineTopology(); CollectionAssert.AreEquivalent(new[] { "node1", "node2" }, res.Select(x => x.ConsistentId)); cluster.SetBaselineTopology(1); Assert.AreEqual("node1", cluster.GetBaselineTopology().Single().ConsistentId); // Set with nodes. cluster.SetBaselineTopology(res); res = cluster.GetBaselineTopology(); CollectionAssert.AreEquivalent(new[] { "node1", "node2" }, res.Select(x => x.ConsistentId)); cluster.SetBaselineTopology(cluster.GetTopology(1)); Assert.AreEqual("node1", cluster.GetBaselineTopology().Single().ConsistentId); // Set to two nodes. cluster.SetBaselineTopology(cluster.GetTopology(2)); } // Check auto activation on cluster restart. using (var ignite = Ignition.Start(cfg1)) using (Ignition.Start(cfg2)) { var cluster = ignite.GetCluster(); Assert.IsTrue(cluster.IsActive()); var res = cluster.GetBaselineTopology(); CollectionAssert.AreEquivalent(new[] { "node1", "node2" }, res.Select(x => x.ConsistentId)); } }
private void StopGrid(StorageMutability mutability) { if (_igniteGrids[(int)mutability] != null) { Ignition.Stop(_igniteGrids[(int)mutability].Name, false); _igniteGrids[(int)mutability] = null; } }
public void TestClusterRestart_ResetsCachedMetadataAndWriterStructures() { var serverCfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { CacheConfiguration = new[] { new CacheConfiguration(CacheName) } }; var clientCfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { IgniteInstanceName = "client", ClientMode = true }; var server = Ignition.Start(serverCfg); var client = Ignition.Start(clientCfg); Assert.AreEqual(2, client.GetCluster().GetNodes().Count); var localNode = client.GetCluster().GetLocalNode(); var nodes = client.GetCluster().GetNodes(); var evt = new ManualResetEventSlim(false); client.ClientReconnected += (sender, args) => evt.Set(); var cache = client.GetCache <int, Person>(CacheName); cache[1] = new Person(1); Task.Factory.StartNew(() => { while (!evt.IsSet) { try { cache[1] = new Person(1); } catch (Exception) { // Ignore exceptions while disconnected, keep on trying to populate writer structure cache. } } }); Ignition.Stop(server.Name, true); var server2 = Ignition.Start(serverCfg); evt.Wait(); // Verify that we can deserialize on server (meta is resent properly). cache[2] = new Person(2); var serverCache = server2.GetCache <int, Person>(CacheName); Assert.AreEqual(2, serverCache[2].Id); // Verify that cached node info is updated on the client. CheckUpdatedNodes(client, localNode, nodes); }
public void Run() { var ignite = Ignition.Start(new IgniteConfiguration(TestUtils.GetTestConfiguration()) { GridName = "newDomainGrid" }); Ignition.Stop(ignite.Name, true); }
public void TestClusterRestart() { var serverCfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { CacheConfiguration = new[] { new CacheConfiguration(CacheName) } }; var clientCfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { GridName = "client", ClientMode = true }; var server = Ignition.Start(serverCfg); var client = Ignition.Start(clientCfg); ClientReconnectEventArgs eventArgs = null; client.ClientReconnected += (sender, args) => { eventArgs = args; }; var cache = client.GetCache <int, int>(CacheName); cache[1] = 1; Ignition.Stop(server.Name, true); var cacheEx = Assert.Throws <CacheException>(() => cache.Get(1)); var ex = cacheEx.InnerException as ClientDisconnectedException; Assert.IsNotNull(ex); // Start the server and wait for reconnect. Ignition.Start(serverCfg); Assert.IsTrue(ex.ClientReconnectTask.Result); // Check the event args. Thread.Sleep(100); // Wait for event handler Assert.IsNotNull(eventArgs); Assert.IsTrue(eventArgs.HasClusterRestarted); // Refresh the cache instance and check that it works. var cache1 = client.GetCache <int, int>(CacheName); Assert.AreEqual(0, cache1.GetSize()); cache1[1] = 2; Assert.AreEqual(2, cache1[1]); // Check that old cache instance does not work. var cacheEx1 = Assert.Throws <InvalidOperationException>(() => cache.Get(1)); Assert.AreEqual("Cache has been closed or destroyed: " + CacheName, cacheEx1.Message); }
public void TestTopologyVersion() { var cluster = _grid1.GetCluster(); var topVer = cluster.TopologyVersion; Ignition.Stop(_grid3.Name, true); Assert.AreEqual(topVer + 1, _grid1.GetCluster().TopologyVersion); _grid3 = Ignition.Start(Configuration(GetConfigs().Item3)); Assert.AreEqual(topVer + 2, _grid1.GetCluster().TopologyVersion); }
public void TestDisposeDoesNotThrow() { var ignite = Ignition.Start(new IgniteConfiguration(GetConfig()) { IgniteInstanceName = TestUtils.TestName }); var tx = ignite.GetTransactions().TxStart(); var transactions = ignite.GetTransactions().GetLocalActiveTransactions(); Ignition.Stop(ignite.Name, true); Assert.DoesNotThrow(() => tx.Dispose()); Assert.DoesNotThrow(() => transactions.Dispose()); }
public void TestFailover() { // Start 3 nodes. Ignition.Start(TestUtils.GetTestConfiguration(name: "0")); Ignition.Start(TestUtils.GetTestConfiguration(name: "1")); Ignition.Start(TestUtils.GetTestConfiguration(name: "2")); // Connect client. var port = IgniteClientConfiguration.DefaultPort; var cfg = new IgniteClientConfiguration { Endpoints = new[] { "localhost", string.Format("127.0.0.1:{0}..{1}", port + 1, port + 2) } }; using (var client = Ignition.StartClient(cfg)) { Assert.AreEqual(0, client.GetCacheNames().Count); // Stop target node. var nodeId = ((IPEndPoint)client.RemoteEndPoint).Port - port; Ignition.Stop(nodeId.ToString(), true); // Check failure. Assert.IsNotNull(GetSocketException(Assert.Catch(() => client.GetCacheNames()))); // Check reconnect. Assert.AreEqual(0, client.GetCacheNames().Count); // Stop target node. nodeId = ((IPEndPoint)client.RemoteEndPoint).Port - port; Ignition.Stop(nodeId.ToString(), true); // Check failure. Assert.IsNotNull(GetSocketException(Assert.Catch(() => client.GetCacheNames()))); // Check reconnect. Assert.AreEqual(0, client.GetCacheNames().Count); // Stop all nodes. Ignition.StopAll(true); Assert.IsNotNull(GetSocketException(Assert.Catch(() => client.GetCacheNames()))); Assert.IsNotNull(GetSocketException(Assert.Catch(() => client.GetCacheNames()))); } }
public void TestWithBeans() { // 1. Test .Net start events. IIgnite grid = Start(CfgBeans); Assert.AreEqual(2, grid.GetConfiguration().LifecycleHandlers.Count); Assert.AreEqual(4, BeforeStartEvts.Count); CheckEvent(BeforeStartEvts[0], null, null, 0, null); CheckEvent(BeforeStartEvts[1], null, null, 1, "1"); CheckEvent(BeforeStartEvts[2], null, null, 0, null); CheckEvent(BeforeStartEvts[3], null, null, 0, null); Assert.AreEqual(4, AfterStartEvts.Count); CheckEvent(AfterStartEvts[0], grid, grid, 0, null); CheckEvent(AfterStartEvts[1], grid, grid, 1, "1"); CheckEvent(AfterStartEvts[2], grid, grid, 0, null); CheckEvent(AfterStartEvts[3], grid, grid, 0, null); // 2. Test Java start events. var res = grid.GetCompute().ExecuteJavaTask <IList>( "org.apache.ignite.platform.lifecycle.PlatformJavaLifecycleTask", null); Assert.AreEqual(2, res.Count); Assert.AreEqual(3, res[0]); Assert.AreEqual(3, res[1]); // 3. Test .Net stop events. Ignition.Stop(grid.Name, false); Assert.AreEqual(4, BeforeStartEvts.Count); Assert.AreEqual(4, AfterStartEvts.Count); Assert.AreEqual(4, BeforeStopEvts.Count); CheckEvent(BeforeStopEvts[0], grid, grid, 0, null); CheckEvent(BeforeStopEvts[1], grid, grid, 1, "1"); CheckEvent(BeforeStopEvts[2], grid, grid, 0, null); CheckEvent(BeforeStopEvts[3], grid, grid, 0, null); Assert.AreEqual(4, AfterStopEvts.Count); CheckEvent(AfterStopEvts[0], grid, grid, 0, null); CheckEvent(AfterStopEvts[1], grid, grid, 1, "1"); CheckEvent(AfterStopEvts[2], grid, grid, 0, null); CheckEvent(AfterStopEvts[3], grid, grid, 0, null); }
public void TestIgniteStartsWithDefaultConfig() { var ignite = Ignition.Start(TestUtils.GetTestConfiguration()); Assert.IsNotNull(ignite); Assert.AreEqual(ignite, Ignition.GetIgnite()); // Second node. var ignite2 = Ignition.Start(TestUtils.GetTestConfiguration(name: "ignite-2")); Assert.AreEqual(2, Ignition.GetAll().Count); // Stop node. Ignition.Stop(ignite.Name, true); Assert.AreEqual(ignite2, Ignition.GetIgnite()); // Stop all. Ignition.StopAll(true); Assert.AreEqual(0, Ignition.GetAll().Count); }
public void TestNoCacheNode() { const string cacheName = "cache"; var cacheNodeCfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { SpringConfigUrl = @"Config\cache-local-node.xml", IgniteInstanceName = "cacheGrid" }; using (var gridNoCache = Ignition.Start(TestUtils.GetTestConfiguration())) { Assert.Throws <ArgumentException>(() => gridNoCache.GetCache <int, int>(cacheName)); var gridWithCache = Ignition.Start(cacheNodeCfg); var streamer = gridNoCache.GetDataStreamer <int, int>(cacheName); streamer.AddData(1, 2); streamer.Flush(); Ignition.Stop(gridWithCache.Name, true); Thread.Sleep(500); // Wait for node to stop var task = streamer.AddData(2, 3); streamer.Flush(); var ex = Assert.Throws <AggregateException>(task.Wait).InnerException; Assert.IsNotNull(ex); Assert.AreEqual("Java exception occurred [class=org.apache.ignite.cache." + "CacheServerNotFoundException, message=Failed to find server node for cache " + "(all affinity nodes have left the grid or cache was stopped): cache]", ex.Message); } }
public void TestWithoutBeans() { // 1. Test start events. IIgnite grid = Start(CfgNoBeans); Assert.AreEqual(2, grid.GetConfiguration().LifecycleHandlers.Count); Assert.AreEqual(2, BeforeStartEvts.Count); CheckEvent(BeforeStartEvts[0], null, null, 0, null); CheckEvent(BeforeStartEvts[1], null, null, 0, null); Assert.AreEqual(2, AfterStartEvts.Count); CheckEvent(AfterStartEvts[0], grid, grid, 0, null); CheckEvent(AfterStartEvts[1], grid, grid, 0, null); // 2. Test stop events. var stoppingCnt = 0; var stoppedCnt = 0; grid.Stopping += (sender, args) => { stoppingCnt++; }; grid.Stopped += (sender, args) => { stoppedCnt++; }; Ignition.Stop(grid.Name, false); Assert.AreEqual(1, stoppingCnt); Assert.AreEqual(1, stoppedCnt); Assert.AreEqual(2, BeforeStartEvts.Count); Assert.AreEqual(2, AfterStartEvts.Count); Assert.AreEqual(2, BeforeStopEvts.Count); CheckEvent(BeforeStopEvts[0], grid, grid, 0, null); CheckEvent(BeforeStopEvts[1], grid, grid, 0, null); Assert.AreEqual(2, AfterStopEvts.Count); CheckEvent(AfterStopEvts[0], grid, grid, 0, null); CheckEvent(AfterStopEvts[1], grid, grid, 0, null); }
public void Test_ScanQueryAfterClientReconnect_ReturnsResults([Values(true, false)] bool emptyFilterObject) { var cache = _client.GetOrCreateCache <int, Item>("Test"); cache.Put(1, new Item { Id = 20, Title = "test" }); Ignition.Stop(_server.Name, false); var evt = new ManualResetEventSlim(false); _client.ClientReconnected += (sender, args) => evt.Set(); _server = StartGrid(0); var restarted = evt.Wait(10000); Assert.IsTrue(restarted); cache = _client.GetOrCreateCache <int, Item>("Test"); cache.Put(1, new Item { Id = 30, Title = "test" }); var filter = emptyFilterObject ? (ICacheEntryFilter <int, Item>) new TestFilter() : new TestFilterWithField { TestValue = 9 }; var cursor = cache.Query(new ScanQuery <int, Item>(filter)); var items = cursor.GetAll(); Assert.AreEqual(30, items.Single().Value.Id); }
public void StopClient() { if (Grid1 != null) { Ignition.Stop(Grid1.Name, true); } if (_fork) { if (_proc2 != null) { _proc2.Kill(); _proc2.Join(); } if (_proc3 != null) { _proc3.Kill(); _proc3.Join(); } } else { if (_grid2 != null) { Ignition.Stop(_grid2.Name, true); } if (_grid3 != null) { Ignition.Stop(_grid3.Name, true); } } }
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)); } }
public void Dispose() { Ignition.Stop(Name, true); }
/// <summary> /// Tests CachePartialUpdateException keys propagation. /// </summary> private static void TestPartialUpdateException <TK>(bool async, Func <int, IIgnite, TK> keyFunc) { using (var grid = StartGrid()) { var cache = grid.GetOrCreateCache <TK, int>("partitioned_atomic").WithNoRetries(); if (typeof(TK) == typeof(IBinaryObject)) { cache = cache.WithKeepBinary <TK, int>(); } // Do cache puts in parallel var putTask = TaskRunner.Run(() => { try { // Do a lot of puts so that one fails during Ignite stop for (var i = 0; i < 1000000; i++) { // ReSharper disable once AccessToDisposedClosure // ReSharper disable once AccessToModifiedClosure var dict = Enumerable.Range(1, 100).ToDictionary(k => keyFunc(k, grid), k => i); if (async) { cache.PutAllAsync(dict).Wait(); } else { cache.PutAll(dict); } } } catch (AggregateException ex) { CheckPartialUpdateException <TK>((CachePartialUpdateException)ex.InnerException); return; } catch (CachePartialUpdateException ex) { CheckPartialUpdateException <TK>(ex); return; } Assert.Fail("CachePartialUpdateException has not been thrown."); }); while (true) { Thread.Sleep(1000); Ignition.Stop("grid_2", true); StartGrid("grid_2"); Thread.Sleep(1000); if (putTask.Exception != null) { throw putTask.Exception; } if (putTask.IsCompleted) { return; } } } }
public void StopGrids() { Ignition.Stop(GridData, true); Ignition.Stop(GridDataNoCfg, true); Ignition.Stop(GridClient, true); }
public void TestClusterRestart() { var serverCfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { CacheConfiguration = new[] { new CacheConfiguration(CacheName) } }; var clientCfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) { IgniteInstanceName = "client", ClientMode = true }; var server = Ignition.Start(serverCfg); Assert.AreEqual(1, server.GetCluster().GetNodes().Count); var client = Ignition.Start(clientCfg); Assert.AreEqual(2, client.GetCluster().GetNodes().Count); ClientReconnectEventArgs eventArgs = null; client.ClientReconnected += (sender, args) => { eventArgs = args; }; var cache = client.GetCache <int, Person>(CacheName); cache[1] = new Person(1); Ignition.Stop(server.Name, true); var cacheEx = Assert.Throws <CacheException>(() => cache.Get(1)); var ex = cacheEx.InnerException as ClientDisconnectedException; Assert.IsNotNull(ex); // Wait a bit for cluster restart detection. Thread.Sleep(1000); // Start the server and wait for reconnect. Ignition.Start(serverCfg); // Check reconnect task. Assert.IsTrue(ex.ClientReconnectTask.Result); // Wait a bit for notifications. Thread.Sleep(100); // Check the event args. Assert.IsNotNull(eventArgs); Assert.IsTrue(eventArgs.HasClusterRestarted); // Refresh the cache instance and check that it works. var cache1 = client.GetCache <int, Person>(CacheName); Assert.AreEqual(0, cache1.GetSize()); cache1[1] = new Person(2); Assert.AreEqual(2, cache1[1].Id); // Check that old cache instance still works. Assert.AreEqual(2, cache.Get(1).Id); }
public void TestFailoverWithRetryPolicyCompletesOperationWithoutException( [Values(true, false)] bool async, [Values(true, false)] bool partitionAware) { // Start 3 nodes. Func <string, IgniteConfiguration> getConfig = name => new IgniteConfiguration(TestUtils.GetTestConfiguration(name: name)) { ClientConnectorConfiguration = new ClientConnectorConfiguration { ThinClientConfiguration = new ThinClientConfiguration { MaxActiveComputeTasksPerConnection = 1 } } }; Ignition.Start(getConfig("0")); Ignition.Start(getConfig("1")); Ignition.Start(getConfig("2")); // Connect client. var port = IgniteClientConfiguration.DefaultPort; var cfg = new IgniteClientConfiguration { Endpoints = new[] { "localhost", string.Format("127.0.0.1:{0}..{1}", port + 1, port + 2) }, RetryPolicy = new ClientRetryAllPolicy(), RetryLimit = 3, EnablePartitionAwareness = partitionAware }; // ReSharper disable AccessToDisposedClosure using (var client = Ignition.StartClient(cfg)) { var cache = client.GetOrCreateCache <int, int>("c"); // Check all DoOp overloads. Action checkOperation = partitionAware ? async ? (Action)(() => Assert.IsFalse(cache.ContainsKeyAsync(1).Result)) : () => Assert.IsFalse(cache.ContainsKey(1)) : async ? (Action)(() => Assert.IsNotNull(client.GetCompute().ExecuteJavaTaskAsync <object>( ComputeClientTests.TestTask, null).Result)) : () => Assert.AreEqual(1, client.GetCacheNames().Count); checkOperation(); // Stop first node. var nodeId = ((IPEndPoint)client.RemoteEndPoint).Port - port; Ignition.Stop(nodeId.ToString(), true); checkOperation(); // Stop second node. nodeId = ((IPEndPoint)client.RemoteEndPoint).Port - port; Ignition.Stop(nodeId.ToString(), true); checkOperation(); // Stop all nodes. Ignition.StopAll(true); Assert.IsNotNull(GetSocketException(Assert.Catch(() => client.GetCacheNames()))); Assert.IsNotNull(GetSocketException(Assert.Catch(() => client.GetCacheNames()))); } }
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); cfg.SpringConfigUrl = cfgs[1]; var grid2 = Ignition.Start(cfg); Assert.AreEqual("grid2", grid2.Name); cfg.SpringConfigUrl = cfgs[2]; var grid3 = Ignition.Start(cfg); Assert.IsNull(grid3.Name); Assert.AreSame(grid1, Ignition.GetIgnite("grid1")); Assert.AreSame(grid2, Ignition.GetIgnite("grid2")); Assert.AreSame(grid3, Ignition.GetIgnite(null)); try { Ignition.GetIgnite("invalid_name"); } catch (IgniteException e) { Console.WriteLine("Expected exception: " + e); } Assert.IsTrue(Ignition.Stop("grid1", true)); try { Ignition.GetIgnite("grid1"); } catch (IgniteException e) { Console.WriteLine("Expected exception: " + e); } grid2.Dispose(); try { Ignition.GetIgnite("grid2"); } catch (IgniteException e) { Console.WriteLine("Expected exception: " + e); } grid3.Dispose(); try { Ignition.GetIgnite(null); } catch (IgniteException e) { Console.WriteLine("Expected exception: " + e); } 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 }) { try { Ignition.GetIgnite(gridName); } catch (IgniteException e) { Console.WriteLine("Expected exception: " + e); } } }
public static void Stop(string name) => Ignition.Stop(name, false);
public void TestFailover() { // Start 3 nodes. Ignition.Start(TestUtils.GetTestConfiguration(name: "0")); Ignition.Start(TestUtils.GetTestConfiguration(name: "1")); Ignition.Start(TestUtils.GetTestConfiguration(name: "2")); // Connect client. var port = IgniteClientConfiguration.DefaultPort; var cfg = new IgniteClientConfiguration { Endpoints = new[] { "localhost", string.Format("127.0.0.1:{0}..{1}", port + 1, port + 2) } }; // ReSharper disable AccessToDisposedClosure using (var client = Ignition.StartClient(cfg)) { Assert.AreEqual(0, client.GetCacheNames().Count); Action checkReconnect = () => { // First operation may fail or may not. // Sometimes the client will switch to another socket in background due to // OnAffinityTopologyVersionChange callback. var timeout = DateTime.Now.AddSeconds(0.3); while (DateTime.Now < timeout) { try { Assert.AreEqual(0, client.GetCacheNames().Count); break; } catch (Exception e) { Assert.IsNotNull(GetSocketException(e)); } } }; // Stop first node. var nodeId = ((IPEndPoint)client.RemoteEndPoint).Port - port; Ignition.Stop(nodeId.ToString(), true); checkReconnect(); // Stop second node. nodeId = ((IPEndPoint)client.RemoteEndPoint).Port - port; Ignition.Stop(nodeId.ToString(), true); checkReconnect(); // Stop all nodes. Ignition.StopAll(true); Assert.IsNotNull(GetSocketException(Assert.Catch(() => client.GetCacheNames()))); Assert.IsNotNull(GetSocketException(Assert.Catch(() => client.GetCacheNames()))); } }
public void TestBaselineTopology() { using (EnvVar.Set("IGNITE_BASELINE_AUTO_ADJUST_ENABLED", "false")) { var cfg1 = new IgniteConfiguration(GetPersistentConfiguration()) { ConsistentId = "node1" }; var cfg2 = new IgniteConfiguration(GetPersistentConfiguration()) { ConsistentId = "node2", IgniteInstanceName = "2" }; using (var ignite = Ignition.Start(cfg1)) { // Start and stop to bump topology version. Ignition.Start(cfg2); Ignition.Stop(cfg2.IgniteInstanceName, true); var cluster = ignite.GetCluster(); Assert.AreEqual(3, cluster.TopologyVersion); // Can not set baseline while inactive. var ex = Assert.Throws <IgniteException>(() => cluster.SetBaselineTopology(2)); Assert.AreEqual("Changing BaselineTopology on inactive cluster is not allowed.", ex.Message); cluster.SetActive(true); // Can not set baseline with offline node. ex = Assert.Throws <IgniteException>(() => cluster.SetBaselineTopology(2)); Assert.AreEqual("Check arguments. Node with consistent ID [node2] not found in server nodes.", ex.Message); cluster.SetBaselineTopology(1); Assert.AreEqual("node1", cluster.GetBaselineTopology().Single().ConsistentId); // Set with node. cluster.SetBaselineTopology(cluster.GetBaselineTopology()); var res = cluster.GetBaselineTopology(); CollectionAssert.AreEquivalent(new[] { "node1" }, res.Select(x => x.ConsistentId)); cluster.SetBaselineTopology(cluster.GetTopology(1)); Assert.AreEqual("node1", cluster.GetBaselineTopology().Single().ConsistentId); // Can not set baseline with offline node. ex = Assert.Throws <IgniteException>(() => cluster.SetBaselineTopology(cluster.GetTopology(2))); Assert.AreEqual("Check arguments. Node with consistent ID [node2] not found in server nodes.", ex.Message); } // Check auto activation on cluster restart. using (var ignite = Ignition.Start(cfg1)) using (Ignition.Start(cfg2)) { var cluster = ignite.GetCluster(); Assert.IsTrue(cluster.IsActive()); var res = cluster.GetBaselineTopology(); CollectionAssert.AreEquivalent(new[] { "node1" }, res.Select(x => x.ConsistentId)); } } }
/// <summary> /// Tests CachePartialUpdateException keys propagation. /// </summary> private static void TestPartialUpdateException <TK>(bool async, Func <int, IIgnite, TK> keyFunc) { using (var grid = StartGrid()) { var cache = grid.Cache <TK, int>("partitioned_atomic").WithNoRetries(); if (async) { cache = cache.WithAsync(); } if (typeof(TK) == typeof(IPortableObject)) { cache = cache.WithKeepPortable <TK, int>(); } // Do cache puts in parallel var putTask = Task.Factory.StartNew(() => { try { // Do a lot of puts so that one fails during Ignite stop for (var i = 0; i < 1000000; i++) { cache.PutAll(Enumerable.Range(1, 100).ToDictionary(k => keyFunc(k, grid), k => i)); if (async) { cache.GetFuture().Get(); } } } catch (CachePartialUpdateException ex) { var failedKeys = ex.GetFailedKeys <TK>(); Assert.IsTrue(failedKeys.Any()); var failedKeysObj = ex.GetFailedKeys <object>(); Assert.IsTrue(failedKeysObj.Any()); return; } Assert.Fail("CachePartialUpdateException has not been thrown."); }); while (true) { Ignition.Stop("grid_2", true); StartGrid("grid_2"); if (putTask.Exception != null) { throw putTask.Exception; } if (putTask.IsCompleted) { return; } } } }
public void Terminate() { Ignition.Stop(Ignite.Name, true); }
public void Stop() { Ignition.Stop(Ignite.Name, false); }