Exemplo n.º 1
0
        public void ClientInactivityTest()
        {
            Client.SetTrace(true);
            Client.SetLogFile("c:\\Users\\zszabo\\logs\\no_service_trace.txt");

            string dbName = "test_db";
            string tableName = "test_table";

            Client client = new Client(Utils.GetConfigNodes());
            Table tbl = Utils.GetOrCreateEmptyTableAndDatabase(client, dbName, tableName);

            for (ulong i = 0; i < 1000; i++)
                tbl.Set(Utils.Id(i), "test");

            client.Submit();

            client.SetGlobalTimeout(30000);
            var timeout = 5 * client.GetGlobalTimeout();
            Console.WriteLine("Now sleeping for " + timeout / 1000 + " seconds");
            Thread.Sleep((int)timeout);

            foreach (string key in tbl.GetKeyIterator(new StringRangeParams()))
                Console.Write(key);

            client.Close();
        }
Exemplo n.º 2
0
        public void CountBeforeSubmit()
        {
            string dbName = "test_db";
            string tableName = "test_table";

            Client client = new Client(Utils.GetConfigNodes());
            Table tbl = Utils.GetOrCreateEmptyTableAndDatabase(client, dbName, tableName);

            for(ulong i = 0; i < 1000; i++)
                tbl.Set(Utils.Id(i), "test");

            var cnt1 = tbl.Count(new ByteRangeParams());

            client.Submit();

            var cnt2 = tbl.Count(new StringRangeParams());

            Console.WriteLine(cnt1 + " - " + cnt2);

            Assert.IsTrue(cnt2 == 1000);

            client.Close();
        }
Exemplo n.º 3
0
        public void CreateAndCloseClients()
        {
            string dbName = "create_and_close_clients_db";
            string tableName = "create_and_close_clients_table";

            Client client1 = new Client(Utils.GetConfigNodes());
            Client client2 = new Client(Utils.GetConfigNodes());

            Table tbl1 = Utils.GetOrCreateEmptyTableAndDatabase(client1, dbName, tableName);
            Table tbl2 = Utils.GetOrCreateEmptyTableAndDatabase(client2, dbName + "_2", tableName);

            tbl1.TruncateTable();

            //client.Submit();

            tbl1.Get("0000000000001");
            tbl1.Set("0000000000001", "test");
            tbl1.Get("0000000000002");
            tbl1.Set("0000000000002", "test");

            client1.Submit();

            tbl1.Get("0000000000001");
            tbl1.Set("0000000000001", "test");
            tbl1.Get("0000000000002");
            tbl1.Set("0000000000002", "test");

            client1.Submit();

            tbl2.Get("0000000000001");
            tbl2.Set("0000000000001", "test");
            tbl2.Get("0000000000002");
            tbl2.Set("0000000000002", "test");

            //client1.Close();
            //client2.Close();
        }
Exemplo n.º 4
0
        public void TruncateAfterSet()
        {
            string dbName = "get_set_db";
            string tableName = "get_set_db_table";
            Client.SetLogFile("f:\\log.txt");
            Client.SetTrace(true);
            Client client = new Client(Utils.GetConfigNodes());
            Table tbl = Utils.GetOrCreateEmptyTableAndDatabase(client, dbName, tableName);

            try
            {

                tbl.Set("0000000000001", "test");
                tbl.Set("0000000000002", "test");

                tbl.TruncateTable();

                client.Submit();

                Assert.Fail("No SDBPException!");
            }
            catch (SDBPException)
            {
            }

            //client.Close();
        }
Exemplo n.º 5
0
        //[TestMethod]
        public void SetGetMP3()
        {
            string dbName = "test_mp3_db";
            string tableName = "test_mp3_table";

            Client client = new Client(Utils.GetConfigNodes());
            Table tbl = Utils.GetOrCreateEmptyTableAndDatabase(client, dbName, tableName);

            // SET MP3 (you will need a valdi path to test.mp3
            byte[] payload = Utils.ReadFile("f:/test.mp3");
            System.Console.WriteLine("mp3 buffer: {0}", payload.GetLength(0));
            tbl.Set(System.Text.Encoding.UTF8.GetBytes("mp3"), payload);

            client.Submit();

            byte[] res = tbl.Get(System.Text.Encoding.UTF8.GetBytes("mp3"));
            System.Console.WriteLine("mp3 buffer: {0}", res.GetLength(0));

            Assert.IsTrue(Utils.ByteArraysEqual(payload, res));
        }
Exemplo n.º 6
0
        public void SequenceResetAndTruncate()
        {
            string dbName = "seq_and_trunc_db";
            string tableNameSeq = "seq_table";
            string tableNameTrunc = "trunc_table";

            Client client = new Client(Utils.GetConfigNodes());
            Table tblSeq = Utils.GetOrCreateEmptyTableAndDatabase(client, dbName, tableNameSeq);
            Table tblTrunc = Utils.GetOrCreateEmptyTableAndDatabase(client, dbName, tableNameTrunc);

            Sequence testSeq = tblSeq.GetSequence("seqIDs");

            try
            {
                testSeq.Reset();

                tblTrunc.TruncateTable();

                client.Submit();

                Assert.Fail("No SDBPException!");
            }
            catch (SDBPException)
            {
            }

            //client.Close();
        }
Exemplo n.º 7
0
        public void SequenceAddAfterSet()
        {
            string dbName = "seq_and_set_db";
            string tableNameSeq = "seq_table";
            string tableNameSet = "set_table";

            Client client = new Client(Utils.GetConfigNodes());
            Table tblSeq = Utils.GetOrCreateEmptyTableAndDatabase(client, dbName, tableNameSeq);
            Table tblSet = Utils.GetOrCreateEmptyTableAndDatabase(client, dbName, tableNameSet);

            Sequence testSeq = tblSeq.GetSequence("seqIDs");

            tblSet.Set("0000000000001", "test");
            tblSet.Set("0000000000002", "test");
            tblSet.Set("0000000000003", "test");

            Console.WriteLine("Next: " + testSeq.GetNext);

            client.Submit();

            client.Close();
        }
Exemplo n.º 8
0
        public void ListTestsWithoutProxies()
        {
            var dbName = "test_db";
            var tableName = "test_table";
            int length = 10 * 1000;
            uint num = 22 * 1000;

            Client client = new Client(Utils.GetConfigNodes());
            Table tbl = Utils.GetOrCreateEmptyTableAndDatabase(client, dbName, tableName);

            var value = Utils.RandomString(length);

            for (ulong i = 0; i < num; i++)
                tbl.Set(Utils.Id(i), value);

            // Submit, no proxied values left
            client.Submit();

            client.SetConsistencyMode(Client.CONSISTENCY_STRICT);
            ListTests(tbl, num);

            client.SetConsistencyMode(Client.CONSISTENCY_RYW);
            ListTests(tbl, num);
        }
Exemplo n.º 9
0
        public void GetSetSubmit()
        {
            string dbName = "get_set_db";
            string tableName = "get_set_db_table";

            Client client = new Client(Utils.GetConfigNodes());
            Table tbl = Utils.GetOrCreateEmptyTableAndDatabase(client, dbName, tableName);

            //client.Submit();

            tbl.Get("0000000000001");
            tbl.Set("0000000000001", "test");
            tbl.Get("0000000000002");
            tbl.Set("0000000000002", "test");

            client.Submit();

            var i = tbl.Count(new ByteRangeParams());
            Assert.IsTrue(i == 2);
        }
Exemplo n.º 10
0
        public static void FixDiffs(Client client, List<ConfigState.ShardServer> shardServers, Int64 tableID, List<string> diffs)
        {
            var i = 0;
            foreach (var key in diffs)
            {
                i += 1;
                byte[] startKey = Utils.StringToByteArray(key);
                byte[] endKey = Utils.NextKey(startKey);
                var serverKeyValues = ConfigStateHelpers.ParallelFetchTableKeyValuesHTTP(shardServers, tableID, startKey, endKey, true);

                if (Array.TrueForAll(serverKeyValues, val => (val.Count == 1 && Utils.ByteArraysEqual(val.First().Key, serverKeyValues[0].First().Key))))
                    continue;

                foreach (var keyValue in serverKeyValues)
                {
                    if (keyValue == null || keyValue.Count == 0)
                        continue;

                    if (keyValue.First().Value.Length > 0)
                    {
                        Assert.IsTrue(Utils.ByteArraysEqual(Utils.StringToByteArray(key), keyValue.First().Key));

                        Console.WriteLine("Setting key {0}", key);
                        Table table = new Table(client, null, (ulong)tableID, "");
                        table.Set(startKey, keyValue.First().Value);
                        client.Submit();
                    }
                }
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Send batched commands to the server.
 /// </summary>
 public void Dispose()
 {
     client.Submit();
 }
Exemplo n.º 12
0
        public static void FillDatabaseWithNumericKeys(string databaseName, string tableName)
        {
            var client = new Client(Utils.GetConfigNodes());
            Assert.IsTrue(ConfigStateHelpers.TryDeleteDatabase(client, databaseName));
            var database = client.CreateDatabase(databaseName);
            Assert.IsNotNull(database, "Cannot create database " + databaseName);
            var table = ConfigStateHelpers.TryCreateTable(database, tableName);
            Assert.IsNotNull(table, "Cannot create table " + tableName);

            System.Console.WriteLine("Filling the database...");

            DateTime last = DateTime.Now;
            for (ulong i = 0; i < 100 * 1000 * 1000; i++)
            {
                var key = Utils.Id(i);
                table.Set(key, key);
                TimeSpan timeSpan = DateTime.Now - last;
                if (timeSpan.TotalSeconds >= 60)
                {
                    System.Console.WriteLine("i: " + i);
                    last = DateTime.Now;
                }
            }

            client.Submit();

            System.Console.WriteLine("Database filling is done.");
        }
Exemplo n.º 13
0
        public static void ThreadFunc()
        {
            //Client.SetTrace(true);
            //Client.SetLogFile("d:/out.txt");

            //string[] controllers = { "127.0.0.1:7080" };
            string[] controllers = { "192.168.137.110:7080", "192.168.137.111:7080", "192.168.137.112:7080" };
            Client   client      = new Client(controllers);

            Quorum   quorum  = client.GetQuorum("test");
            Database db      = client.GetDatabase("test");
            Table    test    = db.GetTable("test");
            Table    indices = db.GetTable("indices");
            Sequence IDs     = indices.GetSequence("IDs");

            //System.Console.WriteLine("Thread.CurrentThread.ManagedThreadId = {0}", Thread.CurrentThread.ManagedThreadId);

            System.Random random = new System.Random(Thread.CurrentThread.ManagedThreadId);

            var value = "";

            while (value.Length < 10 * 1000)
            {
                value += "" + random.Next();
            }

            //using (client.Transaction(quorum, "foo" + random.Next(100)))
            //{
            //    System.Console.WriteLine("Transaction started.");
            //    for (var j = 0; j < 10*1000; j++)
            //            table.Set("" + j, value);

            //    client.CommitTransaction();
            //    System.Console.WriteLine("Transaction finished.");
            //}
            //return;

            ulong ID;

            //for (var i = 0; i < 1000; i++)
            while (true)
            {
                if (random.Next(3) == 0)
                {
                    try
                    {
                        System.Console.WriteLine("Batch started.");
                        for (var j = 0; j < 10; j++)
                        {
                            if (random.Next(2) == 0)
                            {
                                test.Set("" + random.Next(1000 * 1000), value);
                            }
                            else
                            {
                                test.Delete("" + random.Next(1000 * 1000));
                            }
                        }
                        //for (var j = 0; j < 10 * 1000; j++)
                        //    ID = IDs.GetNext;
                        client.Submit();
                        System.Console.WriteLine("Batch finished.");
                    }
                    catch (SDBPException)
                    {
                        System.Console.WriteLine("Batch failed.");
                    }
                    continue;
                }

                //if (random.Next(2) == 0)
                //{
                //    try
                //    {
                //        System.Console.WriteLine("List started.");
                //        var count = 0;
                //        foreach (KeyValuePair<string, string> kv in test.GetKeyValueIterator(new StringRangeParams().Prefix("1")))
                //        {
                //            count++;
                //            //System.Console.WriteLine(kv.Key + " => " + kv.Value);
                //            if (count == 10)
                //                break;
                //        }
                //        System.Console.WriteLine("List finished.");
                //    }
                //    catch (SDBPException)
                //    {
                //        System.Console.WriteLine("List failed.");
                //        // why does this happen
                //    }
                //    continue;
                //}

                while (true)
                {
                    try
                    {
                        using (client.Transaction(quorum, "foo" + random.Next(100)))
                        {
                            System.Console.WriteLine("Transaction started.");
                            for (var j = 0; j < 10; j++)
                            {
                                if (random.Next(2) == 0)
                                {
                                    test.Set("" + random.Next(1000 * 1000), value);
                                }
                                else
                                {
                                    test.Delete("" + random.Next(1000 * 1000));
                                }
                            }
                            //for (var j = 0; j < 1000; j++)
                            //    ID = IDs.GetNext;
                            if (random.Next(2) == 0)
                            {
                                client.CommitTransaction();
                            }
                            else
                            {
                                client.RollbackTransaction();
                            }
                            System.Console.WriteLine("Transaction finished.");
                            break;
                        }
                    }
                    catch (SDBPException)
                    {
                        //System.Console.WriteLine("Exception.");
                        System.Threading.Thread.Sleep(1);
                    }
                }
            }
        }
Exemplo n.º 14
0
        public static void ThreadFunc()
        {
            //Client.SetTrace(true);
            //Client.SetLogFile("d:/out.txt");

            //string[] controllers = { "127.0.0.1:7080" };
            string[] controllers = { "192.168.137.110:7080", "192.168.137.111:7080", "192.168.137.112:7080" };
            Client client = new Client(controllers);

            Quorum quorum = client.GetQuorum("test");
            Database db = client.GetDatabase("test");
            Table test = db.GetTable("test");
            Table indices = db.GetTable("indices");
            Sequence IDs = indices.GetSequence("IDs");

            //System.Console.WriteLine("Thread.CurrentThread.ManagedThreadId = {0}", Thread.CurrentThread.ManagedThreadId);

            System.Random random = new System.Random(Thread.CurrentThread.ManagedThreadId);

            var value = "";
            while (value.Length < 10 * 1000)
                value += "" + random.Next();

            //using (client.Transaction(quorum, "foo" + random.Next(100)))
            //{
            //    System.Console.WriteLine("Transaction started.");
            //    for (var j = 0; j < 10*1000; j++)
            //            table.Set("" + j, value);

            //    client.CommitTransaction();
            //    System.Console.WriteLine("Transaction finished.");
            //}
            //return;

            ulong ID;

            //for (var i = 0; i < 1000; i++)
            while (true)
            {
                if (random.Next(3) == 0)
                {
                    try
                    {
                        System.Console.WriteLine("Batch started.");
                        for (var j = 0; j < 10; j++)
                        {
                            if (random.Next(2) == 0)
                                test.Set("" + random.Next(1000 * 1000), value);
                            else
                                test.Delete("" + random.Next(1000 * 1000));
                        }
                        //for (var j = 0; j < 10 * 1000; j++)
                        //    ID = IDs.GetNext;
                        client.Submit();
                        System.Console.WriteLine("Batch finished.");
                    }
                    catch (SDBPException)
                    {
                        System.Console.WriteLine("Batch failed.");
                    }
                    continue;
                }

                //if (random.Next(2) == 0)
                //{
                //    try
                //    {
                //        System.Console.WriteLine("List started.");
                //        var count = 0;
                //        foreach (KeyValuePair<string, string> kv in test.GetKeyValueIterator(new StringRangeParams().Prefix("1")))
                //        {
                //            count++;
                //            //System.Console.WriteLine(kv.Key + " => " + kv.Value);
                //            if (count == 10)
                //                break;
                //        }
                //        System.Console.WriteLine("List finished.");
                //    }
                //    catch (SDBPException)
                //    {
                //        System.Console.WriteLine("List failed.");
                //        // why does this happen
                //    }
                //    continue;
                //}

                while (true)
                {
                    try
                    {
                        using (client.Transaction(quorum, "foo" + random.Next(100)))
                        {
                            System.Console.WriteLine("Transaction started.");
                            for (var j = 0; j < 10; j++)
                            {
                                if (random.Next(2) == 0)
                                    test.Set("" + random.Next(1000 * 1000), value);
                                else
                                    test.Delete("" + random.Next(1000 * 1000));
                            }
                            //for (var j = 0; j < 1000; j++)
                            //    ID = IDs.GetNext;
                            if (random.Next(2) == 0)
                                client.CommitTransaction();
                            else
                                client.RollbackTransaction();
                            System.Console.WriteLine("Transaction finished.");
                            break;
                        }
                    }
                    catch (SDBPException)
                    {
                        //System.Console.WriteLine("Exception.");
                        System.Threading.Thread.Sleep(1);
                    }
                }
            }
        }
Exemplo n.º 15
0
        public void TestMaxConnections()
        {
            var dbName = "test";
            var tableName = "CreateClientPerRequest";

            // make sure the db and table exists
            Assert.IsNotNull(Utils.GetOrCreateTableAndDatabase(new Client(Utils.GetConfigNodes()), dbName, tableName));

            Client.SetMaxConnections(10);

            for (var i = 0; i < 11; i++)
            {
                Client client = new Client(Utils.GetConfigNodes());
                client.SetGlobalTimeout(15000);
                client.SetMasterTimeout(10000);
                Database db = client.GetDatabase(dbName);
                Table table = db.GetTable(tableName);
                try
                {
                    table.Set("" + i, "" + i);
                    client.Submit();
                }
                catch (SDBPException e)
                {
                    Assert.IsTrue(i == 10 && e.Status == Status.SDBP_FAILURE);
                }
            }
        }
Exemplo n.º 16
0
        public void TestNoPrimaryException()
        {
            try
            {
                // ensure that there is no master
                Client client = new Client(new string[] { "192.168.2.118:7080", "192.168.2.119:7080", "192.168.2.120:7080" });
                client.SetMasterTimeout(5 * 1000);
                client.SetGlobalTimeout(10 * 1000);
                Client.SetTrace(true);
                string configState = client.GetJSONConfigState();
                Database db = client.GetDatabase("test_db");
                Table table = db.GetTable("test_table");
                for (int i = 0; i < 100; i++)
                {
                    table.Set("a", "1");
                    client.Submit();
                    Thread.Sleep(500);
                }
            }
            catch (SDBPException e)
            {
                Assert.IsTrue(e.Status == Status.SDBP_FAILURE);
                return;
            }

            Assert.Fail();
        }