Example #1
0
        public void TestStats()
        {
            testName = "TestStats";
            SetUpTest(true);
            string dbFileName = testHome + "/" +
                                testName + ".db";

            QueueDatabaseConfig dbConfig =
                new QueueDatabaseConfig();

            ConfigCase1(dbConfig);
            QueueDatabase db = QueueDatabase.Open(dbFileName, dbConfig);

            QueueStats stats = db.Stats();

            ConfirmStatsPart1Case1(stats);
            db.Msgfile = testHome + "/" + testName + ".log";
            db.PrintFastStats(true);

            // Put 500 records into the database.
            PutRecordCase1(db, null);

            stats = db.Stats();
            ConfirmStatsPart2Case1(stats);
            db.PrintFastStats();

            db.Close();
        }
Example #2
0
        public void TestMessageFile()
        {
            testName = "TestMessageFile";
            SetUpTest(true);

            // Configure and open an environment.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            envConfig.Create   = true;
            envConfig.UseMPool = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                testHome, envConfig);

            // Configure and open a database.
            QueueDatabaseConfig DBConfig =
                new QueueDatabaseConfig();

            DBConfig.Env      = env;
            DBConfig.Creation = CreatePolicy.IF_NEEDED;

            string        DBFileName = testName + ".db";
            QueueDatabase db         = QueueDatabase.Open(
                DBFileName, DBConfig);

            // Confirm message file does not exist.
            string messageFile = testHome + "/" + "msgfile";

            Assert.AreEqual(false, File.Exists(messageFile));

            // Call set_msgfile() of db.
            db.Msgfile = messageFile;

            // Print db statistic to message file.
            db.PrintStats(true);

            // Confirm message file exists now.
            Assert.AreEqual(true, File.Exists(messageFile));

            db.Msgfile = "";
            string line = null;

            // Read the third line of message file.
            System.IO.StreamReader file = new System.IO.StreamReader(@"" + messageFile);
            line = file.ReadLine();
            line = file.ReadLine();
            line = file.ReadLine();

            // Confirm the message file is not empty.
            Assert.AreEqual(line, "DB handle information:");
            file.Close();

            // Close database and environment.
            db.Close();
            env.Close();
        }
Example #3
0
        public void StatsInTxn(string home, string name, bool ifIsolation)
        {
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            EnvConfigCase1(envConfig);
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                home, envConfig);

            Transaction         openTxn  = env.BeginTransaction();
            QueueDatabaseConfig dbConfig =
                new QueueDatabaseConfig();

            ConfigCase1(dbConfig);
            dbConfig.Env = env;
            QueueDatabase db = QueueDatabase.Open(name + ".db",
                                                  dbConfig, openTxn);

            openTxn.Commit();

            Transaction statsTxn = env.BeginTransaction();
            QueueStats  stats;

            if (ifIsolation == false)
            {
                stats = db.Stats(statsTxn);
            }
            else
            {
                stats = db.Stats(statsTxn, Isolation.DEGREE_ONE);
            }

            ConfirmStatsPart1Case1(stats);
            db.Msgfile = home + "/" + name + ".log";
            db.PrintStats(true);

            // Put 500 records into the database.
            PutRecordCase1(db, statsTxn);

            if (ifIsolation == false)
            {
                stats = db.Stats(statsTxn);
            }
            else
            {
                stats = db.Stats(statsTxn, Isolation.DEGREE_TWO);
            }
            ConfirmStatsPart2Case1(stats);
            db.PrintStats();

            statsTxn.Commit();
            db.Close();
            env.Close();
        }
        //User is connecting to the service, add user to list of registered users
        public int Connect(int userId, int roomNo, string userName, bool isSender = false)
        {
            IQueueMessageCallback registeredUser = OperationContext.Current.GetCallbackChannel <IQueueMessageCallback>();

            Console.WriteLine("User {0} connected at {1}", userName, DateTime.Now.ToShortTimeString());

            //Add checking some credentails

            if (!_callbackList.Select(u => u.RegisteredUser).Contains(registeredUser))
            {
                var connectingUser = new ConnectedUser(userId, registeredUser);

                if (isSender)
                {
                    var queue = QueueDatabase.FindQueue(userId);
                    if (queue != null)
                    {
                        connectingUser.QueueData           = queue;
                        connectingUser.QueueData.Timestamp = DateTime.Now;
                    }
                    connectingUser.QueueData.UserId = userId;
                    connectingUser.QueueData.RoomNo = roomNo;
                    connectingUser.QueueData.Owner  = userName;

                    _callbackList.Add(connectingUser);
                    QueueDatabase.AddQueue(connectingUser.QueueData);
                }
                else
                {
                    //NOT TESTED
                    var queue = QueueDatabase.FindQueueByRoomNo(roomNo);
                    connectingUser.QueueData = queue;

                    _callbackList.Add(connectingUser);
                }
            }

            try
            {
                _callbackList.Select(c => c.RegisteredUser).ToList().ForEach(
                    delegate(IQueueMessageCallback callback) {
                    callback.NotifyOfEstablishedConnection(userName);
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR in callback NotifyOfEstablishedConnection: ");
                Console.WriteLine(ex.Message);
            }

            return(_registeredUsers++);
        }
Example #5
0
 static QueueDatabase()
 {
     _instance = new Lazy<QueueDatabase>(() =>
     {
         var db = new QueueDatabase();
         db.Initialize();
         return db;
     }, true);
 }