示例#1
0
        public void TestCreateFromTemplate()
        {
            // Create a cache with random name
            var randomName = "template" + Guid.NewGuid();

            // Can't get non-existent cache with Cache method
            Assert.Throws <ArgumentException>(() => Ignite.GetCache <int, int>(randomName));
            Assert.IsFalse(Ignite.GetCacheNames().Contains(randomName));

            // Create cache and verify template setting.
            var cache = Ignite.CreateCache <int, int>(randomName);

            Assert.AreEqual(3, cache.GetConfiguration().Backups);
            Assert.IsTrue(Ignite.GetCacheNames().Contains(randomName));

            cache.Put(1, 10);
            Assert.AreEqual(10, cache.Get(1));

            // Can't create again
            Assert.Throws <IgniteException>(() => Ignite.CreateCache <int, int>(randomName));

            var cache0 = Ignite.GetCache <int, int>(randomName);

            Assert.AreEqual(10, cache0.Get(1));
        }
示例#2
0
        /// <summary>
        /// Defines the actions to take when the service is initialised prior to execution
        /// </summary>
        /// <param name="context"></param>
        public void Init(IServiceContext context)
        {
            if (context != null)
            {
                _svcName = context.Name;
            }

            mutableNonSpatialCache = Ignite.GetCache <INonSpatialAffinityKey, byte[]>(CacheName);
        }
示例#3
0
        /// <summary>
        /// Invokes the receiver.
        /// </summary>
        /// <param name="receiver">Receiver.</param>
        /// <param name="grid">Grid.</param>
        /// <param name="cache">Cache.</param>
        /// <param name="stream">Stream.</param>
        /// <param name="keepBinary">Binary flag.</param>
        public static void InvokeReceiver <TK, TV>(IStreamReceiver <TK, TV> receiver, Ignite grid,
                                                   IPlatformTargetInternal cache, IBinaryStream stream, bool keepBinary)
        {
            var reader = grid.Marshaller.StartUnmarshal(stream, keepBinary);

            var size = reader.ReadInt();

            var entries = new List <ICacheEntry <TK, TV> >(size);

            for (var i = 0; i < size; i++)
            {
                entries.Add(new CacheEntry <TK, TV>(reader.ReadObject <TK>(), reader.ReadObject <TV>()));
            }

            receiver.Receive(Ignite.GetCache <TK, TV>(cache, keepBinary), entries);
        }
            public long Invoke()
            {
                var cache = Ignite.GetCache <int, Person>(CacheName);

                // Local partition scan iterates over Platform Cache entries directly.
                var query = new ScanQuery <int, Person>
                {
                    Local     = true,
                    Partition = Partition
                };

                var sum = cache.Query(query)
                          .Select(entry => entry.Value.Data.Sum(c => (long)c))
                          .Sum();

                return(sum);
            }