Beispiel #1
0
        private List <OpResult> doOperation(AtomicBoolean firstTime)
        {
            bool localFirstTime = firstTime.getAndSet(false);

            if (!localFirstTime)
            {
            }

            List <OpResult> opResults = client.getZooKeeper().multi(transaction);

            if (opResults.Count > 0)
            {
                OpResult firstResult = opResults[0];
                if (firstResult is OpResult.ErrorResult)
                {
                    OpResult.ErrorResult error = (OpResult.ErrorResult)firstResult;
                    KeeperException.Code code  = KeeperException.Code.get(error.getErr());
                    if (code == null)
                    {
                        code = KeeperException.Code.UNIMPLEMENTED;
                    }
                    throw KeeperException.create(code);
                }
            }
            return(opResults);
        }
Beispiel #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.io.pagecache.PageCursor io(long pageId, int pf_flags) throws java.io.IOException
            public override PageCursor io(long pageId, int pfFlags)
            {
                try
                {
                    Thread.Sleep(1);
                }
                catch (InterruptedException e)
                {
                    throw new Exception(e);
                }
                if (first.getAndSet(false))
                {
                    throw new IOException(_message);
                }
                return(base.io(pageId, pfFlags));
            }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void failingJobShouldLogAndStopConnection() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FailingJobShouldLogAndStopConnection()
        {
            AtomicBoolean  stopped    = new AtomicBoolean();
            string         id         = System.Guid.randomUUID().ToString();
            BoltConnection connection = NewConnection(id);

            doThrow(new Exception("some unexpected error")).when(connection).processNextBatch();
            doAnswer(inv => stopped.getAndSet(true)).when(connection).stop();

            _boltScheduler.start();
            _boltScheduler.created(connection);
            _boltScheduler.enqueued(connection, Jobs.noop());

            Predicates.await(() => stopped.get(), 1, MINUTES);

            assertFalse(_boltScheduler.isActive(connection));
            verify(connection).processNextBatch();
            verify(connection).stop();

            _logProvider.assertExactly(AssertableLogProvider.inLog(containsString(typeof(BoltServer).Assembly.GetName().Name)).error(containsString("Unexpected error during job scheduling for session"), matchesExceptionMessage(containsString("some unexpected error"))));
        }
Beispiel #4
0
        /**
         * If true is returned, make an attempt at the set of operations
         *
         * @return true/false
         */
        public bool shouldContinue()
        {
            bool localIsDone = isDone.getAndSet(true);

            return(!localIsDone);
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Override @SafeVarargs public final boolean injectFailureOrMischief(Class... failureTypes)
            public override bool InjectFailureOrMischief(params Type[] failureTypes)
            {
                return(NextReadIsInconsistent.getAndSet(false));
            }
Beispiel #6
0
        internal virtual void Rotate()
        {
            if (_rotating.getAndSet(true))
            {
                // Already rotating
                return;
            }

            MemoryStream bufferingOutputStream = new MemoryStream();
            ThreadStart  runnable = () =>
            {
                _logFileLock.writeLock().@lock();
                try
                {
                    try
                    {
                        // Must close file prior to doing any operations on it or else it won't work on Windows
                        try
                        {
                            _outRef.Flush();
                            _outRef.Close();
                            _outRef = _nullStream;
                        }
                        catch (Exception e)
                        {
                            _rotationListener.rotationError(e, bufferingOutputStream);
                            return;
                        }

                        try
                        {
                            if (_fileSystem.fileExists(_outputFile))
                            {
                                ShiftArchivedOutputFiles();
                                _fileSystem.renameFile(_outputFile, ArchivedOutputFile(_outputFile, 1));
                            }
                        }
                        catch (Exception e)
                        {
                            _rotationListener.rotationError(e, bufferingOutputStream);
                            return;
                        }
                    }
                    finally
                    {
                        try
                        {
                            if (!_closed.get() && _outRef.Equals(_nullStream))
                            {
                                _outRef = OpenOutputFile();
                                _rotationListener.outputFileCreated(bufferingOutputStream);
                            }
                        }
                        catch (IOException e)
                        {
                            Console.Error.WriteLine("Failed to open log file after log rotation: " + e.Message);
                            _rotationListener.rotationError(e, bufferingOutputStream);
                        }
                    }

                    if (_rotationDelay > 0)
                    {
                        _earliestRotationTimeRef.set(_currentTimeSupplier.AsLong + _rotationDelay);
                    }
                    _rotationListener.rotationCompleted(bufferingOutputStream);
                }
                finally
                {
                    _rotating.set(false);
                    try
                    {
                        bufferingOutputStream.writeTo(_streamWrapper);
                    }
                    catch (IOException e)
                    {
                        _rotationListener.rotationError(e, _streamWrapper);
                    }
                    _logFileLock.writeLock().unlock();
                }
            };

            try
            {
                _rotationExecutor.execute(runnable);
            }
            catch (Exception e)
            {
                _rotationListener.rotationError(e, _streamWrapper);
                _rotating.set(false);
            }
        }