Пример #1
0
        public void TearDown()
        {
            Ignition.StopAll(true);

            Directory.Delete(TempDir, true);
        }
Пример #2
0
        public static void Main()
        {
            using (var ignite = Ignition.StartFromApplicationConfiguration())
            {
                Console.WriteLine();
                Console.WriteLine(">>> Cache query DDL example started.");

                // Create dummy cache to act as an entry point for SQL queries (new SQL API which do not require this
                // will appear in future versions, JDBC and ODBC drivers do not require it already).
                var cacheCfg = new CacheConfiguration(DummyCacheName)
                {
                    SqlSchema = "PUBLIC",
                    CacheMode = CacheMode.Replicated
                };

                ICache <object, object> cache = ignite.GetOrCreateCache <object, object>(cacheCfg);

                // Create reference City table based on REPLICATED template.
                cache.Query(new SqlFieldsQuery(
                                "CREATE TABLE city (id LONG PRIMARY KEY, name VARCHAR) WITH \"template=replicated\"")).GetAll();

                // Create table based on PARTITIONED template with one backup.
                cache.Query(new SqlFieldsQuery(
                                "CREATE TABLE person (id LONG, name VARCHAR, city_id LONG, PRIMARY KEY (id, city_id)) " +
                                "WITH \"backups=1, affinity_key=city_id\"")).GetAll();

                // Create an index.
                cache.Query(new SqlFieldsQuery("CREATE INDEX on Person (city_id)")).GetAll();

                Console.WriteLine("\n>>> Created database objects.");

                const string addCity = "INSERT INTO city (id, name) VALUES (?, ?)";

                cache.Query(new SqlFieldsQuery(addCity, 1L, "Forest Hill"));
                cache.Query(new SqlFieldsQuery(addCity, 2L, "Denver"));
                cache.Query(new SqlFieldsQuery(addCity, 3L, "St. Petersburg"));

                const string addPerson = "INSERT INTO person (id, name, city_id) values (?, ?, ?)";

                cache.Query(new SqlFieldsQuery(addPerson, 1L, "John Doe", 3L));
                cache.Query(new SqlFieldsQuery(addPerson, 2L, "Jane Roe", 2L));
                cache.Query(new SqlFieldsQuery(addPerson, 3L, "Mary Major", 1L));
                cache.Query(new SqlFieldsQuery(addPerson, 4L, "Richard Miles", 2L));

                Console.WriteLine("\n>>> Populated data.");

                IFieldsQueryCursor res = cache.Query(new SqlFieldsQuery(
                                                         "SELECT p.name, c.name FROM Person p INNER JOIN City c on c.id = p.city_id"));

                Console.WriteLine("\n>>> Query results:");

                foreach (var row in res)
                {
                    Console.WriteLine("{0}, {1}", row[0], row[1]);
                }

                cache.Query(new SqlFieldsQuery("drop table Person")).GetAll();
                cache.Query(new SqlFieldsQuery("drop table City")).GetAll();

                Console.WriteLine("\n>>> Dropped database objects.");
            }

            Console.WriteLine();
            Console.WriteLine(">>> Example finished, press any key to exit ...");
            Console.ReadKey();
        }
Пример #3
0
 /// <summary>
 /// Gets the ignite.
 /// </summary>
 private static IIgnite GetIgnite()
 {
     return(Ignition.GetIgnite("grid-0"));
 }
Пример #4
0
        public static void Main()
        {
            using (var ignite = Ignition.StartFromApplicationConfiguration())
            {
                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();
        }
Пример #5
0
        public static void Main()
        {
            using (var ignite = Ignition.StartFromApplicationConfiguration())
            {
                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();
        }
Пример #6
0
        public void TestJavaServiceCall()
        {
            var serviceName = TestUtils.DeployJavaService(Ignition.GetIgnite());
            var svc         = Client.GetServices().GetServiceProxy <IJavaService>(serviceName);
            var binSvc      = Client.GetServices()
                              .WithKeepBinary()
                              .WithServerKeepBinary()
                              .GetServiceProxy <IJavaService>(serviceName);

            Assert.IsTrue(svc.isInitialized());
            Assert.IsTrue(svc.isExecuted());
            Assert.IsFalse(svc.isCancelled());

            // Primitives.
            Assert.AreEqual(4, svc.test((byte)3));
            Assert.AreEqual(5, svc.test((short)4));
            Assert.AreEqual(6, svc.test(5));
            Assert.AreEqual(6, svc.test((long)5));
            Assert.AreEqual(3.8f, svc.test(2.3f));
            Assert.AreEqual(5.8, svc.test(3.3));
            Assert.IsFalse(svc.test(true));
            Assert.AreEqual('b', svc.test('a'));
            Assert.AreEqual("Foo!", svc.test("Foo"));

            // Nullables (Java wrapper types).
            Assert.AreEqual(4, svc.testWrapper(3));
            Assert.AreEqual(5, svc.testWrapper((short?)4));
            Assert.AreEqual(6, svc.testWrapper((int?)5));
            Assert.AreEqual(6, svc.testWrapper((long?)5));
            Assert.AreEqual(3.8f, svc.testWrapper(2.3f));
            Assert.AreEqual(5.8, svc.testWrapper(3.3));
            Assert.AreEqual(false, svc.testWrapper(true));
            Assert.AreEqual('b', svc.testWrapper('a'));

            // Arrays.
            Assert.AreEqual(new byte[] { 2, 3, 4 }, svc.testArray(new byte[] { 1, 2, 3 }));
            Assert.AreEqual(new short[] { 2, 3, 4 }, svc.testArray(new short[] { 1, 2, 3 }));
            Assert.AreEqual(new[] { 2, 3, 4 }, svc.testArray(new[] { 1, 2, 3 }));
            Assert.AreEqual(new long[] { 2, 3, 4 }, svc.testArray(new long[] { 1, 2, 3 }));
            Assert.AreEqual(new float[] { 2, 3, 4 }, svc.testArray(new float[] { 1, 2, 3 }));
            Assert.AreEqual(new double[] { 2, 3, 4 }, svc.testArray(new double[] { 1, 2, 3 }));
            Assert.AreEqual(new[] { "a1", "b1" }, svc.testArray(new [] { "a", "b" }));
            Assert.AreEqual(new[] { 'c', 'd' }, svc.testArray(new[] { 'b', 'c' }));
            Assert.AreEqual(new[] { false, true, false }, svc.testArray(new[] { true, false, true }));

            // Nulls.
            Assert.AreEqual(9, svc.testNull(8));
            Assert.IsNull(svc.testNull(null));

            // params / varargs.
            Assert.AreEqual(5, svc.testParams(1, 2, 3, 4, "5"));
            Assert.AreEqual(0, svc.testParams());

            // Overloads.
            Assert.AreEqual(3, svc.test(2, "1"));
            Assert.AreEqual(3, svc.test("1", 2));

            // Dates & Timestamps: not supported in Thin Client Services.
            var ex = Assert.Throws <IgniteClientException>(() => svc.test(DateTime.UtcNow));

            StringAssert.StartsWith("Failed to resolve .NET class 'System.DateTime' in Java", ex.Message);

            // Guid.
            var guid = Guid.NewGuid();

            Assert.AreEqual(guid, svc.test(guid));
            Assert.AreEqual(guid, svc.testNullUUID(guid));
            Assert.IsNull(svc.testNullUUID(null));
            Assert.AreEqual(guid, svc.testArray(new Guid?[] { guid })[0]);

            // Binary object.
            Assert.AreEqual(15,
                            binSvc.testBinaryObject(
                                Client.GetBinary().ToBinary <IBinaryObject>(new ServicesTest.PlatformComputeBinarizable {
                Field = 6
            }))
                            .GetField <int>("Field"));

            // Binary object array.
            var arr = new[] { 10, 11, 12 }.Select(
                x => new ServicesTest.PlatformComputeBinarizable {
                Field = x
            }).ToArray();

            var binArr = arr.Select(Client.GetBinary().ToBinary <IBinaryObject>).ToArray();

            Assert.AreEqual(new[] { 11, 12, 13 }, binSvc.testBinaryObjectArray(binArr)
                            .Select(x => x.GetField <int>("Field")));
        }
 public void FixtureSetUp()
 {
     Ignition.Start(TestUtils.GetTestConfiguration(name: "server"));
 }
Пример #8
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));
            }
        }
Пример #9
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
                    }
                }
            };

            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
                });
                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"));
            }
        }
Пример #10
0
        /// <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.GetCache <TK, int>("partitioned_atomic").WithNoRetries();

                if (typeof(TK) == typeof(IBinaryObject))
                {
                    cache = cache.WithKeepBinary <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++)
                        {
                            // 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;
                    }
                }
            }
        }
Пример #11
0
 public void TearDown()
 {
     TestUtils.KillProcesses();
     Ignition.StopAll(true);
 }
Пример #12
0
        public void TestRemoveAll()
        {
            // Use new cache to avoid touching static data.
            var cache = Ignition.GetIgnite().CreateCache <int, Person>(new CacheConfiguration("deleteAllTest",
                                                                                              new QueryEntity(typeof(int), typeof(Person)))
            {
                SqlEscapeAll = GetSqlEscapeAll()
            });

            Enumerable.Range(1, 10).ToList().ForEach(x => cache.Put(x, new Person(x, x.ToString())));

            var queryable = cache.AsCacheQueryable();

            Func <int[]> getKeys = () => cache.Select(x => x.Key).OrderBy(x => x).ToArray();

            // Without predicate.
            var res = queryable.Where(x => x.Key < 3).RemoveAll();

            Assert.AreEqual(2, res);
            Assert.AreEqual(Enumerable.Range(3, 8), getKeys());

            // With predicate.
            res = queryable.RemoveAll(x => x.Key < 7);
            Assert.AreEqual(4, res);
            Assert.AreEqual(Enumerable.Range(7, 4), getKeys());

            // Subquery-style join.
            var ids = GetPersonCache().AsCacheQueryable().Where(x => x.Key == 7).Select(x => x.Key);

            res = queryable.Where(x => ids.Contains(x.Key)).RemoveAll();
            Assert.AreEqual(1, res);
            Assert.AreEqual(Enumerable.Range(8, 3), getKeys());

            // Row number limit.
            res = queryable.Take(2).RemoveAll();
            Assert.AreEqual(2, res);
            Assert.AreEqual(1, getKeys().Length);

            // Unconditional.
            queryable.RemoveAll();
            Assert.AreEqual(0, cache.GetSize());

            // Skip is not supported with DELETE.
            var nex = Assert.Throws <NotSupportedException>(() => queryable.Skip(1).RemoveAll());

            Assert.AreEqual(
                "RemoveAll can not be combined with result operators (other than Take): SkipResultOperator",
                nex.Message);

            // Multiple result operators are not supported with DELETE.
            nex = Assert.Throws <NotSupportedException>(() => queryable.Skip(1).Take(1).RemoveAll());
            Assert.AreEqual(
                "RemoveAll can not be combined with result operators (other than Take): SkipResultOperator, " +
                "TakeResultOperator, RemoveAllResultOperator", nex.Message);

            // Joins are not supported in H2.
            var qry = queryable
                      .Where(x => x.Key == 7)
                      .Join(GetPersonCache().AsCacheQueryable(), p => p.Key, p => p.Key, (p1, p2) => p1);

            var ex = Assert.Throws <IgniteException>(() => qry.RemoveAll());

            Assert.AreEqual("Failed to parse query", ex.Message.Substring(0, 21));
        }
Пример #13
0
        public void FixtureTearDown()
        {
            Ignition.StopAll(true);

            Directory.Delete(_tempDir, true);
        }
Пример #14
0
        public static void Main()
        {
            using (IIgniteClient ignite = Ignition.StartClient(Utils.GetThinClientConfiguration()))
            {
                Console.WriteLine();
                Console.WriteLine(">>> Binary mode example started.");

                // Create new cache and configure queries for Person and Company binary types.
                // Note that there are no such classes defined.
                var cache0 = ignite.GetOrCreateCache <object, object>(new CacheClientConfiguration
                {
                    Name          = CacheName,
                    QueryEntities = new[]
                    {
                        new QueryEntity
                        {
                            KeyType       = typeof(int),
                            ValueTypeName = PersonType,
                            Fields        = new[]
                            {
                                new QueryField(NameField, typeof(string)),
                                new QueryField(CompanyIdField, typeof(int)),
                            },
                            Indexes = new[]
                            {
                                new QueryIndex(false, QueryIndexType.FullText, NameField),
                                new QueryIndex(false, QueryIndexType.Sorted, CompanyIdField)
                            }
                        },
                        new QueryEntity
                        {
                            KeyType       = typeof(int),
                            ValueTypeName = CompanyType,
                            Fields        = new[]
                            {
                                new QueryField(IdField, typeof(int)),
                                new QueryField(NameField, typeof(string))
                            }
                        }
                    }
                });

                // Switch to binary mode to work with data in serialized form.
                var cache = cache0.WithKeepBinary <int, IBinaryObject>();

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

                // Populate cache with sample data entries.
                PopulateCache(cache, ignite.GetBinary());

                // Run read & modify example.
                ReadModifyExample(cache);

                // Run SQL query example.
                SqlQueryExample(cache);

                // Run SQL query with join example.
                SqlJoinQueryExample(cache);

                Console.WriteLine();
            }

            Console.WriteLine();
            Console.WriteLine(">>> Example finished, press any key to exit ...");
            Console.ReadKey();
        }
Пример #15
0
        public void TestSession()
        {
            _dumps = new ConcurrentBag <ICollection <Operation> >();

            var ignite = Ignition.GetIgnite();

            var cache1 = ignite.GetCache <int, int>(Cache1);
            var cache2 = ignite.GetCache <int, int>(Cache2);

            // 1. Test rollback.
            using (var tx = ignite.GetTransactions().TxStart())
            {
                cache1.Put(1, 1);
                cache2.Put(2, 2);

                tx.Rollback();
            }

            // SessionEnd should not be called.
            Assert.AreEqual(0, _dumps.Count);

            // 2. Test puts.
            using (var tx = ignite.GetTransactions().TxStart())
            {
                cache1.Put(1, 1);
                cache2.Put(2, 2);

                tx.Commit();
            }

            Assert.AreEqual(StoreCount, _dumps.Count);

            foreach (var ops in _dumps)
            {
                Assert.AreEqual(2 + StoreCount, ops.Count);
                Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.Write &&
                                             Cache1 == op.CacheName && 1 == op.Key && 1 == op.Value));
                Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.Write &&
                                             Cache2 == op.CacheName && 2 == op.Key && 2 == op.Value));
                Assert.AreEqual(StoreCount, ops.Count(op => op.Type == OperationType.SesEnd && op.Commit));
            }

            _dumps = new ConcurrentBag <ICollection <Operation> >();

            // 3. Test removes.
            using (var tx = ignite.GetTransactions().TxStart())
            {
                cache1.Remove(1);
                cache2.Remove(2);

                tx.Commit();
            }

            Assert.AreEqual(StoreCount, _dumps.Count);
            foreach (var ops in _dumps)
            {
                Assert.AreEqual(2 + StoreCount, ops.Count);

                Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.Delete &&
                                             Cache1 == op.CacheName && 1 == op.Key));
                Assert.AreEqual(1, ops.Count(op => op.Type == OperationType.Delete &&
                                             Cache2 == op.CacheName && 2 == op.Key));
                Assert.AreEqual(StoreCount, ops.Count(op => op.Type == OperationType.SesEnd && op.Commit));
            }
        }
Пример #16
0
 public IgnitionCommand(Ignition ignition)
     : base(ignition.StartTime, ignition.Duration)
 {
     _throttle  = ignition.Throttle;
     _engineIds = ignition.EngineIds;
 }
 public void TearDown()
 {
     Ignition.StopAll(true);
     IgniteProcess.KillAll();
 }
Пример #18
0
 public void FixtureTearDown()
 {
     _ignite.GetCompute().ExecuteJavaTask <object>(StopTask, _javaNodeName);
     Ignition.StopAll(true);
 }
Пример #19
0
        public void TestTearDown()
        {
            ServerServices.CancelAll();

            TestUtils.AssertHandleRegistryIsEmpty(1000, Ignition.GetAll().ToArray());
        }
Пример #20
0
 public void Dispose()
 {
     Ignition.Stop(Name, true);
 }
 public void FixtureTearDown()
 {
     Ignition.StopAll(true);
 }
Пример #22
0
        public void TestMetricsPropagation()
        {
            using (var ignite = Ignition.Start(TestUtils.GetTestConfiguration()))
            {
                using (var inStream = IgniteManager.Memory.Allocate().GetStream())
                {
                    var result = ignite.GetCompute().ExecuteJavaTask <bool>(
                        "org.apache.ignite.platform.PlatformCacheWriteMetricsTask", inStream.MemoryPointer);

                    Assert.IsTrue(result);

                    inStream.SynchronizeInput();

                    var reader = ((Ignite)ignite).Marshaller.StartUnmarshal(inStream);

                    ICacheMetrics metrics = new CacheMetricsImpl(reader);

                    Assert.AreEqual(1, metrics.CacheHits);
                    Assert.AreEqual(2, metrics.CacheHitPercentage);
                    Assert.AreEqual(3, metrics.CacheMisses);
                    Assert.AreEqual(4, metrics.CacheMissPercentage);
                    Assert.AreEqual(5, metrics.CacheGets);
                    Assert.AreEqual(6, metrics.CachePuts);
                    Assert.AreEqual(7, metrics.CacheRemovals);
                    Assert.AreEqual(8, metrics.CacheEvictions);
                    Assert.AreEqual(9, metrics.AverageGetTime);
                    Assert.AreEqual(10, metrics.AveragePutTime);
                    Assert.AreEqual(11, metrics.AverageRemoveTime);
                    Assert.AreEqual(12, metrics.AverageTxCommitTime);
                    Assert.AreEqual(13, metrics.AverageTxRollbackTime);
                    Assert.AreEqual(14, metrics.CacheTxCommits);
                    Assert.AreEqual(15, metrics.CacheTxRollbacks);
                    Assert.AreEqual("myCache", metrics.CacheName);
                    Assert.AreEqual(16, metrics.OverflowSize);
                    Assert.AreEqual(17, metrics.OffHeapGets);
                    Assert.AreEqual(18, metrics.OffHeapPuts);
                    Assert.AreEqual(19, metrics.OffHeapRemovals);
                    Assert.AreEqual(20, metrics.OffHeapEvictions);
                    Assert.AreEqual(21, metrics.OffHeapHits);
                    Assert.AreEqual(22, metrics.OffHeapHitPercentage);
                    Assert.AreEqual(23, metrics.OffHeapMisses);
                    Assert.AreEqual(24, metrics.OffHeapMissPercentage);
                    Assert.AreEqual(25, metrics.OffHeapEntriesCount);
                    Assert.AreEqual(26, metrics.OffHeapPrimaryEntriesCount);
                    Assert.AreEqual(27, metrics.OffHeapBackupEntriesCount);
                    Assert.AreEqual(28, metrics.OffHeapAllocatedSize);
                    Assert.AreEqual(29, metrics.OffHeapMaxSize);
                    Assert.AreEqual(30, metrics.SwapGets);
                    Assert.AreEqual(31, metrics.SwapPuts);
                    Assert.AreEqual(32, metrics.SwapRemovals);
                    Assert.AreEqual(33, metrics.SwapHits);
                    Assert.AreEqual(34, metrics.SwapMisses);
                    Assert.AreEqual(35, metrics.SwapEntriesCount);
                    Assert.AreEqual(36, metrics.SwapSize);
                    Assert.AreEqual(37, metrics.SwapHitPercentage);
                    Assert.AreEqual(38, metrics.SwapMissPercentage);
                    Assert.AreEqual(39, metrics.Size);
                    Assert.AreEqual(40, metrics.KeySize);
                    Assert.AreEqual(true, metrics.IsEmpty);
                    Assert.AreEqual(41, metrics.DhtEvictQueueCurrentSize);
                    Assert.AreEqual(42, metrics.TxThreadMapSize);
                    Assert.AreEqual(43, metrics.TxXidMapSize);
                    Assert.AreEqual(44, metrics.TxCommitQueueSize);
                    Assert.AreEqual(45, metrics.TxPrepareQueueSize);
                    Assert.AreEqual(46, metrics.TxStartVersionCountsSize);
                    Assert.AreEqual(47, metrics.TxCommittedVersionsSize);
                    Assert.AreEqual(48, metrics.TxRolledbackVersionsSize);
                    Assert.AreEqual(49, metrics.TxDhtThreadMapSize);
                    Assert.AreEqual(50, metrics.TxDhtXidMapSize);
                    Assert.AreEqual(51, metrics.TxDhtCommitQueueSize);
                    Assert.AreEqual(52, metrics.TxDhtPrepareQueueSize);
                    Assert.AreEqual(53, metrics.TxDhtStartVersionCountsSize);
                    Assert.AreEqual(54, metrics.TxDhtCommittedVersionsSize);
                    Assert.AreEqual(55, metrics.TxDhtRolledbackVersionsSize);
                    Assert.AreEqual(true, metrics.IsWriteBehindEnabled);
                    Assert.AreEqual(56, metrics.WriteBehindFlushSize);
                    Assert.AreEqual(57, metrics.WriteBehindFlushThreadCount);
                    Assert.AreEqual(58, metrics.WriteBehindFlushFrequency);
                    Assert.AreEqual(59, metrics.WriteBehindStoreBatchSize);
                    Assert.AreEqual(60, metrics.WriteBehindTotalCriticalOverflowCount);
                    Assert.AreEqual(61, metrics.WriteBehindCriticalOverflowCount);
                    Assert.AreEqual(62, metrics.WriteBehindErrorRetryCount);
                    Assert.AreEqual(63, metrics.WriteBehindBufferSize);
                    Assert.AreEqual("foo", metrics.KeyType);
                    Assert.AreEqual("bar", metrics.ValueType);
                    Assert.AreEqual(true, metrics.IsStoreByValue);
                    Assert.AreEqual(true, metrics.IsStatisticsEnabled);
                    Assert.AreEqual(true, metrics.IsManagementEnabled);
                    Assert.AreEqual(true, metrics.IsReadThrough);
                    Assert.AreEqual(true, metrics.IsWriteThrough);
                }
            }
        }
 public void TearDown()
 {
     Ignition.StopAll(true);
 }
Пример #24
0
 public void StopGrids()
 {
     Ignition.StopAll(true);
 }
Пример #25
0
 /** <inheritDoc /> */
 protected override void OnStart(string[] args)
 {
     Ignition.Start(_cfg);
 }
Пример #26
0
 /// <summary>
 /// Gets the client.
 /// </summary>
 protected IIgniteClient GetClient()
 {
     return(Ignition.StartClient(GetClientConfiguration()));
 }
Пример #27
0
        public void AfterTest()
        {
            var cache = Cache();

            for (int i = 0; i < GridCnt; i++)
            {
                for (int j = 0; j < MaxItemCnt; j++)
                {
                    cache.Remove(j);
                }

                Assert.IsTrue(cache.IsEmpty());
            }

            TestUtils.AssertHandleRegistryIsEmpty(300,
                                                  Enumerable.Range(0, GridCnt).Select(x => Ignition.GetIgnite("grid-" + x)).ToArray());

            Console.WriteLine("Test finished: " + TestContext.CurrentContext.Test.Name);
        }
Пример #28
0
 public void BeforeTests()
 {
     Ignition.Start(GetIgniteConfiguration());
 }
Пример #29
0
 /// <summary>
 /// Gets the cache.
 /// </summary>
 protected static ICache <int, T> GetCache <T>()
 {
     return(Ignition.GetIgnite().GetOrCreateCache <int, T>(CacheName));
 }
Пример #30
0
        /// <summary>
        /// Starts the ignite with three policies (two in-memory and one persistent).
        /// </summary>
        private static IIgnite StartIgniteWithThreeDataRegions()
        {
            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
            {
                DataStorageConfiguration = new DataStorageConfiguration()
                {
                    CheckpointFrequency            = CheckpointFrequency,
                    MetricsEnabled                 = true,
                    WalMode                        = WalMode.LogOnly,
                    DefaultDataRegionConfiguration = new DataRegionConfiguration
                    {
                        Name = RegionWithMetrics,
                        PersistenceEnabled = false,
                        MetricsEnabled     = true
                    },
                    DataRegionConfigurations = new[]
                    {
                        new DataRegionConfiguration
                        {
                            Name           = RegionNoMetrics,
                            MetricsEnabled = false
                        },
                        new DataRegionConfiguration()
                        {
                            Name = RegionWithMetricsAndPersistence,
                            PersistenceEnabled = true,
                            MetricsEnabled     = true
                        }
                    }
                },
                WorkDirectory = TempDir
            };

            var ignite = Ignition.Start(cfg);

            ignite.GetCluster().SetActive(true);

            // Create caches and do some things with them.
            var cacheNoMetrics = ignite.CreateCache <int, int>(new CacheConfiguration("cacheNoMetrics")
            {
                DataRegionName = RegionNoMetrics
            });

            cacheNoMetrics.Put(1, 1);
            cacheNoMetrics.Get(1);

            var cacheWithMetrics = ignite.CreateCache <int, int>(new CacheConfiguration("cacheWithMetrics")
            {
                DataRegionName = RegionWithMetrics
            });

            cacheWithMetrics.Put(1, 1);
            cacheWithMetrics.Get(1);

            var cacheWithMetricsAndPersistence =
                ignite.CreateCache <int, int>(new CacheConfiguration("cacheWithMetricsAndPersistence")
            {
                DataRegionName = RegionWithMetricsAndPersistence
            });

            cacheWithMetricsAndPersistence.Put(1, 1);
            cacheWithMetricsAndPersistence.Get(1);

            // Wait for checkpoint. Wait for two times than CheckpointFrequency.
            Thread.Sleep(CheckpointFrequency.Add(CheckpointFrequency));

            return(ignite);
        }