/// <summary>
        /// Write array of integers using standard C# serializer.
        /// </summary>
        public virtual void TestArray(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "serialarraykey");

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

            console.Info("Initialize array");

            int[] array = new int[10000];

            for (int i = 0; i < 10000; i++)
            {
                array[i] = i * i;
            }

            Bin bin = new Bin(args.GetBinName("serialbin"), (object)array);

            // Do a test that pushes this complex object through the serializer
            console.Info("Write array using serializer.");
            client.Put(args.writePolicy, key, bin);

            console.Info("Read array using serializer.");
            Record record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            int[] received;

            try
            {
                received = (int[])record.GetValue(bin.name);
            }
            catch (Exception)
            {
                throw new Exception(string.Format("Failed to parse returned value: namespace={0} set={1} key={2} bin={3}",
                    key.ns, key.setName, key.userKey, bin.name));
            }

            if (received.Length != 10000)
            {
                throw new Exception(string.Format("Array length mismatch: Expected={0:D} Received={1:D}",
                    10000, received.Length));
            }

            for (int i = 0; i < 10000; i++)
            {
                if (received[i] != i * i)
                {
                    throw new Exception(string.Format("Mismatch: index={0:D} expected={1:D} received={2:D}",
                        i, i * i, received[i]));
                }
            }

            console.Info("Read array successful.");
        }
        public void RunSimpleExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "listkey");
            string binName = args.GetBinName("listbin");

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

            IList inputList = new List<Value>();
            inputList.Add(Value.Get(55));
            inputList.Add(Value.Get(77));

            // Write values to empty list.
            Record record = client.Operate(args.writePolicy, key, ListOperation.AppendItems(binName, inputList));

            console.Info("Record: " + record);

            // Pop value from end of list and also return new size of list.
            record = client.Operate(args.writePolicy, key, ListOperation.Pop(binName, -1), ListOperation.Size(binName));

            console.Info("Record: " + record);

            // There should be one result for each list operation on the same list bin.
            // In this case, there are two list operations (pop and size), so there
            // should be two results.
            IList list = record.GetList(binName);

            foreach (object value in list)
            {
                console.Info("Received: " + value);
            }
        }
 private void DeleteRecords(AerospikeClient client, Arguments args, string keyPrefix, int size)
 {
     for (int i = 0; i < size; i++)
     {
         Key key = new Key(args.ns, args.set, keyPrefix + i);
         client.Delete(args.writePolicy, key);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Add integer values.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "addkey");
            string binName = args.GetBinName("addbin");

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

            // Perform some adds and check results.
            Bin bin = new Bin(binName, 10);
            console.Info("Initial add will create record.  Initial value is " + bin.value + '.');
            client.Add(args.writePolicy, key, bin);

            bin = new Bin(binName, 5);
            console.Info("Add " + bin.value + " to existing record.");
            client.Add(args.writePolicy, key, bin);

            Record record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            // The value received from the server is an unsigned byte stream.
            // Convert to an integer before comparing with expected.
            int received = record.GetInt(bin.name);
            int expected = 15;

            if (received == expected)
            {
                console.Info("Add successful: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, received);
            }
            else
            {
                console.Error("Add mismatch: Expected {0}. Received {1}.", expected, received);
            }

            // Demonstrate add and get combined.
            bin = new Bin(binName, 30);
            console.Info("Add " + bin.value + " to existing record.");
            record = client.Operate(args.writePolicy, key, Operation.Add(bin), Operation.Get(bin.name));

            expected = 45;
            received = record.GetInt(bin.name);

            if (received == expected)
            {
                console.Info("Add successful: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, received);
            }
            else
            {
                console.Error("Add mismatch: Expected {0}. Received {1}.", expected, received);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Perform operations on a list within a single bin.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            if (!args.hasLargeDataTypes)
            {
                console.Info("Large set functions are not supported by the connected Aerospike server.");
                return;
            }

            Key key = new Key(args.ns, args.set, "setkey");
            string binName = args.GetBinName("setbin");

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

            // Initialize large set operator.
            Aerospike.Client.LargeSet set = client.GetLargeSet(args.writePolicy, key, binName, null);

            // Write values.
            set.Add(Value.Get("setvalue1"));
            set.Add(Value.Get("setvalue2"));
            set.Add(Value.Get("setvalue3"));

            // Verify large set was created with default configuration.
            IDictionary map = set.GetConfig();

            foreach (DictionaryEntry entry in map)
            {
                console.Info(entry.Key.ToString() + ',' + entry.Value);
            }

            // Remove last value.
            set.Remove(Value.Get("setvalue3"));

            int size = set.Size();

            if (size != 2)
            {
                throw new Exception("Size mismatch. Expected 2 Received " + size);
            }

            string received = (string)set.Get(Value.Get("setvalue2"));
            string expected = "setvalue2";

            if (received != null && received.Equals(expected))
            {
                console.Info("Data matched: namespace={0} set={1} key={2} value={3}", key.ns, key.setName, key.userKey, received);
            }
            else
            {
                console.Error("Data mismatch: Expected {0}. Received {1}.", expected, received);
            }
        }
        public void RunScoreExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "mapkey");
            string binName = args.GetBinName("mapbin");

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

            IDictionary inputMap = new Dictionary<Value, Value>();
            inputMap[Value.Get("Charlie")] = Value.Get(55);
            inputMap[Value.Get("Jim")] = Value.Get(98);
            inputMap[Value.Get("John")] = Value.Get(76);
            inputMap[Value.Get("Harry")] = Value.Get(82);

            // Write values to empty map.
            Record record = client.Operate(args.writePolicy, key,
                MapOperation.PutItems(MapPolicy.Default, binName, inputMap)
                );

            console.Info("Record: " + record);

            // Increment some user scores.
            record = client.Operate(args.writePolicy, key,
                MapOperation.Increment(MapPolicy.Default, binName, Value.Get("John"), Value.Get(5)),
                MapOperation.Decrement(MapPolicy.Default, binName, Value.Get("Jim"), Value.Get(4))
                );

            console.Info("Record: " + record);

            // Get top two scores.
            record = client.Operate(args.writePolicy, key,
                MapOperation.GetByRankRange(binName, -2, 2, MapReturnType.KEY_VALUE)
                );

            // There should be one result for each map operation on the same map bin.
            // In this case, there are two map operations (pop and size), so there
            // should be two results.
            IList results = record.GetList(binName);

            foreach (object value in results)
            {
                console.Info("Received: " + value);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Prepend string to an existing string.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "prependkey");
            string binName = args.GetBinName("prependbin");

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

            Bin bin = new Bin(binName, "World");
            console.Info("Initial prepend will create record.  Initial value is " + bin.value + '.');
            client.Prepend(args.writePolicy, key, bin);

            bin = new Bin(binName, "Hello ");
            console.Info("Prepend \"" + bin.value + "\" to existing record.");
            client.Prepend(args.writePolicy, key, bin);

            Record record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            // The value received from the server is an unsigned byte stream.
            // Convert to an integer before comparing with expected.
            object received = record.GetValue(bin.name);
            string expected = "Hello World";

            if (received.Equals(expected))
            {
                console.Info("Prepend successful: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, received);
            }
            else
            {
                console.Error("Prepend mismatch: Expected {0}. Received {1}.", expected, received);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Write/Read list of compound objects using Aerospike list type with blob entries (Bin.AsList()).
        /// </summary>
        private void TestListCompoundList(AerospikeClient client, Arguments args)
        {
            console.Info("Read/Write ArrayList<CompoundObject> using list with blob entries");
            Key key = new Key(args.ns, args.set, "listkey5");
            client.Delete(args.writePolicy, key);

            List<CompoundObject> list = new List<CompoundObject>();
            list.Add(new CompoundObject("string1", 7));
            list.Add(new CompoundObject("string2", 9));
            list.Add(new CompoundObject("string3", 54));

            Bin bin = new Bin("listbin", list);
            client.Put(args.writePolicy, key, bin);

            Record record = client.Get(args.policy, key, bin.name);
            IList receivedList = (IList)record.GetValue(bin.name);

            ValidateSize(3, receivedList.Count);
            Validate(list[0], receivedList[0]);
            Validate(list[1], receivedList[1]);
            Validate(list[2], receivedList[2]);

            console.Info("Read/Write ArrayList<CompoundObject> successful.");
        }
        /// <summary>
        /// Exercise record generation functionality.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "genkey");
            string binName = args.GetBinName("genbin");

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

            // Set some values for the same record.
            Bin bin = new Bin(binName, "genvalue1");
            console.Info("Put: namespace={0} set={1} key={2} bin={3} value={4}",
                key.ns, key.setName, key.userKey, bin.name, bin.value);

            client.Put(args.writePolicy, key, bin);

            bin = new Bin(binName, "genvalue2");
            console.Info("Put: namespace={0} set={1} key={2} bin={3} value={4}",
                key.ns, key.setName, key.userKey, bin.name, bin.value);

            client.Put(args.writePolicy, key, bin);

            // Retrieve record and its generation count.
            Record record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            object received = record.GetValue(bin.name);
            string expected = bin.value.ToString();

            if (received.Equals(expected))
            {
                console.Info("Get successful: namespace={0} set={1} key={2} bin={3} value={4} generation={5}",
                    key.ns, key.setName, key.userKey, bin.name, received, record.generation);
            }
            else
            {
                throw new Exception(string.Format("Get mismatch: Expected {0}. Received {1}.", expected, received));
            }

            // Set record and fail if it's not the expected generation.
            bin = new Bin(binName, "genvalue3");
            console.Info("Put: namespace={0} set={1} key={2} bin={3} value={4} expected generation={5}",
                key.ns, key.setName, key.userKey, bin.name, bin.value, record.generation);

            WritePolicy writePolicy = new WritePolicy();
            writePolicy.generationPolicy = GenerationPolicy.EXPECT_GEN_EQUAL;
            writePolicy.generation = record.generation;
            client.Put(writePolicy, key, bin);

            // Set record with invalid generation and check results .
            bin = new Bin(binName, "genvalue4");
            writePolicy.generation = 9999;
            console.Info("Put: namespace={0} set={1} key={2} bin={3} value={4} expected generation={5}",
                key.ns, key.setName, key.userKey, bin.name, bin.value, writePolicy.generation);

            try
            {
                client.Put(writePolicy, key, bin);
                throw new Exception("Should have received generation error instead of success.");
            }
            catch (AerospikeException ae)
            {
                if (ae.Result == ResultCode.GENERATION_ERROR)
                {
                    console.Info("Success: Generation error returned as expected.");
                }
                else
                {
                    throw new Exception(string.Format("Unexpected set return code: namespace={0} set={1} key={2} bin={3} value={4} code={5}",
                        key.ns, key.setName, key.userKey, bin.name, bin.value, ae.Result));
                }
            }

            // Verify results.
            record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            received = record.GetValue(bin.name);
            expected = "genvalue3";

            if (received.Equals(expected))
            {
                console.Info("Get successful: namespace={0} set={1} key={2} bin={3} value={4} generation={5}",
                    key.ns, key.setName, key.userKey, bin.name, received, record.generation);
            }
            else
            {
                throw new Exception(string.Format("Get mismatch: Expected {0}. Received {1}.", expected, received));
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Write/Read List/HashMap combination directly instead of relying on default serializer.
        /// </summary>
        private void TestListMapCombined(AerospikeClient client, Arguments args)
        {
            console.Info("Read/Write List/HashMap");
            Key key = new Key(args.ns, args.set, "listmapkey");
            client.Delete(args.writePolicy, key);

            byte[] blob = new byte[] {3, 52, 125};
            List<object> inner = new List<object>();
            inner.Add("string2");
            inner.Add(5);

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

            List<object> list = new List<object>();
            list.Add("string1");
            list.Add(8);
            list.Add(inner);
            list.Add(innerMap);

            Bin bin = new Bin(args.GetBinName("listmapbin"), list);
            client.Put(args.writePolicy, key, bin);

            Record record = client.Get(args.policy, key, bin.name);
            List<object> received = (List<object>) record.GetValue(bin.name);

            ValidateSize(4, received.Count);
            Validate("string1", received[0]);
            // Server convert numbers to long, so must expect long.
            Validate(8L, received[1]);

            List<object> receivedInner = (List<object>)received[2];
            ValidateSize(2, receivedInner.Count);
            Validate("string2", receivedInner[0]);
            Validate(5L, receivedInner[1]);

            Dictionary<object, object> receivedMap = (Dictionary<object, object>)received[3];
            ValidateSize(4, receivedMap.Count);
            Validate(1L, receivedMap["a"]);
            Validate("b", receivedMap[2L]);
            Validate(blob, (byte[])receivedMap[3L]);

            List<object> receivedInner2 = (List<object>)receivedMap["list"];
            ValidateSize(2, receivedInner2.Count);
            Validate("string2", receivedInner2[0]);
            Validate(5L, receivedInner2[1]);

            console.Info("Read/Write List/HashMap successful");
        }
Esempio n. 11
0
        /// <summary>
        /// Simple examples of large list functionality.
        /// </summary>
        private void RunSimpleExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "setkey");
            string binName = args.GetBinName("ListBin");

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

            // Initialize large set operator.
            Aerospike.Client.LargeList llist = client.GetLargeList(args.writePolicy, key, binName);
            string orig1 = "llistValue1";
            string orig2 = "llistValue2";
            string orig3 = "llistValue3";

            // Write values.
            llist.Add(Value.Get(orig1));
            llist.Add(Value.Get(orig2));
            llist.Add(Value.Get(orig3));

            IDictionary map = llist.GetConfig();

            foreach (DictionaryEntry entry in map)
            {
                console.Info(entry.Key.ToString() + ',' + entry.Value);
            }

            IList rangeList = llist.Range(Value.Get(orig2), Value.Get(orig3));

            if (rangeList == null)
            {
                throw new Exception("Range returned null.");
            }

            if (rangeList.Count != 2)
            {
                throw new Exception("Range Size mismatch. Expected 2 Received " + rangeList.Count);
            }
            string v2 = (string) rangeList[0];
            string v3 = (string) rangeList[1];

            if (v2.Equals(orig2) && v3.Equals(orig3))
            {
                console.Info("Range Query matched: v2=" + orig2 + " v3=" + orig3);
            }
            else
            {
                throw new Exception("Range Content mismatch. Expected (" + orig2 + ":" + orig3 +
                    ") Received (" + v2 + ":" + v3 + ")");
            }

            // Remove last value.
            llist.Remove(Value.Get(orig3));

            int size = llist.Size();

            if (size != 2)
            {
                throw new Exception("Size mismatch. Expected 2 Received " + size);
            }

            IList listReceived = llist.Find(Value.Get(orig2));
            string expected = orig2;

            if (listReceived == null)
            {
                console.Error("Data mismatch: Expected " + expected + " Received null");
                return;
            }

            string stringReceived = (string) listReceived[0];

            if (stringReceived != null && stringReceived.Equals(expected))
            {
                console.Info("Data matched: namespace=" + key.ns + " set=" + key.setName + " key=" + key.userKey +
                    " value=" + stringReceived);
            }
            else
            {
                console.Error("Data mismatch: Expected " + expected + " Received " + stringReceived);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Use serialized bin for row in largelist bin. 
        /// </summary>
        private void RunWithSerializedBin(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "accountId");

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

            // Initialize large list operator.
            Aerospike.Client.LargeList list = client.GetLargeList(args.writePolicy, key, "trades");

            // Write trades
            Dictionary<string, Value> dict = new Dictionary<string, Value>();
            MemoryStream ms = new MemoryStream(500);

            DateTime timestamp1 = new DateTime(2014, 6, 25, 12, 18, 43);
            dict["key"] = Value.Get(timestamp1.Ticks);
            BinaryWriter writer = new BinaryWriter(ms);
            writer.Write("IBM");  // ticker
            writer.Write(100);    // qty
            writer.Write(181.82); // price
            dict["value"] = Value.Get(ms.ToArray());
            list.Add(Value.Get(dict));

            DateTime timestamp2 = new DateTime(2014, 6, 26, 9, 33, 17);
            dict["key"] = Value.Get(timestamp2.Ticks);
            ms.SetLength(0);
            writer = new BinaryWriter(ms);
            writer.Write("GE");  // ticker
            writer.Write(500);   // qty
            writer.Write(26.36); // price
            dict["value"] = Value.Get(ms.ToArray());
            list.Add(Value.Get(dict));

            DateTime timestamp3 = new DateTime(2014, 6, 27, 14, 40, 19);
            dict["key"] = Value.Get(timestamp3.Ticks);
            ms.SetLength(0);
            writer = new BinaryWriter(ms);
            writer.Write("AAPL");  // ticker
            writer.Write(75);      // qty
            writer.Write(91.85);   // price
            dict["value"] = Value.Get(ms.ToArray());
            list.Add(Value.Get(dict));

            // Verify list size
            int size = list.Size();

            if (size != 3)
            {
                throw new Exception("List size mismatch. Expected 3 Received " + size);
            }

            // Filter on range of timestamps
            DateTime begin = new DateTime(2014, 6, 26);
            DateTime end = new DateTime(2014, 6, 28);
            IList results = list.Range(Value.Get(begin.Ticks), Value.Get(end.Ticks));

            if (results.Count != 2)
            {
                throw new Exception("Query results size mismatch. Expected 2 Received " + results.Count);
            }

            // Verify data.
            ValidateWithSerializedBin(results, 0, timestamp2, "GE", 500, 26.36);
            ValidateWithSerializedBin(results, 1, timestamp3, "AAPL", 75, 91.85);

            console.Info("Data matched.");
        }
Esempio n. 13
0
        /// <summary>
        /// Write/Read HashMap<String,String> directly instead of relying on default serializer.
        /// </summary>
        private void TestMapStrings(AerospikeClient client, Arguments args)
        {
            console.Info("Read/Write HashMap<String,String>");
            Key key = new Key(args.ns, args.set, "mapkey1");
            client.Delete(args.writePolicy, key);

            Dictionary<object, object> map = new Dictionary<object, object>();
            map["key1"] = "string1";
            map["key2"] = "string2";
            map["key3"] = "string3";

            Bin bin = new Bin(args.GetBinName("mapbin1"), map);
            client.Put(args.writePolicy, key, bin);

            Record record = client.Get(args.policy, key, bin.name);
            Dictionary<object, object> receivedMap = (Dictionary<object, object>)record.GetValue(bin.name);

            ValidateSize(3, receivedMap.Count);
            Validate("string1", receivedMap["key1"]);
            Validate("string2", receivedMap["key2"]);
            Validate("string3", receivedMap["key3"]);

            console.Info("Read/Write HashMap<String,String> successful");
        }
Esempio n. 14
0
        public void RunSimpleExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "mapkey");
            string binName = args.GetBinName("mapbin");

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

            IDictionary inputMap = new Dictionary<Value, Value>();
            inputMap[Value.Get(1)] = Value.Get(55);
            inputMap[Value.Get(2)] = Value.Get(33);

            // Write values to empty map.
            Record record = client.Operate(args.writePolicy, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap));

            console.Info("Record: " + record);

            // Pop value from map and also return new size of map.
            record = client.Operate(args.writePolicy, key, MapOperation.RemoveByKey(binName, Value.Get(1), MapReturnType.VALUE), MapOperation.Size(binName));

            console.Info("Record: " + record);

            // There should be one result for each map operation on the same map bin.
            // In this case, there are two map operations (pop and size), so there
            // should be two results.
            IList results = record.GetList(binName);

            foreach (object value in results)
            {
                console.Info("Received: " + value);
            }
        }
Esempio n. 15
0
        private void RunReplaceOnlyExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "replaceonlykey");
            Bin bin = new Bin("bin", "value");

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

            console.Info("Replace record requiring that it exists: namespace={0} set={1} key={2}",
                key.ns, key.setName, key.userKey);

            try
            {
                WritePolicy policy = new WritePolicy();
                policy.recordExistsAction = RecordExistsAction.REPLACE_ONLY;
                client.Put(policy, key, bin);

                console.Error("Failure. This command should have resulted in an error.");
            }
            catch (AerospikeException ae)
            {
                if (ae.Result == ResultCode.KEY_NOT_FOUND_ERROR)
                {
                    console.Info("Success. Key not found error returned as expected.");
                }
                else
                {
                    throw ae;
                }
            }
        }
 private static void DeleteRecord(AerospikeClient client,
         WritePolicy policy, Key key)
 {
     client.Delete(policy, key);
     CheckKeyExists(client, policy, key);
     Console.WriteLine("Deleted this record: " + key);
     Console.WriteLine("");
 }
        public override void Init(int flowCount, long flowRecordCount)
        {
            string[] str = ConnectionString.Split(';');
            string server = str[0].Split(':')[1];
            int port = Int32.Parse(str[1].Split(':')[1]);
            string ns = str[2].Split(':')[1];
            string set = str[3].Split(':')[1];

            client = new AerospikeClient(server, port);
            indexes = new LargeList[flowCount];

            Key listKey = new Key(ns, set, CollectionName);
            client.Delete(null, listKey);

            WritePolicy policy = new WritePolicy();
            policy.recordExistsAction = RecordExistsAction.REPLACE;

            for (int i = 0; i < flowCount; i++)
                indexes[i] = client.GetLargeList(policy, listKey, CollectionName, null);
        }
Esempio n. 18
0
        /// <summary>
        /// Write/Read ArrayList<String> directly instead of relying on default serializer.
        /// </summary>
        private void TestListStrings(AerospikeClient client, Arguments args)
        {
            console.Info("Read/Write ArrayList<String>");
            Key key = new Key(args.ns, args.set, "listkey1");
            client.Delete(args.writePolicy, key);

            List<object> list = new List<object>();
            list.Add("string1");
            list.Add("string2");
            list.Add("string3");

            Bin bin = new Bin(args.GetBinName("listbin1"), list);
            client.Put(args.writePolicy, key, bin);

            Record record = client.Get(args.policy, key, bin.name);
            List<object> receivedList = (List<object>) record.GetValue(bin.name);

            ValidateSize(3, receivedList.Count);
            Validate("string1", receivedList[0]);
            Validate("string2", receivedList[1]);
            Validate("string3", receivedList[2]);

            console.Info("Read/Write ArrayList<String> successful.");
        }
        /// <summary>
        /// Write list object using standard C# serializer.
        /// </summary>
        public virtual void TestList(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "seriallistkey");

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

            console.Info("Initialize list");

            List<string> list = new List<string>();
            list.Add("string1");
            list.Add("string2");
            list.Add("string3");

            Bin bin = new Bin(args.GetBinName("serialbin"), (object)list);

            console.Info("Write list using serializer.");
            client.Put(args.writePolicy, key, bin);

            console.Info("Read list using serializer.");
            Record record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            List<string> received;

            try
            {
                received = (List<string>)record.GetValue(bin.name);
            }
            catch (Exception e)
            {
                throw new Exception(string.Format("Failed to parse returned value: namespace={0} set={1} key={2} bin={3}",
                    key.ns, key.setName, key.userKey, bin.name), e);
            }

            if (received.Count != 3)
            {
                throw new Exception(string.Format("Array length mismatch: Expected={0:D} Received={1:D}",
                    3, received.Count));
            }

            for (int i = 0; i < received.Count; i++)
            {
                string expected = "string" + (i + 1);
                if (!received[i].Equals(expected))
                {
                    object obj = received[i];
                    throw new Exception(string.Format("Mismatch: index={0:D} expected={1} received={2}",
                        i, expected, obj));
                }
            }

            console.Info("Read list successful.");
        }
        /// <summary>
        /// Write complex object using standard C# serializer.
        /// </summary>
        public virtual void TestComplex(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "serialcomplexkey");

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

            console.Info("Initialize complex object");

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

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

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

            Bin bin = new Bin(args.GetBinName("complexbin"), (object)list);

            console.Info("Write complex object using serializer.");
            client.Put(args.writePolicy, key, bin);

            console.Info("Read complex object using serializer.");
            Record record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            string expected = Util.ListToString(list);
            string received;

            try
            {
                object val = record.GetValue(bin.name);
                received = Util.ObjectToString(val);
            }
            catch (Exception)
            {
                throw new Exception(string.Format("Failed to parse returned value: namespace={0} set={1} key={2} bin={3}",
                    key.ns, key.setName, key.userKey, 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");
                console.Error("Expected " + expected);
                console.Error("Received " + received);
            }
            console.Info("Read complex object successful.");
        }
Esempio n. 21
0
        /// <summary>
        /// Write/Read ArrayList<Object> directly instead of relying on default serializer.
        /// </summary>
        private void TestListComplex(AerospikeClient client, Arguments args)
        {
            console.Info("Read/Write ArrayList<Object>");
            Key key = new Key(args.ns, args.set, "listkey2");
            client.Delete(args.writePolicy, key);

            byte[] blob = new byte[] {3, 52, 125};
            List<object> list = new List<object>();
            list.Add("string1");
            list.Add(2);
            list.Add(blob);

            Bin bin = new Bin(args.GetBinName("listbin2"), list);
            client.Put(args.writePolicy, key, bin);

            Record record = client.Get(args.policy, key, bin.name);
            List<object> receivedList = (List<object>) record.GetValue(bin.name);

            ValidateSize(3, receivedList.Count);
            Validate("string1", receivedList[0]);
            // Server convert numbers to long, so must expect long.
            Validate(2L, receivedList[1]);
            Validate(blob, (byte[])receivedList[2]);

            console.Info("Read/Write ArrayList<Object> successful.");
        }
        public virtual void SetUp()
        {
            try
            {
                Console.WriteLine("Creating AerospikeClient");
                ClientPolicy clientPolicy = new ClientPolicy();
                clientPolicy.timeout = TIMEOUT;
                client = new AerospikeClient(clientPolicy, HOST, PORT);
                client.writePolicyDefault.expiration = EXPIRY;
                //client.writePolicyDefault.recordExistsAction = RecordExistsAction.REPLACE;

                Key key = new Key (NS, SET, "CDT-list-test-key");
                client.Delete(null, key);
                key = new Key(NS, SET, "setkey");
                client.Delete(null, key);
                key = new Key(NS, SET, "accountId");
                client.Delete(null, key);

            } catch (Exception ex)
            {
                caughtException = ex;
                Console.WriteLine(string.Format("TestFixtureSetUp failed in {0} - {1} {2}", this.GetType(), caughtException.GetType(), caughtException.Message));
                Console.WriteLine (caughtException.StackTrace);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Use default serialized bin for row in largelist bin. 
        /// </summary>
        private void RunWithDefaultSerializedBin(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "accountId");
            object value1 = new CompoundObject("IBM", 100);
            object value2 = new CompoundObject("GE", 500);
            object value3 = new CompoundObject("AAPL", 75);

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

            // Initialize large list operator.
            Aerospike.Client.LargeList list = client.GetLargeList(args.writePolicy, key, "trades");

            // Write trades
            Dictionary<string, Value> dict = new Dictionary<string, Value>();

            DateTime timestamp1 = new DateTime(2014, 6, 25, 12, 18, 43);
            dict["key"] = Value.Get(timestamp1.Ticks);
            dict["value"] = Value.Get(value1);
            list.Add(Value.Get(dict));

            DateTime timestamp2 = new DateTime(2014, 6, 26, 9, 33, 17);
            dict["key"] = Value.Get(timestamp2.Ticks);
            dict["value"] = Value.Get(value2);
            list.Add(Value.Get(dict));

            DateTime timestamp3 = new DateTime(2014, 6, 27, 14, 40, 19);
            dict["key"] = Value.Get(timestamp3.Ticks);
            dict["value"] = Value.Get(value3);
            list.Add(Value.Get(dict));

            // Verify list size
            int size = list.Size();

            if (size != 3)
            {
                throw new Exception("List size mismatch. Expected 3 Received " + size);
            }

            // Filter on range of timestamps
            DateTime begin = new DateTime(2014, 6, 26);
            DateTime end = new DateTime(2014, 6, 28);
            IList results = list.Range(Value.Get(begin.Ticks), Value.Get(end.Ticks));

            if (results.Count != 2)
            {
                throw new Exception("Query results size mismatch. Expected 2 Received " + results.Count);
            }

            // Verify data.
            ValidateDefault(results, 0, timestamp2, value2);
            ValidateDefault(results, 1, timestamp3, value3);

            console.Info("Data matched.");
        }
Esempio n. 24
0
        /// <summary>
        /// Use distinct sub-bins for row in largelist bin. 
        /// </summary>
        private void RunWithDistinctBins(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "accountId");

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

            // Initialize large list operator.
            Aerospike.Client.LargeList list = client.GetLargeList(args.writePolicy, key, "trades");

            // Write trades
            Dictionary<string,Value> dict = new Dictionary<string,Value>();

            DateTime timestamp1 = new DateTime(2014, 6, 25, 12, 18, 43);
            dict["key"] = Value.Get(timestamp1.Ticks);
            dict["ticker"] = Value.Get("IBM");
            dict["qty"] = Value.Get(100);
            dict["price"] = Value.Get(BitConverter.GetBytes(181.82));
            list.Add(Value.Get(dict));

            DateTime timestamp2 = new DateTime(2014, 6, 26, 9, 33, 17);
            dict["key"] = Value.Get(timestamp2.Ticks);
            dict["ticker"] = Value.Get("GE");
            dict["qty"] = Value.Get(500);
            dict["price"] = Value.Get(BitConverter.GetBytes(26.36));
            list.Add(Value.Get(dict));

            DateTime timestamp3 = new DateTime(2014, 6, 27, 14, 40, 19);
            dict["key"] = Value.Get(timestamp3.Ticks);
            dict["ticker"] = Value.Get("AAPL");
            dict["qty"] = Value.Get(75);
            dict["price"] = Value.Get(BitConverter.GetBytes(91.85));
            list.Add(Value.Get(dict));

            // Verify list size
            int size = list.Size();

            if (size != 3)
            {
                throw new Exception("List size mismatch. Expected 3 Received " + size);
            }

            // Filter on range of timestamps
            DateTime begin = new DateTime(2014, 6, 26);
            DateTime end = new DateTime(2014, 6, 28);
            IList results = list.Range(Value.Get(begin.Ticks), Value.Get(end.Ticks));

            if (results.Count != 2)
            {
                throw new Exception("Query results size mismatch. Expected 2 Received " + results.Count);
            }

            // Verify data.
            ValidateWithDistinctBins(results, 0, timestamp2, "GE", 500, 26.36);
            ValidateWithDistinctBins(results, 1, timestamp3, "AAPL", 75, 91.85);

            console.Info("Data matched.");

            console.Info("Run large list scan.");
            IList rows = list.Scan();
            foreach (IDictionary row in rows)
            {
                foreach (DictionaryEntry entry in row)
                {
                    //console.Info(entry.Key.ToString());
                    //console.Info(entry.Value.ToString());
                }
            }
            console.Info("Large list scan complete.");
        }
        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);
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Write/Read HashMap<Object,Object> directly instead of relying on default serializer.
        /// </summary>
        private void TestMapComplex(AerospikeClient client, Arguments args)
        {
            console.Info("Read/Write HashMap<Object,Object>");
            Key key = new Key(args.ns, args.set, "mapkey2");
            client.Delete(args.writePolicy, key);

            byte[] blob = new byte[] {3, 52, 125};
            List<int> list = new List<int>();
            list.Add(100034);
            list.Add(12384955);
            list.Add(3);
            list.Add(512);

            Dictionary<object, object> map = new Dictionary<object, object>();
            map["key1"] = "string1";
            map["key2"] = 2;
            map["key3"] = blob;
            map["key4"] = list;

            Bin bin = new Bin(args.GetBinName("mapbin2"), map);
            client.Put(args.writePolicy, key, bin);

            Record record = client.Get(args.policy, key, bin.name);
            Dictionary<object, object> receivedMap = (Dictionary<object, object>)record.GetValue(bin.name);

            ValidateSize(4, receivedMap.Count);
            Validate("string1", receivedMap["key1"]);
            // Server convert numbers to long, so must expect long.
            Validate(2L, receivedMap["key2"]);
            Validate(blob, (byte[])receivedMap["key3"]);

            IList receivedInner = (IList)receivedMap["key4"];
            ValidateSize(4, receivedInner.Count);
            Validate(100034L, receivedInner[0]);
            Validate(12384955L, receivedInner[1]);
            Validate(3L, receivedInner[2]);
            Validate(512L, receivedInner[3]);

            console.Info("Read/Write HashMap<Object,Object> successful");
        }