Esempio n. 1
0
 public void TestFixtureSetUp()
 {
     Ignition.Start(GetConfig());
 }
Esempio n. 2
0
 public void test()
 {
     using (var ignite = Ignition.Start()) {
     }
 }
Esempio n. 3
0
        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));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the Ignite instance.
        /// </summary>
        private static IIgnite GetOrStartIgnite(IgniteConfiguration cfg)
        {
            cfg = cfg ?? new IgniteConfiguration();

            return(Ignition.TryGetIgnite(cfg.GridName) ?? Ignition.Start(cfg));
        }
Esempio n. 5
0
        /// <summary>
        ///  Starts test grids.
        /// </summary>
        private static void StartGrids()
        {
            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
            {
                DataStorageConfiguration = new DataStorageConfiguration
                {
                    WalMode                            = WalMode.Fsync,
                    WalSegmentSize                     = 16 * 1 << 20, // 16 MB.
                        PageSize                       = 1 << 10,      // 1 KB.
                        MetricsEnabled                 = true,
                        CheckpointFrequency            = CheckpointFrequency,
                        DefaultDataRegionConfiguration = new DataRegionConfiguration
                            {
                            Name = PersistenceRegionName,
                            PersistenceEnabled = true,
                            MetricsEnabled     = true,
                            MaxSize            = 50 * 1 << 20 // 50 MB.
                        },
                        DataRegionConfigurations = new[]
                            {
                            new DataRegionConfiguration
                            {
                                Name               = MemoryRegionName,
                                MetricsEnabled     = true,
                                PersistenceEnabled = false,
                                MaxSize            = 10 * 1 << 20 // 10 MB.
                            }
                        },
                },
                WorkDirectory      = TempDir,
                CacheConfiguration = new List <CacheConfiguration>
                {
                    new CacheConfiguration(MemCacheName)
                    {
                        WriteSynchronizationMode = CacheWriteSynchronizationMode.FullSync,
                        AtomicityMode            = CacheAtomicityMode.Transactional,
                        AffinityFunction         = new RendezvousAffinityFunction
                        {
                            ExcludeNeighbors = false,
                            Partitions       = 32
                        },
                        Backups        = 1,
                        DataRegionName = MemoryRegionName,
                    },
                    new CacheConfiguration(PersistenceCacheName)
                    {
                        WriteSynchronizationMode = CacheWriteSynchronizationMode.FullSync,
                        AtomicityMode            = CacheAtomicityMode.Transactional,
                        AffinityFunction         = new RendezvousAffinityFunction
                        {
                            ExcludeNeighbors = false,
                            Partitions       = 32
                        },
                        Backups        = 1,
                        DataRegionName = PersistenceRegionName
                    }
                }
            };

            for (int i = 0; i < GridCount; i++)
            {
                cfg.IgniteInstanceName = "grid-" + i;
                cfg.ConsistentId       = "grid-" + i;

                Ignition.Start(cfg);
            }

            cfg.IgniteInstanceName = "client";
            cfg.ClientMode         = true;

            var client = Ignition.Start(cfg);

            client.GetCluster().SetActive(true);
        }
Esempio n. 6
0
 public void TestSetUp()
 {
     // Start fresh cluster for each test
     _grid       = Ignition.Start(Config("config\\compute\\compute-grid1.xml"));
     _clientGrid = Ignition.Start(Config("config\\compute\\compute-grid3.xml"));
 }
Esempio n. 7
0
        /// <summary>
        /// Application entry point.
        /// </summary>
        internal static void Main(string[] args)
        {
            IgniteConfiguration cfg;

            bool svc     = false;
            bool install = false;

            try
            {
                // Check for special cases.
                if (args.Length > 0)
                {
                    string first = args[0].ToLower();

                    if (Help.Contains(first))
                    {
                        PrintHelp();

                        return;
                    }

                    if (Svc.Equals(first))
                    {
                        args = RemoveFirstArg(args);

                        svc = true;
                    }

                    else if (SvcInstall.Equals(first))
                    {
                        args = RemoveFirstArg(args);

                        install = true;
                    }
                    else if (SvcUninstall.Equals(first))
                    {
                        IgniteService.Uninstall();

                        return;
                    }
                }

                if (!svc)
                {
                    // Pick application configuration.
                    cfg = new IgniteConfiguration();

                    new AppSettingsConfigurator().Configure(cfg, ConfigurationManager.AppSettings);

                    // Pick command line arguments.
                    new ArgsConfigurator().Configure(cfg, args);

                    if (install)
                    {
                        IgniteService.DoInstall(cfg);
                    }
                    else
                    {
                        Ignition.Start(cfg);

                        IgniteManager.DestroyJvm();
                    }

                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: " + e.Message);

                Environment.Exit(-1);
            }

            // If we are here, then this is a service call.
            cfg = new IgniteConfiguration();

            // Use only arguments, not app.config.
            new ArgsConfigurator().Configure(cfg, args);

            ServiceBase.Run(new IgniteService(cfg));
        }
Esempio n. 8
0
        public void TestCompactFooterOnline()
        {
            var ignite = Ignition.Start(TestUtils.GetTestConfiguration());

            TestOffsets(() => ((Ignite)ignite).Marshaller);
        }
Esempio n. 9
0
 public IIgnite Start()
 {
     return(Ignition.Start(_clientCfg));
 }
Esempio n. 10
0
 public void TestInvalidMarshaller()
 {
     Assert.Throws <IgniteException>(() => Ignition.Start("config\\marshaller-invalid.xml"));
 }
Esempio n. 11
0
        public void TestQueryEntityConfiguration()
        {
            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
            {
                BinaryConfiguration = new BinaryConfiguration(typeof(QueryPerson)),
                CacheConfiguration  = new[]
                {
                    new CacheConfiguration(CacheName, new QueryEntity(typeof(int), typeof(QueryPerson))
                    {
                        TableName = "CustomTableName",
                        Fields    = new[]
                        {
                            new QueryField("Name", typeof(string)),
                            new QueryField("Age", typeof(int)),
                            new QueryField("Birthday", typeof(DateTime)),
                        },
                        Indexes = new[]
                        {
                            new QueryIndex
                            {
                                InlineSize = 2048,
                                IndexType  = QueryIndexType.FullText,
                                Fields     = new[]
                                {
                                    new QueryIndexField
                                    {
                                        IsDescending = false,
                                        Name         = "Name"
                                    }
                                }
                            },
                            new QueryIndex("Age")
                        }
                    })
                }
            };

            using (var ignite = Ignition.Start(cfg))
            {
                var cache = ignite.GetCache <int, QueryPerson>(CacheName);

                Assert.IsNotNull(cache);

                cache[1] = new QueryPerson("Arnold", 10);
                cache[2] = new QueryPerson("John", 20);

                using (var cursor = cache.Query(new SqlQuery(typeof(QueryPerson), "age > ? and birthday < ?",
                                                             10, DateTime.UtcNow)))
                {
                    Assert.AreEqual(2, cursor.GetAll().Single().Key);
                }

                using (var cursor = cache.Query(new SqlFieldsQuery(
                                                    "select _key from CustomTableName where age > ? and birthday < ?", 10, DateTime.UtcNow)))
                {
                    Assert.AreEqual(2, cursor.GetAll().Single()[0]);
                }

                using (var cursor = cache.Query(new TextQuery(typeof(QueryPerson), "Ar*")))
                {
                    Assert.AreEqual(1, cursor.GetAll().Single().Key);
                }
            }
        }
Esempio n. 12
0
        public static void Main()
        {
            var cfg = new IgniteConfiguration
            {
                SpringConfigUrl = @"platforms\dotnet\examples\config\examples-config.xml",
                JvmOptions      = new List <string> {
                    "-Xms512m", "-Xmx512m"
                }
            };

            using (var ignite = Ignition.Start(cfg))
            {
                Console.WriteLine();
                Console.WriteLine(">>> Cache store example started.");

                var cache = ignite.GetOrCreateCache <int, Employee>(new CacheConfiguration
                {
                    Name              = CacheName,
                    ReadThrough       = true,
                    WriteThrough      = true,
                    CacheStoreFactory = new EmployeeStoreFactory()
                });

                // Clean up caches on all nodes before run.
                cache.Clear();

                Console.WriteLine();
                Console.WriteLine(">>> Cleared values from cache.");
                Console.WriteLine(">>> Current cache size: " + cache.GetSize());

                // Load entries from store which pass provided filter.
                cache.LoadCache(new EmployeeStorePredicate());

                Console.WriteLine();
                Console.WriteLine(">>> Loaded entry from store through ICache.LoadCache().");
                Console.WriteLine(">>> Current cache size: " + cache.GetSize());

                // Load entry from store calling ICache.Get() method.
                Employee emp = cache.Get(2);

                Console.WriteLine();
                Console.WriteLine(">>> Loaded entry from store through ICache.Get(): " + emp);
                Console.WriteLine(">>> Current cache size: " + cache.GetSize());

                // Put an entry to the cache
                cache.Put(3, new Employee(
                              "James Wilson",
                              12500,
                              new Address("1096 Eddy Street, San Francisco, CA", 94109),
                              new List <string> {
                    "Human Resources", "Customer Service"
                }
                              ));

                Console.WriteLine();
                Console.WriteLine(">>> Put entry to cache. ");
                Console.WriteLine(">>> Current cache size: " + cache.GetSize());

                // Clear values again.
                cache.Clear();

                Console.WriteLine();
                Console.WriteLine(">>> Cleared values from cache again.");
                Console.WriteLine(">>> Current cache size: " + cache.GetSize());

                // Read values from cache after clear.
                Console.WriteLine();
                Console.WriteLine(">>> Read values after clear:");

                for (int i = 1; i <= 3; i++)
                {
                    Console.WriteLine(">>>     Key=" + i + ", value=" + cache.Get(i));
                }
            }

            Console.WriteLine();
            Console.WriteLine(">>> Example finished, press any key to exit ...");
            Console.ReadKey();
        }
Esempio n. 13
0
 /** <inheritDoc /> */
 protected override void OnStart(string[] args)
 {
     Ignition.Start(_cfg);
 }
Esempio n. 14
0
        public void TestAllConfigurationProperties()
        {
            var cfg = new IgniteConfiguration(GetCustomConfig());

            using (var ignite = Ignition.Start(cfg))
            {
                var resCfg = ignite.GetConfiguration();

                var disco    = (TcpDiscoverySpi)cfg.DiscoverySpi;
                var resDisco = (TcpDiscoverySpi)resCfg.DiscoverySpi;

                Assert.AreEqual(disco.NetworkTimeout, resDisco.NetworkTimeout);
                Assert.AreEqual(disco.AckTimeout, resDisco.AckTimeout);
                Assert.AreEqual(disco.MaxAckTimeout, resDisco.MaxAckTimeout);
                Assert.AreEqual(disco.SocketTimeout, resDisco.SocketTimeout);
                Assert.AreEqual(disco.JoinTimeout, resDisco.JoinTimeout);

                Assert.AreEqual(disco.LocalAddress, resDisco.LocalAddress);
                Assert.AreEqual(disco.LocalPort, resDisco.LocalPort);
                Assert.AreEqual(disco.LocalPortRange, resDisco.LocalPortRange);
                Assert.AreEqual(disco.MaxMissedClientHeartbeats, resDisco.MaxMissedClientHeartbeats);
                Assert.AreEqual(disco.MaxMissedHeartbeats, resDisco.MaxMissedHeartbeats);
                Assert.AreEqual(disco.ReconnectCount, resDisco.ReconnectCount);
                Assert.AreEqual(disco.StatisticsPrintFrequency, resDisco.StatisticsPrintFrequency);
                Assert.AreEqual(disco.ThreadPriority, resDisco.ThreadPriority);
                Assert.AreEqual(disco.TopologyHistorySize, resDisco.TopologyHistorySize);

                var ip    = (TcpDiscoveryStaticIpFinder)disco.IpFinder;
                var resIp = (TcpDiscoveryStaticIpFinder)resDisco.IpFinder;

                // There can be extra IPv6 endpoints
                Assert.AreEqual(ip.Endpoints, resIp.Endpoints.Take(2).Select(x => x.Trim('/')).ToArray());

                Assert.AreEqual(cfg.GridName, resCfg.GridName);
                Assert.AreEqual(cfg.IncludedEventTypes, resCfg.IncludedEventTypes);
                Assert.AreEqual(cfg.MetricsExpireTime, resCfg.MetricsExpireTime);
                Assert.AreEqual(cfg.MetricsHistorySize, resCfg.MetricsHistorySize);
                Assert.AreEqual(cfg.MetricsLogFrequency, resCfg.MetricsLogFrequency);
                Assert.AreEqual(cfg.MetricsUpdateFrequency, resCfg.MetricsUpdateFrequency);
                Assert.AreEqual(cfg.NetworkSendRetryCount, resCfg.NetworkSendRetryCount);
                Assert.AreEqual(cfg.NetworkTimeout, resCfg.NetworkTimeout);
                Assert.AreEqual(cfg.NetworkSendRetryDelay, resCfg.NetworkSendRetryDelay);
                Assert.AreEqual(cfg.WorkDirectory, resCfg.WorkDirectory);
                Assert.AreEqual(cfg.JvmClasspath, resCfg.JvmClasspath);
                Assert.AreEqual(cfg.JvmOptions, resCfg.JvmOptions);
                Assert.IsTrue(File.Exists(resCfg.JvmDllPath));
                Assert.AreEqual(cfg.Localhost, resCfg.Localhost);
                Assert.AreEqual(cfg.IsDaemon, resCfg.IsDaemon);
                Assert.AreEqual(cfg.IsLateAffinityAssignment, resCfg.IsLateAffinityAssignment);
                Assert.AreEqual(cfg.UserAttributes, resCfg.UserAttributes);

                var atm    = cfg.AtomicConfiguration;
                var resAtm = resCfg.AtomicConfiguration;
                Assert.AreEqual(atm.AtomicSequenceReserveSize, resAtm.AtomicSequenceReserveSize);
                Assert.AreEqual(atm.Backups, resAtm.Backups);
                Assert.AreEqual(atm.CacheMode, resAtm.CacheMode);

                var tx    = cfg.TransactionConfiguration;
                var resTx = resCfg.TransactionConfiguration;
                Assert.AreEqual(tx.DefaultTimeout, resTx.DefaultTimeout);
                Assert.AreEqual(tx.DefaultTransactionConcurrency, resTx.DefaultTransactionConcurrency);
                Assert.AreEqual(tx.DefaultTransactionIsolation, resTx.DefaultTransactionIsolation);
                Assert.AreEqual(tx.PessimisticTransactionLogLinger, resTx.PessimisticTransactionLogLinger);
                Assert.AreEqual(tx.PessimisticTransactionLogSize, resTx.PessimisticTransactionLogSize);

                var com    = (TcpCommunicationSpi)cfg.CommunicationSpi;
                var resCom = (TcpCommunicationSpi)resCfg.CommunicationSpi;
                Assert.AreEqual(com.AckSendThreshold, resCom.AckSendThreshold);
                Assert.AreEqual(com.ConnectTimeout, resCom.ConnectTimeout);
                Assert.AreEqual(com.DirectBuffer, resCom.DirectBuffer);
                Assert.AreEqual(com.DirectSendBuffer, resCom.DirectSendBuffer);
                Assert.AreEqual(com.IdleConnectionTimeout, resCom.IdleConnectionTimeout);
                Assert.AreEqual(com.LocalAddress, resCom.LocalAddress);
                Assert.AreEqual(com.LocalPort, resCom.LocalPort);
                Assert.AreEqual(com.LocalPortRange, resCom.LocalPortRange);
                Assert.AreEqual(com.MaxConnectTimeout, resCom.MaxConnectTimeout);
                Assert.AreEqual(com.MessageQueueLimit, resCom.MessageQueueLimit);
                Assert.AreEqual(com.ReconnectCount, resCom.ReconnectCount);
                Assert.AreEqual(com.SelectorsCount, resCom.SelectorsCount);
                Assert.AreEqual(com.SlowClientQueueLimit, resCom.SlowClientQueueLimit);
                Assert.AreEqual(com.SocketReceiveBufferSize, resCom.SocketReceiveBufferSize);
                Assert.AreEqual(com.SocketSendBufferSize, resCom.SocketSendBufferSize);
                Assert.AreEqual(com.TcpNoDelay, resCom.TcpNoDelay);
                Assert.AreEqual(com.UnacknowledgedMessagesBufferSize, resCom.UnacknowledgedMessagesBufferSize);
            }
        }
Esempio n. 15
0
        public void TestAllConfigurationProperties()
        {
            var cfg = new IgniteConfiguration(GetCustomConfig());

            using (var ignite = Ignition.Start(cfg))
            {
                var resCfg = ignite.GetConfiguration();

                var disco    = (TcpDiscoverySpi)cfg.DiscoverySpi;
                var resDisco = (TcpDiscoverySpi)resCfg.DiscoverySpi;

                Assert.AreEqual(disco.NetworkTimeout, resDisco.NetworkTimeout);
                Assert.AreEqual(disco.AckTimeout, resDisco.AckTimeout);
                Assert.AreEqual(disco.MaxAckTimeout, resDisco.MaxAckTimeout);
                Assert.AreEqual(disco.SocketTimeout, resDisco.SocketTimeout);
                Assert.AreEqual(disco.JoinTimeout, resDisco.JoinTimeout);

                Assert.AreEqual(disco.LocalAddress, resDisco.LocalAddress);
                Assert.AreEqual(disco.LocalPort, resDisco.LocalPort);
                Assert.AreEqual(disco.LocalPortRange, resDisco.LocalPortRange);
                Assert.AreEqual(disco.ReconnectCount, resDisco.ReconnectCount);
                Assert.AreEqual(disco.StatisticsPrintFrequency, resDisco.StatisticsPrintFrequency);
                Assert.AreEqual(disco.ThreadPriority, resDisco.ThreadPriority);
                Assert.AreEqual(disco.TopologyHistorySize, resDisco.TopologyHistorySize);

                var ip    = (TcpDiscoveryStaticIpFinder)disco.IpFinder;
                var resIp = (TcpDiscoveryStaticIpFinder)resDisco.IpFinder;

                // There can be extra IPv6 endpoints
                Assert.AreEqual(ip.Endpoints, resIp.Endpoints.Take(2).Select(x => x.Trim('/')).ToArray());

                Assert.AreEqual(cfg.IgniteInstanceName, resCfg.IgniteInstanceName);
                Assert.AreEqual(cfg.IgniteHome, resCfg.IgniteHome);
                Assert.AreEqual(cfg.IncludedEventTypes, resCfg.IncludedEventTypes);
                Assert.AreEqual(cfg.MetricsExpireTime, resCfg.MetricsExpireTime);
                Assert.AreEqual(cfg.MetricsHistorySize, resCfg.MetricsHistorySize);
                Assert.AreEqual(cfg.MetricsLogFrequency, resCfg.MetricsLogFrequency);
                Assert.AreEqual(cfg.MetricsUpdateFrequency, resCfg.MetricsUpdateFrequency);
                Assert.AreEqual(cfg.NetworkSendRetryCount, resCfg.NetworkSendRetryCount);
                Assert.AreEqual(cfg.NetworkTimeout, resCfg.NetworkTimeout);
                Assert.AreEqual(cfg.NetworkSendRetryDelay, resCfg.NetworkSendRetryDelay);
                Assert.AreEqual(cfg.WorkDirectory.Trim('\\'), resCfg.WorkDirectory.Trim('\\'));
                Assert.AreEqual(cfg.JvmClasspath, resCfg.JvmClasspath);
                Assert.AreEqual(cfg.JvmOptions, resCfg.JvmOptions);
                Assert.IsTrue(File.Exists(resCfg.JvmDllPath));
                Assert.AreEqual(cfg.Localhost, resCfg.Localhost);
                Assert.AreEqual(cfg.IsDaemon, resCfg.IsDaemon);
                Assert.AreEqual(IgniteConfiguration.DefaultIsLateAffinityAssignment, resCfg.IsLateAffinityAssignment);
                Assert.AreEqual(cfg.UserAttributes, resCfg.UserAttributes);

                var atm    = cfg.AtomicConfiguration;
                var resAtm = resCfg.AtomicConfiguration;
                Assert.AreEqual(atm.AtomicSequenceReserveSize, resAtm.AtomicSequenceReserveSize);
                Assert.AreEqual(atm.Backups, resAtm.Backups);
                Assert.AreEqual(atm.CacheMode, resAtm.CacheMode);

                var tx    = cfg.TransactionConfiguration;
                var resTx = resCfg.TransactionConfiguration;
                Assert.AreEqual(tx.DefaultTimeout, resTx.DefaultTimeout);
                Assert.AreEqual(tx.DefaultTransactionConcurrency, resTx.DefaultTransactionConcurrency);
                Assert.AreEqual(tx.DefaultTransactionIsolation, resTx.DefaultTransactionIsolation);
                Assert.AreEqual(tx.PessimisticTransactionLogLinger, resTx.PessimisticTransactionLogLinger);
                Assert.AreEqual(tx.PessimisticTransactionLogSize, resTx.PessimisticTransactionLogSize);

                var com    = (TcpCommunicationSpi)cfg.CommunicationSpi;
                var resCom = (TcpCommunicationSpi)resCfg.CommunicationSpi;
                Assert.AreEqual(com.AckSendThreshold, resCom.AckSendThreshold);
                Assert.AreEqual(com.ConnectTimeout, resCom.ConnectTimeout);
                Assert.AreEqual(com.DirectBuffer, resCom.DirectBuffer);
                Assert.AreEqual(com.DirectSendBuffer, resCom.DirectSendBuffer);
                Assert.AreEqual(com.IdleConnectionTimeout, resCom.IdleConnectionTimeout);
                Assert.AreEqual(com.LocalAddress, resCom.LocalAddress);
                Assert.AreEqual(com.LocalPort, resCom.LocalPort);
                Assert.AreEqual(com.LocalPortRange, resCom.LocalPortRange);
                Assert.AreEqual(com.MaxConnectTimeout, resCom.MaxConnectTimeout);
                Assert.AreEqual(com.MessageQueueLimit, resCom.MessageQueueLimit);
                Assert.AreEqual(com.ReconnectCount, resCom.ReconnectCount);
                Assert.AreEqual(com.SelectorsCount, resCom.SelectorsCount);
                Assert.AreEqual(com.SlowClientQueueLimit, resCom.SlowClientQueueLimit);
                Assert.AreEqual(com.SocketReceiveBufferSize, resCom.SocketReceiveBufferSize);
                Assert.AreEqual(com.SocketSendBufferSize, resCom.SocketSendBufferSize);
                Assert.AreEqual(com.TcpNoDelay, resCom.TcpNoDelay);
                Assert.AreEqual(com.UnacknowledgedMessagesBufferSize, resCom.UnacknowledgedMessagesBufferSize);

                Assert.AreEqual(cfg.FailureDetectionTimeout, resCfg.FailureDetectionTimeout);
                Assert.AreEqual(cfg.ClientFailureDetectionTimeout, resCfg.ClientFailureDetectionTimeout);
                Assert.AreEqual(cfg.LongQueryWarningTimeout, resCfg.LongQueryWarningTimeout);

                Assert.AreEqual(cfg.PublicThreadPoolSize, resCfg.PublicThreadPoolSize);
                Assert.AreEqual(cfg.StripedThreadPoolSize, resCfg.StripedThreadPoolSize);
                Assert.AreEqual(cfg.ServiceThreadPoolSize, resCfg.ServiceThreadPoolSize);
                Assert.AreEqual(cfg.SystemThreadPoolSize, resCfg.SystemThreadPoolSize);
                Assert.AreEqual(cfg.AsyncCallbackThreadPoolSize, resCfg.AsyncCallbackThreadPoolSize);
                Assert.AreEqual(cfg.ManagementThreadPoolSize, resCfg.ManagementThreadPoolSize);
                Assert.AreEqual(cfg.DataStreamerThreadPoolSize, resCfg.DataStreamerThreadPoolSize);
                Assert.AreEqual(cfg.UtilityCacheThreadPoolSize, resCfg.UtilityCacheThreadPoolSize);
                Assert.AreEqual(cfg.QueryThreadPoolSize, resCfg.QueryThreadPoolSize);

                Assert.AreEqual(cfg.ConsistentId, resCfg.ConsistentId);

                var binCfg = cfg.BinaryConfiguration;
                Assert.IsFalse(binCfg.CompactFooter);

                var typ = binCfg.TypeConfigurations.Single();
                Assert.AreEqual("myType", typ.TypeName);
                Assert.IsTrue(typ.IsEnum);
                Assert.AreEqual("affKey", typ.AffinityKeyFieldName);
                Assert.AreEqual(false, typ.KeepDeserialized);

                Assert.IsNotNull(resCfg.PluginConfigurations);
                Assert.AreEqual(cfg.PluginConfigurations, resCfg.PluginConfigurations);

                var eventCfg    = cfg.EventStorageSpi as MemoryEventStorageSpi;
                var resEventCfg = resCfg.EventStorageSpi as MemoryEventStorageSpi;
                Assert.IsNotNull(eventCfg);
                Assert.IsNotNull(resEventCfg);
                Assert.AreEqual(eventCfg.ExpirationTimeout, resEventCfg.ExpirationTimeout);
                Assert.AreEqual(eventCfg.MaxEventCount, resEventCfg.MaxEventCount);

                var sql    = cfg.SqlConnectorConfiguration;
                var resSql = resCfg.SqlConnectorConfiguration;

                Assert.AreEqual(sql.Host, resSql.Host);
                Assert.AreEqual(sql.Port, resSql.Port);
                Assert.AreEqual(sql.PortRange, resSql.PortRange);
                Assert.AreEqual(sql.MaxOpenCursorsPerConnection, resSql.MaxOpenCursorsPerConnection);
                Assert.AreEqual(sql.SocketReceiveBufferSize, resSql.SocketReceiveBufferSize);
                Assert.AreEqual(sql.SocketSendBufferSize, resSql.SocketSendBufferSize);
                Assert.AreEqual(sql.TcpNoDelay, resSql.TcpNoDelay);
                Assert.AreEqual(sql.ThreadPoolSize, resSql.ThreadPoolSize);

                TestUtils.AssertReflectionEqual(cfg.DataStorageConfiguration, resCfg.DataStorageConfiguration);
            }
        }
Esempio n. 16
0
 public void BeforeTests()
 {
     Ignition.Start(GetIgniteConfiguration());
 }
Esempio n. 17
0
        public void FixtureSetUp()
        {
            _runDbConsole = false;  // set to true to open H2 console

            if (_runDbConsole)
            {
                Environment.SetEnvironmentVariable("IGNITE_H2_DEBUG_CONSOLE", "true");
            }

            Ignition.Start(GetConfig());
            Ignition.Start(GetConfig("grid2"));

            // Populate caches
            var cache       = GetPersonCache();
            var personCache = GetSecondPersonCache();

            for (var i = 0; i < PersonCount; i++)
            {
                cache.Put(i, new Person(i, string.Format(" Person_{0}  ", i))
                {
                    Address = new Address {
                        Zip = i, Street = "Street " + i, AliasTest = i
                    },
                    OrganizationId = i % 2 + 1000,
                    Birthday       = StartDateTime.AddYears(i),
                    AliasTest      = -i
                });

                var i2 = i + PersonCount;
                personCache.Put(i2, new Person(i2, "Person_" + i2)
                {
                    Address = new Address {
                        Zip = i2, Street = "Street " + i2
                    },
                    OrganizationId = i % 2 + 1000,
                    Birthday       = StartDateTime.AddYears(i)
                });
            }

            var orgCache = GetOrgCache();

            orgCache[1000] = new Organization {
                Id = 1000, Name = "Org_0"
            };
            orgCache[1001] = new Organization {
                Id = 1001, Name = "Org_1"
            };
            orgCache[1002] = new Organization {
                Id = 1002, Name = null
            };

            var roleCache = GetRoleCache();

            roleCache[new RoleKey(1, 101)] = new Role {
                Name = "Role_1", Date = StartDateTime
            };
            roleCache[new RoleKey(2, 102)] = new Role {
                Name = "Role_2", Date = StartDateTime.AddYears(1)
            };
            roleCache[new RoleKey(3, 103)] = new Role {
                Name = null, Date = StartDateTime.AddHours(5432)
            };
        }
 public virtual void GlobalSetup()
 {
     Ignite = Ignition.Start(Utils.GetIgniteConfiguration());
     Cache  = Ignite.GetOrCreateCache <int, int>("c");
 }
Esempio n. 19
0
        public void TestAllConfigurationProperties()
        {
            var cfg = new IgniteConfiguration(GetCustomConfig());

            using (var ignite = Ignition.Start(cfg))
            {
                var resCfg = ignite.GetConfiguration();

                var disco    = (TcpDiscoverySpi)cfg.DiscoverySpi;
                var resDisco = (TcpDiscoverySpi)resCfg.DiscoverySpi;

                Assert.AreEqual(disco.NetworkTimeout, resDisco.NetworkTimeout);
                Assert.AreEqual(disco.AckTimeout, resDisco.AckTimeout);
                Assert.AreEqual(disco.MaxAckTimeout, resDisco.MaxAckTimeout);
                Assert.AreEqual(disco.SocketTimeout, resDisco.SocketTimeout);
                Assert.AreEqual(disco.JoinTimeout, resDisco.JoinTimeout);

                Assert.AreEqual(disco.LocalAddress, resDisco.LocalAddress);
                Assert.AreEqual(disco.LocalPort, resDisco.LocalPort);
                Assert.AreEqual(disco.LocalPortRange, resDisco.LocalPortRange);
                Assert.AreEqual(disco.MaxMissedClientHeartbeats, resDisco.MaxMissedClientHeartbeats);
                Assert.AreEqual(disco.MaxMissedHeartbeats, resDisco.MaxMissedHeartbeats);
                Assert.AreEqual(disco.ReconnectCount, resDisco.ReconnectCount);
                Assert.AreEqual(disco.StatisticsPrintFrequency, resDisco.StatisticsPrintFrequency);
                Assert.AreEqual(disco.ThreadPriority, resDisco.ThreadPriority);
                Assert.AreEqual(disco.TopologyHistorySize, resDisco.TopologyHistorySize);

                var ip    = (TcpDiscoveryStaticIpFinder)disco.IpFinder;
                var resIp = (TcpDiscoveryStaticIpFinder)resDisco.IpFinder;

                // There can be extra IPv6 endpoints
                Assert.AreEqual(ip.Endpoints, resIp.Endpoints.Take(2).Select(x => x.Trim('/')).ToArray());

                Assert.AreEqual(cfg.GridName, resCfg.GridName);
                Assert.AreEqual(cfg.IncludedEventTypes, resCfg.IncludedEventTypes);
                Assert.AreEqual(cfg.MetricsExpireTime, resCfg.MetricsExpireTime);
                Assert.AreEqual(cfg.MetricsHistorySize, resCfg.MetricsHistorySize);
                Assert.AreEqual(cfg.MetricsLogFrequency, resCfg.MetricsLogFrequency);
                Assert.AreEqual(cfg.MetricsUpdateFrequency, resCfg.MetricsUpdateFrequency);
                Assert.AreEqual(cfg.NetworkSendRetryCount, resCfg.NetworkSendRetryCount);
                Assert.AreEqual(cfg.NetworkTimeout, resCfg.NetworkTimeout);
                Assert.AreEqual(cfg.NetworkSendRetryDelay, resCfg.NetworkSendRetryDelay);
                Assert.AreEqual(cfg.WorkDirectory.Trim('\\'), resCfg.WorkDirectory.Trim('\\'));
                Assert.AreEqual(cfg.JvmClasspath, resCfg.JvmClasspath);
                Assert.AreEqual(cfg.JvmOptions, resCfg.JvmOptions);
                Assert.IsTrue(File.Exists(resCfg.JvmDllPath));
                Assert.AreEqual(cfg.Localhost, resCfg.Localhost);
                Assert.AreEqual(cfg.IsDaemon, resCfg.IsDaemon);
                Assert.AreEqual(cfg.IsLateAffinityAssignment, resCfg.IsLateAffinityAssignment);
                Assert.AreEqual(cfg.UserAttributes, resCfg.UserAttributes);

                var atm    = cfg.AtomicConfiguration;
                var resAtm = resCfg.AtomicConfiguration;
                Assert.AreEqual(atm.AtomicSequenceReserveSize, resAtm.AtomicSequenceReserveSize);
                Assert.AreEqual(atm.Backups, resAtm.Backups);
                Assert.AreEqual(atm.CacheMode, resAtm.CacheMode);

                var tx    = cfg.TransactionConfiguration;
                var resTx = resCfg.TransactionConfiguration;
                Assert.AreEqual(tx.DefaultTimeout, resTx.DefaultTimeout);
                Assert.AreEqual(tx.DefaultTransactionConcurrency, resTx.DefaultTransactionConcurrency);
                Assert.AreEqual(tx.DefaultTransactionIsolation, resTx.DefaultTransactionIsolation);
                Assert.AreEqual(tx.PessimisticTransactionLogLinger, resTx.PessimisticTransactionLogLinger);
                Assert.AreEqual(tx.PessimisticTransactionLogSize, resTx.PessimisticTransactionLogSize);

                var com    = (TcpCommunicationSpi)cfg.CommunicationSpi;
                var resCom = (TcpCommunicationSpi)resCfg.CommunicationSpi;
                Assert.AreEqual(com.AckSendThreshold, resCom.AckSendThreshold);
                Assert.AreEqual(com.ConnectTimeout, resCom.ConnectTimeout);
                Assert.AreEqual(com.DirectBuffer, resCom.DirectBuffer);
                Assert.AreEqual(com.DirectSendBuffer, resCom.DirectSendBuffer);
                Assert.AreEqual(com.IdleConnectionTimeout, resCom.IdleConnectionTimeout);
                Assert.AreEqual(com.LocalAddress, resCom.LocalAddress);
                Assert.AreEqual(com.LocalPort, resCom.LocalPort);
                Assert.AreEqual(com.LocalPortRange, resCom.LocalPortRange);
                Assert.AreEqual(com.MaxConnectTimeout, resCom.MaxConnectTimeout);
                Assert.AreEqual(com.MessageQueueLimit, resCom.MessageQueueLimit);
                Assert.AreEqual(com.ReconnectCount, resCom.ReconnectCount);
                Assert.AreEqual(com.SelectorsCount, resCom.SelectorsCount);
                Assert.AreEqual(com.SlowClientQueueLimit, resCom.SlowClientQueueLimit);
                Assert.AreEqual(com.SocketReceiveBufferSize, resCom.SocketReceiveBufferSize);
                Assert.AreEqual(com.SocketSendBufferSize, resCom.SocketSendBufferSize);
                Assert.AreEqual(com.TcpNoDelay, resCom.TcpNoDelay);
                Assert.AreEqual(com.UnacknowledgedMessagesBufferSize, resCom.UnacknowledgedMessagesBufferSize);

                Assert.AreEqual(cfg.FailureDetectionTimeout, resCfg.FailureDetectionTimeout);

                var swap    = (FileSwapSpaceSpi)cfg.SwapSpaceSpi;
                var resSwap = (FileSwapSpaceSpi)resCfg.SwapSpaceSpi;
                Assert.AreEqual(swap.MaximumSparsity, resSwap.MaximumSparsity);
                Assert.AreEqual(swap.BaseDirectory, resSwap.BaseDirectory);
                Assert.AreEqual(swap.MaximumWriteQueueSize, resSwap.MaximumWriteQueueSize);
                Assert.AreEqual(swap.ReadStripesNumber, resSwap.ReadStripesNumber);
                Assert.AreEqual(swap.WriteBufferSize, resSwap.WriteBufferSize);

                var binCfg = cfg.BinaryConfiguration;
                Assert.IsFalse(binCfg.CompactFooter);

                var typ = binCfg.TypeConfigurations.Single();
                Assert.AreEqual("myType", typ.TypeName);
                Assert.IsTrue(typ.IsEnum);
                Assert.AreEqual("affKey", typ.AffinityKeyFieldName);
                Assert.AreEqual(false, typ.KeepDeserialized);

                CollectionAssert.AreEqual(new[] { "fld1", "fld2" },
                                          ((BinaryFieldEqualityComparer)typ.EqualityComparer).FieldNames);
            }
        }
Esempio n. 20
0
        public void TestCacheDataSurvivesNodeRestart(
            [Values(true, false)] bool withCacheStore,
            [Values(true, false)] bool withCustomAffinity)
        {
            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
            {
                DataStorageConfiguration = new DataStorageConfiguration
                {
                    StoragePath    = Path.Combine(_tempDir, "Store"),
                    WalPath        = Path.Combine(_tempDir, "WalStore"),
                    WalArchivePath = Path.Combine(_tempDir, "WalArchive"),
                    MetricsEnabled = true,
                    DefaultDataRegionConfiguration = new DataRegionConfiguration
                    {
                        PageEvictionMode   = DataPageEvictionMode.Disabled,
                        Name               = DataStorageConfiguration.DefaultDataRegionName,
                        PersistenceEnabled = true
                    },
                    DataRegionConfigurations = new[]
                    {
                        new DataRegionConfiguration
                        {
                            Name = "volatileRegion",
                            PersistenceEnabled = false
                        }
                    }
                }
            };

            const string cacheName         = "persistentCache";
            const string volatileCacheName = "volatileCache";

            // Start Ignite, put data, stop.
            using (var ignite = Ignition.Start(cfg))
            {
                ignite.GetCluster().SetActive(true);

                // Create cache with default region (persistence enabled), add data.
                var cache = ignite.CreateCache <int, int>(new CacheConfiguration
                {
                    Name = cacheName,
                    CacheStoreFactory = withCacheStore ? new CustomStoreFactory() : null,
                    AffinityFunction  = withCustomAffinity ? new CustomAffinityFunction() : null
                });
                cache[1] = 1;

                // Check some metrics.
                CheckDataStorageMetrics(ignite);

                // Create cache with non-persistent region.
                var volatileCache = ignite.CreateCache <int, int>(new CacheConfiguration
                {
                    Name           = volatileCacheName,
                    DataRegionName = "volatileRegion"
                });
                volatileCache[2] = 2;
            }

            // Verify directories.
            Assert.IsTrue(Directory.Exists(cfg.DataStorageConfiguration.StoragePath));
            Assert.IsTrue(Directory.Exists(cfg.DataStorageConfiguration.WalPath));
            Assert.IsTrue(Directory.Exists(cfg.DataStorageConfiguration.WalArchivePath));

            // Start Ignite, verify data survival.
            using (var ignite = Ignition.Start(cfg))
            {
                ignite.GetCluster().SetActive(true);

                // Persistent cache already exists and contains data.
                var cache = ignite.GetCache <int, int>(cacheName);
                Assert.AreEqual(1, cache[1]);

                // Non-persistent cache does not exist.
                var ex = Assert.Throws <ArgumentException>(() => ignite.GetCache <int, int>(volatileCacheName));
                Assert.AreEqual("Cache doesn't exist: volatileCache", ex.Message);
            }

            // Delete store directory.
            Directory.Delete(_tempDir, true);

            // Start Ignite, verify data loss.
            using (var ignite = Ignition.Start(cfg))
            {
                ignite.GetCluster().SetActive(true);

                Assert.IsFalse(ignite.GetCacheNames().Contains(cacheName));
            }
        }
Esempio n. 21
0
        public void TestFixtureSetUp()
        {
            TestUtils.KillProcesses();

            _grid = Ignition.Start(Configuration(SpringCfgPath));
        }
Esempio n. 22
0
        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, 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);

            // 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, int>(CacheName);

            Assert.AreEqual(0, cache1.GetSize());

            cache1[1] = 2;
            Assert.AreEqual(2, cache1[1]);

            // Check that old cache instance still works.
            Assert.AreEqual(2, cache.Get(1));
        }
Esempio n. 23
0
        public static void Main()
        {
            var cfg = new IgniteConfiguration
            {
                SpringConfigUrl = @"platforms\dotnet\examples\config\examples-config.xml",
                JvmOptions      = new List <string> {
                    "-Xms512m", "-Xmx512m"
                }
            };

            using (var ignite = Ignition.Start(cfg))
            {
                var remotes = ignite.GetCluster().ForRemotes();

                if (remotes.GetNodes().Count == 0)
                {
                    Console.WriteLine(">>> This example requires remote nodes to be started.");
                    Console.WriteLine(">>> Please start at least 1 remote node.");
                    Console.WriteLine(">>> Refer to example's documentation for details on configuration.");
                }
                else
                {
                    Console.WriteLine(">>> Messaging example started.");
                    Console.WriteLine();

                    // Set up local listeners
                    var localMessaging = ignite.GetCluster().ForLocal().GetMessaging();

                    var msgCount = remotes.GetNodes().Count * 10;

                    var orderedCounter   = new CountdownEvent(msgCount);
                    var unorderedCounter = new CountdownEvent(msgCount);

                    localMessaging.LocalListen(new LocalListener(unorderedCounter), Topic.Unordered);

                    localMessaging.LocalListen(new LocalListener(orderedCounter), Topic.Ordered);

                    // Set up remote listeners
                    var remoteMessaging = remotes.GetMessaging();

                    var idUnordered = remoteMessaging.RemoteListen(new RemoteUnorderedListener(), Topic.Unordered);
                    var idOrdered   = remoteMessaging.RemoteListen(new RemoteOrderedListener(), Topic.Ordered);

                    // Send unordered
                    Console.WriteLine(">>> Sending unordered messages...");

                    for (var i = 0; i < 10; i++)
                    {
                        remoteMessaging.Send(i, Topic.Unordered);
                    }

                    Console.WriteLine(">>> Finished sending unordered messages.");

                    // Send ordered
                    Console.WriteLine(">>> Sending ordered messages...");

                    for (var i = 0; i < 10; i++)
                    {
                        remoteMessaging.SendOrdered(i, Topic.Ordered);
                    }

                    Console.WriteLine(">>> Finished sending ordered messages.");

                    Console.WriteLine(">>> Check output on all nodes for message printouts.");
                    Console.WriteLine(">>> Waiting for messages acknowledgements from all remote nodes...");

                    unorderedCounter.Wait();
                    orderedCounter.Wait();

                    // Unsubscribe
                    remoteMessaging.StopRemoteListen(idUnordered);
                    remoteMessaging.StopRemoteListen(idOrdered);
                }
            }

            Console.WriteLine();
            Console.WriteLine(">>> Example finished, press any key to exit ...");
            Console.ReadKey();
        }
Esempio n. 24
0
        public static String GetSearch()
        {
            /* var config = new IgniteConfiguration
             * {
             *   DiscoverySpi = new TcpDiscoverySpi
             *   {
             *       IpFinder = new TcpDiscoveryStaticIpFinder
             *       {
             *           Endpoints = new[] { "192.168.1.38:47500..47509" }
             *       },
             *       SocketTimeout = TimeSpan.FromSeconds(0.3)
             *   },
             *   IncludedEventTypes = EventType.CacheAll,
             *   PersistentStoreConfiguration = new PersistentStoreConfiguration()
             *
             * };*/



            // var stateListData = "[{ 123 : { name: 'Alabama', abbreviation: 'AL' }}, {124 : { name: 'Alaska', abbreviation: 'AK' }}, {125 : { name: 'AmericanSamoa', abbreviation: 'AS' }}, {126 : { name: 'Arizona', abbreviation: 'AZ' }}, {127 : { name: 'Arkansas', abbreviation: 'AR' }}, { 128 : { name: 'California', abbreviation: 'CA' }}, { 129 : { name: 'Colorado', abbreviation: 'CO' }}]";
            //List<String> records = JsonConvert.DeserializeObject<List<String>>(stateListData);

            Ignition.ClientMode = true;

            /* var cfg = new IgniteConfiguration
             * {
             *   // Register custom class for Ignite serialization
             *   BinaryConfiguration = new BinaryConfiguration(typeof(Details))
             * };*/
            IIgnite ignite = Ignition.Start();
            var     cache  = ignite.GetOrCreateCache <int, Details>(
                new CacheConfiguration("DetailsCache", typeof(Details)));


            String value = null;

            // ICache<int, Details> cache = ignite.GetOrCreateCache<int, Details>("details");
            cache[1] = new Details {
                Name = "John Doe", Age = 20
            };
            cache[2] = new Details {
                Name = "Fred", Age = 23
            };
            cache[3] = new Details {
                Name = "John moe", Age = 18
            };
            cache[4] = new Details {
                Name = "Anglina Chris", Age = 35
            };
            cache[5] = new Details {
                Name = "Donna Paul Anderson", Age = 45
            };
            cache[6] = new Details {
                Name = "Donna Spectre", Age = 48
            };
            cache[7] = new Details {
                Name = "Mike Ross", Age = 27
            };
            cache[8] = new Details {
                Name = "Louis Litt", Age = 57
            };
            cache[9] = new Details {
                Name = "Scottie", Age = 38
            };
            cache[10] = new Details {
                Name = "Scottie", Age = 28
            };

            //cache.Put()

            // Query for all people with "Master Degree" in their resumes.


            //IIgnite ignite = Ignition.Start();
            // ICache<String, String> cache = ignite.GetOrCreateCache<String, String>("SearchListData");
            // for (int i = 0; i < 10; i++)
            //   cache.Put(i, cache[i]);

            /* IQueryCursor<ICacheEntry<int, Details>> cursor = cache.Query(new TextQuery(typeof(Details), "J*n*"));
             *
             * foreach (var cacheEntry in cursor)
             *    Console.WriteLine(cacheEntry);*/


            ArrayList list = new ArrayList();

            foreach (ICacheEntry <int, Details> cacheEntry in cache)
            {
                list.Add(cacheEntry.Key);
                value = cacheEntry.ToString();
                Console.WriteLine(value);
            }
            // JObject json = JObject.Parse(value);
            //  ArrayList list1 = JsonConvert.DeserializeObject(value);
            //  List<Details> list = JsonConvert.DeserializeObject<List<Details>>(value);

            // Console.WriteLine(json);


            //var cache = ignite.GetOrCreateCache<int, Person>("myCache");

            // Query for all people with "Master Degree" in their resumes.
            var cursor1 = cache.Query(new TextQuery("Details", "J*n*"));

            // var query = new TextQuery("","");

            // Iterate over results. Using 'foreach' loop will close the cursor automatically.
            foreach (var cacheEntry in cursor1)
            {
                Console.WriteLine(cacheEntry.Value);
            }
            string jsonString = JsonConvert.SerializeObject(value);

            Console.WriteLine(jsonString);



            /*for (int i = 0; i < 10; i++)
             * {
             *  value = cache.Get(i).ToString();
             *  Console.WriteLine("Got [key={0}, val={1}]", i, cache.Get(i).ToString());
             * }*/
            //cache.Put(key, );
            // String value = cache.Get(key);
            //Console.WriteLine(value);
            return(value);
        }
Esempio n. 25
0
        public void TestStore()
        {
            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
            {
                // Disable compact footers to test grid restart with persistent store
                // (Because store operates on raw binary objects).
                BinaryConfiguration = new BinaryConfiguration {
                    CompactFooter = false
                },
                CacheConfiguration = new[]
                {
                    new CacheConfiguration("default")
                    {
                        CacheStoreFactory = new StoreFactory(),
                        ReadThrough       = true,
                        WriteThrough      = true,
                        KeepBinaryInStore = true
                    }
                }
            };

            using (var ignite = Ignition.Start(TestUtils.GetTestConfiguration()))
            {
                // Put through dynamically started cache
                var dynCache = ignite.CreateCache <int, Foo>(new CacheConfiguration("dynCache")
                {
                    CacheStoreFactory = new StoreFactory(),
                    ReadThrough       = true,
                    WriteThrough      = true,
                    KeepBinaryInStore = true
                });
                dynCache[2] = new Foo {
                    Str = "test2", Int = 3
                };

                // Start another server node so that store is initialized there
                using (var ignite2 = Ignition.Start(new IgniteConfiguration(TestUtils.GetTestConfiguration())
                {
                    IgniteInstanceName = "grid2"
                }))
                {
                    var dynCache2 = ignite2.GetCache <int, Foo>(dynCache.Name);

                    Assert.AreEqual("test2", dynCache2[2].Str);
                    Assert.AreEqual(3, dynCache2[2].Int);
                }
            }

            using (var ignite = Ignition.Start(cfg))
            {
                // Put through statically started cache
                var staticCache = ignite.GetCache <int, Foo>("default");
                staticCache[1] = new Foo {
                    Str = "test", Int = 2
                };
            }

            using (var ignite = Ignition.Start(cfg))
            {
                var foo  = ignite.GetCache <int, Foo>("default")[1];
                var foo2 = ignite.GetCache <int, Foo>("default")[2];

                Assert.AreEqual("test", foo.Str);
                Assert.AreEqual(2, foo.Int);

                Assert.AreEqual("test2", foo2.Str);
                Assert.AreEqual(3, foo2.Int);

                // Client node
                using (var igniteClient = Ignition.Start(new IgniteConfiguration(cfg)
                {
                    ClientMode = true,
                    IgniteInstanceName = "grid2"
                }))
                {
                    var fooClient  = igniteClient.GetCache <int, Foo>("default")[1];
                    var fooClient2 = igniteClient.GetCache <int, Foo>("default")[2];

                    Assert.AreEqual("test", fooClient.Str);
                    Assert.AreEqual(2, fooClient.Int);

                    Assert.AreEqual("test2", fooClient2.Str);
                    Assert.AreEqual(3, fooClient2.Int);
                }
            }

            // Delete directory and check that store no longer works
            ClearMarshallerWorkDir();

            using (var ignite = Ignition.Start(cfg))
            {
                var ex = Assert.Throws <BinaryObjectException>(() => ignite.GetCache <int, Foo>("default").Get(1));

                Assert.IsTrue(ex.Message.Contains("Unknown pair"));
            }
        }
Esempio n. 26
0
        public static void Main()
        {
            using (var ignite = Ignition.Start(Utils.GetServerNodeConfiguration()))
            {
                Console.WriteLine();
                Console.WriteLine(">>> Transaction example started.");

                var cache = ignite.GetOrCreateCache <int, Account>(new CacheConfiguration
                {
                    Name          = CacheName,
                    AtomicityMode = CacheAtomicityMode.Transactional
                });

                InitAccounts(cache);

                Console.WriteLine("\n>>> Transferring with Ignite transaction API...");

                // Transfer money between accounts in a single transaction.
                using (var tx = cache.Ignite.GetTransactions().TxStart(TransactionConcurrency.Pessimistic,
                                                                       TransactionIsolation.RepeatableRead))
                {
                    Account acc1 = cache.Get(1);
                    Account acc2 = cache.Get(2);

                    acc1.Balance += 100;
                    acc2.Balance -= 100;

                    cache.Put(1, acc1);
                    cache.Put(2, acc2);

                    tx.Commit();
                }

                DisplayAccounts(cache);

                InitAccounts(cache);

                Console.WriteLine("\n>>> Transferring with TransactionScope API...");

                // Do the same transaction with TransactionScope API.
                using (var ts = new TransactionScope())
                {
                    Account acc1 = cache.Get(1);
                    Account acc2 = cache.Get(2);

                    acc1.Balance += 100;
                    acc2.Balance -= 100;

                    cache.Put(1, acc1);
                    cache.Put(2, acc2);

                    ts.Complete();
                }

                DisplayAccounts(cache);
            }

            Console.WriteLine();
            Console.WriteLine(">>> Example finished, press any key to exit ...");
            Console.ReadKey();
        }
Esempio n. 27
0
 public void SetUp()
 {
     Ignition.Start(TestUtils.GetTestConfiguration());
 }
Esempio n. 28
0
        public static void Main()
        {
            Console.WriteLine();
            Console.WriteLine(">>> Client reconnect example started.");

            var evt = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem(_ => RunServer(evt));

            // Wait a moment for server to begin startup.
            Thread.Sleep(200);

            var cfg = new IgniteConfiguration(GetIgniteConfiguration())
            {
                ClientMode = true
            };

            using (var ignite = Ignition.Start(cfg))
            {
                Console.WriteLine(">>> Client node connected to the cluster.");

                if (ignite.GetCluster().GetNodes().Count > 2)
                {
                    throw new Exception("Extra nodes detected. " +
                                        "ClientReconnectExample should be run without external nodes.");
                }

                var cache = ignite.GetCache <int, string>(CacheName);

                for (var i = 0; i < 10; i++)
                {
                    try
                    {
                        Console.WriteLine(">>> Put value with key: " + i);
                        cache.Put(i, "val" + i);

                        Thread.Sleep(500);
                    }
                    catch (CacheException e)
                    {
                        var disconnectedException = e.InnerException as ClientDisconnectedException;

                        if (disconnectedException != null)
                        {
                            Console.WriteLine(
                                "\n>>> Client disconnected from the cluster. Failed to put value with key: " + i);

                            disconnectedException.ClientReconnectTask.Wait();

                            Console.WriteLine("\n>>> Client reconnected to the cluster.");

                            // Updating the reference to the cache. The client reconnected to the new cluster.
                            cache = ignite.GetCache <int, string>(CacheName);
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                // Stop the server node.
                evt.Set();

                Console.WriteLine();
                Console.WriteLine(">>> Example finished, press any key to exit ...");
                Console.ReadKey();
            }
        }
Esempio n. 29
0
        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);
                cluster.SetBaselineAutoAdjustEnabledFlag(false);

                // 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));
                }
        }
        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);
                }
            }
        }