public void CreateClientPerRequest() { var dbName = "test"; var tableName = "CreateClientPerRequest"; // make sure the db and table exists Assert.IsNotNull(Utils.GetOrCreateTableAndDatabase(new Client(Config.GetNodes()), dbName, tableName)); // without connection pooling Client.SetConnectionPoolSize(0); for (var i = 0; i < 100 * 1000; i++) { Client client = new Client(Config.GetNodes()); Database db = client.GetDatabase(dbName); Table table = db.GetTable(tableName); table.Set("" + i, "" + i); } // with connection pooling Client.SetConnectionPoolSize(100); for (var i = 0; i < 100 * 1000; i++) { Client client = new Client(Config.GetNodes()); Database db = client.GetDatabase(dbName); Table table = db.GetTable(tableName); table.Set("" + i, "" + i); } }
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); } } }
// test entry point public static void Main(string[] args) { //Client.SetTrace(true); string[] controllers = { "192.168.1.234:7080" }; Client client = new Client(controllers); Database db = client.GetDatabase("test"); Table table = db.GetTable("test"); table.Set("foo", "foo"); System.Console.WriteLine(table.Get("foo")); if (table.Get("bar") == null) System.Console.WriteLine("null"); }
public static bool TryDeleteDatabase(Client client, string databaseName) { try { var database = client.GetDatabase(databaseName); try { database.DeleteDatabase(); return true; } catch (SDBPException) { return false; } } catch (SDBPException) { return true; } }
public void TestListTable() { var dbName = "Benchmark"; var tableName = "fileContentLockStartDateIndex"; Client client = new Client(Utils.GetConfigNodes()); Database db = client.GetDatabase(dbName); Table tbl = db.GetTable(tableName); var counter = 0; foreach (var kv in tbl.GetKeyValueIterator(new ByteRangeParams())) { counter++; } client.Close(); }
public void ListTestLinq() { Client client = new Client(Utils.GetConfigNodes()); Table table = client.GetDatabase("Benchmark").GetTable("transactionNetworkTransaction"); byte[] prefix = Utils.StringToByteArray("N:0000000000000|T:000000"); byte[] startKey = Utils.StringToByteArray("N:0000000000000|T:0000001250847|"); var rangeParams = new ByteRangeParams().StartKey(startKey).Prefix(prefix); ByteKeyValueIterator iterator = table.GetKeyValueIterator(rangeParams); var list = new List<KeyValuePair<byte[], byte[]>>(); list.AddRange(iterator.Select(kv => kv)); }
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); } } } }
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); } } } }
private void MultiThreadedClientThreadFunc() { var dbName = "test"; var tableName = "MultiThreadedClient"; Random rnd = new Random(); Client client = null; Database db = null; Table table = null; Utils.GetOrCreateTableAndDatabase(new Client(Utils.GetConfigNodes()), dbName, tableName); while (isMultiThreadedClientRunning) { string key = "" + rnd.Next(10000); //Thread.Sleep(10); try { switch (rnd.Next(4)) { case 0: client = new Client(Utils.GetConfigNodes()); client.SetGlobalTimeout(15 * 1000); db = client.GetDatabase(dbName); table = db.GetTable(tableName); break; case 1: client = null; Thread.Sleep(100); break; case 2: if (client != null) { string value = table.Get(key); if (value != null) { try { long.Parse(value); } catch (FormatException e) { Console.WriteLine(e.Message); } } } break; case 3: if (client != null) { table.Add(key, 1); } break; } } catch (SDBPException e) { Console.WriteLine(e.Message); Assert.Fail(e.Message); } } }
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(); }