Ejemplo n.º 1
0
        private void btnDatabaseInit_Click(object sender, EventArgs e)
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {
                if (db.KeyspaceExists(KeyspaceName))
                {
                    db.DropKeyspace(KeyspaceName);
                }

                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
                {
                    Name = KeyspaceName,
                }, db);

                keyspace.TryCreateSelf();

                String CQL = @"CREATE TABLE razgovori(kluc text, direction text, caller ascii, called text, start text, duration text,
                                     amount float, amount_ddv float, godina int, mesec int, 
                                     PRIMARY KEY(godina,mesec,caller,start,called,direction)
                                );";

                db.ExecuteNonQuery(CQL);
                //CQL = "CREATE INDEX ON razgovori(godina);";
                //db.ExecuteNonQuery(CQL);

                CQL = @"CREATE TABLE phonebook(kluc text, name text, surname text, number text, phone_type text, 
                                     PRIMARY KEY(surname,name,number)
                                );";
                db.ExecuteNonQuery(CQL);
                CQL = "CREATE INDEX ON phonebook(name);";
                db.ExecuteNonQuery(CQL);
            }
        }
Ejemplo n.º 2
0
        private static void SetupKeyspace()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {
                if (db.KeyspaceExists(KeyspaceName))
                {
                    db.DropKeyspace(KeyspaceName);
                }

                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
                {
                    Name = KeyspaceName,
                }, db);

                keyspace.TryCreateSelf();

                // create super column family using API
                keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
                {
                    FamilyName             = "razgovor",
                    FamilyType             = ColumnType.Super,
                    KeyValueType           = CassandraType.AsciiType,
                    SuperColumnNameType    = CassandraType.AsciiType,
                    ColumnNameType         = CassandraType.UTF8Type,
                    DefaultColumnValueType = CassandraType.UTF8Type
                });

                db.ExecuteNonQuery(@"CREATE TABLE poraka(
    naslov text,
    sodrzina text,
    PRIMARY KEY(naslov)
);");
            }
        }
Ejemplo n.º 3
0
        private static void SetupKeyspace()
        {
            if (CassandraSession.KeyspaceExists(server, keyspaceName))
            {
                CassandraSession.DropKeyspace(server, keyspaceName);
            }

            var keyspace = new CassandraKeyspace(keyspaceName);

            keyspace.TryCreateSelf(server);
            keyspace.TryCreateColumnFamily <UTF8Type>(server, "Posts");
            keyspace.TryCreateColumnFamily <LongType>(server, "Tags");
            keyspace.TryCreateColumnFamily <TimeUUIDType, UTF8Type>(server, "Comments");
        }
Ejemplo n.º 4
0
        private static void SetupKeyspace()
        {
            using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
            {
                if (db.KeyspaceExists(KeyspaceName))
                {
                    db.DropKeyspace(KeyspaceName);
                }

                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
                {
                    Name = KeyspaceName,
                }, db);

                keyspace.TryCreateSelf();

                // create column family using CQL
                db.ExecuteNonQuery(@"
				CREATE COLUMNFAMILY Posts (
				KEY ascii PRIMARY KEY,
				Title text,
				Body text,
				Author text,
				PostedOn timestamp
				);"                );

                // create column family using API
                keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
                {
                    FamilyName             = "Tags",
                    KeyValueType           = CassandraType.AsciiType,
                    ColumnNameType         = CassandraType.Int32Type,
                    DefaultColumnValueType = CassandraType.UTF8Type
                });

                // create super column family using API
                keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
                {
                    FamilyName             = "Comments",
                    FamilyType             = ColumnType.Super,
                    KeyValueType           = CassandraType.AsciiType,
                    SuperColumnNameType    = CassandraType.DateType,
                    ColumnNameType         = CassandraType.UTF8Type,
                    DefaultColumnValueType = CassandraType.UTF8Type
                });
            }
        }
Ejemplo n.º 5
0
		private static void SetupKeyspace()
		{
			using (var db = new CassandraContext(keyspace: KeyspaceName, server: Server))
			{
				if (db.KeyspaceExists(KeyspaceName))
					db.DropKeyspace(KeyspaceName);

				var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
				{
					Name = KeyspaceName,
				}, db);

				keyspace.TryCreateSelf();

				// create column family using CQL
				db.ExecuteNonQuery(@"
				CREATE COLUMNFAMILY Posts (
				KEY ascii PRIMARY KEY,
				Title text,
				Body text,
				Author text,
				PostedOn timestamp
				);");

				// create column family using API
				keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
				{
					FamilyName = "Tags",
					KeyValueType = CassandraType.AsciiType,
					ColumnNameType = CassandraType.Int32Type,
					DefaultColumnValueType = CassandraType.UTF8Type
				});

				// create super column family using API
				keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema
				{
					FamilyName = "Comments",
					FamilyType = ColumnType.Super,
					KeyValueType = CassandraType.AsciiType,
					SuperColumnNameType = CassandraType.DateType,
					ColumnNameType = CassandraType.UTF8Type,
					DefaultColumnValueType = CassandraType.UTF8Type
				});
			}
		}
        public void Init()
        {
            _context = new CassandraContext(keyspace: DummiesKeySpace, host: "localhost");
            if (!_context.KeyspaceExists(DummiesKeySpace))
            {
                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
                {
                    Name = DummiesKeySpace,
                }, _context);
                keyspace.TryCreateSelf();
                _context.ExecuteQuery(
                    @"
                CREATE COLUMNFAMILY Dummies (
	            KEY ascii PRIMARY KEY,
	            Blob blob
                );");
                _context.SaveChanges();
            }

            _dummies = _context.GetColumnFamily("Dummies");
        }
Ejemplo n.º 7
0
        public static void Test()
        {
            int TestTimeInMinutes = 10;

            int  ThreadCount  = 50;
            int  ThreadCount2 = 10;
            int  TimeOut_Sec  = 5;
            bool usePooling   = true;

            object        alive_monitor   = new object();
            bool          alive_condition = true;
            List <Thread> threads         = new List <Thread>();

            int    thrStarted_cnt     = 0;
            object thrStarted_monitor = new object();

            //initialize
            CassandraContext main_db = new CassandraContext(new ConnectionBuilder(keyspace: KeyspaceName, server: Server, cqlVersion: CqlVersion.Cql3, pooling: usePooling));

            {
                if (main_db.KeyspaceExists(KeyspaceName))
                {
                    main_db.DropKeyspace(KeyspaceName);
                }

                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
                {
                    Name = KeyspaceName,
                }, main_db);

                keyspace.TryCreateSelf();

                CreateTablesIfNotExists(main_db);
            }

            for (int tI = 0; tI < ThreadCount; tI++)
            {
                int thrNo = tI;
                var thr   = new Thread(() =>
                {
                    Console.Write("(*" + thrNo + ")");
                    try
                    {
                        CassandraContext db = new CassandraContext(new ConnectionBuilder(keyspace: KeyspaceName, server: Server, cqlVersion: CqlVersion.Cql3, pooling: usePooling));
                        lock (thrStarted_monitor)
                        {
                            thrStarted_cnt++;
                            Monitor.PulseAll(thrStarted_monitor);
                        }

                        while (true)
                        {
                            var job = GetJob(db, 10);
                            if (job != null)
                            {
                                Console.Write("-");
                                if (job.GetLogic() == null || job.GetCommand() == null)
                                {
                                    Console.WriteLine("Error");
                                }
                                DeleteJob(db, job);
                            }
                            else
                            {
                                lock (alive_monitor)
                                {
                                    if (!alive_condition)
                                    {
                                        return;
                                    }
                                    else
                                    {
                                        Monitor.Wait(alive_monitor, TimeOut_Sec * 1000);
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        Console.Write("(~" + thrNo + ")");
                    }
                });
                threads.Add(thr);
                thr.Start();
            }

            for (int tI = 0; tI < ThreadCount2; tI++)
            {
                int thrNo = tI;
                var thr   = new Thread(() =>
                {
                    Console.Write("<*" + thrNo + ">");
                    try
                    {
                        CassandraContext db = new CassandraContext(new ConnectionBuilder(keyspace: KeyspaceName, server: Server, cqlVersion: CqlVersion.Cql3, pooling: usePooling));
                        lock (thrStarted_monitor)
                        {
                            thrStarted_cnt++;
                            Monitor.PulseAll(thrStarted_monitor);
                        }

                        while (true)
                        {
                            StringBuilder sb = new StringBuilder();
                            for (int i = 0; i < 100; i++)
                            {
                                sb.AppendLine(Guid.NewGuid().ToString());
                            }
                            AddJob(db, sb.ToString(), Guid.NewGuid().ToString());
                            Console.Write("+");
                            Thread.Sleep(100);
                            lock (alive_monitor)
                            {
                                if (!alive_condition)
                                {
                                    return;
                                }
                            }
                        }
                    }
                    finally
                    {
                        Console.Write("<~" + thrNo + ">");
                    }
                });
                threads.Add(thr);
                thr.Start();
            }

            while (true)
            {
                lock (thrStarted_monitor)
                {
                    Monitor.Wait(thrStarted_monitor);
                    if (thrStarted_cnt == ThreadCount + ThreadCount2)
                    {
                        break;
                    }
                }
            }

            //wait for ten minutes
            Thread.Sleep(TestTimeInMinutes * 60 * 1000);

            lock (alive_monitor)
            {
                alive_condition = false;
                Monitor.PulseAll(alive_monitor);
            }
            foreach (var thr in threads)
            {
                thr.Join();
            }

            var j = main_db.ExecuteQuery(SelectCQL_Main(1)).ToArray();
            var c = main_db.ExecuteQuery(SelectCQL_Trans(1)).ToArray();

            if (j.Count() > 0 || c.Count() > 0)
            {
                Console.WriteLine("Error");
            }

            Console.WriteLine("Finished");
        }
		public void ResetDatabase()
		{
			using (var session = new CassandraSession(ConnectionBuilder))
			using (var db = new CassandraContext(session))
			{
				db.ThrowErrors = true;
				db.TryDropKeyspace(Keyspace);

				var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema {
					Name = Keyspace
				}, db);
				db.Keyspace = keyspace;

				keyspace.TryCreateSelf();
				keyspace.TryCreateColumnFamily<AsciiType>("Standard");
				keyspace.TryCreateColumnFamily<AsciiType, AsciiType>("Super");
				keyspace.TryCreateColumnFamily<AsciiType>("StandardAsciiType");
				keyspace.TryCreateColumnFamily<BytesType>("StandardBytesType");
				keyspace.TryCreateColumnFamily<IntegerType>("StandardIntegerType");
				keyspace.TryCreateColumnFamily<LexicalUUIDType>("StandardLexicalUUIDType");
				keyspace.TryCreateColumnFamily<LongType>("StandardLongType");
				keyspace.TryCreateColumnFamily<TimeUUIDType>("StandardTimeUUIDType");
				keyspace.TryCreateColumnFamily<UTF8Type>("StandardUTF8Type");
				keyspace.TryCreateColumnFamily<UUIDType>("StandardUUIDType");
				keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema() {
					FamilyName = "Counters",
					ColumnNameType = CassandraType.AsciiType,
					DefaultColumnValueType = CassandraType.CounterColumnType
				});
				keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
					FamilyName = "StandardDecimalType",
					ColumnNameType = CassandraType.DecimalType
				});
				keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
					FamilyName = "StandardCompositeType",
					ColumnNameType = CassandraType.CompositeType(new[] { CassandraType.AsciiType, CassandraType.DoubleType })
				});
				keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
					FamilyName = "StandardDynamicCompositeType",
					ColumnNameType = CassandraType.DynamicCompositeType(new Dictionary<char, CassandraType> { { 'a', CassandraType.AsciiType }, { 'd', CassandraType.DoubleType } })
				});

				db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Users (
	Id int PRIMARY KEY,
	Name ascii,
	Email ascii,
	Age int
);", CqlVersion.Cql);
				db.ExecuteNonQuery(@"CREATE INDEX User_Age ON Users (Age);", CqlVersion.Cql);
				db.Keyspace.ClearCachedKeyspaceSchema();

				var family = db.GetColumnFamily<AsciiType>("Standard");
				var superFamily = db.GetColumnFamily<AsciiType, AsciiType>("Super");
				var userFamily = db.GetColumnFamily("Users");
				var counterFamily = db.GetColumnFamily("Counters");

				ResetFamily(family);
				ResetSuperFamily(superFamily);
				ResetUsersFamily(userFamily);
				ResetCounterColumnFamily(counterFamily);
			}
		}
Ejemplo n.º 9
0
        private static void SetupKeyspace()
        {
            if (CassandraSession.KeyspaceExists(server, keyspaceName))
                CassandraSession.DropKeyspace(server, keyspaceName);

            var keyspace = new CassandraKeyspace(keyspaceName);
            keyspace.TryCreateSelf(server);
            keyspace.TryCreateColumnFamily<UTF8Type>(server, "Posts");
            keyspace.TryCreateColumnFamily<LongType>(server, "Tags");
            keyspace.TryCreateColumnFamily<TimeUUIDType, UTF8Type>(server, "Comments");
        }
        public void ResetDatabase()
        {
            using (var session = new CassandraSession(ConnectionBuilder))
                using (var db = new CassandraContext(session))
                {
                    db.ThrowErrors = true;
                    db.TryDropKeyspace(Keyspace);

                    var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema {
                        Name = Keyspace
                    }, db);
                    db.Keyspace = keyspace;

                    keyspace.TryCreateSelf();
                    keyspace.TryCreateColumnFamily <AsciiType>("Standard");
                    keyspace.TryCreateColumnFamily <AsciiType, AsciiType>("Super");
                    keyspace.TryCreateColumnFamily <AsciiType>("StandardAsciiType");
                    keyspace.TryCreateColumnFamily <BytesType>("StandardBytesType");
                    keyspace.TryCreateColumnFamily <IntegerType>("StandardIntegerType");
                    keyspace.TryCreateColumnFamily <LexicalUUIDType>("StandardLexicalUUIDType");
                    keyspace.TryCreateColumnFamily <LongType>("StandardLongType");
                    keyspace.TryCreateColumnFamily <TimeUUIDType>("StandardTimeUUIDType");
                    keyspace.TryCreateColumnFamily <UTF8Type>("StandardUTF8Type");
                    keyspace.TryCreateColumnFamily <UUIDType>("StandardUUIDType");
                    keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema()
                    {
                        FamilyName             = "Counters",
                        ColumnNameType         = CassandraType.AsciiType,
                        DefaultColumnValueType = CassandraType.CounterColumnType
                    });
                    keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema(type: ColumnType.Super)
                    {
                        FamilyName             = "SuperCounters",
                        SuperColumnNameType    = CassandraType.AsciiType,
                        ColumnNameType         = CassandraType.AsciiType,
                        DefaultColumnValueType = CassandraType.CounterColumnType
                    });
                    keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
                        FamilyName     = "StandardDecimalType",
                        ColumnNameType = CassandraType.DecimalType
                    });
                    keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
                        FamilyName     = "StandardCompositeType",
                        ColumnNameType = CassandraType.CompositeType(new[] { CassandraType.AsciiType, CassandraType.DoubleType })
                    });
                    keyspace.TryCreateColumnFamily(new CassandraColumnFamilySchema {
                        FamilyName     = "StandardDynamicCompositeType",
                        ColumnNameType = CassandraType.DynamicCompositeType(new Dictionary <char, CassandraType> {
                            { 'a', CassandraType.AsciiType }, { 'd', CassandraType.DoubleType }
                        })
                    });

                    db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY ""Users"" (
	Id int PRIMARY KEY,
	Name ascii,
	Email ascii,
	Age int
);");
                    db.ExecuteNonQuery(@"CREATE INDEX User_Age ON ""Users"" (Age);");

                    db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Cql3List (
    Id int PRIMARY KEY,
    TagList list<text> --list of strings
);");

                    db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Cql3Set (
    Id int PRIMARY KEY,
    TagSet set<uuid> --set of Guids
);");

                    db.ExecuteNonQuery(@"
CREATE COLUMNFAMILY Cql3Map (
    Id int PRIMARY KEY,
    TagMap map<bigint,uuid> --map of long integers and Guids
);");
                    db.Keyspace.ClearCachedKeyspaceSchema();

                    var family        = db.GetColumnFamily <AsciiType>("Standard");
                    var superFamily   = db.GetColumnFamily <AsciiType, AsciiType>("Super");
                    var userFamily    = db.GetColumnFamily("Users");
                    var counterFamily = db.GetColumnFamily("Counters");

                    ResetFamily(family);
                    ResetSuperFamily(superFamily);
                    ResetUsersFamily(userFamily);
                    ResetCounterColumnFamily(counterFamily);
                }
        }
Ejemplo n.º 11
0
        public static void Test()
        {
            int TestTimeInMinutes = 10;

            int ThreadCount = 50;
            int ThreadCount2 = 10;
            int TimeOut_Sec = 5;
            bool usePooling = true;

            object alive_monitor = new object();
            bool alive_condition = true;
            List<Thread> threads = new List<Thread>();

            int thrStarted_cnt = 0;
            object thrStarted_monitor = new object();

            //initialize
            CassandraContext main_db = new CassandraContext(new ConnectionBuilder(keyspace: KeyspaceName, server: Server, cqlVersion: CqlVersion.Cql3, pooling: usePooling));
            {
                if (main_db.KeyspaceExists(KeyspaceName))
                    main_db.DropKeyspace(KeyspaceName);

                var keyspace = new CassandraKeyspace(new CassandraKeyspaceSchema
                {
                    Name = KeyspaceName,
                }, main_db);

                keyspace.TryCreateSelf();

                CreateTablesIfNotExists(main_db);
            }

            for (int tI = 0; tI < ThreadCount; tI++)
            {
                int thrNo = tI;
                var thr = new Thread(() =>
                {

                    Console.Write("(*" + thrNo + ")");
                    try
                    {
                        CassandraContext db = new CassandraContext(new ConnectionBuilder(keyspace: KeyspaceName, server: Server, cqlVersion: CqlVersion.Cql3, pooling: usePooling));
                        lock (thrStarted_monitor)
                        {
                            thrStarted_cnt++;
                            Monitor.PulseAll(thrStarted_monitor);
                        }

                        while (true)
                        {
                            var job = GetJob(db, 10);
                            if (job != null)
                            {
                                Console.Write("-");
                                if (job.GetLogic() == null || job.GetCommand() == null)
                                    Console.WriteLine("Error");
                                DeleteJob(db, job);
                            }
                            else
                            {
                                lock (alive_monitor)
                                {
                                    if (!alive_condition)
                                        return;
                                    else
                                        Monitor.Wait(alive_monitor, TimeOut_Sec * 1000);
                                }
                            }
                        }
                    }
                    finally
                    {
                        Console.Write("(~" + thrNo + ")");
                    }
                });
                threads.Add(thr);
                thr.Start();
            }

            for (int tI = 0; tI < ThreadCount2; tI++)
            {
                int thrNo = tI;
                var thr = new Thread(() =>
                {
                    Console.Write("<*" + thrNo + ">");
                    try
                    {
                        CassandraContext db = new CassandraContext(new ConnectionBuilder(keyspace: KeyspaceName, server: Server, cqlVersion: CqlVersion.Cql3, pooling: usePooling));
                        lock (thrStarted_monitor)
                        {
                            thrStarted_cnt++;
                            Monitor.PulseAll(thrStarted_monitor);
                        }

                        while (true)
                        {
                            StringBuilder sb = new StringBuilder();
                            for (int i = 0; i < 100; i++)
                                sb.AppendLine(Guid.NewGuid().ToString());
                            AddJob(db, sb.ToString(), Guid.NewGuid().ToString());
                            Console.Write("+");
                            Thread.Sleep(100);
                            lock (alive_monitor)
                            {
                                if (!alive_condition)
                                    return;
                            }
                        }
                    }
                    finally
                    {
                        Console.Write("<~" + thrNo + ">");
                    }
                });
                threads.Add(thr);
                thr.Start();
            }

            while (true)
            {
                lock (thrStarted_monitor)
                {
                    Monitor.Wait(thrStarted_monitor);
                    if (thrStarted_cnt == ThreadCount+ThreadCount2)
                        break;
                }
            }

            //wait for ten minutes
            Thread.Sleep(TestTimeInMinutes * 60 * 1000);

            lock (alive_monitor)
            {
                alive_condition = false;
                Monitor.PulseAll(alive_monitor);
            }
            foreach (var thr in threads)
            {
                thr.Join();
            }

            var j = main_db.ExecuteQuery(SelectCQL_Main(1)).ToArray();
            var c = main_db.ExecuteQuery(SelectCQL_Trans(1)).ToArray();
            if (j.Count() > 0 || c.Count() > 0)
                Console.WriteLine("Error");

            Console.WriteLine("Finished");
        }