private void SetupDefaultCluster() { if (CCMCluster != null) { CCMCluster.Discard(); } CCMCluster = CCMBridge.CCMCluster.Create(2, Cluster.Builder()); session = CCMCluster.Session; cluster = CCMCluster.Cluster; session.CreateKeyspaceIfNotExists(ksname); session.ChangeKeyspace(ksname); }
public void DCAwareRoundRobinTestCCM() { var builder = Cluster.Builder().WithLoadBalancingPolicy(new DCAwareRoundRobinPolicy("dc2")); CCMBridge.CCMCluster c = CCMBridge.CCMCluster.Create(2, 2, builder); createMultiDCSchema(c.Session); try { init(c, 12); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "1", 0); assertQueried(Options.Default.IP_PREFIX + "2", 0); assertQueried(Options.Default.IP_PREFIX + "3", 6); assertQueried(Options.Default.IP_PREFIX + "4", 6); } catch (Exception e) { c.ErrorOut(); throw e; } finally { resetCoordinators(); c.Discard(); } }
public void Dispose() { if (CCMCluster != null) { CCMCluster.Discard(); } }
public void CreateKeyspaceWithPropertiesTest(string strategy_class) { CCMCluster = CCMBridge.CCMCluster.Create(2, Cluster.Builder()); try { Session = CCMCluster.Session; Cluster = CCMCluster.Cluster; Randomm rndm = new Randomm(DateTime.Now.Millisecond); bool durable_writes = rndm.NextBoolean(); int?replication_factor = null; int?data_centers_count = null; Dictionary <string, int> datacenters_replication_factors = null; if (strategy_class == ReplicationStrategies.SimpleStrategy) { replication_factor = rndm.Next(1, 21); Session.CreateKeyspaceIfNotExists(Keyspace, ReplicationStrategies.CreateSimpleStrategyReplicationProperty((int)replication_factor), durable_writes); Session.ChangeKeyspace(Keyspace); } else if (strategy_class == ReplicationStrategies.NetworkTopologyStrategy) { data_centers_count = rndm.Next(1, 11); datacenters_replication_factors = new Dictionary <string, int>((int)data_centers_count); for (int i = 0; i < data_centers_count; i++) { datacenters_replication_factors.Add("dc" + i.ToString(), rndm.Next(1, 21)); } Session.CreateKeyspaceIfNotExists(Keyspace, ReplicationStrategies.CreateNetworkTopologyStrategyReplicationProperty(datacenters_replication_factors), durable_writes); } KeyspaceMetadata ksmd = Cluster.Metadata.GetKeyspace(Keyspace); Assert.Equal(strategy_class, ksmd.StrategyClass); Assert.Equal(durable_writes, ksmd.DurableWrites); if (replication_factor != null) { Assert.Equal(replication_factor, ksmd.Replication["replication_factor"]); } if (datacenters_replication_factors != null) { Assert.True(datacenters_replication_factors.SequenceEqual(ksmd.Replication)); } } finally { CCMCluster.Discard(); } }
public void tokenAwareWithRF2TestCCM() { var builder = Cluster.Builder().WithLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())); CCMBridge.CCMCluster c = CCMBridge.CCMCluster.Create(2, builder); createSchema(c.Session, 2); try { init(c, 12); query(c, 12); // Not the best test ever, we should use OPP and check we do it the // right nodes. But since M3P is hard-coded for now, let just check // we just hit only one node. assertQueried(Options.Default.IP_PREFIX + "1", 0); assertQueried(Options.Default.IP_PREFIX + "2", 12); assertQueried(Options.Default.IP_PREFIX + "3", 0); resetCoordinators(); c.CCMBridge.BootstrapNode(3); TestUtils.waitFor(Options.Default.IP_PREFIX + "3", c.Cluster, 60); query(c, 12); // We should still be hitting only one node assertQueried(Options.Default.IP_PREFIX + "1", 0); assertQueried(Options.Default.IP_PREFIX + "2", 12); assertQueried(Options.Default.IP_PREFIX + "3", 0); resetCoordinators(); c.CCMBridge.Stop(2); TestUtils.waitForDown(Options.Default.IP_PREFIX + "2", c.Cluster, 60); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "1", 6); assertQueried(Options.Default.IP_PREFIX + "2", 0); assertQueried(Options.Default.IP_PREFIX + "3", 6); } catch (Exception e) { c.ErrorOut(); throw e; } finally { resetCoordinators(); c.Discard(); } }
public void checkMetadata(string TableName = null, string KeyspaceName = null, TableOptions tableOptions = null) { CCMCluster = CCMBridge.CCMCluster.Create(2, Cluster.Builder()); try { Session = CCMCluster.Session; Cluster = CCMCluster.Cluster; Session.CreateKeyspaceIfNotExists(Keyspace); Session.ChangeKeyspace(Keyspace); checkPureMetadata(TableName, KeyspaceName, tableOptions); } finally { CCMCluster.Discard(); } }
public void forceStopCCM() { var builder = Cluster.Builder().WithLoadBalancingPolicy(new RoundRobinPolicy()); builder.WithQueryTimeout(10000); CCMBridge.CCMCluster c = CCMBridge.CCMCluster.Create(4, builder); createSchema(c.Session); try { init(c, 12); query(c, 12); resetCoordinators(); c.CCMBridge.ForceStop(1); c.CCMBridge.ForceStop(2); TestUtils.waitForDown(Options.Default.IP_PREFIX + "1", c.Cluster, 40); TestUtils.waitForDown(Options.Default.IP_PREFIX + "2", c.Cluster, 40); query(c, 12); c.CCMBridge.ForceStop(3); c.CCMBridge.ForceStop(4); TestUtils.waitForDown(Options.Default.IP_PREFIX + "3", c.Cluster, 40); TestUtils.waitForDown(Options.Default.IP_PREFIX + "4", c.Cluster, 40); try { query(c, 12); Assert.Fail(); } catch (NoHostAvailableException e) { // No more nodes so ... } } catch (Exception e) { c.ErrorOut(); throw e; } finally { resetCoordinators(); c.Discard(); } }
public void roundRobinTestCCM() { var builder = Cluster.Builder().WithLoadBalancingPolicy(new RoundRobinPolicy()); CCMBridge.CCMCluster c = CCMBridge.CCMCluster.Create(2, builder); createSchema(c.Session); try { init(c, 12); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "1", 6); assertQueried(Options.Default.IP_PREFIX + "2", 6); resetCoordinators(); c.CCMBridge.BootstrapNode(3); TestUtils.waitFor(Options.Default.IP_PREFIX + "3", c.Cluster, 60); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "1", 4); assertQueried(Options.Default.IP_PREFIX + "2", 4); assertQueried(Options.Default.IP_PREFIX + "3", 4); resetCoordinators(); c.CCMBridge.DecommissionNode(1); TestUtils.waitForDecommission(Options.Default.IP_PREFIX + "1", c.Cluster, 60); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "2", 6); assertQueried(Options.Default.IP_PREFIX + "3", 6); } catch (Exception e) { c.ErrorOut(); throw e; } finally { resetCoordinators(); c.Discard(); } }
public void checkKSMetadata() { CCMCluster = CCMBridge.CCMCluster.Create(2, Cluster.Builder()); try { Session = CCMCluster.Session; Cluster = CCMCluster.Cluster; Session.CreateKeyspaceIfNotExists(Keyspace); Session.ChangeKeyspace(Keyspace); string keyspacename = "keyspace" + Guid.NewGuid().ToString("N").ToLower(); bool durableWrites = false; string strgyClass = "SimpleStrategy"; short rplctnFactor = 1; Session.WaitForSchemaAgreement( Session.Execute( string.Format(@"CREATE KEYSPACE {0} WITH replication = {{ 'class' : '{1}', 'replication_factor' : {2} }} AND durable_writes={3};" , keyspacename, strgyClass, rplctnFactor.ToString(), durableWrites.ToString())) ); Session.ChangeKeyspace(keyspacename); for (int i = 0; i < 10; i++) { checkPureMetadata("table" + Guid.NewGuid().ToString("N"), keyspacename); } KeyspaceMetadata ksmd = Cluster.Metadata.GetKeyspace(keyspacename); Assert.True(ksmd.DurableWrites == durableWrites); Assert.True(ksmd.Replication.Where(opt => opt.Key == "replication_factor").First().Value == rplctnFactor); Assert.True(ksmd.StrategyClass == strgyClass); } finally { CCMCluster.Discard(); } }
public void mixedDurationTestCCM() { if (CCMCluster != null) CCMCluster.Discard(); CCMCluster = CCMBridge.CCMCluster.Create(3, Cluster.Builder()); cluster = CCMCluster.Cluster; session = CCMCluster.Session; session.CreateKeyspace("large_data", ReplicationStrategies.CreateSimpleStrategyReplicationProperty(3)); session.ChangeKeyspace("large_data"); session.WaitForSchemaAgreement( session.Execute(String.Format("CREATE TABLE {0} (k INT, i INT, PRIMARY KEY(k, i))", "wide_rows"))); session.WaitForSchemaAgreement( session.Execute(String.Format("CREATE TABLE {0} (k INT, i INT, PRIMARY KEY(k, i))", "wide_batch_rows"))); session.WaitForSchemaAgreement( session.Execute(String.Format("CREATE TABLE {0} (k INT, i BLOB, PRIMARY KEY(k, i))", "wide_byte_rows"))); session.WaitForSchemaAgreement( session.Execute(String.Format("CREATE TABLE {0} (k int PRIMARY KEY, i text)", "large_text"))); // Create the extra wide table definition StringBuilder tableDeclaration = new StringBuilder(); tableDeclaration.Append("CREATE TABLE wide_table ("); tableDeclaration.Append("k INT PRIMARY KEY"); for (int i = 0; i < 330; ++i) { tableDeclaration.Append(String.Format(", {0} INT", createColumnName(i))); } tableDeclaration.Append(")"); session.WaitForSchemaAgreement( session.Execute(tableDeclaration.ToString()) ); Random rndm = new Random(DateTime.Now.Millisecond); try { for (int i = 0; i < 10; ++i) { switch ((int)rndm.Next(0,5)) { case 0: testWideRows(); break; case 1: testWideBatchRows(); break; case 2: testByteRows(); break; case 3: testLargeText(); break; case 4: testWideTable(); break; default: break; } } } catch (Exception e) { CCMCluster.ErrorOut(); throw e; } finally { CCMCluster.Discard(); } }
public void parallelInsertTestGeneric(int nThreads, int cpCon) { CCMBridge.ReusableCCMCluster.Setup(3, 0, true); string datacenter = "datacenter1"; long constDelayMS = 500; int queryTimeout = Timeout.Infinite; int coreConnectionPerHost = 2; int maxConnectionPerHost = 8; CCMBridge.CCMCluster ccmCluster = CCMBridge.CCMCluster.Create(3, initialize(datacenter, constDelayMS, queryTimeout, coreConnectionPerHost, maxConnectionPerHost, cpCon)); CCMBridge.ReusableCCMCluster.Build(initialize(datacenter, constDelayMS, queryTimeout, coreConnectionPerHost, maxConnectionPerHost, cpCon)); Session = ccmCluster.Session; Console.WriteLine("Start parallel insert test (" + nThreads + " , " + cpCon + ")"); string keyspaceName = "testkeyspace1" + nThreads + "x" + cpCon; // Console.WriteLine("Creating keyspace"); try { Session.WaitForSchemaAgreement( Session.Execute( string.Format(@"CREATE KEYSPACE {0} WITH replication = {{ 'class' : 'SimpleStrategy', 'replication_factor' : 1 }};" , keyspaceName))); } catch (AlreadyExistsException) { } Session.ChangeKeyspace(keyspaceName); string tableName = "testtable"; try { Session.WaitForSchemaAgreement( Session.Execute(string.Format(@"CREATE TABLE {0}( tweet_id int, author text, body text, isok boolean, PRIMARY KEY(tweet_id))", tableName))); } catch (AlreadyExistsException) { } // Console.WriteLine("Prepare statement"); PreparedStatement insertPrep = Session.Prepare("INSERT INTO " + tableName + @" ( tweet_id, author, isok, body) VALUES (?,?,?,?);"); // Console.WriteLine("Insert Values"); int RowsNo = 100000; int stepSize = RowsNo / nThreads; Thread[] tasks = new Thread[nThreads]; object monit = new object(); int readyCnt = 0; for (int i = 0; i < nThreads; i++) { var startIndex = i * stepSize; var endIndex = (i + 1) * stepSize; tasks[i] = new Thread(() => { lock (monit) { readyCnt++; Monitor.Wait(monit); } insertRange(insertPrep, startIndex, endIndex); }); tasks[i].Start(); } Stopwatch t = Stopwatch.StartNew(); lock (monit) { while (true) { if (readyCnt < nThreads) { Monitor.Exit(monit); Thread.Sleep(100); Monitor.Enter(monit); } else { t.Restart(); Monitor.PulseAll(monit); break; } } } foreach (var task in tasks) { task.Join(); } Console.WriteLine("Avg query response time " + ((double)totalElapsedTime) / (double)RowsNo + "ms"); Console.WriteLine("Avg single insert time " + ((double)t.ElapsedMilliseconds) / (double)RowsNo + "ms"); RETRY: try { using (var res = Session.Execute(string.Format(@"SELECT COUNT(*) FROM {0} LIMIT {1}", tableName, RowsNo + 100), ConsistencyLevel.Quorum)) { var cnt = res.GetRows().FirstOrDefault().GetValue <long>(0); Assert.Equal(RowsNo, cnt); } } catch (Exception) { goto RETRY; } Session.Execute(string.Format(@"DROP TABLE {0};", tableName)); Session.Execute(string.Format(@"DROP KEYSPACE {0};", keyspaceName)); CCMBridge.ReusableCCMCluster.Drop(); ccmCluster.Discard(); }
public void testRFThreeDowngradingCLTwoDCsDCAware() { var builder = Cluster.Builder().WithLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy("dc2"))).WithRetryPolicy(DowngradingConsistencyRetryPolicy.Instance); CCMBridge.CCMCluster c = CCMBridge.CCMCluster.Create(3, 3, builder); createMultiDCSchema(c.Session, 3, 3); try { init(c, 12, ConsistencyLevel.Two); query(c, 12, ConsistencyLevel.Two); assertQueried(Options.Default.IP_PREFIX + "1", 0); assertQueried(Options.Default.IP_PREFIX + "2", 0); assertQueried(Options.Default.IP_PREFIX + "3", 0); // BUG: JAVA-88 //assertQueried(Options.Default.IP_PREFIX + "4", 12); //assertQueried(Options.Default.IP_PREFIX + "5", 0); //assertQueried(Options.Default.IP_PREFIX + "6", 0); resetCoordinators(); c.CCMBridge.ForceStop(2); // FIXME: This sleep is needed to allow the waitFor() to work Thread.Sleep(20000); TestUtils.waitForDownWithWait(Options.Default.IP_PREFIX + "2", c.Cluster, 5); List <ConsistencyLevel> acceptedList = new List <ConsistencyLevel>() { ConsistencyLevel.Any, ConsistencyLevel.One, ConsistencyLevel.Two, ConsistencyLevel.Quorum, ConsistencyLevel.Three, ConsistencyLevel.All, ConsistencyLevel.LocalQuorum, ConsistencyLevel.EachQuorum }; List <ConsistencyLevel> failList = new List <ConsistencyLevel>(); // Test successful writes foreach (var cl in acceptedList) { try { init(c, 12, cl); } catch (Exception e) { Assert.Fail(String.Format("Test failed at CL.{0} with message: {1}", cl, e.Message)); } } // Test successful reads foreach (var cl in acceptedList) { try { query(c, 12, cl); } catch (InvalidQueryException e) { List <String> acceptableErrorMessages = new List <string>() { "EACH_QUORUM ConsistencyLevel is only supported for writes", "ANY ConsistencyLevel is only supported for writes" }; Assert.True(acceptableErrorMessages.Contains(e.Message), String.Format("Received: {0}", e.Message)); } } // Test writes which should fail foreach (var cl in failList) { try { init(c, 12, cl); Assert.Fail(String.Format("Test passed at CL.{0}.", cl)); } catch (UnavailableException e) { // expected to fail when the client has already marked the // node as DOWN } catch (WriteTimeoutException e) { // expected to fail when the client hasn't marked the' // node as DOWN yet } } // Test reads which should fail foreach (var cl in failList) { try { query(c, 12, cl); Assert.Fail(String.Format("Test passed at CL.{0}.", cl)); } catch (ReadTimeoutException e) { // expected to fail when the client hasn't marked the' // node as DOWN yet } catch (UnavailableException e) { // expected to fail when the client has already marked the // node as DOWN } } } catch (Exception e) { c.ErrorOut(); throw e; } finally { resetCoordinators(); c.Discard(); } }
public void testRFThreeDowngradingCL(Builder builder) { CCMBridge.CCMCluster c = CCMBridge.CCMCluster.Create(3, builder); createSchema(c.Session, 3); try { init(c, 12, ConsistencyLevel.All); query(c, 12, ConsistencyLevel.All); resetCoordinators(); c.CCMBridge.ForceStop(2); TestUtils.waitForDownWithWait(Options.Default.IP_PREFIX + "2", c.Cluster, 5); List <ConsistencyLevel> acceptedList = new List <ConsistencyLevel>() { ConsistencyLevel.Any, ConsistencyLevel.One, ConsistencyLevel.Two, ConsistencyLevel.Quorum, ConsistencyLevel.Three, ConsistencyLevel.All }; List <ConsistencyLevel> failList = new List <ConsistencyLevel>() { }; // Test successful writes foreach (var cl in acceptedList) { try { init(c, 12, cl); } catch (Exception e) { Assert.Fail(String.Format("Test failed at CL.{0} with message: {1}", cl, e.Message)); } } // Test successful reads foreach (var cl in acceptedList) { try { query(c, 12, cl); } catch (InvalidQueryException e) { List <String> acceptableErrorMessages = new List <string>() { "ANY ConsistencyLevel is only supported for writes" }; Assert.True(acceptableErrorMessages.Contains(e.Message)); } } // Test writes which should fail foreach (var cl in failList) { try { init(c, 12, cl); Assert.Fail(String.Format("Test passed at CL.{0}.", cl)); } catch (InvalidQueryException e) { List <String> acceptableErrorMessages = new List <string>() { "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", "consistency level EACH_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)" }; Assert.True(acceptableErrorMessages.Contains(e.Message), String.Format("Received: {0}", e.Message)); } catch (UnavailableException e) { // expected to fail when the client has already marked the // node as DOWN } catch (WriteTimeoutException e) { // expected to fail when the client hasn't marked the' // node as DOWN yet } } // Test reads which should fail foreach (var cl in failList) { try { query(c, 12, cl); Assert.Fail(String.Format("Test passed at CL.{0}.", cl)); } catch (InvalidQueryException e) { List <String> acceptableErrorMessages = new List <string>() { "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", "EACH_QUORUM ConsistencyLevel is only supported for writes" }; Assert.True(acceptableErrorMessages.Contains(e.Message), String.Format("Received: {0}", e.Message)); } catch (ReadTimeoutException e) { // expected to fail when the client hasn't marked the' // node as DOWN yet } catch (UnavailableException e) { // expected to fail when the client has already marked the // node as DOWN } } } catch (Exception e) { c.ErrorOut(); throw e; } finally { resetCoordinators(); c.Discard(); } }
public void testRFTwoDowngradingCL() { var builder = Cluster.Builder().WithLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())).WithRetryPolicy(DowngradingConsistencyRetryPolicy.Instance); CCMBridge.CCMCluster c = CCMBridge.CCMCluster.Create(3, builder); createSchema(c.Session, 2); try { init(c, 12, ConsistencyLevel.Two); query(c, 12, ConsistencyLevel.Two); var assC = coordinators.First().Key.ToString(); var awareCoord = int.Parse(assC.Substring(assC.Length - 1)); assertQueried(Options.Default.IP_PREFIX + awareCoord.ToString(), 12); resetCoordinators(); c.CCMBridge.ForceStop(awareCoord); TestUtils.waitForDownWithWait(Options.Default.IP_PREFIX + awareCoord.ToString(), c.Cluster, 30); List <ConsistencyLevel> acceptedList = new List <ConsistencyLevel>() { ConsistencyLevel.Any, ConsistencyLevel.One, ConsistencyLevel.Two, ConsistencyLevel.Quorum, ConsistencyLevel.Three, ConsistencyLevel.All }; List <ConsistencyLevel> failList = new List <ConsistencyLevel>() { }; // Test successful writes foreach (var cl in acceptedList) { try { init(c, 12, cl); } catch (Exception e) { Assert.Fail(String.Format("Test failed at CL.{0} with message: {1}", cl, e.Message)); } } // Test successful reads foreach (var cl in acceptedList) { try { query(c, 12, cl); } catch (InvalidQueryException e) { List <String> acceptableErrorMessages = new List <string>() { "ANY ConsistencyLevel is only supported for writes" }; Assert.True(acceptableErrorMessages.Contains(e.Message)); } } // Test writes which should fail foreach (var cl in failList) { try { init(c, 12, cl); Assert.Fail(String.Format("Test passed at CL.{0}.", cl)); } catch (InvalidQueryException e) { List <String> acceptableErrorMessages = new List <string>() { "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", "consistency level EACH_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)" }; Assert.True(acceptableErrorMessages.Contains(e.Message), String.Format("Received: {0}", e.Message)); } catch (UnavailableException e) { // expected to fail when the client has already marked the // node as DOWN } catch (WriteTimeoutException e) { // expected to fail when the client hasn't marked the' // node as DOWN yet } } // Test reads which should fail foreach (var cl in failList) { try { query(c, 12, cl); Assert.Fail(String.Format("Test passed at CL.{0}.", cl)); } catch (InvalidQueryException e) { List <String> acceptableErrorMessages = new List <string>() { "consistency level LOCAL_QUORUM not compatible with replication strategy (org.apache.cassandra.locator.SimpleStrategy)", "EACH_QUORUM ConsistencyLevel is only supported for writes" }; Assert.True(acceptableErrorMessages.Contains(e.Message), String.Format("Received: {0}", e.Message)); } catch (ReadTimeoutException e) { // expected to fail when the client hasn't marked the' // node as DOWN yet } catch (UnavailableException e) { // expected to fail when the client has already marked the // node as DOWN } } } catch (Exception e) { c.ErrorOut(); throw e; } finally { resetCoordinators(); c.Discard(); } }
public void dcAwareRoundRobinTestWithOneRemoteHostCCM() { var builder = Cluster.Builder().WithLoadBalancingPolicy(new DCAwareRoundRobinPolicy("dc2", 1)); CCMBridge.CCMCluster c = CCMBridge.CCMCluster.Create(2, 2, builder); createMultiDCSchema(c.Session); try { init(c, 12); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "1", 0); assertQueried(Options.Default.IP_PREFIX + "2", 0); assertQueried(Options.Default.IP_PREFIX + "3", 6); assertQueried(Options.Default.IP_PREFIX + "4", 6); assertQueried(Options.Default.IP_PREFIX + "5", 0); resetCoordinators(); c.CCMBridge.BootstrapNode(5, "dc3"); TestUtils.waitFor(Options.Default.IP_PREFIX + "5", c.Cluster, 60); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "1", 0); assertQueried(Options.Default.IP_PREFIX + "2", 0); assertQueried(Options.Default.IP_PREFIX + "3", 6); assertQueried(Options.Default.IP_PREFIX + "4", 6); assertQueried(Options.Default.IP_PREFIX + "5", 0); resetCoordinators(); c.CCMBridge.DecommissionNode(3); c.CCMBridge.DecommissionNode(4); TestUtils.waitForDecommission(Options.Default.IP_PREFIX + "3", c.Cluster, 20); TestUtils.waitForDecommission(Options.Default.IP_PREFIX + "4", c.Cluster, 20); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "1", 0); assertQueried(Options.Default.IP_PREFIX + "2", 0); assertQueried(Options.Default.IP_PREFIX + "3", 0); assertQueried(Options.Default.IP_PREFIX + "4", 0); assertQueried(Options.Default.IP_PREFIX + "5", 12); resetCoordinators(); c.CCMBridge.DecommissionNode(5); TestUtils.waitForDecommission(Options.Default.IP_PREFIX + "5", c.Cluster, 20); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "1", 0); assertQueried(Options.Default.IP_PREFIX + "2", 12); assertQueried(Options.Default.IP_PREFIX + "3", 0); assertQueried(Options.Default.IP_PREFIX + "4", 0); assertQueried(Options.Default.IP_PREFIX + "5", 0); resetCoordinators(); c.CCMBridge.DecommissionNode(2); TestUtils.waitForDecommission(Options.Default.IP_PREFIX + "2", c.Cluster, 20); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "1", 12); assertQueried(Options.Default.IP_PREFIX + "2", 0); assertQueried(Options.Default.IP_PREFIX + "3", 0); assertQueried(Options.Default.IP_PREFIX + "4", 0); assertQueried(Options.Default.IP_PREFIX + "5", 0); resetCoordinators(); c.CCMBridge.ForceStop(1); TestUtils.waitForDown(Options.Default.IP_PREFIX + "2", c.Cluster, 20); try { query(c, 12); Assert.Fail(); } catch (NoHostAvailableException e) { // No more nodes so ... } } catch (Exception e) { c.ErrorOut(); throw e; } finally { resetCoordinators(); c.Discard(); } }
public void mixedDurationTestCCM() { if (CCMCluster != null) { CCMCluster.Discard(); } CCMCluster = CCMBridge.CCMCluster.Create(3, Cluster.Builder()); cluster = CCMCluster.Cluster; session = CCMCluster.Session; session.CreateKeyspace("large_data", ReplicationStrategies.CreateSimpleStrategyReplicationProperty(3)); session.ChangeKeyspace("large_data"); session.WaitForSchemaAgreement( session.Execute(String.Format("CREATE TABLE {0} (k INT, i INT, PRIMARY KEY(k, i))", "wide_rows"))); session.WaitForSchemaAgreement( session.Execute(String.Format("CREATE TABLE {0} (k INT, i INT, PRIMARY KEY(k, i))", "wide_batch_rows"))); session.WaitForSchemaAgreement( session.Execute(String.Format("CREATE TABLE {0} (k INT, i BLOB, PRIMARY KEY(k, i))", "wide_byte_rows"))); session.WaitForSchemaAgreement( session.Execute(String.Format("CREATE TABLE {0} (k int PRIMARY KEY, i text)", "large_text"))); // Create the extra wide table definition StringBuilder tableDeclaration = new StringBuilder(); tableDeclaration.Append("CREATE TABLE wide_table ("); tableDeclaration.Append("k INT PRIMARY KEY"); for (int i = 0; i < 330; ++i) { tableDeclaration.Append(String.Format(", \"{0}\" INT", createColumnName(i))); } tableDeclaration.Append(")"); session.WaitForSchemaAgreement( session.Execute(tableDeclaration.ToString()) ); Random rndm = new Random(DateTime.Now.Millisecond); try { for (int i = 0; i < 10; ++i) { switch ((int)rndm.Next(0, 5)) { case 0: testWideRows(); break; case 1: testWideBatchRows(); break; case 2: testByteRows(); break; case 3: testLargeText(); break; case 4: testWideTable(); break; default: break; } } } catch (Exception e) { CCMCluster.ErrorOut(); throw e; } finally { CCMCluster.Discard(); } }
public void dcAwareRoundRobinTestWithOneRemoteHostCCM() { var builder = Cluster.Builder().WithLoadBalancingPolicy(new DCAwareRoundRobinPolicy("dc2", 1)); CCMBridge.CCMCluster c = CCMBridge.CCMCluster.Create(2, 1, builder); createMultiDCSchema(c.Session); try { init(c, 12); query(c, 12); assertQueried(CCMBridge.IP_PREFIX + "1", 0); assertQueried(CCMBridge.IP_PREFIX + "2", 0); assertQueried(CCMBridge.IP_PREFIX + "3", 12); assertQueried(CCMBridge.IP_PREFIX + "4", 0); resetCoordinators(); c.CassandraCluster.BootstrapNode(4, "dc3"); c.Session.Execute("ALTER KEYSPACE " + TestUtils.SIMPLE_KEYSPACE + " WITH REPLICATION ={'class' : 'NetworkTopologyStrategy','dc1' : 1, 'dc2' : 1, 'dc3' : 1}"); TestUtils.waitFor(CCMBridge.IP_PREFIX + "4", c.Cluster, 60); query(c, 12); assertQueried(CCMBridge.IP_PREFIX + "1", 0); assertQueried(CCMBridge.IP_PREFIX + "2", 0); assertQueried(CCMBridge.IP_PREFIX + "3", 12); assertQueried(CCMBridge.IP_PREFIX + "4", 0); resetCoordinators(); c.CassandraCluster.DecommissionNode(3); TestUtils.waitForDecommission(CCMBridge.IP_PREFIX + "3", c.Cluster, 20); query(c, 12); assertQueried(CCMBridge.IP_PREFIX + "1", 6); assertQueried(CCMBridge.IP_PREFIX + "2", 0); assertQueried(CCMBridge.IP_PREFIX + "3", 0); assertQueried(CCMBridge.IP_PREFIX + "4", 6); resetCoordinators(); c.CassandraCluster.DecommissionNode(4); TestUtils.waitForDecommission(CCMBridge.IP_PREFIX + "4", c.Cluster, 20); query(c, 12); assertQueried(CCMBridge.IP_PREFIX + "1", 12); assertQueried(CCMBridge.IP_PREFIX + "2", 0); assertQueried(CCMBridge.IP_PREFIX + "3", 0); assertQueried(CCMBridge.IP_PREFIX + "4", 0); resetCoordinators(); c.CassandraCluster.DecommissionNode(1); TestUtils.waitForDecommission(CCMBridge.IP_PREFIX + "1", c.Cluster, 20); query(c, 12); assertQueried(CCMBridge.IP_PREFIX + "1", 0); assertQueried(CCMBridge.IP_PREFIX + "2", 12); assertQueried(CCMBridge.IP_PREFIX + "3", 0); assertQueried(CCMBridge.IP_PREFIX + "4", 0); resetCoordinators(); c.CassandraCluster.ForceStop(2); TestUtils.waitForDown(CCMBridge.IP_PREFIX + "2", c.Cluster, 20); try { query(c, 12); Assert.Fail(); } catch (NoHostAvailableException e) { // No more nodes so ... } } catch (Exception e) { c.ErrorOut(); throw e; } finally { resetCoordinators(); c.Discard(); } }
public void tokenAwareTest(bool usePrepared) { var builder = Cluster.Builder().WithLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy())); CCMBridge.CCMCluster c = CCMBridge.CCMCluster.Create(2, builder); createSchema(c.Session); try { //c.Cluster.RefreshSchema(); init(c, 12); query(c, 12); // Not the best test ever, we should use OPP and check we do it the // right nodes. But since M3P is hard-coded for now, let just check // we just hit only one node. assertQueried(Options.Default.IP_PREFIX + "1", 0); assertQueried(Options.Default.IP_PREFIX + "2", 12); resetCoordinators(); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "1", 0); assertQueried(Options.Default.IP_PREFIX + "2", 12); resetCoordinators(); c.CCMBridge.ForceStop(2); TestUtils.waitForDown(Options.Default.IP_PREFIX + "2", c.Cluster, 60); try { query(c, 12, usePrepared); Assert.Fail(); } catch (UnavailableException e) { } catch (ReadTimeoutException e) { } resetCoordinators(); c.CCMBridge.Start(2); TestUtils.waitFor(Options.Default.IP_PREFIX + "2", c.Cluster, 60); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "1", 0); assertQueried(Options.Default.IP_PREFIX + "2", 12); resetCoordinators(); c.CCMBridge.DecommissionNode(2); TestUtils.waitForDecommission(Options.Default.IP_PREFIX + "2", c.Cluster, 60); query(c, 12); assertQueried(Options.Default.IP_PREFIX + "1", 12); assertQueried(Options.Default.IP_PREFIX + "2", 0); } catch (Exception e) { c.ErrorOut(); throw e; } finally { resetCoordinators(); c.Discard(); } }
public void dcAwareRoundRobinTestWithOneRemoteHostCCM() { var builder = Cluster.Builder().WithLoadBalancingPolicy(new DCAwareRoundRobinPolicy("dc2", 1)); CCMBridge.CCMCluster c = CCMBridge.CCMCluster.Create(2, 2, builder); createMultiDCSchema(c.Session); try { init(c, 12); query(c, 12); var hosts = new string[] { "unused", Options.Default.IP_PREFIX + "1", Options.Default.IP_PREFIX + "2", Options.Default.IP_PREFIX + "3", Options.Default.IP_PREFIX + "4", Options.Default.IP_PREFIX + "5" }; var hostsDc1 = new string[] { hosts[1], hosts[2] }; var hostsDc2 = new string[] { hosts[3], hosts[4] }; // verify queries went to local DC; therein distributed equally assertQueriedSet(hostsDc1, 0); assertQueried(hosts[3], 6); assertQueried(hosts[4], 6); assertQueried(hosts[5], 0); resetCoordinators(); c.CCMBridge.BootstrapNode(5, "dc3"); TestUtils.waitFor(hosts[5], c.Cluster, 60); query(c, 12); // verify queries went to local DC; therein distributed equally assertQueriedSet(hostsDc1, 0); assertQueried(hosts[3], 6); assertQueried(hosts[4], 6); assertQueried(hosts[5], 0); resetCoordinators(); c.CCMBridge.DecommissionNode(3); c.CCMBridge.DecommissionNode(4); TestUtils.waitForDecommission(hosts[3], c.Cluster, 20); TestUtils.waitForDecommission(hosts[4], c.Cluster, 20); query(c, 12); // verify queries distributed equally across remote DCs assertQueriedSet(hostsDc1, 6); assertQueriedSet(hostsDc2, 0); assertQueried(hosts[5], 6); resetCoordinators(); c.CCMBridge.DecommissionNode(5); TestUtils.waitForDecommission(hosts[5], c.Cluster, 20); query(c, 12); // verify queries went to the only live DC assertQueriedSet(hostsDc1, 12); assertQueriedSet(hostsDc2, 0); assertQueried(hosts[5], 0); resetCoordinators(); c.CCMBridge.DecommissionNode(2); TestUtils.waitForDecommission(hosts[2], c.Cluster, 20); query(c, 12); // verify queries went to the only live node assertQueried(hosts[1], 12); assertQueried(hosts[2], 0); assertQueriedSet(hostsDc2, 0); assertQueried(hosts[5], 0); resetCoordinators(); c.CCMBridge.ForceStop(1); TestUtils.waitForDown(hosts[2], c.Cluster, 20); // verify no host exception with all nodes down try { query(c, 12); Assert.Fail(); } catch (NoHostAvailableException e) { // No more nodes so ... } } catch (Exception e) { c.ErrorOut(); throw e; } finally { resetCoordinators(); c.Discard(); } }