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); } } }
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(); }
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(); }
public void TestNoMasterException() { // This test is not working, because it always throws Status.SDBP_NOCONNECTION 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); string configState = client.GetJSONConfigState(); } catch (SDBPException e) { Assert.IsTrue(e.Status == Status.SDBP_NOMASTER); return; } Assert.Fail(); }
public void TestNoConnectionException() { try { // bad port Client client = new Client(new string[] { "127.0.0.1:1" }); client.SetMasterTimeout(5 * 1000); client.SetGlobalTimeout(10 * 1000); string configState = client.GetJSONConfigState(); } catch (SDBPException e) { Assert.IsTrue(e.Status == Status.SDBP_NOCONNECTION); return; } Assert.Fail(); }
public void TestConfigState() { Client client = new Client(Utils.GetConfigNodes()); client.SetGlobalTimeout(15000); string config_string = client.GetJSONConfigState(); System.Console.WriteLine(config_string); ConfigState conf = Utils.JsonDeserialize<ConfigState>(System.Text.Encoding.UTF8.GetBytes(config_string)); }