Пример #1
0
        private void PutAccounts(IRemoteCache <int, Account> remoteCache)
        {
            Account account1 = new Account();

            account1.Id           = 1;
            account1.Description  = "John Doe's first bank account";
            account1.CreationDate = MakeDate("2013-01-03");

            remoteCache.Put(4, account1);

            Account account2 = new Account();

            account2.Id           = 2;
            account2.Description  = "John Doe's second bank account";
            account2.CreationDate = MakeDate("2013-01-04");

            remoteCache.Put(5, account2);

            Account account3 = new Account();

            account3.Id           = 3;
            account3.CreationDate = MakeDate("2013-01-20");

            remoteCache.Put(6, account3);
        }
 public void PopulateCache()
 {
     defaultCache = remoteManager.GetCache<String,String>();
     defaultCache.Put("key1", "hydrogen");
     defaultCache.Put("key2", "helium");
     defaultCache.Put("key3", "lithium");
 }
Пример #3
0
        public void ReadRollbackOnExistent()
        {
            InitializeRemoteCacheManager(true);
            IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>("non_xa", true);
            var txManager = remoteManager.GetTransactionManager();

            string k1   = "key13";
            string oldv = "oxygen";
            string v1   = "boron";
            string rv1;

            cache.Clear();
            string oldrv1 = cache.Put(k1, oldv);

            Assert.IsNull(oldrv1);
            try
            {
                txManager.Begin();
                oldrv1 = cache.Put(k1, v1);
                Assert.AreEqual(oldrv1, oldv);
                // Check the correct value from the tx context
                rv1 = cache.Get(k1);
                Assert.AreEqual(rv1, v1);
            } finally {
                txManager.Rollback();
            }
            // Check the correct value from remote cache
            rv1 = cache.Get(k1);
            Assert.AreEqual(oldrv1, oldv);
        }
Пример #4
0
        public void ChangeExistentAndCommit()
        {
            InitializeRemoteCacheManager(true);
            IRemoteCache <string, string> cache = remoteManager.GetCache <string, string>("non_xa", true);
            var txManager = remoteManager.GetTransactionManager();

            string k1 = "key13";
            string v0 = "carbon";
            string v1 = "boron";
            string rv1;

            cache.Clear();
            cache.Put(k1, v0);
            try
            {
                txManager.Begin();
                cache.Put(k1, v1);
                // Check the correct value from the tx context
                rv1 = cache.Get(k1);
                Assert.AreEqual(rv1, v1);
                txManager.Commit();
            }
            catch (Exception ex)
            {
                // try to release the tx resources
                txManager.Rollback();
                throw ex;
            }
            // Check the correct value from remote cache
            rv1 = cache.Get(k1);
            Assert.AreEqual(rv1, v1);
        }
Пример #5
0
 protected void TestPutClear(IRemoteCache <string, string> cache)
 {
     cache.Put(K1, V1);
     cache.Put(K2, V2);
     cache.Clear();
     Assert.IsTrue(cache.IsEmpty());
 }
Пример #6
0
        protected void TestPutClearAsync(IRemoteCache <string, string> cache)
        {
            cache.Put(K1, V1);
            cache.Put(K2, V2);
            Task task = cache.ClearAsync();

            task.Wait(5000);
            Assert.IsTrue(cache.IsEmpty());
        }
Пример #7
0
        protected void TestPutGetBulk(IRemoteCache <string, string> cache)
        {
            cache.Remove(K1);
            cache.Remove(K2);
            ulong before = cache.Size();

            cache.Put(K1, V1);
            cache.Put(K2, V2);
            Assert.AreEqual(before + 2, cache.GetBulk().Count);
        }
Пример #8
0
        protected void TestPutKeySet(IRemoteCache <string, string> cache)
        {
            cache.Remove(K1);
            cache.Remove(K2);
            ulong before = cache.Size();

            cache.Put(K1, V1);
            cache.Put(K2, V2);
            ISet <string> keyset = cache.KeySet();

            Assert.AreEqual(before + 2, keyset.Count);
        }
Пример #9
0
        public void ProjectionBasicContQueryTest()
        {
            int joined = 0, updated = 0, leaved = 0;

            object[] uT = null, lT = null;
            try
            {
                IRemoteCache <int, User> userCache = remoteManager.GetCache <int, User>(NAMED_CACHE);
                userCache.Clear();
                Semaphore    s  = new Semaphore(0, 1);
                QueryRequest qr = new QueryRequest();
                qr.QueryString = "select id, name from sample_bank_account.User";
                Event.ContinuousQueryListener <int, object[]> cql = new Event.ContinuousQueryListener <int, object[]>(qr.QueryString);
                cql.JoiningCallback = (int k, object[] v) => { joined++; };
                cql.UpdatedCallback = (int k, object[] v) => {
                    uT = v;
                    updated++;
                };
                cql.LeavingCallback = (int k, object[] v) => {
                    lT = v;
                    leaved++;
                    s.Release();
                };

                userCache.AddContinuousQueryListener(cql);

                User u1 = CreateUser1(userCache);
                User u2 = CreateUser2(userCache);

                userCache.Put(1, u1);
                userCache.Put(2, u2);
                u1.Name    = "Jerry";
                u1.Surname = "Mouse";
                userCache.Put(1, u1);
                userCache.Remove(2);
                s.WaitOne(10000);
                userCache.RemoveContinuousQueryListener(cql);
                userCache.Clear();
                remoteManager.Stop();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Assert.AreEqual(2, joined);
            Assert.AreEqual(1, updated);
            Assert.AreEqual(1, leaved);
            Assert.AreEqual(uT, new object[] { 1, "Jerry" });
            Assert.AreEqual(lT, new object[] { 2, "Spider" });
        }
Пример #10
0
 protected void TestPutRemoveContains(IRemoteCache <string, string> cache)
 {
     cache.Put(K1, V1);
     Assert.IsTrue(cache.ContainsKey(K1));
     cache.Remove(K1);
     Assert.IsFalse(cache.ContainsKey(K1));
 }
Пример #11
0
        protected void TestAddRemoveListener(IRemoteCache <string, string> cache)
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Remove(K1);
                cache.Remove(K2);
                cl.filterFactoryName    = "";
                cl.converterFactoryName = "";
                cl.AddListener(listener.CreatedEventAction);
                cache.AddClientListener(cl, new string[] { }, new string[] { }, null);
                cache.Put(K1, V1);
                var remoteEvent = listener.PollCreatedEvent();
                Assert.AreEqual(K1, remoteEvent.GetKey());
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
Пример #12
0
        private static void putPersons(IRemoteCache <int, Person> cache)
        {
            Console.WriteLine(">>> Loading persons");
            string[] firstNames = File.ReadAllLines(@"..\..\First_Names.csv", Encoding.UTF8);
            string[] lastNames  = File.ReadAllLines(@"..\..\Last_Names.csv", Encoding.UTF8);
            int      key        = 1;

            foreach (string lastName in lastNames)
            {
                foreach (string firstName in firstNames)
                {
                    Random randomAge = new Random();

                    cache.Put(key, new Person {
                        Id = key, FirstName = firstName, Surname = lastName, Age = randomAge.Next(120)
                    });

                    key++;
                    if ((key % 100000) == 0)
                    {
                        Console.WriteLine("  " + key);

                        if (key == 1000000)
                        {
                            return;
                        }
                    }
                }
            }
            Console.WriteLine(">>> Loading persons DONE");
        }
Пример #13
0
        public void BeforeClass()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222);
            conf.ConnectionTimeout(90000).SocketTimeout(6000);
            conf.Marshaller(new BasicTypesProtoStreamMarshaller());
            remoteManager = new RemoteCacheManager(conf.Build(), true);

            IRemoteCache <String, String> metadataCache = remoteManager.GetCache <String, String>(PROTOBUF_METADATA_CACHE_NAME);

            metadataCache.Remove(ERRORS_KEY_SUFFIX);
            metadataCache.Put("sample_bank_account/bank.proto", File.ReadAllText("proto2/bank.proto"));
            if (metadataCache.ContainsKey(ERRORS_KEY_SUFFIX))
            {
                Assert.Fail("fail: error in registering .proto model");
            }
            remoteManager.Administration().CreateCacheWithXml <object, object>(NAMED_CACHE,
                                                                               "<infinispan><cache-container><distributed-cache name=\"" + NAMED_CACHE + "\">" +
                                                                               "            <indexing> " +
                                                                               "           <indexed-entities> " +
                                                                               "             <indexed-entity>sample_bank_account.User</indexed-entity>" +
                                                                               "             <indexed-entity>sample_bank_account.Transaction</indexed-entity>" +
                                                                               "         </indexed-entities>" +
                                                                               "     </indexing> " +
                                                                               " </distributed-cache> " +
                                                                               " </cache-container></infinispan>");
            IRemoteCache <String, Transaction> transactionCache = remoteManager.GetCache <String, Transaction>(NAMED_CACHE);

            Assert.NotNull(transactionCache);
            PutTransactions(transactionCache);
        }
Пример #14
0
        public void PutAndReadWithNonTxCache()
        {
            InitializeRemoteCacheManager(true);
            InitializeNonTxRemoteCacheManager(true);
            IRemoteCache <string, string> cache      = remoteManager.GetCache <string, string>("non_xa", true);
            IRemoteCache <string, string> nonTxCache = nonTxRemoteManager.GetCache <string, string>("non_xa", true);
            var txManager = remoteManager.GetTransactionManager();

            string k1 = "key13";
            string v1 = "boron";
            string rv1;

            cache.Clear();
            try
            {
                txManager.Begin();
                string oldv1 = nonTxCache.Put(k1, v1);
                // Check the correct value from the tx context
                rv1 = nonTxCache.Get(k1);
                Assert.AreEqual(rv1, v1);
                rv1 = cache.Remove(k1);
                rv1 = cache.Get(k1);
                Assert.IsNull(rv1);
            } finally {
                txManager.Rollback();
            }
            rv1 = nonTxCache.Get(k1);
            Assert.AreEqual(rv1, v1);
        }
Пример #15
0
        public void CustomEventsTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cl.filterFactoryName    = "";
                cl.converterFactoryName = "";
                cl.converterFactoryName = "to-string-converter-factory";
                cl.AddListener(listener.CreatedEventAction);
                cl.AddListener(listener.ModifiedEventAction);
                cl.AddListener(listener.RemovedEventAction);
                cl.AddListener(listener.ExpiredEventAction);
                cl.AddListener(listener.CustomEventAction);
                cache.AddClientListener(cl, new string[] { }, new string[] { }, null);
                cache.Put("key1", "value1");
                AssertOnlyCustom("custom event: key1 value1", listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
Пример #16
0
        public void BeforeClass()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222);
            conf.ConnectionTimeout(90000).SocketTimeout(6000);
            conf.Marshaller(new BasicTypesProtoStreamMarshaller());
            remoteManager = new RemoteCacheManager(conf.Build(), true);

            IRemoteCache <String, String> metadataCache = remoteManager.GetCache <String, String>(PROTOBUF_METADATA_CACHE_NAME);

            metadataCache.Clear();
            metadataCache.Put("sample_bank_account/bank.proto", File.ReadAllText("proto2/bank.proto"));
            if (metadataCache.ContainsKey(ERRORS_KEY_SUFFIX))
            {
                Assert.Fail("fail: error in registering .proto model");
            }

            IRemoteCache <int, User> userCache = remoteManager.GetCache <int, User>(NAMED_CACHE);

            userCache.Clear();
            PutUsers(userCache);
            IRemoteCache <int, Account> accountCache = remoteManager.GetCache <int, Account>(NAMED_CACHE);

            PutAccounts(accountCache);
            IRemoteCache <int, Transaction> transactionCache = remoteManager.GetCache <int, Transaction>(NAMED_CACHE);

            PutTransactions(transactionCache);
        }
Пример #17
0
        public void IncludeCurrentStateEventTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cache.Put("key1", "value1");
                cl.filterFactoryName    = "";
                cl.converterFactoryName = "";
                cl.includeCurrentState  = true;
                cl.AddListener(listener.CreatedEventAction);
                AssertNoEvents(listener);
                cache.AddClientListener(cl, new string[] { }, new string[] { }, null);
                AssertOnlyCreated("key1", listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
Пример #18
0
        private void TestPut(IRemoteCache <string, string> testCache)
        {
            string k1 = "key13";
            string v1 = "boron";

            testCache.Put(k1, v1);
            Assert.AreEqual(v1, testCache.Get(k1));
        }
Пример #19
0
        protected void TestPutGetVersioned(IRemoteCache <string, string> cache)
        {
            cache.Put(K1, V1);
            IVersionedValue <string> value = cache.GetVersioned(K1);

            Assert.AreEqual(V1, value.GetValue());
            Assert.AreNotEqual(0, value.GetVersion());
        }
Пример #20
0
 public void FailoverTest()
 {
     Assert.IsNull(cache1.Put("k1", "v1"));
     Assert.AreEqual("v1", cache1.Get("k1"), "Expected v1 from cache1");
     Assert.AreEqual("v1", cache2.Get("k1"), "Expected v1 from cache2");
     XSiteTestSuite.server1.ShutDownHotrodServer();
     //client1 should failover
     Assert.AreEqual("v1", cache1.Get("k1"), "Expected v1 from cache1 after failover");
     Assert.AreEqual("v1", cache2.Get("k1"), "Expected v1 from cache2 after failover");
     XSiteTestSuite.server1.StartHotRodServer();
     manager1.SwitchToDefaultCluster();
     //client1 should get null as state transfer is not enabled
     Assert.IsNull(cache1.Get("k1"));
     Assert.IsNull(cache1.Put("k2", "v2"));
     Assert.AreEqual("v2", cache1.Get("k2"));
     //double check client2
     Assert.AreEqual("v1", cache2.Get("k1"), "Expected v1 from cache2 after starting LON back again");
 }
Пример #21
0
        protected void TestPutRemoveAsyncContains(IRemoteCache <string, string> cache)
        {
            cache.Put(K1, V1);
            Assert.IsTrue(cache.ContainsKey(K1));
            Task <string> result = cache.RemoveAsync(K1);

            result.Wait(5000);
            Assert.IsFalse(cache.ContainsKey(K1));
        }
Пример #22
0
        private static void putPerson(IRemoteCache <int, Person> cache)
        {
            Person p = new Person();

            p.Id         = readInt("Enter person id: ");
            p.Name       = readString("Enter person name: ");
            p.Email      = readString("Enter person email: ");
            p.Department = (p.Id % 2 == 0) ? "EVEN" : "ODD";
            cache.Put(p.Id, p);
        }
Пример #23
0
        protected void TestPutReplaceWithVersion(IRemoteCache <string, string> cache)
        {
            cache.Put(K1, V1);
            IVersionedValue <string> value = cache.GetVersioned(K1);
            ulong version = value.GetVersion();

            cache.ReplaceWithVersion(K1, V2, version);
            value = cache.GetVersioned(K1);
            Assert.AreEqual(V2, value.GetValue());
            Assert.IsTrue(value.GetVersion() != version);
        }
Пример #24
0
        protected void TestPutReplaceWithVersionAsync(IRemoteCache <string, string> cache)
        {
            cache.Put(K1, V1);
            IVersionedValue <string> value = cache.GetVersioned(K1);
            ulong       version            = value.GetVersion();
            Task <bool> result             = cache.ReplaceWithVersionAsync(K1, V2, version);

            result.Wait(5000);
            value = cache.GetVersioned(K1);
            Assert.AreEqual(V2, value.GetValue());
            Assert.IsTrue(value.GetVersion() != version);
        }
Пример #25
0
        public void FilterEventsTest()
        {
            LoggingEventListener <string> listener = new LoggingEventListener <string>();
            IRemoteCache <string, string> cache    = remoteManager.GetCache <string, string>();

            Event.ClientListener <string, string> cl = new Event.ClientListener <string, string>();
            try
            {
                cache.Clear();
                cl.filterFactoryName    = "string-is-equal-filter-factory";
                cl.converterFactoryName = "";
                cl.AddListener(listener.CreatedEventAction);
                cl.AddListener(listener.ModifiedEventAction);
                cl.AddListener(listener.RemovedEventAction);
                cl.AddListener(listener.ExpiredEventAction);
                cl.AddListener(listener.CustomEventAction);
                cache.AddClientListener(cl, new string[] { "wantedkeyprefix" }, new string[] { }, null);
                AssertNoEvents(listener);
                cache.Put("key1", "value1");
                cache.Put("wantedkeyprefix_key1", "value2");
                //only one received; one is ignored
                AssertOnlyCreated("wantedkeyprefix_key1", listener);
                AssertNoEvents(listener);
                cache.Replace("key1", "modified");
                cache.Replace("wantedkeyprefix_key1", "modified");
                AssertOnlyModified("wantedkeyprefix_key1", listener);
                AssertNoEvents(listener);
                cache.Remove("key1");
                cache.Remove("wantedkeyprefix_key1");
                AssertOnlyRemoved("wantedkeyprefix_key1", listener);
                AssertNoEvents(listener);
            }
            finally
            {
                if (cl.listenerId != null)
                {
                    cache.RemoveClientListener(cl);
                }
            }
        }
Пример #26
0
        static void Main(string[] args)
        {
            RemoteCacheManager remoteManager;
            const string       ERRORS_KEY_SUFFIX            = ".errors";
            const string       PROTOBUF_METADATA_CACHE_NAME = "___protobuf_metadata";

            ConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddServer()
            .Host(args.Length > 1 ? args[0] : "127.0.0.1")
            .Port(args.Length > 2 ? int.Parse(args[1]) : 11222);

            builder.Marshaller(new BasicTypesProtoStreamMarshaller());
            remoteManager = new RemoteCacheManager(builder.Build(), true);

            IRemoteCache <String, String> metadataCache = remoteManager.GetCache <String, String>(PROTOBUF_METADATA_CACHE_NAME);
            IRemoteCache <int, Person>    testCache     = remoteManager.GetCache <int, Person>("namedCache");

            // Installing the entities model into the Infinispan __protobuf_metadata cache
            metadataCache.Put("sample_person/person.proto", File.ReadAllText("../../resources/proto2/person.proto"));

            // Console.WriteLine(File.ReadAllText("../../resources/proto2/person.proto"));
            if (metadataCache.ContainsKey(ERRORS_KEY_SUFFIX))
            {
                Console.WriteLine("fail: error in registering .proto model");
                Environment.Exit(-1);
            }

            testCache.Clear();
            // Fill the application cache
            putPersons(testCache);

            // Run a query
            QueryRequest qr = new QueryRequest();

            qr.JpqlString = "from quickstart.Person where surname like '%ou%'";
            QueryResponse result = testCache.Query(qr);


            List <Person> listOfUsers = new List <Person>();


            unwrapResults(result, listOfUsers);
            Console.WriteLine("There are " + listOfUsers.Count + " Users:");

            foreach (Person user in listOfUsers)
            {
                Console.WriteLine(user.ToString());
                System.Threading.Thread.Sleep(1000);
            }
            System.Threading.Thread.Sleep(5000);
        }
Пример #27
0
        protected void TestPutRemoveWithVersion(IRemoteCache <string, string> cache)
        {
            cache.Put(K1, V1);
            IVersionedValue <string> value = cache.GetVersioned(K1);
            ulong version = value.GetVersion();

            cache.RemoveWithVersion(K1, version);
            value = cache.GetVersioned(K1);
            if (value != null)
            {
                Assert.AreNotEqual(value.GetVersion(), version);
            }
        }
Пример #28
0
        public void EntityBasicContQueryTest()
        {
            int joined = 0, updated = 0, leaved = 0;

            try
            {
                IRemoteCache <int, User> userCache = remoteManager.GetCache <int, User>(NAMED_CACHE);
                userCache.Clear();
                Semaphore    s  = new Semaphore(0, 1);
                QueryRequest qr = new QueryRequest();
                // JpqlString will be deprecated please use QueryString
                // qr.JpqlString = "from sample_bank_account.User";
                qr.QueryString = "from sample_bank_account.User";

                Event.ContinuousQueryListener <int, User> cql = new Event.ContinuousQueryListener <int, User>(qr.QueryString);
                cql.JoiningCallback = (int k, User v) => { joined++; };
                cql.LeavingCallback = (int k, User v) => { leaved++; s.Release(); };
                cql.UpdatedCallback = (int k, User v) => { updated++; };
                userCache.AddContinuousQueryListener(cql);

                User u = CreateUser1(userCache);
                userCache.Put(1, u);
                u.Name    = "Jerry";
                u.Surname = "Mouse";
                userCache.Put(1, u);
                userCache.Remove(1);
                s.WaitOne(10000);
                userCache.RemoveContinuousQueryListener(cql);
                userCache.Clear();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Assert.AreEqual(1, joined);
            Assert.AreEqual(1, updated);
            Assert.AreEqual(1, leaved);
        }
Пример #29
0
        public void ConflictsAndFail()
        {
            InitializeRemoteCacheManager(true);
            InitializeNonTxRemoteCacheManager(true);
            IRemoteCache <string, string> cache      = remoteManager.GetCache <string, string>("non_xa", true);
            IRemoteCache <string, string> nonTxCache = nonTxRemoteManager.GetCache <string, string>("non_xa", true);
            var txManager = remoteManager.GetTransactionManager();

            string k1 = "key13";
            string v1 = "boron";
            string k2 = "key14";
            string v2 = "helium";
            string vx = "calcium";

            cache.Clear();
            try
            {
                txManager.Begin();

                string oldv1 = cache.Put(k1, v1);
                string oldv2 = cache.Put(k2, v2);
                // Check the correct value from the tx context
                string rv1 = nonTxCache.Put(k1, vx);
                Assert.IsNull(rv1);
                Assert.Throws <Infinispan.HotRod.Exceptions.HotRodClientRollbackException>(() =>
                {
                    txManager.Commit();
                });
            }
            catch (Exception ex)
            {
                // try to release the tx resources
                txManager.Rollback();
                throw ex;
            }
            Assert.AreEqual(cache.Get(k1), vx);
            Assert.IsNull(cache.Get(k2));
        }
Пример #30
0
        protected void TestPutRemoveWithVersionAsync(IRemoteCache <string, string> cache)
        {
            cache.Put(K1, V1);
            IVersionedValue <string> value = cache.GetVersioned(K1);
            ulong       version            = value.GetVersion();
            Task <bool> result             = cache.RemoveWithVersionAsync(K1, version);

            result.Wait(5000);
            value = cache.GetVersioned(K1);
            if (value != null)
            {
                Assert.AreNotEqual(value.GetVersion(), version);
            }
        }
        public void PutTest()
        {
            String key         = UniqueKey.NextKey();
            ulong  initialSize = cache.Size();

            cache.Put(key, "chlorine");
            Assert.AreEqual("chlorine", cache.Put(key, "Berilium"));
            Assert.AreEqual(initialSize + 1, cache.Size());
        }
Пример #32
0
 public static void LoadTestCache(IRemoteCache<String, String> cache, String fileName)
 {
     System.IO.StreamReader file = new System.IO.StreamReader(fileName);
     try
     {
         String line;
         int counter = 0;
         while ((line = file.ReadLine()) != null)
         {
             cache.Put("line" + counter++, line);
         }
     }
     finally
     {
         file.Close();
     }
 }
Пример #33
0
 public static void LoadScriptCache(IRemoteCache<String, String> cache, String scriptKey, String fileName)
 {
     string text = System.IO.File.ReadAllText(fileName);
     cache.Put(scriptKey, text);
 }
Пример #34
0
        private void PutUsers(IRemoteCache<int, User> remoteCache)
        {
            User user1 = new User();
            user1.Id = 1;
            user1.Name = "John";
            user1.Surname = "Doe";
            user1.Gender = User.Types.Gender.MALE;
            user1.Age = 22;
            user1.Notes = "Lorem ipsum dolor sit amet";
            List<String> accountIds = new List<String>();
            accountIds.Add("1");
            accountIds.Add("2");
            user1.AccountIds.Add(accountIds);
            User.Types.Address address1 = new User.Types.Address();
            address1.Street = "Main Street";
            address1.PostCode = "X1234";
            address1.Number = 156;
            List<User.Types.Address> addresses = new List<User.Types.Address>();
            addresses.Add(address1);
            user1.Addresses.Add(addresses);

            remoteCache.Put(1, user1);

            User user2 = new User();
            user2.Id = 2;
            user2.Name = "Spider";
            user2.Surname = "Man";
            user2.Gender = User.Types.Gender.MALE;
            accountIds = new List<String>();
            accountIds.Add("3");
            user2.AccountIds.Add(accountIds);
            User.Types.Address address2 = new User.Types.Address();
            address2.Street = "Old Street";
            address2.PostCode = "Y12";
            address2.Number = -12;
            User.Types.Address address3 = new User.Types.Address();
            address3.Street = "Bond Street";
            address3.PostCode = "ZZ";
            address3.Number = 312;
            addresses = new List<User.Types.Address>();
            addresses.Add(address2);
            addresses.Add(address3);
            user2.Addresses.Add(addresses);

            remoteCache.Put(2, user2);

            User user3 = new User();
            user3.Id = 3;
            user3.Name = "Spider";
            user3.Surname = "Woman";
            user3.Gender = User.Types.Gender.FEMALE;

            remoteCache.Put(3, user3);
            accountIds = new List<String>();
            user3.AccountIds.Add(accountIds);
        }
Пример #35
0
        private void PutAccounts(IRemoteCache<int, Account> remoteCache)
        {
            Account account1 = new Account();
            account1.Id = 1;
            account1.Description = "John Doe's first bank account";
            account1.CreationDate = MakeDate("2013-01-03");

            remoteCache.Put(4, account1);

            Account account2 = new Account();
            account2.Id = 2;
            account2.Description = "John Doe's second bank account";
            account2.CreationDate = MakeDate("2013-01-04");

            remoteCache.Put(5, account2);

            Account account3 = new Account();
            account3.Id = 3;
            account3.CreationDate = MakeDate("2013-01-20");

            remoteCache.Put(6, account3);
        }
Пример #36
0
        private void PutTransactions(IRemoteCache<int, Transaction> remoteCache)
        {
            Transaction transaction0 = new Transaction();
            transaction0.Id = 0;
            transaction0.Description = "Birthday present";
            transaction0.AccountId = 1;
            transaction0.Amount = 1800;
            transaction0.Date = MakeDate("2012-09-07");
            transaction0.IsDebit = false;
            transaction0.IsValid = true;

            remoteCache.Put(7, transaction0);

            Transaction transaction1 = new Transaction();
            transaction1.Id = 1;
            transaction1.Description = "Feb. rent payment";
            transaction1.AccountId = 1;
            transaction1.Amount = 1500;
            transaction1.Date = MakeDate("2013-01-05");
            transaction1.IsDebit = true;
            transaction1.IsValid = true;

            remoteCache.Put(8, transaction1);

            Transaction transaction2 = new Transaction();
            transaction2.Id = 2;
            transaction2.Description = "Starbucks";
            transaction2.AccountId = 1;
            transaction2.Amount = 23;
            transaction2.Date = MakeDate("2013-01-09");
            transaction2.IsDebit = true;
            transaction2.IsValid = true;

            remoteCache.Put(9, transaction2);

            Transaction transaction3 = new Transaction();
            transaction3.Id = 3;
            transaction3.Description = "Hotel";
            transaction3.AccountId = 2;
            transaction3.Amount = 45;
            transaction3.Date = MakeDate("2013-02-27");
            transaction3.IsDebit = true;
            transaction3.IsValid = true;

            remoteCache.Put(10, transaction3);

            Transaction transaction4 = new Transaction();
            transaction4.Id = 4;
            transaction4.Description = "Last january";
            transaction4.AccountId = 2;
            transaction4.Amount = 95;
            transaction4.Date = MakeDate("2013-01-31");
            transaction4.IsDebit = true;
            transaction4.IsValid = true;

            remoteCache.Put(11, transaction4);

            Transaction transaction5 = new Transaction();
            transaction5.Id = 5;
            transaction5.Description = "-Popcorn";
            transaction5.AccountId = 2;
            transaction5.Amount = 4;
            transaction5.Date = MakeDate("2013-01-01");
            transaction5.IsDebit = true;
            transaction5.IsValid = true;

            remoteCache.Put(12, transaction5);
        }
        private void PutTransactions(IRemoteCache<String, Transaction> remoteCache)
        {
            Transaction transaction0 = new Transaction();
            transaction0.Id = 0;
            transaction0.Description = "Birthday present";
            transaction0.AccountId = 1;
            transaction0.Amount = 1800;
            transaction0.Date = MakeDate("2012-09-07");
            transaction0.IsDebit = false;
            transaction0.IsValid = true;

            remoteCache.Put("transaction_" + transaction0.Id, transaction0);

            Transaction transaction1 = new Transaction();
            transaction1.Id = 1;
            transaction1.Description = "Feb. rent payment";
            transaction1.LongDescription = "Feb. rent payment";
            transaction1.AccountId = 1;
            transaction1.Amount = 1500;
            transaction1.Date = MakeDate("2013-01-05");
            transaction1.IsDebit = true;
            transaction1.IsValid = true;

            remoteCache.Put("transaction_" + transaction1.Id, transaction1);

            Transaction transaction2 = new Transaction();
            transaction2.Id = 2;
            transaction2.Description = "Starbucks";
            transaction2.LongDescription = "Starbucks";
            transaction2.AccountId = 1;
            transaction2.Amount = 23;
            transaction2.Date = MakeDate("2013-01-09");
            transaction2.IsDebit = true;
            transaction2.IsValid = true;

            remoteCache.Put("transaction_" + transaction2.Id, transaction2);

            Transaction transaction3 = new Transaction();
            transaction3.Id = 3;
            transaction3.Description = "Hotel";
            transaction3.AccountId = 2;
            transaction3.Amount = 45;
            transaction3.Date = MakeDate("2013-02-27");
            transaction3.IsDebit = true;
            transaction3.IsValid = true;

            remoteCache.Put("transaction_" + transaction3.Id, transaction3);

            Transaction transaction4 = new Transaction();
            transaction4.Id = 4;
            transaction4.Description = "Last january";
            transaction4.LongDescription = "Last january";
            transaction4.AccountId = 2;
            transaction4.Amount = 95;
            transaction4.Date = MakeDate("2013-01-31");
            transaction4.IsDebit = true;
            transaction4.IsValid = true;

            remoteCache.Put("transaction_" + transaction4.Id, transaction4);

            Transaction transaction5 = new Transaction();
            transaction5.Id = 5;
            transaction5.Description = "-Popcorn";
            transaction5.LongDescription = "-Popcorn";
            transaction5.AccountId = 2;
            transaction5.Amount = 5;
            transaction5.Date = MakeDate("2013-01-01");
            transaction5.IsDebit = true;
            transaction5.IsValid = true;

            remoteCache.Put("transaction_" + transaction5.Id, transaction5);

            for (int i = 0; i < 50; i++)
            {
                Transaction transaction = new Transaction();
                transaction.Id = 50 + i;
                transaction.Description = "Expensive shoes " + i;
                transaction.LongDescription = "Expensive shoes. Just beer, really " + i;
                transaction.AccountId = 2;
                transaction.Amount = 100 + i;
                transaction.Date = MakeDate("2013-08-20");
                transaction.IsDebit = true;
                transaction.IsValid = true;
                remoteCache.Put("transaction_" + transaction.Id, transaction);
            }
        }