Ejemplo n.º 1
0
        internal static void valueComparator(CqlRowSet rowset, List <object[]> insertedRows)
        {
            Assert.True(rowset.RowsCount == insertedRows.Count, string.Format("Returned rows count is not equal with the count of rows that were inserted! \n Returned: {0} \n Expected: {1} \n", rowset.RowsCount, insertedRows.Count));
            int i = 0;

            foreach (var row in rowset.GetRows())
            {
                if (row.Columns.Any(col => col.GetType() == typeof(byte[])))
                {
                    for (int j = 0; j < row.Length; j++)
                    {
                        Assert.True(row[j].GetType() == typeof(byte[]) ? Assert.ArrEqual((byte[])row[j], (byte[])insertedRows[i][j]) : row[j].Equals(insertedRows[i][j]));
                    }
                }
                else
                {
                    for (int m = 0; m < row.Columns.Length; m++)
                    {
                        if (!row.Columns[m].Equals(insertedRows[i][m]))
                        {
                            insertedRows.Reverse();// To check if needed and why
                            if (!row.Columns[m].Equals(insertedRows[i][m]))
                            {
                                insertedRows.Reverse();
                            }
                        }
                        Assert.True(row.Columns[m].Equals(insertedRows[i][m]), "Inserted data !Equals with returned data.");
                    }
                }
                i++;
            }
        }
 ///  Coordinator management/count
 public static void addCoordinator(CqlRowSet rs)
 {
     IPAddress coordinator = rs.QueriedHost;
     if (!coordinators.ContainsKey(coordinator))
         coordinators.Add(coordinator, 0);
     var n = coordinators[coordinator];
     coordinators[coordinator] = n + 1;
 }
        public CqlRowSet GetRows()
        {
            Statement    query       = new SimpleStatement("SELECT * FROM simplex.songs;");
            IAsyncResult asyncResult = Session.BeginExecute(query, null, null);

            asyncResult.AsyncWaitHandle.WaitOne();
            CqlRowSet result = Session.EndExecute(asyncResult);

            return(result);
        }
Ejemplo n.º 4
0
 internal CqlReader(CqlRowSet rows)
 {
     this.popul = rows;
     for (int idx = 0; idx < popul.Columns.Length; idx++)
     {
         colidx.Add(popul.Columns[idx].Name, idx);
     }
     enumRows   = popul.GetRows();
     enumerRows = enumRows.GetEnumerator();
 }
Ejemplo n.º 5
0
        ///  Coordinator management/count

        public static void addCoordinator(CqlRowSet rs)
        {
            IPAddress coordinator = rs.QueriedHost;

            if (!coordinators.ContainsKey(coordinator))
            {
                coordinators.Add(coordinator, 0);
            }
            var n = coordinators[coordinator];

            coordinators[coordinator] = n + 1;
        }
 public void PrintResults(CqlRowSet results)
 {
     Console.WriteLine(String.Format("{0, -30}\t{1, -20}\t{2, -20}\t{3, -30}",
                                     "title", "album", "artist", "tags"));
     Console.WriteLine("-------------------------------+-----------------------+--------------------+-------------------------------");
     foreach (CqlRow row in results.GetRows())
     {
         Console.WriteLine(String.Format("{0, -30}\t{1, -20}\t{2, -20}\t{3}",
                                         row.GetValue <String>("title"), row.GetValue <String>("album"),
                                         row.GetValue <String>("artist"), Prettify(row.GetValue <List <String> >("tags")
                                                                                   )));
     }
 }
Ejemplo n.º 7
0
 private static void DisplayKeyspace(CqlRowSet result)
 {
     try
     {
         foreach (var resKeyspace in result.GetRows())
         {
             Console.WriteLine("durable_writes={0} keyspace_name={1} strategy_Class={2} strategy_options={3}",
                               resKeyspace.GetValue <bool>("durable_writes"),
                               resKeyspace.GetValue <string>("keyspace_name"),
                               resKeyspace.GetValue <string>("strategy_class"),
                               resKeyspace.GetValue <string>("strategy_options"));
         }
         Console.WriteLine();
     }
     catch (Exception ex)
     {
         Console.WriteLine("Command failed {0}", ex.Message);
     }
 }
Ejemplo n.º 8
0
        public void QuerySchema()
        {
            _session.Execute(
                "UPDATE simplex.songs " +
                "SET tags = tags + { 'entre-deux-guerres' } " +
                "WHERE id = 756716f7-2e54-4715-9f00-91dcbea6cf50;");

            CqlRowSet results = _session.Execute(
                "SELECT * FROM simplex.songs " +
                "WHERE id = 756716f7-2e54-4715-9f00-91dcbea6cf50;");

            Console.WriteLine(String.Format("{0, -30}\t{1, -20}\t{2, -20}\t{3, -30}",
                                            "title", "album", "artist", "tags"));
            Console.WriteLine("-------------------------------+-----------------------+--------------------+-------------------------------");
            foreach (CqlRow row in results.GetRows())
            {
                Console.WriteLine(String.Format("{0, -30}\t{1, -20}\t{2, -20}\t{3}",
                                                row.GetValue <String>("title"), row.GetValue <String>("album"),
                                                row.GetValue <String>("artist"), Prettify(row.GetValue <List <String> >("tags"))));
            }
        }
Ejemplo n.º 9
0
        public void checkingOrderOfCollection(string CassandraCollectionType, Type TypeOfDataToBeInputed, Type TypeOfKeyForMap = null, string pendingMode = "")
        {
            string cassandraDataTypeName    = QueryTools.convertTypeNameToCassandraEquivalent(TypeOfDataToBeInputed);
            string cassandraKeyDataTypeName = "";

            string openBracket  = CassandraCollectionType == "list" ? "[" : "{";
            string closeBracket = CassandraCollectionType == "list" ? "]" : "}";
            string mapSyntax    = "";

            string randomKeyValue = string.Empty;

            if (TypeOfKeyForMap != null)
            {
                cassandraKeyDataTypeName = QueryTools.convertTypeNameToCassandraEquivalent(TypeOfKeyForMap);
                mapSyntax = cassandraKeyDataTypeName + ",";

                if (TypeOfKeyForMap == typeof(DateTimeOffset))
                {
                    randomKeyValue = (string)(Randomm.RandomVal(typeof(DateTimeOffset)).GetType().GetMethod("ToString", new Type[] { typeof(string) }).Invoke(Randomm.RandomVal(typeof(DateTimeOffset)), new object[1] {
                        "yyyy-MM-dd H:mm:sszz00"
                    }) + "' : '");
                }
                else
                {
                    randomKeyValue = Randomm.RandomVal(TypeOfDataToBeInputed) + "' : '";
                }
            }


            string tableName = "table" + Guid.NewGuid().ToString("N");

            try
            {
                Session.Cluster.WaitForSchemaAgreement(
                    QueryTools.ExecuteSyncNonQuery(Session, string.Format(@"CREATE TABLE {0}(
         tweet_id uuid PRIMARY KEY,
         some_collection {1}<{2}{3}>
         );", tableName, CassandraCollectionType, mapSyntax, cassandraDataTypeName)));
            }
            catch (AlreadyExistsException)
            {
            }
            Guid tweet_id = Guid.NewGuid();

            StringBuilder longQ = new StringBuilder();

            longQ.AppendLine("BEGIN BATCH ");

            int          CollectionElementsNo = 100;
            List <Int32> orderedAsInputed     = new List <Int32>(CollectionElementsNo);

            string inputSide = "some_collection + {1}";

            if (CassandraCollectionType == "list" && pendingMode == "prepending")
            {
                inputSide = "{1} + some_collection";
            }

            for (int i = 0; i < CollectionElementsNo; i++)
            {
                var data = i * (i % 2);
                longQ.AppendFormat(@"UPDATE {0} SET some_collection = " + inputSide + " WHERE tweet_id = {2};"
                                   , tableName, openBracket + randomKeyValue + data + closeBracket, tweet_id.ToString());
                orderedAsInputed.Add(data);
            }

            longQ.AppendLine("APPLY BATCH;");
            QueryTools.ExecuteSyncNonQuery(Session, longQ.ToString(), "Inserting...");

            if (CassandraCollectionType == "set")
            {
                orderedAsInputed.Sort();
                orderedAsInputed.RemoveRange(0, orderedAsInputed.LastIndexOf(0));
            }
            else if (CassandraCollectionType == "list" && pendingMode == "prepending")
            {
                orderedAsInputed.Reverse();
            }

            CqlRowSet rs = Session.Execute(string.Format("SELECT * FROM {0};", tableName), ConsistencyLevel.Default);

            using (rs)
            {
                int ind = 0;
                foreach (var row in rs.GetRows())
                {
                    foreach (var value in row[1] as System.Collections.IEnumerable)
                    {
                        Assert.True(orderedAsInputed[ind] == (int)value);
                        ind++;
                    }
                }
            }

            QueryTools.ExecuteSyncQuery(Session, string.Format("SELECT * FROM {0};", tableName));
            QueryTools.ExecuteSyncNonQuery(Session, string.Format("DROP TABLE {0};", tableName));
        }
Ejemplo n.º 10
0
 internal static void valueComparator(CqlRowSet rowset, List<object[]> insertedRows)
 {
     Assert.True(rowset.RowsCount == insertedRows.Count, string.Format("Returned rows count is not equal with the count of rows that were inserted! \n Returned: {0} \n Expected: {1} \n", rowset.RowsCount, insertedRows.Count));
     int i = 0;
     foreach (var row in rowset.GetRows())
     {
         if (row.Columns.Any(col => col.GetType() == typeof(byte[])))
             for (int j = 0; j < row.Length; j++)
                 Assert.True(row[j].GetType() == typeof(byte[]) ? Assert.ArrEqual((byte[])row[j], (byte[])insertedRows[i][j]) : row[j].Equals(insertedRows[i][j]));
         else
         {
             for (int m = 0; m < row.Columns.Length; m++)
             {
                 if (!row.Columns[m].Equals(insertedRows[i][m]))
                 {
                     insertedRows.Reverse();// To check if needed and why
                     if (!row.Columns[m].Equals(insertedRows[i][m]))
                         insertedRows.Reverse();
                 }
                 Assert.True(row.Columns[m].Equals(insertedRows[i][m]), "Inserted data !Equals with returned data.");
             }
         }
         i++;
     }
 }