public IgniteViewModel() { Task.Run(() => { var cfg = new IgniteClientConfiguration { Host = "127.0.0.1" }; try { Console.WriteLine("Connecting..."); _client = Ignition.StartClient(cfg); var cacheNames = _client.GetCacheNames(); Status = $"Connected to Ignite cluster. Found {cacheNames.Count} caches."; Caches = cacheNames.Select(x => new CacheViewModel(_client, x)).ToArray(); Console.WriteLine("CONNECTED."); } catch (Exception e) { Status = "Failed to connect: " + e; Console.WriteLine(e); throw; } }); }
public void TestReconnectToOldNodeDisablesPartitionAwareness() { IIgniteClient client = null; var clientConfiguration = new IgniteClientConfiguration(JavaServer.GetClientConfiguration()) { EnablePartitionAwareness = true, Logger = new ListLogger(new ConsoleLogger { MinLevel = LogLevel.Trace }) }; try { using (StartNewServer()) { client = Ignition.StartClient(clientConfiguration); var cache = client.GetOrCreateCache <int, int>(TestContext.CurrentContext.Test.Name); cache.Put(1, 42); Assert.AreEqual(42, cache.Get(1)); Assert.IsTrue(client.GetConfiguration().EnablePartitionAwareness); } Assert.Catch(() => client.GetCacheNames()); using (StartOldServer()) { var cache = client.GetOrCreateCache <int, int>(TestContext.CurrentContext.Test.Name); cache.Put(1, 42); Assert.AreEqual(42, cache.Get(1)); Assert.IsFalse(client.GetConfiguration().EnablePartitionAwareness); var log = ((ListLogger)client.GetConfiguration().Logger).Entries .FirstOrDefault(e => e.Message.StartsWith("Partition")); Assert.IsNotNull(log); Assert.AreEqual("Partition awareness has been disabled: " + "server protocol version 1.0.0 is lower than required 1.4.0", log.Message); } } finally { if (client != null) { client.Dispose(); } } }
/// <summary> /// Asserts client connection count. /// </summary> protected static void AssertClientConnectionCount(IIgniteClient client, int count) { var res = TestUtils.WaitForCondition(() => { // Perform any operation to cause topology update. try { client.GetCacheNames(); } catch (Exception) { // Ignore. } return(count == client.GetConnections().Count()); }, 9000); if (!res) { Assert.Fail("Client connection count mismatch: expected {0}, but was {1}", count, client.GetConnections().Count()); } var cluster = Ignition.GetAll().First().GetCluster(); foreach (var connection in client.GetConnections()) { var server = cluster.GetNode(connection.NodeId); Assert.IsNotNull(server); var remoteEndPoint = (IPEndPoint)connection.RemoteEndPoint; Assert.AreEqual(server.GetAttribute <int>("clientListenerPort"), remoteEndPoint.Port); var ipAddresses = server.Addresses .Select(a => a.Split('%').First()) // Trim IPv6 scope. .Select(IPAddress.Parse) .ToArray(); CollectionAssert.Contains(ipAddresses, remoteEndPoint.Address); var localEndPoint = (IPEndPoint)connection.LocalEndPoint; CollectionAssert.Contains(new[] { IPAddress.Loopback, IPAddress.IPv6Loopback }, localEndPoint.Address); } }