Exemple #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="T:CacheManager"/> class.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public CacheManager()
        {
            if (!Properties.Settings.Default.UseFileCache)
            {
                return;
            }

            // Register the remote class
            if (Properties.Settings.Default.UseRemoteCache)
            {
                if (RemotingConfiguration.IsWellKnownClientType(typeof(RemoteCacheManager)) == null)
                {
                    // save temporary config file to configure the type
                    string config = string.Format("<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
                                                  "<configuration><system.runtime.remoting><application><client>" +
                                                  "<wellknown  type=\"SIL.FieldWorks.Tools.FileCache.RemoteCacheManager, RemoteFileCache\" " +
                                                  "url=\"tcp://{0}:8700/FileCache.rem\"/></client>" +
                                                  "<channels><channel ref=\"tcp\" port=\"0\"><serverProviders><formatter ref=\"binary\" typeFilterLevel=\"Full\" />" +
                                                  "</serverProviders><clientProviders><formatter ref=\"binary\" typeFilterLevel=\"Full\"/></clientProviders>" +
                                                  "</channel></channels></application></system.runtime.remoting></configuration>",
                                                  Properties.Settings.Default.RemoteHost);
                    string       tempConfigFile = Path.GetTempFileName();
                    StreamWriter writer         = new StreamWriter(tempConfigFile);
                    writer.Write(config);
                    writer.Close();

                    RemotingConfiguration.Configure(tempConfigFile, true);

                    // now delete our temporary config file
                    File.Delete(tempConfigFile);
                }

                m_remoteCacheMgr = new RemoteCacheManager();
            }
        }
Exemple #2
0
        public void RemoteMapReduceWithStreamsTest()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222);
            conf.ConnectionTimeout(90000).SocketTimeout(6000);
            marshaller = new JBasicMarshaller();
            conf.Marshaller(marshaller);
            remoteManager = new RemoteCacheManager(conf.Build(), true);
            IRemoteCache <string, string> scriptCache = remoteManager.GetCache <string, string>(PROTOBUF_SCRIPT_CACHE_NAME);
            IRemoteCache <string, string> testCache   = remoteManager.GetCache <string, string>();

            try
            {
                const string scriptName = "wordCountStream.js";
                ScriptUtils.LoadTestCache(testCache, "macbeth.txt");
                ScriptUtils.LoadScriptCache(scriptCache, scriptName, scriptName);

                Dictionary <string, object> scriptArgs = new Dictionary <string, object>();

                var       result = (System.Int64)testCache.Execute(scriptName, scriptArgs);
                const int expectedMacbethCount = 287;
                Assert.AreEqual(expectedMacbethCount, result);
            }
            finally
            {
                testCache.Clear();
            }
        }
Exemple #3
0
        public void BeforeClass()
        {
            d = delegate()
            {
                b = new BS();
                return(b);
            };
            BS b2;
            FailOverRequestBalancingStrategyProducerDelegate d2 = delegate()
            {
                b2 = new BS();
                return(b2);
            };

            conf1 = new ConfigurationBuilder();
            conf1.AddServer().Host("127.0.0.1").Port(11222);
            ccb  = conf1.AddCluster("nyc");
            ccb1 = ccb.AddClusterNode("127.0.0.1", 11322);
            conf1.BalancingStrategyProducer(d);
            configu1 = conf1.Build();
            manager1 = new RemoteCacheManager(configu1, true);
            cache1   = manager1.GetCache <String, String>();

            conf2 = new ConfigurationBuilder();
            conf2.AddServer().Host("127.0.0.1").Port(11322);
            conf2.AddCluster("lon").AddClusterNode("127.0.0.1", 11222);
            conf2.BalancingStrategyProducer(d2);
            configu2      = conf2.Build();
            remoteManager = new RemoteCacheManager(configu2, true);
            cache2        = remoteManager.GetCache <String, String>();
        }
Exemple #4
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);
        }
Exemple #5
0
        /// <summary>
        /// This is the Sample Application that uses the Infinispan .NET client library.
        /// </summary>
        /// <param name="args">string</param>
        static void Main(string[] args)
        {
            //Create new Configuration, overriding the setting in the App.config file.
            ClientConfig conf = new ClientConfig("127.0.0.1", 11222, "default", 0, false);
            //Here we are using a custom Serializer
            Serializer s = new DefaultSerializer();
            //Create a new RemoteCacheManager
            RemoteCacheManager manager = new RemoteCacheManager(conf, s);
            //Get hold of a cache from the remote cache manager
            RemoteCache cache = manager.getCache();

            //First Check Whether the cache exists
            Console.WriteLine("Ping Result : " + cache.ping());
            //Put a new value "germanium" with key "key 1" into cache
            cache.put <String, String>("key 1", "germanium", 0, 0);
            //Get the value of entry with key "key 1"
            Console.WriteLine("key 1 value : " + cache.get <String>("key 1"));
            //Put if absent is used to add entries if they are not existing in the cache
            cache.putIfAbsent <String, String>("key 1", "trinitrotoluene", 0, 0);
            cache.putIfAbsent <String, String>("key 2", "formaldehyde", 0, 0);
            Console.WriteLine("key 1 value after PutIfAbsent: " + cache.get <String>("key 1"));
            Console.WriteLine("Key 2 value after PutIfAbsent: " + cache.get <String>("key 2"));
            //Replace an existing value with a new one.
            // cache.replace<String, String>("key 1", "fluoride",0,0);
            Console.WriteLine("key 1 value after replace: " + cache.get <String>("key 1"));
            //Check whether a particular key exists
            Console.WriteLine("key 1 is exist ?: " + cache.containsKey("key 1"));
            //Remove a particular entry from the cache
            // cache.remove<String>("key 1");
            Console.WriteLine("key 1 is exist after remove?: " + cache.containsKey("key 1"));

            Console.ReadLine();
        }
        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);
        }
 public void BeforeClass()
 {
     ConfigurationBuilder conf = new ConfigurationBuilder();
     conf.AddServer().Host("127.0.0.1").Port(11222);
     conf.ConnectionTimeout(90000).SocketTimeout(6000);
     RemoteCacheManager remoteManager = new RemoteCacheManager(conf.Build(), true);
     cache = remoteManager.GetCache<String, String>();
 }
 public void BeforeClass() {
     ConfigurationBuilder conf = new ConfigurationBuilder();
     conf.AddServer().Host("127.0.0.1").Port(11222);
     conf.ConnectionTimeout(90000).SocketTimeout(6000);
     marshaller = new JBasicMarshaller();
     conf.Marshaller(marshaller);
     remoteManager = new RemoteCacheManager(conf.Build(), true);
 }
Exemple #9
0
        public void RemoteTaskDefaultMarshallerTest()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222);
            conf.ConnectionTimeout(90000).SocketTimeout(6000);
            remoteManager = new RemoteCacheManager(conf.Build(), true);
            RemoteTaskTest();
        }
Exemple #10
0
        public void BeforeClass()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222);
            conf.ConnectionTimeout(90000).SocketTimeout(6000);
            conf.ProtocolVersion("2.7");
            remoteManager = new RemoteCacheManager(conf.Build(), true);
        }
Exemple #11
0
        public void BeforeClass()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

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

            cache = remoteManager.GetCache <String, String>(true);
        }
Exemple #12
0
 public void BeforeClass()
 {
     confBuilder = new ConfigurationBuilder();
     confBuilder.AddServer().Host("127.0.0.1").Port(11222);
     confBuilder.ConnectionTimeout(90000).SocketTimeout(6000);
     marshaller = new JBasicMarshaller();
     confBuilder.Marshaller(marshaller);
     conf          = confBuilder.Build();
     remoteManager = new RemoteCacheManager(conf, true);
 }
        private void InitializeRemoteCacheManager(bool started)
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222).ProtocolVersion("2.8");
            conf.ConnectionTimeout(90000).SocketTimeout(6000);
            marshaller = new JBasicMarshaller();
            conf.Marshaller(marshaller);
            remoteManager = new RemoteCacheManager(conf.Build(), started);
        }
Exemple #14
0
        public void BeforeClass()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222)
            .ConnectionTimeout(90000).SocketTimeout(6000)
            .NearCache().Mode(NearCacheMode.INVALIDATED).MaxEntries(10);
            marshaller = new JBasicMarshaller();
            conf.Marshaller(marshaller);
            remoteManager = new RemoteCacheManager(conf.Build(), true);
        }
Exemple #15
0
        public void RemoteTaskJBasicMarshallerTest()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222);
            conf.ConnectionTimeout(90000).SocketTimeout(6000);
            conf.ProtocolVersion("2.6");
            marshaller = new JBasicMarshaller();
            conf.Marshaller(marshaller);
            remoteManager = new RemoteCacheManager(conf.Build(), true);
            RemoteTaskTest();
        }
Exemple #16
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);
        }
Exemple #17
0
        public void BeforeClass()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

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

            cache            = remoteManager.GetCache <object, object>();
            transcodingCache = remoteManager.GetCache <object, object>("transcodingCache");
        }
Exemple #18
0
        public void SNI2CorrectCredentialsTest()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();
            conf.AddServer().Host("127.0.0.1").Port(11222).ConnectionTimeout(90000).SocketTimeout(900);
            conf.Marshaller(new JBasicMarshaller());
            registerServerCAFile(conf, "keystore_server_sni2.pem", "sni2");
            RemoteCacheManager remoteManager = new RemoteCacheManager(conf.Build(), true);
            IRemoteCache<string, string> testCache = remoteManager.GetCache<string, string>();

            testCache.Clear();
            string k1 = "key13";
            string v1 = "boron";
            testCache.Put(k1, v1);
            Assert.AreEqual(v1, testCache.Get(k1));
        }
Exemple #19
0
        public void SSLSuccessfullServerAndClientAuthTest()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();
            conf.AddServer().Host("127.0.0.1").Port(11222).ConnectionTimeout(90000).SocketTimeout(900);
            registerServerCAFile(conf, "infinispan-ca.pem");
            conf.Marshaller(new JBasicMarshaller());

            RemoteCacheManager remoteManager = new RemoteCacheManager(conf.Build(), true);
            IRemoteCache<string, string> testCache = remoteManager.GetCache<string, string>();

            testCache.Clear();
            string k1 = "key13";
            string v1 = "boron";
            testCache.Put(k1, v1);
            Assert.AreEqual(v1, testCache.Get(k1));
        }
Exemple #20
0
        void changeCounterFromAnotherCacheManager()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

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

            var    rcm         = remoteManager.GetCounterManager();
            string counterName = "weak1TestAddRemoveListener";
            var    counter     = rcm.GetWeakCounter(counterName);

            counter.Increment();
            remoteManager.Stop();
        }
 static void Main()
 {
     // Create a configuration for a locally-running server
     ConfigurationBuilder builder = new ConfigurationBuilder();
     Configuration conf = builder.AddServers("127.0.0.1:11222").Build();
     // Initialize the remote cache manager
     RemoteCacheManager remoteManager = new RemoteCacheManager(conf);
     // Connect to the server
     remoteManager.Start();
     // Store a value
     IRemoteCache<string,string> cache=remoteManager.GetCache<string, string>();
     cache.Put("key", "value");
     // Retrieve the value and print it out
     Console.WriteLine("key = {0}", cache.Get("key"));
     // Stop the cache manager and release all resources
     remoteManager.Stop();
 }
Exemple #22
0
        private IRemoteCache <string, string> InitCache(string mech, string serverName, string username, string password)
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222).ConnectionTimeout(90000).SocketTimeout(900);
            //registerServerCAFile(conf, "infinispan-ca.pem");
            conf.Security().Authentication()
            .Enable()
            .ServerFQDN(serverName)
            .SaslMechanism(mech)
            .SetupCallback(() => username, () => password, () => "ApplicationRealm");
            conf.Marshaller(new JBasicMarshaller());
            Configuration      c             = conf.Build();
            RemoteCacheManager remoteManager = new RemoteCacheManager(c, true);

            return(remoteManager.GetCache <string, string>("authCache"));
        }
Exemple #23
0
        public void MD5AutheticationWithEasySaslSetupTest()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222).ConnectionTimeout(90000).SocketTimeout(900);
            conf.Security().Authentication()
            .Enable()
            .ServerFQDN("node0")
            .SaslMechanism("DIGEST-MD5")
            .SetupCallback("supervisor", "lessStrongPassword", "ApplicationRealm");
            conf.Marshaller(new JBasicMarshaller());
            Configuration                 c             = conf.Build();
            RemoteCacheManager            remoteManager = new RemoteCacheManager(c, true);
            IRemoteCache <string, string> testCache     = remoteManager.GetCache <string, string>("authCache");

            TestPut(testCache);
        }
Exemple #24
0
        static void main()
        {
            // Create a configuration for a locally-running server
            ConfigurationBuilder builder = new ConfigurationBuilder();

            conf = builder.AddServers("127.0.0.1:11222").Build();
            // Initialize the remote cache manager
            remoteManager = new RemoteCacheManager(conf, new DefaultSerializer());
            // Connect to the server
            remoteManager.Start();
            // Store a value
            cache.Put("key", "value");
            // Retrieve the value and print it out
            Console.WriteLine("key = {0}", cache.Get("key"));
            // Stop the cache manager and release all resources
            remoteManager.Stop();
        }
Exemple #25
0
        public void permanentCacheTest()
        {
            String cacheName = "cache4PermanentTest";
            var    flags     = new HashSet <AdminFlag>();

            flags.Add(AdminFlag.PERMANENT);
            remoteManager.Administration().WithFlags(flags).CreateCache <string, string>(cacheName, "template");
            remoteManager.Stop();
            ClusterTestSuite.server1.ShutDownHotrodServer();
            ClusterTestSuite.server2.ShutDownHotrodServer();
            ClusterTestSuite.server1.StartHotRodServer();
            ClusterTestSuite.server2.StartHotRodServer();
            remoteManager = ClusterTestSuite.getRemoteCacheManager();
            var ex = Assert.Throws <Infinispan.HotRod.Exceptions.HotRodClientException>(() =>
                                                                                        { remoteManager.Administration().CreateCache <string, string>(cacheName, "template"); });

            StringAssert.Contains("ISPN000507:", ex.Message);
        }
        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.Put("sample_bank_account/bank.proto", File.ReadAllText("proto2/bank.proto"));
            if (metadataCache.ContainsKey(ERRORS_KEY_SUFFIX))
            {
                Console.WriteLine("fail: error in registering .proto model");
                Environment.Exit(-1);
            }

            IRemoteCache<String, Transaction> transactionCache = remoteManager.GetCache<String, Transaction>(NAMED_CACHE);
            PutTransactions(transactionCache);
        }
Exemple #27
0
        private void ConfigureSecuredCaches(string serverCAFile, string clientCertFile, string sni = "")
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222).ConnectionTimeout(90000).SocketTimeout(900);
            marshaller = new JBasicMarshaller();
            conf.Marshaller(marshaller);
            SslConfigurationBuilder sslConf = conf.Ssl();

            conf.Security().Authentication()
            .Enable()
            .SaslMechanism("EXTERNAL")
            .ServerFQDN("node0");

            RegisterServerCAFile(sslConf, serverCAFile, sni);
            RegisterClientCertificateFile(sslConf, clientCertFile);

            RemoteCacheManager remoteManager = new RemoteCacheManager(conf.Build(), true);

            testCache   = remoteManager.GetCache <string, string>();
            scriptCache = remoteManager.GetCache <string, string>("___script_cache");
        }
Exemple #28
0
        static void Main(string[] args)
        {
            var confBuilder = new ConfigurationBuilder();

            confBuilder.AddServer().Host("127.0.0.1").Port(11222);
            var rcm = new RemoteCacheManager(confBuilder.Build());

            rcm.Start();
            var cache = rcm.GetCache <string, string>();

            string key = "prefix_for_key_";
            string val = "prefix_for_value_";
            var    ts  = new Thread[50];

            for (int i = 0; i < 10; i++)
            {
                ts[i] = new Thread(() => NewMethod(cache, "th" + i + key, "th" + i + val));
                ts[i].Start();
            }
            ts[0].Join();
            rcm.Stop();
        }
Exemple #29
0
        public void StartHotrodServer()
        {
            ConfigurationBuilder builder = new ConfigurationBuilder();

            conf = builder.AddServers("127.0.0.1:11222").Build();

            string jbossHome = System.Environment.GetEnvironmentVariable("JBOSS_HOME");

            if (jbossHome == null)
            {
                throw new Exception("JBOSS_HOME env variable not set.");
            }

            Assert.IsTrue(PortProbe.IsPortClosed(conf.Servers()[0].Host(),
                                                 conf.Servers()[0].Port(),
                                                 millisTimeout: 10000),
                          "Another process already listening on the same ip/port.");

            hrServer = new Process();
            hrServer.StartInfo.FileName        = buildStartCommand(jbossHome);
            hrServer.StartInfo.UseShellExecute = false;
            if (PlatformUtils.isUnix())
            {
                // Drop the output generated by the server on the console (data present in log file).
                hrServer.StartInfo.RedirectStandardOutput = true;
                hrServer.StartInfo.RedirectStandardError  = true;
                hrServer.OutputDataReceived += new DataReceivedEventHandler(DropOutputHandler);
                hrServer.ErrorDataReceived  += new DataReceivedEventHandler(DropOutputHandler);
            }
            hrServer.Start();

            Assert.IsTrue(PortProbe.IsPortOpen(conf.Servers()[0].Host(),
                                               conf.Servers()[0].Port()),
                          "Server not listening on the expected ip/port.");

            remoteManager = new RemoteCacheManager(conf, serializer);
            remoteManager.Start();
        }
Exemple #30
0
        private IRemoteCache <String, String> InitCache(string user, string password, string cacheName = AUTH_CACHE)
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.ProtocolVersion("2.8").AddServer()
            .Host(HOTROD_HOST)
            .Port(HOTROD_PORT)
            .ConnectionTimeout(90000)
            .SocketTimeout(900);
            AuthenticationConfigurationBuilder authBuilder = conf.Security().Authentication();

            authBuilder.Enable()
            .SaslMechanism(GetMech())
            .ServerFQDN("node0")
            .SetupCallback(user, password, REALM);
            marshaller = new JBasicMarshaller();
            conf.Marshaller(marshaller);
            Configuration                 c             = conf.Build();
            RemoteCacheManager            remoteManager = new RemoteCacheManager(c, true);
            IRemoteCache <string, string> cache         = remoteManager.GetCache <string, string>(cacheName);

            return(cache);
        }
Exemple #31
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Executes in two distinct scenarios.
        /// 1. If disposing is true, the method has been called directly
        /// or indirectly by a user's code via the Dispose method.
        /// Both managed and unmanaged resources can be disposed.
        /// 2. If disposing is false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference (access)
        /// other managed objects, as they already have been garbage collected.
        /// Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing">if set to <c>true</c> this method is called from the
        /// Dispose() method, if set to <c>false</c> it's called from finalizer.</param>
        /// <remarks>
        /// If any exceptions are thrown, that is fine.
        /// If the method is being done in a finalizer, it will be ignored.
        /// If it is thrown by client code calling Dispose,
        /// it needs to be handled by fixing the bug.
        /// If subclasses override this method, they should call the base implementation.
        /// </remarks>
        /// ------------------------------------------------------------------------------------
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Dispose managed resources here.
                if (m_remoteCacheMgr != null)
                {
                    try
                    {
                        m_remoteCacheMgr.Close();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Got exception accessing remote cache: " + e.Message);
                    }
                }
            }

            // Dispose unmanaged resources here
            m_remoteCacheMgr = null;

            base.Dispose(disposing);
        }
Exemple #32
0
        public void RemoteTaskWithIntArgs()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();

            conf.AddServer().Host("127.0.0.1").Port(11222);
            conf.ConnectionTimeout(90000).SocketTimeout(6000);
            remoteManager = new RemoteCacheManager(conf.Build(), true);
            string script = "// mode=local,language=javascript \n"
                            + "var x = k+v; \n"
                            + "x; \n";
            LoggingEventListener <string> listener    = new LoggingEventListener <string>();
            IRemoteCache <string, string> testCache   = remoteManager.GetCache <string, string>();
            IRemoteCache <string, string> scriptCache = remoteManager.GetCache <string, string>(PROTOBUF_SCRIPT_CACHE_NAME, new JBasicMarshaller());
            const string scriptName = "putit-get.js";

            scriptCache.Put(scriptName, script);
            Dictionary <string, object> scriptArgs = new Dictionary <string, object>();

            scriptArgs.Add("k", (int)1);
            scriptArgs.Add("v", (int)2);
            object v = testCache.Execute(scriptName, scriptArgs);

            Assert.AreEqual(3, v);
        }
Exemple #33
0
        public void SNIUntrustedTest()
        {
            ConfigurationBuilder conf = new ConfigurationBuilder();
            conf.AddServer().Host("127.0.0.1").Port(11222).ConnectionTimeout(90000).SocketTimeout(900);
            conf.Marshaller(new JBasicMarshaller());
            registerServerCAFile(conf, "malicious.pem", "sni3-untrusted");

            RemoteCacheManager remoteManager = new RemoteCacheManager(conf.Build(), true);
            IRemoteCache<string, string> testCache = remoteManager.GetCache<string, string>();

            testCache.Clear();
            string k1 = "key13";
            string v1 = "boron";
            testCache.Put(k1, v1);
            Assert.Fail("Should not get here");
        }
        /*
         * public void BeforeClass()
         * {
         *  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);
         */
        static void Main()
        {
            // Create a configuration for a locally-running server
            ConfigurationBuilder conf = new ConfigurationBuilder();

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

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

            metadataCache.Put("quickstart/addressbook.proto", File.ReadAllText("addressbook.proto"));
            if (metadataCache.ContainsKey(ERRORS_KEY_SUFFIX))
            {
                Console.WriteLine("fail: error in registering .proto model");
                Environment.Exit(-1);
            }
            IRemoteCache <int, Person> cache = remoteManager.GetCache <int, Person>(NAMED_CACHE);

            bool quit = false;

            displayActions();
            while (!quit)
            {
                int action = readAction();

                switch (action)
                {
                case 1:
                    putPerson(cache);
                    break;

                case 2:
                    removePerson(cache);
                    break;

                case 3:
                    addPhone(cache);
                    break;

                case 4:
                    removePhone(cache);
                    break;

                case 5:
                    queryPersonByName(cache);
                    break;

                case 6:
                    queryPersonByPhone(cache);
                    break;

                case 7:
                    addMemo(cache);
                    break;

                case 8:
                    fullTextOnMemo(cache);
                    break;

                case 9:
                    projectAllNames(cache);
                    break;

                case 10:
                    countByDepartment(cache);
                    break;

                case 11:
                    printAll(cache);
                    break;

                case 12:
                    cache.Clear();
                    Console.WriteLine("Cache cleared");
                    break;

                case 13:
                    quit = true;
                    Console.WriteLine("Bye!");
                    break;

                case 0:
                    displayActions();
                    break;

                default:
                    Console.Error.WriteLine("Invalid action: " + action);
                    break;
                }
            }
            remoteManager.Stop();
        }
Exemple #35
0
 public Codec(RemoteCacheManager rm)
 {
     cacheManager = rm;
     logger = LogManager.GetLogger("Codec");
 }
        public void StartHotrodServer()
        {
            ConfigurationBuilder builder = new ConfigurationBuilder();
            conf = builder.AddServers("127.0.0.1:11222").Build();

            string jbossHome = System.Environment.GetEnvironmentVariable("JBOSS_HOME");
            if (jbossHome == null)
            {
                throw new Exception("JBOSS_HOME env variable not set.");
            }

            Assert.IsTrue(PortProbe.IsPortClosed(conf.Servers()[0].Host(),
                                                 conf.Servers()[0].Port(),
                                                 millisTimeout:10000),
                          "Another process already listening on the same ip/port.");

            hrServer = new Process();
            hrServer.StartInfo.FileName = buildStartCommand(jbossHome);
            hrServer.StartInfo.UseShellExecute = false;
            if (PlatformUtils.isUnix()) {
                // Drop the output generated by the server on the console (data present in log file).
                hrServer.StartInfo.RedirectStandardOutput = true;
                hrServer.StartInfo.RedirectStandardError = true;
                hrServer.OutputDataReceived += new DataReceivedEventHandler(DropOutputHandler);
                hrServer.ErrorDataReceived += new DataReceivedEventHandler(DropOutputHandler);
            }
            hrServer.Start();

            Assert.IsTrue(PortProbe.IsPortOpen(conf.Servers()[0].Host(),
                                               conf.Servers()[0].Port()),
                          "Server not listening on the expected ip/port.");

            remoteManager = new RemoteCacheManager(conf, serializer);
            remoteManager.Start();
        }
Exemple #37
0
 public void BeforeAnyTest()
 {
     ClusterTestSuite.EnsureServersUp();
     remoteManager = ClusterTestSuite.getRemoteCacheManager();
 }