示例#1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestMonitor()
        {
            Log.Info("Mocking bad health check, waiting for UNHEALTHY");
            svc.isHealthy = false;
            WaitForState(hm, HealthMonitor.State.ServiceUnhealthy);
            Log.Info("Returning to healthy state, waiting for HEALTHY");
            svc.isHealthy = true;
            WaitForState(hm, HealthMonitor.State.ServiceHealthy);
            Log.Info("Returning an IOException, as if node went down");
            // should expect many rapid retries
            int countBefore = createProxyCount.Get();

            svc.actUnreachable = true;
            WaitForState(hm, HealthMonitor.State.ServiceNotResponding);
            // Should retry several times
            while (createProxyCount.Get() < countBefore + 3)
            {
                Thread.Sleep(10);
            }
            Log.Info("Returning to healthy state, waiting for HEALTHY");
            svc.actUnreachable = false;
            WaitForState(hm, HealthMonitor.State.ServiceHealthy);
            hm.Shutdown();
            hm.Join();
            NUnit.Framework.Assert.IsFalse(hm.IsAlive());
        }
示例#2
0
        public virtual void TestRenewal()
        {
            // Keep track of how many times the lease gets renewed
            AtomicInteger leaseRenewalCount = new AtomicInteger();

            Org.Mockito.Mockito.DoAnswer(new _Answer_99(leaseRenewalCount)).When(MockDfsclient
                                                                                 ).RenewLease();
            // Set up a file so that we start renewing our lease.
            DFSOutputStream mockStream = Org.Mockito.Mockito.Mock <DFSOutputStream>();
            long            fileId     = 123L;

            renewer.Put(fileId, mockStream, MockDfsclient);
            // Wait for lease to get renewed
            long failTime = Time.MonotonicNow() + 5000;

            while (Time.MonotonicNow() < failTime && leaseRenewalCount.Get() == 0)
            {
                Sharpen.Thread.Sleep(50);
            }
            if (leaseRenewalCount.Get() == 0)
            {
                NUnit.Framework.Assert.Fail("Did not renew lease at all!");
            }
            renewer.CloseFile(fileId, MockDfsclient);
        }
            public TestResults(int happenings, bool shouldLog)
            {
                this.shouldLog = shouldLog;

                var counts  = new List <int>();
                var highest = new AtomicInteger(0);

                safely = AccessSafely
                         .AfterCompleting(happenings)
                         .WritingWith <int, ILogger>("results", (count, logger) =>
                {
                    if (shouldLog)
                    {
                        logger.Debug($"CountTakerActor: take: {count}");
                    }

                    if (count > highest.Get())
                    {
                        if (shouldLog)
                        {
                            logger.Debug($"CountTakerActor: take: {count} > {highest.Get()}");
                        }
                        highest.Set(count);
                    }

                    counts.Add(highest.Get());
                })
                         .ReadingWith("results", () => counts)
                         .ReadingWith("highest", highest.Get);
            }
            public AccessSafely StopCountAccessCompletes(int times)
            {
                stopCountAccess = AccessSafely
                                  .AfterCompleting(times)
                                  .WritingWith("value", (int value) => stopCount.Set(stopCount.Get() + value))
                                  .ReadingWith("value", () => stopCount.Get());

                return(stopCountAccess);
            }
示例#5
0
 public AccessSafely AfterCompleting(int times)
 {
     Access = AccessSafely
              .AfterCompleting(times)
              .WritingWith("pongCount", (int increment) => PongCount.Set(PongCount.Get() + increment))
              .ReadingWith("pongCount", () => PongCount.Get())
              .WritingWith("stopCount", (int increment) => StopCount.Set(StopCount.Get() + increment))
              .ReadingWith("stopCount", () => StopCount.Get());
     return(Access);
 }
示例#6
0
        private void TestNoLostInvalidationsStrict(bool strict)
        {
            // run test
            RunTestInternal();

            if (!strict)
            {
                // test eventually consistent
                Thread.Sleep(TimeSpan.FromSeconds(10));
            }
            var valuePutLast = _valuePut.Get();
            var valueMapStr  = _map.Get(Key);
            var valueMap     = int.Parse(valueMapStr);

            // fail if not eventually consistent
            string msg = null;

            if (valueMap < valuePutLast)
            {
                msg = "Near Cache did *not* become consistent. (valueMap = " + valueMap + ", valuePut = " + valuePutLast + ").";

                // flush Near Cache and re-fetch value
                FlushClientNearCache(_map);
                var valueMap2Str = _map.Get(Key);
                var valueMap2    = int.Parse(valueMap2Str);

                // test again
                if (valueMap2 < valuePutLast)
                {
                    msg += " Unexpected inconsistency! (valueMap2 = " + valueMap2 + ", valuePut = " + valuePutLast + ").";
                }
                else
                {
                    msg += " Flushing the Near Cache cleared the inconsistency. (valueMap2 = " + valueMap2 + ", valuePut = " +
                           valuePutLast + ").";
                }
            }
            // stop client
            ClientInternal.GetLifecycleService().Terminate();

            // fail after stopping hazelcast instance
            if (msg != null)
            {
                Logger.Warning(msg);
                Assert.Fail(msg);
            }

            // fail if strict is required and assertion was violated
            if (strict && _assertionViolationCount.Get() > 0)
            {
                msg = "Assertion violated " + _assertionViolationCount.Get() + " times.";
                Logger.Warning(msg);
                Assert.Fail(msg);
            }
        }
示例#7
0
        /// <summary>
        /// Expert: increments the refCount of this IndexReader
        /// instance only if the IndexReader has not been closed yet
        /// and returns <code>true</code> iff the refCount was
        /// successfully incremented, otherwise <code>false</code>.
        /// If this method returns <code>false</code> the reader is either
        /// already closed or is currently being closed. Either way this
        /// reader instance shouldn't be used by an application unless
        /// <code>true</code> is returned.
        /// <p>
        /// RefCounts are used to determine when a
        /// reader can be closed safely, i.e. as soon as there are
        /// no more references.  Be sure to always call a
        /// corresponding <seealso cref="#decRef"/>, in a finally clause;
        /// otherwise the reader may never be closed.  Note that
        /// <seealso cref="#close"/> simply calls decRef(), which means that
        /// the IndexReader will not really be closed until {@link
        /// #decRef} has been called for all outstanding
        /// references.
        /// </summary>
        /// <seealso cref= #decRef </seealso>
        /// <seealso cref= #incRef </seealso>
        public bool TryIncRef()
        {
            int count;

            while ((count = refCount.Get()) > 0)
            {
                if (refCount.CompareAndSet(count, count + 1))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#8
0
        public void TestThatActorAnswersEventually()
        {
            var access = AccessSafely.AfterCompleting(1);

            access.WritingWith <int>("answer", answer => _value.Set(answer));
            access.ReadingWith("answer", () => _value.Get());

            _answerGiver.Calculate("10", 5).AndThenConsume(answer => access.WriteUsing("answer", answer));

            var answer = access.ReadFrom <int>("answer");

            Assert.Equal(50, answer);
        }
        public AccessSafely AfterCompleting(int times)
        {
            Access = AccessSafely.AfterCompleting(times);

            Access
            .WritingWith <int, string>("projections", (val, id) => {
                _projections.Set(_projections.Get() + val);
                ProjectedDataIds.Add(id);
            })
            .ReadingWith("projections", () => _projections.Get())
            .ReadingWith <int, string>("projectionId", index => ProjectedDataIds[index]);

            return(Access);
        }
示例#10
0
        // If parameter is true we throw exception as soon as they appear otherwise we aggregate them
        public void Cancel(bool throwOnFirstException)
        {
            CheckDisposed();

            if (canceled)
            {
                return;
            }

            //Thread.MemoryBarrier ();
            canceled = true;

            handle.Set();
            if (linkedTokens != null)
            {
                UnregisterLinkedTokens();
            }

            List <Exception> exceptions = null;

            try {
                Action cb;
                for (int id = int.MinValue + 1; id <= currId.Get(); id++)
                {
                    if (!callbacks.TryRemove(new CancellationTokenRegistration(id, this), out cb))
                    {
                        continue;
                    }
                    if (cb == null)
                    {
                        continue;
                    }

                    if (throwOnFirstException)
                    {
                        cb();
                    }
                    else
                    {
                        try {
                            cb();
                        } catch (Exception e) {
                            if (exceptions == null)
                            {
                                exceptions = new List <Exception> ();
                            }

                            exceptions.Add(e);
                        }
                    }
                }
            } finally {
                callbacks.Clear();
            }

            if (exceptions != null)
            {
                throw new AggregateException(exceptions);
            }
        }
            public AccessSafely AfterCompleting(int times)
            {
                Access = AccessSafely
                         .AfterCompleting(times)

                         .WritingWith("afterFailureCount", (int increment) => AfterFailureCount.Set(AfterFailureCount.Get() + increment))
                         .ReadingWith("afterFailureCount", () => AfterFailureCount.Get())

                         .WritingWith("afterFailureCountCount", (int increment) => AfterFailureCountCount.Set(AfterFailureCountCount.Get() + increment))
                         .ReadingWith("afterFailureCountCount", () => AfterFailureCountCount.Get())

                         .WritingWith("afterRestartCount", (int increment) => AfterRestartCount.Set(AfterRestartCount.Get() + increment))
                         .ReadingWith("afterRestartCount", () => AfterRestartCount.Get())

                         .WritingWith("afterStopCount", (int increment) => AfterStopCount.Set(AfterStopCount.Get() + increment))
                         .ReadingWith("afterStopCount", () => AfterStopCount.Get())

                         .WritingWith("beforeRestartCount", (int increment) => BeforeRestartCount.Set(BeforeRestartCount.Get() + increment))
                         .ReadingWith("beforeRestartCount", () => BeforeRestartCount.Get())

                         .WritingWith("beforeResume", (int increment) => BeforeResume.Set(BeforeResume.Get() + increment))
                         .ReadingWith("beforeResume", () => BeforeResume.Get())

                         .WritingWith("beforeStartCount", (int increment) => BeforeStartCount.Set(BeforeStartCount.Get() + increment))
                         .ReadingWith("beforeStartCount", () => BeforeStartCount.Get())

                         .WritingWith("failNowCount", (int increment) => FailNowCount.Set(FailNowCount.Get() + increment))
                         .ReadingWith("failNowCount", () => FailNowCount.Get())

                         .WritingWith("stoppedCount", (int increment) => StoppedCount.Set(StoppedCount.Get() + increment))
                         .ReadingWith("stoppedCount", () => StoppedCount.Get());

                return(Access);
            }
示例#12
0
        /// <summary>
        /// Answer the total of writes completed after ensuring that it surpasses <paramref name="lesser"/>,
        /// or if <paramref name="retries"/> is reached first throw <code>InvalidOperationException</code>.
        /// </summary>
        /// <param name="lesser">The int value that must be surpassed.</param>
        /// <param name="retries">The long number of retries before failing.</param>
        /// <returns></returns>
        public virtual int TotalWritesGreaterThan(int lesser, long retries)
        {
            using (var waiter = new AutoResetEvent(false))
            {
                for (long count = 0; count < retries; ++count)
                {
                    lock (@lock)
                    {
                        var total = totalWrites.Get();
                        if (total > lesser)
                        {
                            return(total);
                        }
                    }

                    try
                    {
                        waiter.WaitOne(TimeSpan.FromMilliseconds(1));
                    }
                    catch { }
                }
            }

            throw new InvalidOperationException($"Did not reach expected value: {lesser + 1}");
        }
示例#13
0
 /// <summary>
 /// A server method implemented using
 /// <see cref="RetryCache"/>
 /// .
 /// </summary>
 /// <param name="input">
 /// is returned back in echo, if
 /// <paramref name="success"/>
 /// is true.
 /// </param>
 /// <param name="failureOuput">
 /// returned on failure, if
 /// <paramref name="success"/>
 /// is false.
 /// </param>
 /// <param name="methodTime">
 /// time taken by the operation. By passing smaller/larger
 /// value one can simulate an operation that takes short/long time.
 /// </param>
 /// <param name="success">whether this operation completes successfully or not</param>
 /// <returns>
 /// return the input parameter
 /// <paramref name="input"/>
 /// , if
 /// <paramref name="success"/>
 /// is
 /// true, else return
 /// <paramref name="failureOutput"/>
 /// .
 /// </returns>
 /// <exception cref="System.Exception"/>
 internal virtual int Echo(int input, int failureOutput, long methodTime, bool success
                           )
 {
     RetryCache.CacheEntryWithPayload entry = RetryCache.WaitForCompletion(retryCache,
                                                                           null);
     if (entry != null && entry.IsSuccess())
     {
         System.Console.Out.WriteLine("retryCount incremented " + retryCount.Get());
         retryCount.IncrementAndGet();
         return((int)entry.GetPayload());
     }
     try
     {
         operationCount.IncrementAndGet();
         if (methodTime > 0)
         {
             Thread.Sleep(methodTime);
         }
     }
     finally
     {
         RetryCache.SetState(entry, success, input);
     }
     return(success ? input : failureOutput);
 }
示例#14
0
        public AccessSafely AfterCompleting(int times)
        {
            Access = AccessSafely.AfterCompleting(times);

            Access
            .WritingWith <int>("confirmDispatched", i => _confirmDispatchedResultedIn.IncrementAndGet())
            .WritingWith <int>("readTextResultedIn", i => _readTextResultedIn.IncrementAndGet())
            .WritingWith <int>("writeTextResultedIn", i => _writeTextResultedIn.IncrementAndGet())
            .WritingWith <Result>("textReadResult", i => _textReadResult.Set(i))
            .WritingWith <Result>("textWriteResult", i => _textWriteResult.Set(i))
            .WritingWith <object>("stateHolder", i => _stateHolder.Set(i))
            .WritingWith <Result>("textWriteAccumulatedResults", i => _textWriteAccumulatedResults.Enqueue(i))
            .WritingWith <Metadata>("metadataHolder", i => _metadataHolder.Set(i))
            .WritingWith <StorageException>("errorCauses", i => _errorCauses.Enqueue(i))
            .ReadingWith("confirmDispatched", () => _confirmDispatchedResultedIn.Get())
            .ReadingWith("readTextResultedIn", () => _readTextResultedIn.IncrementAndGet())
            .ReadingWith("writeTextResultedIn", () => _writeTextResultedIn.IncrementAndGet())
            .ReadingWith("textReadResult", () => _textReadResult.Get())
            .ReadingWith("textWriteResult", () => _textWriteResult.Get())
            .ReadingWith("stateHolder", () => _stateHolder.Get())
            .ReadingWith("textWriteAccumulatedResults", () =>
            {
                _textWriteAccumulatedResults.TryDequeue(out var writeResult);
                return(writeResult);
            })
            .ReadingWith("metadataHolder", () => _metadataHolder.Get())
            .ReadingWith("errorCauses", () =>
            {
                _errorCauses.TryDequeue(out var exception);
                return(exception);
            });

            return(Access);
        }
示例#15
0
        internal bool AnyChanges()
        {
            if (InfoStream.IsEnabled("DW"))
            {
                InfoStream.Message("DW", "anyChanges? numDocsInRam=" + NumDocsInRAM.Get() + " deletes=" + AnyDeletions() + " hasTickets:" + TicketQueue.HasTickets() + " pendingChangesInFullFlush: " + PendingChangesInCurrentFullFlush);
            }

            /*
             * changes are either in a DWPT or in the deleteQueue.
             * yet if we currently flush deletes and / or dwpt there
             * could be a window where all changes are in the ticket queue
             * before they are published to the IW. ie we need to check if the
             * ticket queue has any tickets.
             */
            return(NumDocsInRAM.Get() != 0 || AnyDeletions() || TicketQueue.HasTickets() || PendingChangesInCurrentFullFlush);
        }
        public void TestThatStatefulEntityPreservesRestores()
        {
            RaceConditions.Set(0);

            var entityId = $"{_idGenerator.Next(10_000)}";
            var state    = new Entity1State(entityId, "Sally", 23);

            var entity1 = _world.ActorFor <IEntity1>(() => new Entity1Actor(RaceConditions, entityId));

            Assert.Equal(state, entity1.DefineWith(state.Name, state.Age).Await());
            Assert.Equal(state, entity1.Current().Await());

            entity1.ChangeName("Sally Jane");
            var newState = entity1.Current().Await();

            Assert.Equal("Sally Jane", newState.Name);

            entity1.IncreaseAge();
            newState = entity1.Current().Await();
            Assert.Equal(24, newState.Age);

            var restoredEntity1      = _world.ActorFor <IEntity1>(() => new Entity1Actor(RaceConditions, entityId));
            var restoredEntity1State = restoredEntity1.Current().Await();

            Assert.NotNull(restoredEntity1State);

            // check whether race conditions have been reproduced
            Assert.Equal(0, RaceConditions.Get());
        }
示例#17
0
            internal void put(File file)
            {
                int curCacheCount = cacheCount.Get();

                while (curCacheCount + 1 > countLimit)
                {
                    long freedSize = removeNext();

                    cacheSize.AddAndGet(-freedSize);

                    curCacheCount = cacheCount.AddAndGet(-1);
                }

                cacheCount.AddAndGet(1);

                long valueSize    = calculateSize(file);
                long curCacheSize = cacheSize.Get();

                while (curCacheSize + valueSize > sizeLimit)
                {
                    long freedSize = removeNext();
                    curCacheSize = cacheSize.AddAndGet(-freedSize);
                }

                cacheSize.AddAndGet(valueSize);

                long currentTime = ConvertUtils.GetCurrentTimeMillis();

                file.SetLastModified(currentTime);
                lastUsageDates.TryAdd(file, currentTime);
            }
示例#18
0
        public virtual void Sampling()
        {
            string dir      = TestDirHelper.GetTestDir().GetAbsolutePath();
            string services = StringUtils.Join(",", Arrays.AsList(typeof(InstrumentationService
                                                                         ).FullName, typeof(SchedulerService).FullName));
            Configuration conf = new Configuration(false);

            conf.Set("server.services", services);
            Org.Apache.Hadoop.Lib.Server.Server server = new Org.Apache.Hadoop.Lib.Server.Server
                                                             ("server", dir, dir, dir, dir, conf);
            server.Init();
            Org.Apache.Hadoop.Lib.Service.Instrumentation instrumentation = server.Get <Org.Apache.Hadoop.Lib.Service.Instrumentation
                                                                                        >();
            AtomicInteger count = new AtomicInteger();

            Instrumentation.Variable <long> varToSample = new _Variable_389(count);
            instrumentation.AddSampler("g", "s", 10, varToSample);
            Sleep(2000);
            int i = count.Get();

            NUnit.Framework.Assert.IsTrue(i > 0);
            IDictionary <string, IDictionary <string, object> > snapshot = instrumentation.GetSnapshot
                                                                               ();
            IDictionary <string, IDictionary <string, object> > samplers = (IDictionary <string,
                                                                                         IDictionary <string, object> >)snapshot["samplers"];

            InstrumentationService.Sampler sampler = (InstrumentationService.Sampler)samplers
                                                     ["g"]["s"];
            NUnit.Framework.Assert.IsTrue(sampler.GetRate() > 0);
            server.Destroy();
        }
示例#19
0
        public virtual int RefCount()
        {
            int rc = RefCount_Renamed.Get();

            Debug.Assert(rc >= 0);
            return(rc);
        }
        public AccessSafely AfterCompleting <TState, TSource>(int times)
        {
            _access = AccessSafely.AfterCompleting(times);

            _access
            .WritingWith <int>("confirmDispatchedResultedIn", increment => _confirmDispatchedResultedIn.AddAndGet(increment))
            .ReadingWith("confirmDispatchedResultedIn", () => _confirmDispatchedResultedIn.Get())

            .WritingWith <StoreData <TSource> >("writeStoreData", data =>
            {
                _writeObjectResultedIn.AddAndGet(data.ResultedIn);
                _objectWriteResult.Set(data.Result);
                _objectWriteAccumulatedResults.Enqueue(data.Result);
                _objectState.Set(data.State);
                data.Sources.ForEach(source => _sources.Enqueue(source));
                _metadataHolder.Set(data.Metadata);
                if (data.ErrorCauses != null)
                {
                    _errorCauses.Enqueue(data.ErrorCauses);
                }
            })
            .WritingWith <StoreData <TSource> >("readStoreData", data =>
            {
                _readObjectResultedIn.AddAndGet(data.ResultedIn);
                _objectReadResult.Set(data.Result);
                _objectWriteAccumulatedResults.Enqueue(data.Result);
                _objectState.Set(data.State);
                data.Sources.ForEach(source => _sources.Enqueue(source));
                _metadataHolder.Set(data.Metadata);
                if (data.ErrorCauses != null)
                {
                    _errorCauses.Enqueue(data.ErrorCauses);
                }
            })
            .ReadingWith("readObjectResultedIn", () => _readObjectResultedIn.Get())
            .ReadingWith("objectReadResult", () => _objectReadResult.Get())
            .ReadingWith("objectWriteResult", () => _objectWriteResult.Get())
            .ReadingWith("objectWriteAccumulatedResults", () =>
            {
                _objectWriteAccumulatedResults.TryDequeue(out var result);
                return(result);
            })
            .ReadingWith("objectWriteAccumulatedResultsCount", () => _objectWriteAccumulatedResults.Count)
            .ReadingWith("metadataHolder", () => _metadataHolder.Get())
            .ReadingWith("objectState", () => (TState)_objectState.Get())
            .ReadingWith("sources", () =>
            {
                _sources.TryDequeue(out var result);
                return(result);
            })
            .ReadingWith("errorCauses", () =>
            {
                _errorCauses.TryDequeue(out var result);
                return(result);
            })
            .ReadingWith("errorCausesCount", () => _errorCauses.Count)
            .ReadingWith("writeObjectResultedIn", () => _writeObjectResultedIn.Get());

            return(_access);
        }
示例#21
0
        public void TestDirectoryScan()
        {
            var scanFound = new AtomicInteger(0);

            var address1 = World.AddressFactory.UniqueWith("test-actor1");
            var address2 = World.AddressFactory.UniqueWith("test-actor2");
            var address3 = World.AddressFactory.UniqueWith("test-actor3");
            var address4 = World.AddressFactory.UniqueWith("test-actor4");
            var address5 = World.AddressFactory.UniqueWith("test-actor5");
            var address6 = World.AddressFactory.UniqueWith("test-actor6");
            var address7 = World.AddressFactory.UniqueWith("test-actor7");

            World.Stage.Directory.Register(address1, new TestInterfaceActor());
            World.Stage.Directory.Register(address2, new TestInterfaceActor());
            World.Stage.Directory.Register(address3, new TestInterfaceActor());
            World.Stage.Directory.Register(address4, new TestInterfaceActor());
            World.Stage.Directory.Register(address5, new TestInterfaceActor());

            var until = Until(7);
            Action <INoProtocol> afterConsumer = actor =>
            {
                Assert.NotNull(actor);
                scanFound.IncrementAndGet();
                until.Happened();
            };

            World.Stage.ActorOf <INoProtocol>(address5).AndThenConsume(afterConsumer);
            World.Stage.ActorOf <INoProtocol>(address4).AndThenConsume(afterConsumer);
            World.Stage.ActorOf <INoProtocol>(address3).AndThenConsume(afterConsumer);
            World.Stage.ActorOf <INoProtocol>(address2).AndThenConsume(afterConsumer);
            World.Stage.ActorOf <INoProtocol>(address1).AndThenConsume(afterConsumer);

            World.Stage.ActorOf <INoProtocol>(address6)
            .AndThenConsume(actor =>
            {
                Assert.Null(actor);
                until.Happened();
            })
            .Otherwise(actor =>
            {
                Assert.Null(actor);
                until.Happened();
                return(null);
            });
            World.Stage.ActorOf <INoProtocol>(address7)
            .AndThenConsume(actor =>
            {
                Assert.Null(actor);
                until.Happened();
            })
            .Otherwise(actor =>
            {
                Assert.Null(actor);
                until.Happened();
                return(null);
            });

            until.Completes();
            Assert.Equal(5, scanFound.Get());
        }
示例#22
0
        public override ClusterMetrics GetClusterMetrics()
        {
            int numMapTasks    = map_tasks.Get();
            int numReduceTasks = reduce_tasks.Get();

            return(new ClusterMetrics(numMapTasks, numReduceTasks, numMapTasks, numReduceTasks
                                      , 0, 0, 1, 1, jobs.Count, 1, 0, 0));
        }
示例#23
0
        public void TestThatAFailureIsNotComposedWithAtLeastConsume()
        {
            var currentValue = new AtomicInteger(42);

            Failure.Of <Exception, int>(RandomException()).AtLeastConsume(currentValue.Set);

            Assert.Equal(42, currentValue.Get());
        }
示例#24
0
        public void TestThatAFailureIsNotComposedWithAndThen()
        {
            var currentValue = new AtomicInteger(0);

            Failure.Of <Exception, int>(RandomException()).AndThen(currentValue.GetAndSet);

            Assert.Equal(0, currentValue.Get());
        }
 public AccessSafely AfterCompleting(int times)
 {
     Access = AccessSafely
              .AfterCompleting(times)
              .WritingWith("informedCount", (int increment) => informedCount.Set(informedCount.Get() + increment))
              .ReadingWith("informedCount", () => informedCount.Get());
     return(Access);
 }
示例#26
0
 /// <exception cref="System.IO.IOException"/>
 public override void SetReadyToFlush()
 {
     Transmit();
     lock (this)
     {
         syncLatch = new CountDownLatch(outstandingRequests.Get());
     }
 }
示例#27
0
 public void Take(int count)
 {
     if (count > Highest.Get())
     {
         Highest.Set(count);
     }
     Until.Happened();
 }
示例#28
0
        public virtual void TestBooleanScorerMax()
        {
            Directory         dir = NewDirectory();
            RandomIndexWriter riw = new RandomIndexWriter(Random(), dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));

            int docCount = AtLeast(10000);

            for (int i = 0; i < docCount; i++)
            {
                Document doc = new Document();
                doc.Add(NewField("field", "a", TextField.TYPE_NOT_STORED));
                riw.AddDocument(doc);
            }

            riw.ForceMerge(1);
            IndexReader r = riw.Reader;

            riw.Dispose();

            IndexSearcher s  = NewSearcher(r);
            BooleanQuery  bq = new BooleanQuery();

            bq.Add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);
            bq.Add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);

            Weight w = s.CreateNormalizedWeight(bq);

            Assert.AreEqual(1, s.IndexReader.Leaves.Count);
            BulkScorer scorer = w.BulkScorer(s.IndexReader.Leaves[0], false, null);

            FixedBitSet   hits = new FixedBitSet(docCount);
            AtomicInteger end  = new AtomicInteger();
            Collector     c    = new CollectorAnonymousInnerClassHelper(this, scorer, hits, end);

            while (end.Get() < docCount)
            {
                int inc = TestUtil.NextInt(Random(), 1, 1000);
                end.AddAndGet(inc);
                scorer.Score(c, end.Get());
            }

            Assert.AreEqual(docCount, hits.Cardinality());
            r.Dispose();
            dir.Dispose();
        }
示例#29
0
        public void TestThatAtLeastConsumedIsCalledWhenASuccess()
        {
            var currentValue = new AtomicInteger(0);
            var initialValue = RandomInt();

            Success.Of <Exception, int>(initialValue).AtLeastConsume(currentValue.Set);

            Assert.Equal(initialValue, currentValue.Get());
        }
示例#30
0
        public void TestThatResolveGoesThroughTheFailureBranchWhenFailedOutcome()
        {
            var currentValue  = new AtomicInteger(0);
            var failedBranch  = RandomInt();
            var successBranch = RandomInt();

            var outcome = Failure.Of <Exception, int>(RandomException())
                          .Resolve(
                ex =>
            {
                currentValue.Set(failedBranch);
                return(failedBranch);
            },
                currentValue.GetAndSet);

            Assert.Equal(outcome, currentValue.Get());
            Assert.Equal(failedBranch, currentValue.Get());
        }