private void Connect()
        {
            const int retryCount = 20; // With 20 retries we'll wait at most 11 seconds until fail.
            var       exceptions = new Stack <Exception>();

            _client = null;
            long timeToWait = 100;

            for (var i = 0; i < retryCount; ++i)
            {
                try
                {
                    var clientConfiguration = Db4oClientServerLegacyConfigurationBridge.AsClientConfiguration(Config());
                    _client = Db4oClientServer.OpenClient(clientConfiguration, "localhost", Port, USER_NAME, USER_PWD);
                    return;
                }
                catch (Exception e)
                {
                    if (NotTheSameAsLast(e, exceptions))
                    {
                        exceptions.Push(e);
                    }
                }
                Runtime4.Sleep(timeToWait);
                if (i == 10)
                {
                    timeToWait = 1000;
                }
            }

            FailConnect(retryCount, exceptions);
        }
Example #2
0
 /// <exception cref="System.Exception"></exception>
 protected virtual void WaitForAllTasksDone()
 {
     while (!AreAllTasksDone())
     {
         Runtime4.Sleep(1);
     }
 }
        public virtual void TestLoopWithTimeoutReturnsWhenBlockIsFalse()
        {
            StopWatch watch = new AutoStopWatch();

            Runtime4.Retry(500, new _IClosure4_14());
            Assert.IsSmaller(500, watch.Peek());
        }
Example #4
0
        /// <exception cref="System.Exception"></exception>
        public virtual void TestDrainTo()
        {
            IPausableBlockingQueue4 queue = new PausableBlockingQueue();

            queue.Add(new object());
            queue.Add(new object());
            queue.Pause();
            Collection4 list = new Collection4();
            Thread      t    = ExecuteAfter("Pausable queue drainer", 0, new _IRunnable_66(queue, list
                                                                                           ));

            Runtime4.SleepThrowsOnInterrupt(200);
            lock (list)
            {
                Assert.AreEqual(0, list.Size());
            }
            Assert.IsTrue(queue.HasNext());
            queue.Resume();
            t.Join();
            lock (list)
            {
                Assert.AreEqual(2, list.Size());
            }
            Assert.IsFalse(queue.HasNext());
        }
Example #5
0
 public virtual void TestKeptAliveClient()
 {
     ClientTimeOutTestCase.Item item = new ClientTimeOutTestCase.Item("one");
     Store(item);
     Runtime4.Sleep(Timeout * 2);
     Assert.AreSame(item, ((ClientTimeOutTestCase.Item)RetrieveOnlyInstance(typeof(ClientTimeOutTestCase.Item
                                                                                   ))));
 }
        public virtual void TestLoopWithTimeoutReturnsAfterTimeout()
        {
            StopWatch watch = new AutoStopWatch();

            Runtime4.Retry(500, new _IClosure4_24());
            watch.Stop();
            Assert.IsGreaterOrEqual(500, watch.Elapsed());
        }
 public override void Run()
 {
     while (NotStopped())
     {
         _dispatcher.Write(Msg.Ping);
         Runtime4.Sleep(1);
     }
 }
 public virtual void EnsureStarted()
 {
     _thread.Start();
     while (!IsRunning())
     {
         Runtime4.Sleep(10);
     }
     Runtime4.Sleep(10);
 }
        public virtual void TestTimeoutNext()
        {
            ITimeoutBlockingQueue4 queue = new TimeoutBlockingQueue(300);

            queue.Pause();
            queue.Add(new object());
            queue.Check();
            Assert.IsNull(queue.TryNext());
            Runtime4.SleepThrowsOnInterrupt(500);
            queue.Check();
            Assert.IsNotNull(queue.TryNext());
        }
Example #10
0
        /// <exception cref="System.Exception"></exception>
        public virtual void _test()
        {
            ObjectServerImpl serverImpl = (ObjectServerImpl)ClientServerFixture().Server();
            IEnumerator      iter       = serverImpl.IterateDispatchers();

            iter.MoveNext();
            IServerMessageDispatcher serverDispatcher = (IServerMessageDispatcher)iter.Current;
            IClientMessageDispatcher clientDispatcher = ((ClientObjectContainer)Db()).MessageDispatcher
                                                            ();

            clientDispatcher.Close();
            Runtime4.Sleep(1000);
            Assert.IsFalse(serverDispatcher.IsMessageDispatcherAlive());
        }
 public void OnMessage(Msg msg)
 {
     if (msg is MQueryExecute)
     {
         this._enclosing.processingMessage = true;
         barrier.Add(new object());
         Runtime4.Sleep(500);
         this._enclosing.processingMessage = false;
     }
     else
     {
         if (msg is MIsAlive)
         {
             Assert.IsFalse(this._enclosing.processingMessage);
         }
     }
 }
Example #12
0
            public void Run()
            {
                lock (this._enclosing._lock)
                {
                    this._enclosing.CheckClosed();
                    if (this._enclosing._backupFile != null)
                    {
                        throw new BackupInProgressException();
                    }
                    this._enclosing._backupFile = new BlockAwareBin(targetStorage.Open(new BinConfiguration
                                                                                           (path, true, this._enclosing._file.Length(), false, this._enclosing._blockConverter
                                                                                           .BlocksToBytes(1))));
                }
                long pos = 0;

                byte[] buffer = new byte[8192];
                while (true)
                {
                    lock (this._enclosing._lock)
                    {
                        int read = this._enclosing._file.Read(pos, buffer);
                        if (read <= 0)
                        {
                            break;
                        }
                        this._enclosing._backupFile.Write(pos, buffer, read);
                        pos += read;
                    }
                    // Let the database engine continue to do
                    // some work if it likes to.
                    Runtime4.Sleep(1);
                }
                lock (this._enclosing._lock)
                {
                    try
                    {
                        Db4objects.Db4o.Internal.IoAdaptedObjectContainer.SyncAndClose(this._enclosing._backupFile
                                                                                       );
                    }
                    finally
                    {
                        this._enclosing._backupFile = null;
                    }
                }
            }
Example #13
0
 public virtual void Run()
 {
     try
     {
         for (var i = 0; i < NumIterations; i++)
         {
             Exercise(_db);
             Runtime4.Sleep(1);
         }
     }
     catch (Exception ex)
     {
         lock (_exceptions)
         {
             _exceptions.Add(ex);
         }
     }
 }
Example #14
0
        /// <exception cref="System.Exception"></exception>
        public virtual void Test()
        {
            IExtObjectContainer db         = Fixture().Db();
            ObjectServerImpl    serverImpl = (ObjectServerImpl)ClientServerFixture().Server();

            try
            {
                IEnumerator iter = serverImpl.IterateDispatchers();
                iter.MoveNext();
                ServerMessageDispatcherImpl serverDispatcher = (ServerMessageDispatcherImpl)iter.
                                                               Current;
                serverDispatcher.Socket().Close();
                Runtime4.Sleep(1000);
                Assert.Expect(typeof(DatabaseClosedException), new _ICodeBlock_30(db));
                Assert.IsTrue(db.IsClosed());
            }
            finally
            {
                serverImpl.Close();
            }
        }
Example #15
0
        public virtual void Conc(IExtObjectContainer oc, int seq)
        {
            EventRegistry(oc).Committed += new System.EventHandler <Db4objects.Db4o.Events.CommitEventArgs>
                                               (new _IEventListener4_74(oc).OnEvent);
            CommittedCallbackRefreshTestCase.Item[] items = new CommittedCallbackRefreshTestCase.Item
                                                            [Count];
            IObjectSet objectSet = NewQuery(typeof(CommittedCallbackRefreshTestCase.Item)).Execute
                                       ();
            int count = 0;

            while (objectSet.HasNext())
            {
                lock (_lock)
                {
                    items[count] = (CommittedCallbackRefreshTestCase.Item)objectSet.Next();
                    items[count].Check();
                    count++;
                }
            }
            for (int i = 0; i < items.Length; i++)
            {
                lock (_lock)
                {
                    items[i].Update();
                    Store(items[i]._subItem);
                    Store(items[i]);
                }
                Db().Commit();
            }
            Runtime4.Sleep(1000);
            for (int i = 0; i < items.Length; i++)
            {
                lock (_lock)
                {
                    items[i].Check();
                }
            }
            Runtime4.Sleep(3000);
        }
        public virtual void Conc(IExtObjectContainer oc, int seq)
        {
            EventRegistry(oc).Committed += new _IEventListener4_74(oc).OnEvent;
            var items = new Item
                        [Count];
            var objectSet = NewQuery(typeof(Item)).Execute
                                ();
            var count = 0;

            while (objectSet.HasNext())
            {
                lock (_lock)
                {
                    items[count] = (Item)objectSet.Next();
                    items[count].Check();
                    count++;
                }
            }
            for (var i = 0; i < items.Length; i++)
            {
                lock (_lock)
                {
                    items[i].Update();
                    Store(items[i]._subItem);
                    Store(items[i]);
                }
                Db().Commit();
            }
            Runtime4.Sleep(1000);
            for (var i = 0; i < items.Length; i++)
            {
                lock (_lock)
                {
                    items[i].Check();
                }
            }
            Runtime4.Sleep(3000);
        }
Example #17
0
 public virtual void ProcessMessage(IMessageContext con, object message)
 {
     Runtime4.Sleep(3000);
 }
Example #18
0
 public virtual void ProcessMessage(IMessageContext con, object message)
 {
     _clientWasBlocked = true;
     Runtime4.Sleep(Timeout * 3);
 }