Exemplo n.º 1
0
        public void TestClientOnlyPlatformCache()
        {
            var cache = _grid.CreateCache <int, int>(TestUtils.TestName);

            cache[1] = 2;

            var clientCache = _client.CreateNearCache <int, int>(cache.Name, new NearCacheConfiguration(),
                                                                 new PlatformCacheConfiguration());

            Assert.AreEqual(2, clientCache[1]);
            Assert.AreEqual(1, clientCache.GetLocalSize(CachePeekMode.Platform));

            var clientCache2 = _client.GetOrCreateNearCache <int, int>(cache.Name, new NearCacheConfiguration(),
                                                                       new PlatformCacheConfiguration());

            Assert.AreEqual(2, clientCache2[1]);
            Assert.AreEqual(1, clientCache2.GetLocalSize(CachePeekMode.Platform));

            var clientCache3 = _client.CreateCache <int, int>(new CacheConfiguration(cache.Name + "3"),
                                                              new NearCacheConfiguration(), new PlatformCacheConfiguration());

            clientCache3[1] = 2;
            Assert.AreEqual(2, clientCache3.LocalPeek(1, CachePeekMode.Platform));

            var clientCache4 = _client.GetOrCreateCache <int, int>(new CacheConfiguration(cache.Name + "4"),
                                                                   new NearCacheConfiguration(), new PlatformCacheConfiguration());

            clientCache4[1] = 2;
            Assert.AreEqual(2, clientCache4.LocalPeek(1, CachePeekMode.Platform));
        }
Exemplo n.º 2
0
        private static void PerformClientReconnect(IIgnite client)
        {
            var disconnectedEvt = new ManualResetEventSlim(false);

            client.ClientDisconnected += (sender, args) => { disconnectedEvt.Set(); };

            var reconnectedEvt = new ManualResetEventSlim(false);
            ClientReconnectEventArgs reconnectEventArgs = null;

            client.ClientReconnected += (sender, args) =>
            {
                reconnectEventArgs = args;
                reconnectedEvt.Set();
            };

            var gridName = string.Format("%{0}%", client.Name);

            TestUtilsJni.SuspendThreads(gridName);
            Thread.Sleep(9000);
            TestUtilsJni.ResumeThreads(gridName);

            Assert.Catch(() => client.CreateCache <int, int>("_fail").Put(1, 1));

            var disconnected = disconnectedEvt.Wait(TimeSpan.FromSeconds(3));

            Assert.IsTrue(disconnected);

            Assert.Catch(() => client.CreateCache <int, int>("_fail").Put(1, 1));
            var reconnected = reconnectedEvt.Wait(TimeSpan.FromSeconds(15));

            Assert.IsTrue(reconnected);
            Assert.IsFalse(reconnectEventArgs.HasClusterRestarted);
        }
Exemplo n.º 3
0
        public void TestCreateNearCacheOnClientNode()
        {
            const string cacheName = "client_cache";

            _client.CreateCache <int, int>(cacheName);

            // Near cache can't be started on client node
            Assert.Throws <CacheException>(
                () => _client.CreateNearCache <int, int>(cacheName, new NearCacheConfiguration()));
        }
        public void TestDynamicCache()
        {
            var cache = _grid.CreateCache <int, int>(new CacheConfiguration(DynCacheName)
            {
                PluginConfigurations = new[] { new CacheJavaPluginConfiguration() }
            });

            VerifyCachePlugin(cache);
        }
Exemplo n.º 5
0
        public void InitClient()
        {
            _grid = Ignition.Start(TestUtils.GetTestConfiguration());

            Ignition.Start(new IgniteConfiguration(TestUtils.GetTestConfiguration())
            {
                IgniteInstanceName = "grid1"
            });

            _cache = _grid.CreateCache <int, int?>(CacheName);
        }
Exemplo n.º 6
0
        public void TestCreateNearCache(
            [Values(CacheMode.Partitioned, CacheMode.Replicated)]
            CacheMode cacheMode,
            [Values(CacheAtomicityMode.Atomic, CacheAtomicityMode.Transactional)]
            CacheAtomicityMode atomicityMode)
        {
            var cacheName = string.Format("dyn_cache_{0}_{1}", cacheMode, atomicityMode);

            var cfg = new CacheConfiguration(cacheName)
            {
                AtomicityMode = atomicityMode,
                CacheMode     = cacheMode
            };

            var cache = _grid.CreateCache <int, int>(cfg);

            cache[1] = 1;

            var nearCacheConfiguration = new NearCacheConfiguration();
            var nearCache = _client.CreateNearCache <int, int>(cacheName, nearCacheConfiguration);

            Assert.AreEqual(1, nearCache[1]);

            // Create when exists.
            nearCache = _client.CreateNearCache <int, int>(cacheName, nearCacheConfiguration);
            Assert.AreEqual(1, nearCache[1]);

            // Update entry.
            cache[1] = 2;
            Assert.True(TestUtils.WaitForCondition(() => nearCache[1] == 2, 300));

            // Update through near.
            nearCache[1] = 3;
            Assert.AreEqual(3, nearCache[1]);

            // Remove.
            cache.Remove(1);
            Assert.True(TestUtils.WaitForCondition(() => !nearCache.ContainsKey(1), 300));
        }
Exemplo n.º 7
0
        public void TestAffinityCallWithPartition([Values(true, false)] bool async)
        {
            var cacheName = DefaultCacheName;
            var aff       = _grid1.GetAffinity(cacheName);
            var localNode = _grid1.GetCluster().GetLocalNode();
            var part      = aff.GetPrimaryPartitions(localNode).First();
            var compute   = _grid1.GetCompute();

            Func <IEnumerable <string>, int> action = names => async
                ? compute.AffinityCallAsync(names, part, new ComputeFunc()).Result
                : compute.AffinityCall(names, part, new ComputeFunc());

            // One cache.
            var res = action(new[] { cacheName });

            Assert.AreEqual(res, ComputeFunc.InvokeCount);
            Assert.AreEqual(localNode.Id, ComputeFunc.LastNodeId);

            // Two caches.
            var cache = _grid1.CreateCache <int, int>(TestUtils.TestName);

            res = action(new[] { cacheName, cache.Name });

            Assert.AreEqual(res, ComputeFunc.InvokeCount);
            Assert.AreEqual(localNode.Id, ComputeFunc.LastNodeId);

            // Empty caches.
            var ex = Assert.Throws <ArgumentException>(() => action(new string[0]));

            StringAssert.StartsWith("cacheNames can not be empty", ex.Message);

            // Invalid cache name.
            Assert.Throws <AggregateException>(() => action(new[] { "bad" }));

            // Invalid partition.
            Assert.Throws <ArgumentException>(() => compute.AffinityCall(new[] { cacheName }, -1, new ComputeFunc()));
        }
Exemplo n.º 8
0
        public void GlobalSetup()
        {
            _ignite = Ignition.Start();

            _cache = _ignite.CreateCache <int, Person>("normalCache");

            _cacheWithPlatformCache = _ignite.CreateCache <int, Person>(new CacheConfiguration
            {
                Name = "platformEnabledCache",
                PlatformCacheConfiguration = new PlatformCacheConfiguration
                {
                    KeyTypeName   = typeof(int).AssemblyQualifiedName,
                    ValueTypeName = typeof(Person).AssemblyQualifiedName
                }
            });

            var data = Enumerable.Range(1, 10000)
                       .Select(Person.CreateInstance <Person>)
                       .Select(p => new KeyValuePair <int, Person>(p.Id, p))
                       .ToArray();

            _cache.PutAll(data);
            _cacheWithPlatformCache.PutAll(data);
        }
Exemplo n.º 9
0
        public IgniteLogic()
        {
            var cfg = new IgniteConfiguration()
            {
            };


            _instance = Ignition.TryGetIgnite() ?? Ignition.Start();

            var cache = _instance.CreateCache <int, Test3>("ab");

            var retcur = cache.Query(new SqlQuery(typeof(Test3), ""));

            var itemlist = retcur.GetAll().Select(p => p.Value);
        }
        public void GlobalSetup()
        {
            _ignite = Ignition.Start();

            // Reduce number of partitions to reduce overhead.
            // With real-world data sets this won't be needed.
            var affinityFunction = new RendezvousAffinityFunction
            {
                Partitions = 10
            };

            _cache = _ignite.CreateCache <int, Person>(new CacheConfiguration
            {
                Name             = "normalCache",
                AffinityFunction = affinityFunction
            });

            _cacheWithPlatformCache = _ignite.CreateCache <int, Person>(new CacheConfiguration
            {
                Name                       = "platformEnabledCache",
                AffinityFunction           = affinityFunction,
                PlatformCacheConfiguration = new PlatformCacheConfiguration
                {
                    KeyTypeName   = typeof(int).AssemblyQualifiedName,
                    ValueTypeName = typeof(Person).AssemblyQualifiedName
                }
            });

            var data = Enumerable.Range(1, 100000)
                       .Select(x => Person.CreateInstance <Person>(x, dataSize: 10))
                       .Select(p => new KeyValuePair <int, Person>(p.Id, p))
                       .ToArray();

            _cache.PutAll(data);
            _cacheWithPlatformCache.PutAll(data);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Creates the cache.
 /// </summary>
 private static ICache <int, int> CreateCache(PartitionLossPolicy policy, IIgnite ignite)
 {
     return(ignite.CreateCache <int, int>(new CacheConfiguration(CacheName)
     {
         CacheMode = CacheMode.Partitioned,
         Backups = 0,
         WriteSynchronizationMode = CacheWriteSynchronizationMode.FullSync,
         PartitionLossPolicy = policy,
         AffinityFunction = new RendezvousAffinityFunction
         {
             ExcludeNeighbors = false,
             Partitions = 32
         }
     }));
 }
Exemplo n.º 12
0
        public void TestCreateNearCache()
        {
            const string cacheName = "dyn_cache";

            var cache = _grid.CreateCache <int, string>(cacheName);

            cache[1] = "1";

            var nearCache = _grid.CreateNearCache <int, string>(cacheName, new NearCacheConfiguration());

            Assert.AreEqual("1", nearCache[1]);

            // Create when exists
            nearCache = _grid.CreateNearCache <int, string>(cacheName, new NearCacheConfiguration());
            Assert.AreEqual("1", nearCache[1]);
        }
Exemplo n.º 13
0
        public void TestAddRemoveFieldsDynamically()
        {
            var cache1 = _node1.CreateCache <int, DynamicFieldSetSerializable>("c");
            var cache2 = _node2.GetCache <int, DynamicFieldSetSerializable>("c");

            // Put/get without optional fields.
            var noFields = new DynamicFieldSetSerializable();

            cache1[1] = noFields;

            AssertExtensions.ReflectionEqual(noFields, cache1[1]);
            AssertExtensions.ReflectionEqual(noFields, cache2[1]);

            Assert.AreEqual(new[] { "WriteBar", "WriteFoo" }, GetFields(0));
            Assert.AreEqual(new[] { "WriteBar", "WriteFoo" }, GetFields(1));

            // Put/get with one optional field.
            var oneField = new DynamicFieldSetSerializable
            {
                Bar      = "abc",
                WriteBar = true
            };

            cache1[2] = oneField;

            AssertExtensions.ReflectionEqual(oneField, cache1[2]);
            AssertExtensions.ReflectionEqual(oneField, cache2[2]);
            Assert.AreEqual(new[] { "Bar", "WriteBar", "WriteFoo" }, GetFields(0));
            Assert.AreEqual(new[] { "Bar", "WriteBar", "WriteFoo" }, GetFields(1));

            // Put/get with another optional field.
            var oneField2 = new DynamicFieldSetSerializable
            {
                Foo      = 25,
                WriteFoo = true
            };

            cache1[3] = oneField2;

            AssertExtensions.ReflectionEqual(oneField2, cache1[3]);
            AssertExtensions.ReflectionEqual(oneField2, cache2[3]);

            Assert.AreEqual(new[] { "Bar", "Foo", "WriteBar", "WriteFoo" }, GetFields(0));
            Assert.AreEqual(new[] { "Bar", "Foo", "WriteBar", "WriteFoo" }, GetFields(1));
        }
Exemplo n.º 14
0
        public void TestCreateNearCache()
        {
            const string cacheName = "dyn_cache";

            var cache = _grid.CreateCache <int, string>(new CacheConfiguration(cacheName));

            cache[1] = "1";

            using (var client = Ignition.Start(new IgniteConfiguration(TestUtils.GetTestConfiguration())
            {
                ClientMode = true,
                IgniteInstanceName = "client"
            }))
            {
                var nearCache = client.CreateNearCache <int, string>(cacheName, new NearCacheConfiguration());
                Assert.AreEqual("1", nearCache[1]);

                // Create when exists.
                nearCache = client.CreateNearCache <int, string>(cacheName, new NearCacheConfiguration());
                Assert.AreEqual("1", nearCache[1]);
            }
        }
Exemplo n.º 15
0
 public static ICache <T, object> CreateBinaryCache <T>(this IIgnite ignite, string name)
 {
     return(ignite.CreateCache <T, object>(name).WithKeepBinary <T, object>());
 }
Exemplo n.º 16
0
 /** <inheritdoc /> */
 public ICache <TK, TV> CreateCache <TK, TV>(string name)
 {
     return(_ignite.CreateCache <TK, TV>(name));
 }
Exemplo n.º 17
0
 public static ICache <T, object> CreateBinaryCache <T>(this IIgnite ignite, CacheConfiguration cacheConfiguration)
 {
     return(ignite.CreateCache <T, object>(cacheConfiguration).WithKeepBinary <T, object>());
 }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            string   s;
            DateTime startTime;
            DateTime endTime;

            IgniteConfiguration cfg = new IgniteConfiguration()
            {
                IgniteInstanceName = "TRex",

                // Register custom class for Ignite serialization
                BinaryConfiguration = new Apache.Ignite.Core.Binary.BinaryConfiguration(typeof(MyCacheClass))
            };

            IIgnite ignite = Ignition.Start(cfg);

            // Add a cache to Ignite
            ICache <string, MyCacheClass> cache = ignite.CreateCache <string, MyCacheClass>
                                                      (new CacheConfiguration()
            {
                Name                      = "TestCache",
                CopyOnRead                = false,
                KeepBinaryInStore         = false,
                CacheStoreFactory         = new TRexCacheStoreFactory(),
                ReadThrough               = true,
                WriteThrough              = true,
                WriteBehindFlushFrequency = new TimeSpan(0, 0, 5),     // 5 seconds
                EvictionPolicy            = new LruEvictionPolicy()
                {
                    MaxMemorySize = 1000000,
                }
            });

            int NumCacheEntries = 5000;

            // Add a cache item
            cache.Put("First", new MyCacheClass("FirstItem"));

            // Add a collectikon of items
            startTime = DateTime.Now;
            for (int i = 0; i < NumCacheEntries; i++)
            {
                cache.Put("First" + i, new MyCacheClass("First" + i));
            }
            endTime = DateTime.Now;

            s = string.Format("{0}", endTime - startTime);
            Console.WriteLine("Time to add cache items with serialisation: {0}", s);

            int sumsum = 0;

            // Query back the cache items with serialisation
            startTime = DateTime.Now;
            for (int i = 0; i < NumCacheEntries; i++)
            {
                MyCacheClass first = cache.Get("First" + i);

                int sum = 0;
                for (int ii = 0; ii < first.localData.Length; ii++)
                {
                    sum += first.localData[ii];
                }
                sumsum += sum;
            }
            endTime = DateTime.Now;

            s = string.Format("{0}", endTime - startTime);
            Console.WriteLine("Time to query cache items with serialisation: {0}, sum = {1}", s, sumsum);

            var binCache = cache.WithKeepBinary <string, IBinaryObject>();

            //            IBinaryObject binCacheItem = binCache["First"];
            //            Console.WriteLine(binCacheItem.GetField<string>("Name"));

            // Query back the cache items without serialisation (using BinaryObject)
            startTime = DateTime.Now;
            for (int i = 0; i < NumCacheEntries; i++)
            {
                IBinaryObject binCacheItem = binCache["First" + i];

                byte[] bytes = binCacheItem.GetField <byte[]>("localData");

                int sum = 0;
                for (int ii = 0; ii < bytes.Length; ii++)
                {
                    sum += bytes[ii];
                }
                sumsum += sum;
            }
            endTime = DateTime.Now;

            s = string.Format("{0}", endTime - startTime);
            Console.WriteLine("Time to query cache items without serialisation: {0}, sum = {1}", s, sumsum);

            // Get compute instance over all nodes in the cluster.
            ICompute      compute  = ignite.GetCompute();
            IClusterGroup compute2 = ignite.GetCompute().ClusterGroup;



            // Execute a map reduce on the cluster
            if (compute2.ForServers()?.GetNodes()?.Any() == true)
            {
                try
                {
                    string mapReduceResult = ignite.GetCompute().Execute <string, string, string>(new MyComputeTask(), "Bob");
                    Console.WriteLine("Mapreduce result = '{0}'", mapReduceResult);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception executing mapReduce execution\r\n: {0}", e);
                }
            }
            else
            {
                Console.WriteLine("Calling cluster mapReduce broadcast function: No servers present in cluster");
            }

            // Execute a command using affinity on the cluster
            try
            {
                string affinityResult = ignite.GetCompute().AffinityCall <string>("TestCache", "First", new AffinityComputeFunc("First"));
                Console.WriteLine("Affinity result = '{0}'", affinityResult);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception executing affinity execution\r\n: {0}", e);
            }

            if (ignite == null)
            {
                Console.WriteLine("Ignite instance is null at end of method");
            }
            Console.ReadKey();
        }