Ejemplo n.º 1
0
        public void readTimeoutExceptionCCM()
        {
            var builder = Cluster.Builder();

            CCMBridge.CCMCluster cluster = CCMBridge.CCMCluster.Create(3, builder);
            try
            {
                Session   session = cluster.Session;
                CCMBridge bridge  = cluster.CCMBridge;

                String keyspace          = "TestKeyspace";
                String table             = "TestTable";
                int    replicationFactor = 3;
                String key = "1";

                session.Cluster.WaitForSchemaAgreement(
                    session.Execute(String.Format(TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, replicationFactor)));
                session.Execute("USE " + keyspace);
                session.Cluster.WaitForSchemaAgreement(
                    session.Execute(String.Format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, table)));

                session.Execute(new SimpleStatement(String.Format(TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).SetConsistencyLevel(ConsistencyLevel.All));
                session.Execute(new SimpleStatement(String.Format(TestUtils.SELECT_ALL_FORMAT, table)).SetConsistencyLevel(ConsistencyLevel.All)).Dispose();

                bridge.ForceStop(2);
                try
                {
                    session.Execute(new SimpleStatement(String.Format(TestUtils.SELECT_ALL_FORMAT, table)).SetConsistencyLevel(ConsistencyLevel.All)).Dispose();
                }
                catch (ReadTimeoutException e)
                {
                    Assert.Equal(e.ConsistencyLevel, ConsistencyLevel.All);
                    Assert.Equal(e.ReceivedAcknowledgements, 2);
                    Assert.Equal(e.RequiredAcknowledgements, 3);
                    Assert.Equal(e.WasDataRetrieved, true);

                    //ReadTimeoutException copy = (ReadTimeoutException)e.copy();
                    //Assert.Equal(copy.Message, e.Message);
                    //Assert.Equal(copy.WasDataRetrieved, e.WasDataRetrieved);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                cluster.Discard();
            }
        }
Ejemplo n.º 2
0
        public void rowsetIteratedTwice()
        {
            var builder = Cluster.Builder();

            CCMBridge.CCMCluster cluster = CCMBridge.CCMCluster.Create(1, builder);
            try
            {
                Session   session = cluster.Session;
                CCMBridge bridge  = cluster.CCMBridge;

                String keyspace = "TestKeyspace";
                String table    = "TestTable";
                String key      = "1";

                session.Cluster.WaitForSchemaAgreement(
                    session.Execute(String.Format(TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, 1))
                    );
                session.Execute("USE " + keyspace);
                session.Cluster.WaitForSchemaAgreement(
                    session.Execute(String.Format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, table))
                    );

                session.Execute(new SimpleStatement(String.Format(TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)));
                var rowset = session.Execute(new SimpleStatement(String.Format(TestUtils.SELECT_ALL_FORMAT, table))).GetRows();
                var cnt    = rowset.Count();
                try
                {
                    foreach (var r in rowset)
                    {
                        Console.Write(r.GetValue <string>("k"));
                    }
                    Assert.Fail();
                }
                catch (InvalidOperationException)
                {
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                cluster.Discard();
            }
        }
Ejemplo n.º 3
0
        public void unavailableExceptionCCM()
        {
            var builder = Cluster.Builder();

            CCMBridge.CCMCluster cluster = CCMBridge.CCMCluster.Create(3, builder);
            try
            {
                Session   session = cluster.Session;
                CCMBridge bridge  = cluster.CCMBridge;

                String keyspace          = "TestKeyspace";
                String table             = "TestTable";
                int    replicationFactor = 3;
                String key = "1";

                session.Cluster.WaitForSchemaAgreement(
                    session.Execute(String.Format(TestUtils.CREATE_KEYSPACE_SIMPLE_FORMAT, keyspace, replicationFactor))
                    );
                session.Execute("USE " + keyspace);
                session.Cluster.WaitForSchemaAgreement(
                    session.Execute(String.Format(TestUtils.CREATE_TABLE_SIMPLE_FORMAT, table))
                    );

                session.Execute(new SimpleStatement(String.Format(TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).SetConsistencyLevel(ConsistencyLevel.All));
                session.Execute(new SimpleStatement(String.Format(TestUtils.SELECT_ALL_FORMAT, table)).SetConsistencyLevel(ConsistencyLevel.All)).Dispose();

                bridge.Stop(2);
                // Ensure that gossip has reported the node as down.
                Thread.Sleep(1000);

                try
                {
                    session.Execute(new SimpleStatement(String.Format(TestUtils.SELECT_ALL_FORMAT, table)).SetConsistencyLevel(ConsistencyLevel.All)).Dispose();
                }
                catch (UnavailableException e)
                {
                    Assert.Equal(e.Consistency, ConsistencyLevel.All);
                    Assert.Equal(e.RequiredReplicas, replicationFactor);
                    Assert.Equal(e.AliveReplicas, replicationFactor - 1);
                }

                try
                {
                    session.Execute(new SimpleStatement(String.Format(TestUtils.INSERT_FORMAT, table, key, "foo", 42, 24.03f)).SetConsistencyLevel(ConsistencyLevel.All));
                }
                catch (UnavailableException e)
                {
                    String expectedError = String.Format("Not enough replica available for query at consistency {0} ({1} required but only {2} alive)", ConsistencyLevel.All, 3, 2);
                    Assert.Equal(e.Message, expectedError);
                    Assert.Equal(e.Consistency, ConsistencyLevel.All);
                    Assert.Equal(e.RequiredReplicas, replicationFactor);
                    Assert.Equal(e.AliveReplicas, replicationFactor - 1);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                cluster.Discard();
            }
        }
 protected void query(CCMBridge.CCMCluster c, int n, ConsistencyLevel cl)
 {
     query(c, n, false, cl);
 }
 protected void query(CCMBridge.CCMCluster c, int n, bool usePrepared, ConsistencyLevel cl)
 {
     if (usePrepared)
     {
         BoundStatement bs = prepared.Bind(0);
         for (int i = 0; i < n; ++i)
             addCoordinator(c.Session.Execute(bs));
     }
     else
     {
         CassandraRoutingKey routingKey = new CassandraRoutingKey();
         routingKey.RawRoutingKey = Enumerable.Repeat((byte)0x00, 4).ToArray();
         for (int i = 0; i < n; ++i)
             addCoordinator(c.Session.Execute(new SimpleStatement(String.Format("SELECT * FROM {0} WHERE k = 0", TABLE)).SetRoutingKey(routingKey).SetConsistencyLevel(cl)));
     }
 }
 /// <summary>
 ///  Query methods that handle reads based on PreparedStatements and/or
 ///  ConsistencyLevels.
 /// </summary>
 protected void query(CCMBridge.CCMCluster c, int n)
 {
     query(c, n, false, ConsistencyLevel.One);
 }
 protected void query(CCMBridge.CCMCluster c, int n, bool usePrepared)
 {
     query(c, n, usePrepared, ConsistencyLevel.One);
 }
 protected void init(CCMBridge.CCMCluster c, int n, ConsistencyLevel cl)
 {
     init(c, n, false, cl);
 }
        //Only for tests purpose:
        //private class InsertQuery : CqlCommand
        //{
        //    string Query;
        //    internal InsertQuery(string query)
        //    {
        //        this.Query = query;
        //    }
        //    public override string GetCql()
        //    {
        //        return Query;
        //    }
        //}
        protected void init(CCMBridge.CCMCluster c, int n, bool batch, ConsistencyLevel cl)
        {
            CassandraRoutingKey routingKey = new CassandraRoutingKey();
            routingKey.RawRoutingKey = Enumerable.Repeat((byte)0x00, 4).ToArray();

            // We don't use insert for our test because the resultSet don't ship the queriedHost
            // Also note that we don't use tracing because this would trigger requests that screw up the test'
            for (int i = 0; i < n; ++i)
                if (batch)
                // BUG: WriteType == SIMPLE
                {
                    StringBuilder bth = new StringBuilder();
                    bth.AppendLine("BEGIN BATCH");
                    bth.AppendLine(String.Format("INSERT INTO {0}(k, i) VALUES (0, 0)", TestUtils.SIMPLE_TABLE));
                    bth.AppendLine("APPLY BATCH");

                    var qh = c.Session.Execute(new SimpleStatement(bth.ToString()).SetRoutingKey(routingKey).SetConsistencyLevel(cl)).QueriedHost;
                }
                else
                {
                    var qh = c.Session.Execute(new SimpleStatement(String.Format("INSERT INTO {0}(k, i) VALUES (0, 0)", TestUtils.SIMPLE_TABLE)).SetRoutingKey(routingKey).SetConsistencyLevel(cl)).QueriedHost;
                }

            prepared = c.Session.Prepare("SELECT * FROM " + TestUtils.SIMPLE_TABLE + " WHERE k = ?").SetConsistencyLevel(cl);
        }
Ejemplo n.º 10
0
 protected void init(CCMBridge.CCMCluster c, int n, bool batch)
 {
     init(c, n, batch, ConsistencyLevel.One);
 }
Ejemplo n.º 11
0
 /// <summary>
 ///  Init methods that handle writes using batch and consistency options.
 /// </summary>
 protected void init(CCMBridge.CCMCluster c, int n)
 {
     init(c, n, false, ConsistencyLevel.One);
 }
Ejemplo n.º 12
0
 protected void query(CCMBridge.CCMCluster c, int n, bool usePrepared, ConsistencyLevel cl)
 {
     if (usePrepared)
     {
         BoundStatement bs = prepared.Bind(0);
         for (int i = 0; i < n; ++i)
         {
             IPAddress ccord;
             ConsistencyLevel cac;
             using (var rs = c.Session.Execute(bs))
             {
                 ccord = rs.Info.QueriedHost;
                 cac = rs.Info.AchievedConsistency;
             }
             addCoordinator(ccord, cac);
         }
     }
     else
     {
         RoutingKey routingKey = new RoutingKey();
         routingKey.RawRoutingKey = Enumerable.Repeat((byte)0x00, 4).ToArray();
         for (int i = 0; i < n; ++i)
         {
             IPAddress ccord;
             ConsistencyLevel cac;
             using (var rs = c.Session.Execute(new SimpleStatement(String.Format("SELECT * FROM {0} WHERE k = 0", TABLE)).SetRoutingKey(routingKey).SetConsistencyLevel(cl)))
             {
                 ccord = rs.Info.QueriedHost;
                 cac = rs.Info.AchievedConsistency;
                 Console.WriteLine(string.Format("Query {0} executed by {1} with consistency {2}", i.ToString(), ccord.ToString(), cac.ToString()));
             }
             addCoordinator(ccord, cac);
         }
     }
 }
 private void query(CCMBridge.CCMCluster c, int n)
 {
     query(c, n, false);
 }
        private void init(CCMBridge.CCMCluster c, int n)
        {
            // We don't use insert for our test because the resultSet don't ship the queriedHost
            // Also note that we don't use tracing because this would trigger requests that screw up the test'
            for (int i = 0; i < n; ++i)
                c.Session.Execute(String.Format("INSERT INTO {0}(k, i) VALUES (0, 0)", TABLE));

            prepared = c.Session.Prepare("SELECT * FROM " + TABLE + " WHERE k = ?");
        }