예제 #1
0
        private void WriteBlobUsingUdf(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "udfkey6");
            string binName = args.GetBinName("udfbin6");

            byte[] blob;

            // Create packed blob using standard C# tools.
            using (MemoryStream ms = new MemoryStream())
            {
                Formatter.Default.Serialize(ms, 9845);
                Formatter.Default.Serialize(ms, "Hello world.");
                blob = ms.ToArray();
            }

            client.Execute(args.writePolicy, key, "record_example", "writeBin", Value.Get(binName), Value.Get(blob));
            byte[] received       = (byte[])client.Execute(args.writePolicy, key, "record_example", "readBin", Value.Get(binName));
            string receivedString = Util.BytesToString(received);
            string expectedString = Util.BytesToString(blob);

            if (receivedString.Equals(expectedString))
            {
                console.Info("Blob data matched: namespace={0} set={1} key={2} bin={3} value={4}",
                             key.ns, key.setName, key.userKey, binName, receivedString);
            }
            else
            {
                throw new Exception(string.Format("Mismatch: expected={0} received={1}", expectedString, receivedString));
            }
        }
예제 #2
0
        private void WriteIfGenerationNotChanged(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "udfkey2");
            Bin bin = new Bin(args.GetBinName("udfbin2"), "string value");

            // Seed record.
            client.Put(args.writePolicy, key, bin);

            // Get record generation.
            long gen = (long)client.Execute(args.writePolicy, key, "record_example", "getGeneration");

            // Write record if generation has not changed.
            client.Execute(args.writePolicy, key, "record_example", "writeIfGenerationNotChanged", Value.Get(bin.name), bin.value, Value.Get(gen));
            console.Info("Record written.");
        }
예제 #3
0
        } //batchGetUserTweets

        public void updatePasswordUsingUDF()
        {
            //Assembly assembly = Assembly.GetExecutingAssembly();
            ////Policy policy = new Policy();
            ////policy.SetTimeout(100);
            //RegisterTask rtask = client.Register(policy, "updateUserPwd.lua", "updateUserPwd.lua", Language.LUA);
            //rtask.Wait();



            Record userRecord = null;
            Key    userKey    = null;

            // Get username
            string username;

            Console.WriteLine("\nEnter username:"******"test", "users", username);
                userRecord = client.Get(null, userKey);
                if (userRecord != null)
                {
                    // Get new password
                    string password;
                    Console.WriteLine("Enter new password for " + username + ":");
                    password = Console.ReadLine();

                    //string luaDirectory = @"..\..\udf";
                    //LuaConfig.PackagePath = luaDirectory + @"\?.lua";
                    //string filename = "updateUserPwd.lua";
                    //string path = Path.Combine(luaDirectory, filename);
                    //RegisterTask rt = client.Register(null, path, filename, Language.LUA);
                    //rt.Wait();

                    Assembly assembly = Assembly.GetExecutingAssembly();
                    Policy   policy   = new Policy();
                    policy.SetTimeout(100);
                    RegisterTask rtask = client.Register(policy, "updateUserPwd.lua", "updateUserPwd.lua", Language.LUA);
                    rtask.Wait();

                    string updatedPassword = client.Execute(null, userKey, "updateUserPwd", "updatePassword", Value.Get(password)).ToString();
                    Console.WriteLine("\nINFO: The password has been set to: " + updatedPassword);
                }
                else
                {
                    Console.WriteLine("ERROR: User record not found!");
                }
            }
            else
            {
                Console.WriteLine("ERROR: User record not found!");
            }
        } //updatePasswordUsingUDF
예제 #4
0
        private void WriteIfNotExists(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "udfkey3");
            string binName = "udfbin3";

            // Delete record if it already exists.
            client.Delete(args.writePolicy, key);

            // Write record only if not already exists. This should succeed.
            client.Execute(args.writePolicy, key, "record_example", "writeUnique", Value.Get(binName), Value.Get("first"));

            // Verify record written.
            Record record   = client.Get(args.policy, key, binName);
            string expected = "first";
            string received = (string)record.GetValue(binName);

            if (received != null && received.Equals(expected))
            {
                console.Info("Record written: namespace={0} set={1} key={2} bin={3} value={4}",
                             key.ns, key.setName, key.userKey, binName, received);
            }
            else
            {
                console.Error("Data mismatch: Expected {0}. Received {1}.", expected, received);
            }

            // Write record second time. This should fail.
            console.Info("Attempt second write.");
            client.Execute(args.writePolicy, key, "record_example", "writeUnique", Value.Get(binName), Value.Get("second"));

            // Verify record not written.
            record   = client.Get(args.policy, key, binName);
            received = (string)record.GetValue(binName);

            if (received != null && received.Equals(expected))
            {
                console.Info("Success. Record remained unchanged: namespace={0} set={1} key={2} bin={3} value={4}",
                             key.ns, key.setName, key.userKey, binName, received);
            }
            else
            {
                console.Error("Data mismatch: Expected {0}. Received {1}.", expected, received);
            }
        }
예제 #5
0
        private void WriteListMapUsingUdf(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "udfkey5");

            List <object> inner = new List <object>();

            inner.Add("string2");
            inner.Add(8L);

            Dictionary <object, object> innerMap = new Dictionary <object, object>();

            innerMap["a"]    = 1L;
            innerMap[2L]     = "b";
            innerMap["list"] = inner;

            List <object> list = new List <object>();

            list.Add("string1");
            list.Add(4L);
            list.Add(inner);
            list.Add(innerMap);

            string binName = args.GetBinName("udfbin5");

            client.Execute(args.writePolicy, key, "record_example", "writeBin", Value.Get(binName), Value.Get(list));

            object received       = client.Execute(args.writePolicy, key, "record_example", "readBin", Value.Get(binName));
            string receivedString = Util.ListToString((List <object>)received);
            string expectedString = Util.ListToString(list);

            if (receivedString.Equals(expectedString))
            {
                console.Info("UDF data matched: namespace={0} set={1} key={2} bin={3} value={4}",
                             key.ns, key.setName, key.userKey, binName, received);
            }
            else
            {
                console.Error("UDF data mismatch");
                console.Error("Expected " + list);
                console.Error("Received " + received);
            }
        }
예제 #6
0
        } //getUserTweets

        public void updatePasswordUsingUDF()
        {
            Record userRecord = null;
            Key    userKey    = null;

            // Get username
            string username;

            Console.WriteLine("\nEnter username:"******"test", "users", username);
                userRecord = client.Get(null, userKey);
                if (userRecord != null)
                {
                    //Get new password
                    string password;
                    Console.WriteLine("Enter new password for " + username + ":");
                    password = Console.ReadLine();

                    // TODO: Update userRecord using UDF
                    // Exercise R2
                    // NOTE: UDF registration has been included here for convenience and to demonstrate the syntax.
                    // NOTE: The recommended way of registering UDFs in production env is via AQL
                    string luaDirectory = @"..\..\udf";
                    LuaConfig.PackagePath = luaDirectory + @"\?.lua";
                    string       filename = "updateUserPwd.lua";
                    string       path     = Path.Combine(luaDirectory, filename);
                    RegisterTask rt       = client.Register(null, path, filename, Language.LUA);
                    rt.Wait();

                    // TODO: Execute the UDF updatePassword.lua
                    // Exercise R2
                    string updatedPassword = client.Execute(null, userKey, "updateUserPwd", "updatePassword", Value.Get(password)).ToString();

                    // TODO: Output the updated passord returned by the UDF
                    // Exercise R2
                    Console.WriteLine("\nINFO: The password has been set to: " + updatedPassword);
                }
                else
                {
                    Console.WriteLine("\nERROR: User record not found.");
                }
            }
            else
            {
                Console.WriteLine("\nERROR: Invalid user name.");
            }
        } //updatePasswordUsingUDF
예제 #7
0
        private void WriteWithValidation(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "udfkey4");
            string binName = "udfbin4";

            // Lua function writeWithValidation accepts number between 1 and 10.
            // Write record with valid value.
            console.Info("Write with valid value.");
            client.Execute(args.writePolicy, key, "record_example", "writeWithValidation", Value.Get(binName), Value.Get(4));

            // Write record with invalid value.
            console.Info("Write with invalid value.");

            try
            {
                client.Execute(args.writePolicy, key, "record_example", "writeWithValidation", Value.Get(binName), Value.Get(11));
                console.Error("UDF should not have succeeded!");
            }
            catch (Exception)
            {
                console.Info("Success. UDF resulted in exception as expected.");
            }
        }
예제 #8
0
        public static void RunTest()
        {
            AerospikeClient client = new AerospikeClient("172.28.128.3", 3000);

            try
            {
                QueryTest.RunTest();
                //Querytestten gelen binler;
                string binName  = "querybinint";
                string binName2 = "querybinint2";



                Policy policy = new Policy();
                policy.SetTimeout(100);


                //Assembly assembly = Assembly.GetExecutingAssembly();
                //RegisterTask rtask = client.Register(policy, "example.lua", "example.lua", Language.LUA);
                //rtask.Wait();


                //rtask.Wait();
                //if (rtask.IsDone())
                //{
                //    Console.WriteLine("done");

                //}

                int begin = 1;
                int end   = 10;

                Statement stmt = new Statement();
                stmt.SetNamespace("test");
                stmt.SetSetName("QueryTest");
                stmt.SetFilter(Filter.Range("querybinint", begin, end));

                ExecuteTask task = client.Execute(null, stmt, "example", "processRecord", Value.Get(binName), Value.Get(binName2), Value.Get(100));
                //task.Wait(3000, 3000);
                task.Wait();
            }
            finally
            {
                client.Close();
            }
        }
예제 #9
0
        } //getUser

        public void updatePasswordUsingUDF()
        {
            Record userRecord = null;
            Key    userKey    = null;

            // Get username
            string username;

            Console.WriteLine("\nEnter username:"******"test", "users", username);
                userRecord = client.Get(null, userKey);
                if (userRecord != null)
                {
                    // Get new password
                    string password;
                    Console.WriteLine("Enter new password for " + username + ":");
                    password = Console.ReadLine();

                    // NOTE: UDF registration has been included here for convenience and to demonstrate the syntax. The recommended way of registering UDFs in production env is via AQL
                    string luaDirectory = @"..\..\udf";
                    LuaConfig.PackagePath = luaDirectory + @"\?.lua";
                    string       filename = "updateUserPwd.lua";
                    string       path     = Path.Combine(luaDirectory, filename);
                    RegisterTask rt       = client.Register(null, path, filename, Language.LUA);
                    rt.Wait();

                    string updatedPassword = client.Execute(null, userKey, "updateUserPwd", "updatePassword", Value.Get(password)).ToString();
                    Console.WriteLine("\nINFO: The password has been set to: " + updatedPassword);
                }
                else
                {
                    Console.WriteLine("ERROR: User record not found!");
                }
            }
            else
            {
                Console.WriteLine("ERROR: User record not found!");
            }
        } //updatePasswordUsingUDF
예제 #10
0
        private void ServerSideExists(AerospikeClient client, WritePolicy policy, Key key, Bin bin, int search, bool expected)
        {
            long lexists = (long)client.Execute(policy, key, "record_example", "valueExists", Value.Get(bin.name), Value.Get(search));
            bool exists  = (lexists != 0);

            if (expected && exists)
            {
                console.Info("Value found as expected.");
                return;
            }

            if (!expected && !exists)
            {
                console.Info("Value not found as expected.");
                return;
            }

            console.Error("Data mismatch. Expected " + expected + " Received " + exists);
        }
예제 #11
0
        private void RunQueryExecute(AerospikeClient client, Arguments args, string indexName, string binName1, string binName2)
        {
            int begin = 3;
            int end   = 9;

            console.Info("For ns={0} set={1} index={2} bin={3} >= {4} <= {5}", args.ns, args.set, indexName, binName1, begin, end);
            console.Info("Even integers: add 100 to existing " + binName1);
            console.Info("Multiple of 5: delete " + binName2 + " bin");
            console.Info("Multiple of 9: delete record");

            Statement stmt = new Statement();

            stmt.SetNamespace(args.ns);
            stmt.SetSetName(args.set);
            stmt.SetFilters(Filter.Range(binName1, begin, end));

            ExecuteTask task = client.Execute(args.writePolicy, stmt, "record_example", "processRecord", Value.Get(binName1), Value.Get(binName2), Value.Get(100));

            task.Wait();
        }
예제 #12
0
        private void WriteUsingUdf(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "udfkey1");
            Bin bin = new Bin(args.GetBinName("udfbin1"), "string value");

            client.Execute(args.writePolicy, key, "record_example", "writeBin", Value.Get(bin.name), bin.value);

            Record record   = client.Get(args.policy, key, bin.name);
            string expected = bin.value.ToString();
            string received = (string)record.GetValue(bin.name);

            if (received != null && received.Equals(expected))
            {
                console.Info("Data matched: namespace={0} set={1} key={2} bin={3} value={4}",
                             key.ns, key.setName, key.userKey, bin.name, received);
            }
            else
            {
                console.Error("Data mismatch: Expected {0}. Received {1}.", expected, received);
            }
        }
예제 #13
0
 /// <summary>
 /// Add a value to the set.  If the set does not exist, create it using specified userModule configuration.
 /// </summary>
 /// <param name="value">value to add</param>
 public void Add(Value value)
 {
     client.Execute(policy, key, PackageName, "add", binName, value, createModule);
 }
 /// <summary>
 /// Push value onto stack.  If the stack does not exist, create it using specified userModule configuration.
 /// </summary>
 /// <param name="value">value to push</param>
 public void Push(Value value)
 {
     client.Execute(policy, key, PackageName, "push", binName, value, createModule);
 }
예제 #15
0
        public static void WriteListMapUsingUdf()
        {
            AerospikeClient client  = new AerospikeClient("172.28.128.3", 3000);
            ClientPolicy    policy1 = new ClientPolicy();

            policy1.maxConnsPerNode = 1000;


            try
            {
                Key key = new Key("test", "WriteListSet", "udfkey5");

                List <object> inner = new List <object>();
                inner.Add("string2");
                inner.Add(8L);

                //List<object> PersonInner = new List<object>();
                //inner.Add(1L);
                //inner.Add("Ahmet");
                //inner.Add("Sekmen");

                List <object> PersonInner = new List <object>();
                for (int i = 0; i < 99000; i++)
                {
                    PersonInner.Add(i);
                    PersonInner.Add("Ahmet");
                    PersonInner.Add("Sekmen");
                }

                List <Person> PersonNesne = new List <Person>();
                PersonNesne.Add(new Person()
                {
                    Id = 2, Name = "anastasia", Surname = "Sekmen"
                });
                PersonNesne.Add(new Person()
                {
                    Id = 3, Name = "anastasia", Surname = "Sekmen"
                });


                Dictionary <object, object> innerMap = new Dictionary <object, object>();
                innerMap["a"]    = 1L;
                innerMap[2L]     = "b";
                innerMap["list"] = inner;

                //Dictionary<object, object> personMap = new Dictionary<object, object>();
                //innerMap["a"] = 1L;
                //innerMap[2L] = "b";
                //innerMap["list"] = inner;

                List <object> list = new List <object>();
                list.Add("string1");
                list.Add(4L);
                list.Add(inner);
                list.Add(innerMap);
                list.Add(PersonInner);
                list.Add(PersonNesne);


                string binName = "udfbin5";

                WritePolicy policy = new WritePolicy();
                policy.SetTimeout(5000);

                client.Execute(policy, key, "example", "writeBin", Value.Get(binName), Value.Get(list));



                IList received = (IList)client.Execute(policy, key, "example", "readBin", Value.Get(binName));


                //Assert.IsNotNull(received);

                //Assert.AreEqual(list.Count, received.Count);
                //Assert.AreEqual(list[0], received[0]);
                //Assert.AreEqual(list[1], received[1]);
                //CollectionAssert.AreEqual((IList)list[2], (IList)received[2]);

                IDictionary exp = (IDictionary)list[3];
                IDictionary rec = (IDictionary)received[3];


                //Assert.AreEqual(exp["a"], rec["a"]);
                //Assert.AreEqual(exp[2L], rec[2L]);
                //CollectionAssert.AreEqual((IList)exp["list"], (IList)rec["list"]);
            }
            finally
            {
                client.Close();
            }
        }