Beispiel #1
0
        public static void Main()
        {
            ComputerSpecifications.Dump();

            var running = new AtomicBoolean(true);
            
            using (var aeron = Aeron.Connect())
            using (var publication = aeron.AddPublication(Channel, StreamID))
            using (var subscription = aeron.AddSubscription(Channel, StreamID))
            {
                var subscriber = new Subscriber(running, subscription);
                var subscriberThread = new Thread(subscriber.Run) {Name = "subscriber"};
                var publisherThread = new Thread(new Publisher(running, publication).Run) {Name = "publisher"};
                var rateReporterThread = new Thread(new RateReporter(running, subscriber).Run) {Name = "rate-reporter"};

                rateReporterThread.Start();
                subscriberThread.Start();
                publisherThread.Start();

                Console.WriteLine("Press any key to stop...");
                Console.Read();

                running.Set(false);
                
                subscriberThread.Join();
                publisherThread.Join();
                rateReporterThread.Join();
            }
        }
Beispiel #2
0
        public static void Main()
        {
            Console.WriteLine("Subscribing to " + Channel + " on stream Id " + StreamID);

            var ctx = new Aeron.Context()
                .AvailableImageHandler(SamplesUtil.PrintUnavailableImage)
                .UnavailableImageHandler(SamplesUtil.PrintUnavailableImage);

            var reporter = new RateReporter(1000, SamplesUtil.PrintRate);
            var fragmentAssembler = new FragmentAssembler(SamplesUtil.RateReporterHandler(reporter));
            var running = new AtomicBoolean(true);

            var t = new Thread(subscription => SamplesUtil.SubscriberLoop(fragmentAssembler.OnFragment, FragmentCountLimit, running)((Subscription) subscription));
            var report = new Thread(reporter.Run);

            using (var aeron = Aeron.Connect(ctx))
            using (var subscription = aeron.AddSubscription(Channel, StreamID))
            {
                t.Start(subscription);
                report.Start();

                Console.ReadLine();
                Console.WriteLine("Shutting down...");
                running.Set(false);
                reporter.Halt();

                t.Join();
                report.Join();
            }
        }
        public virtual void TestAccquireReleaseRace()
        {
            DocumentsWriterStallControl ctrl = new DocumentsWriterStallControl();
            ctrl.UpdateStalled(false);
            AtomicBoolean stop = new AtomicBoolean(false);
            AtomicBoolean checkPoint = new AtomicBoolean(true);

            int numStallers = AtLeast(1);
            int numReleasers = AtLeast(1);
            int numWaiters = AtLeast(1);
            var sync = new Synchronizer(numStallers + numReleasers, numStallers + numReleasers + numWaiters);
            var threads = new ThreadClass[numReleasers + numStallers + numWaiters];
            IList<Exception> exceptions = new SynchronizedCollection<Exception>();
            for (int i = 0; i < numReleasers; i++)
            {
                threads[i] = new Updater(stop, checkPoint, ctrl, sync, true, exceptions);
            }
            for (int i = numReleasers; i < numReleasers + numStallers; i++)
            {
                threads[i] = new Updater(stop, checkPoint, ctrl, sync, false, exceptions);
            }
            for (int i = numReleasers + numStallers; i < numReleasers + numStallers + numWaiters; i++)
            {
                threads[i] = new Waiter(stop, checkPoint, ctrl, sync, exceptions);
            }

            Start(threads);
            int iters = AtLeast(10000);
            float checkPointProbability = TEST_NIGHTLY ? 0.5f : 0.1f;
            for (int i = 0; i < iters; i++)
            {
                if (checkPoint.Get())
                {
                    Assert.IsTrue(sync.UpdateJoin.@await(new TimeSpan(0, 0, 0, 10)), "timed out waiting for update threads - deadlock?");
                    if (exceptions.Count > 0)
                    {
                        foreach (Exception throwable in exceptions)
                        {
                            Console.WriteLine(throwable.ToString());
                            Console.Write(throwable.StackTrace);
                        }
                        Assert.Fail("got exceptions in threads");
                    }

                    if (ctrl.HasBlocked() && ctrl.Healthy)
                    {
                        AssertState(numReleasers, numStallers, numWaiters, threads, ctrl);
                    }

                    checkPoint.Set(false);
                    sync.Waiter.countDown();
                    sync.LeftCheckpoint.@await();
                }
                Assert.IsFalse(checkPoint.Get());
                Assert.AreEqual(0, sync.Waiter.Remaining);
                if (checkPointProbability >= (float)Random().NextDouble())
                {
                    sync.Reset(numStallers + numReleasers, numStallers + numReleasers + numWaiters);
                    checkPoint.Set(true);
                }
            }
            if (!checkPoint.Get())
            {
                sync.Reset(numStallers + numReleasers, numStallers + numReleasers + numWaiters);
                checkPoint.Set(true);
            }

            Assert.IsTrue(sync.UpdateJoin.@await(new TimeSpan(0, 0, 0, 10)));
            AssertState(numReleasers, numStallers, numWaiters, threads, ctrl);
            checkPoint.Set(false);
            stop.Set(true);
            sync.Waiter.countDown();
            sync.LeftCheckpoint.@await();

            for (int i = 0; i < threads.Length; i++)
            {
                ctrl.UpdateStalled(false);
                threads[i].Join(2000);
                if (threads[i].IsAlive && threads[i] is Waiter)
                {
                    if (threads[i].State == ThreadState.WaitSleepJoin)
                    {
                        Assert.Fail("waiter is not released - anyThreadsStalled: " + ctrl.AnyStalledThreads());
                    }
                }
            }
        }
        public virtual void TestNRTOpenExceptions()
        {
            // LUCENE-5262: test that several failed attempts to obtain an NRT reader
            // don't leak file handles.
            MockDirectoryWrapper dir = (MockDirectoryWrapper)GetAssertNoDeletesDirectory(NewMockDirectory());
            AtomicBoolean shouldFail = new AtomicBoolean();
            dir.FailOn(new FailureAnonymousInnerClassHelper(shouldFail));

            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
            conf.SetMergePolicy(NoMergePolicy.COMPOUND_FILES); // prevent merges from getting in the way
            IndexWriter writer = new IndexWriter(dir, conf);

            // create a segment and open an NRT reader
            writer.AddDocument(new Document());
            writer.Reader.Dispose();

            // add a new document so a new NRT reader is required
            writer.AddDocument(new Document());

            // try to obtain an NRT reader twice: first time it fails and closes all the
            // other NRT readers. second time it fails, but also fails to close the
            // other NRT reader, since it is already marked closed!
            for (int i = 0; i < 2; i++)
            {
                shouldFail.Set(true);
                try
                {
                    writer.Reader.Dispose();
                }
                catch (FakeIOException e)
                {
                    // expected
                    if (VERBOSE)
                    {
                        Console.WriteLine("hit expected fake IOE");
                    }
                }
            }

            writer.Dispose();
            dir.Dispose();
        }
Beispiel #5
0
 public void SetApplyAllDeletes()
 {
     flushDeletes.Set(true);
 }
        private readonly IDictionary <SegmentCoreReaders, bool?> warmed = new WeakDictionary <SegmentCoreReaders, bool?>(); //new ConcurrentHashMapWrapper<SegmentCoreReaders, bool?>(new HashMap<SegmentCoreReaders, bool?>());
        // Collections.synchronizedMap(new WeakHashMap<SegmentCoreReaders, bool?>());

        public virtual void RunTest(string testName)
        {
            failed.Set(false);
            addCount.Set(0);
            delCount.Set(0);
            packCount.Set(0);

            long t0 = Environment.TickCount;

            Random        random  = new Random(Random().Next());
            LineFileDocs  docs    = new LineFileDocs(random, DefaultCodecSupportsDocValues());
            DirectoryInfo tempDir = CreateTempDir(testName);

            dir = GetDirectory(NewMockFSDirectory(tempDir)); // some subclasses rely on this being MDW
            if (dir is BaseDirectoryWrapper)
            {
                ((BaseDirectoryWrapper)dir).CheckIndexOnClose = false; // don't double-checkIndex, we do it ourselves.
            }
            MockAnalyzer analyzer = new MockAnalyzer(Random());

            analyzer.MaxTokenLength = TestUtil.NextInt(Random(), 1, IndexWriter.MAX_TERM_LENGTH);
            IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer).SetInfoStream(new FailOnNonBulkMergesInfoStream());

            if (LuceneTestCase.TEST_NIGHTLY)
            {
                // newIWConfig makes smallish max seg size, which
                // results in tons and tons of segments for this test
                // when run nightly:
                MergePolicy mp = conf.MergePolicy;
                if (mp is TieredMergePolicy)
                {
                    ((TieredMergePolicy)mp).MaxMergedSegmentMB = 5000.0;
                }
                else if (mp is LogByteSizeMergePolicy)
                {
                    ((LogByteSizeMergePolicy)mp).MaxMergeMB = 1000.0;
                }
                else if (mp is LogMergePolicy)
                {
                    ((LogMergePolicy)mp).MaxMergeDocs = 100000;
                }
            }

            conf.SetMergedSegmentWarmer(new IndexReaderWarmerAnonymousInnerClassHelper(this));

            if (VERBOSE)
            {
                conf.SetInfoStream(new PrintStreamInfoStreamAnonymousInnerClassHelper(this, Console.Out));
            }
            writer = new IndexWriter(dir, conf);
            TestUtil.ReduceOpenFiles(writer);

            TaskScheduler es = Random().NextBoolean() ? null : TaskScheduler.Default;

            DoAfterWriter(es);

            int NUM_INDEX_THREADS = TestUtil.NextInt(Random(), 2, 4);

            int RUN_TIME_SEC = LuceneTestCase.TEST_NIGHTLY ? 300 : RANDOM_MULTIPLIER;

            ISet <string>             delIDs     = new ConcurrentHashSet <string>(new HashSet <string>());
            ISet <string>             delPackIDs = new ConcurrentHashSet <string>(new HashSet <string>());
            ConcurrentQueue <SubDocs> allSubDocs = new ConcurrentQueue <SubDocs>();

            long stopTime = Environment.TickCount + (RUN_TIME_SEC * 1000);

            ThreadClass[] indexThreads = LaunchIndexingThreads(docs, NUM_INDEX_THREADS, stopTime, delIDs, delPackIDs, allSubDocs.ToList());

            if (VERBOSE)
            {
                Console.WriteLine("TEST: DONE start " + NUM_INDEX_THREADS + " indexing threads [" + (Environment.TickCount - t0) + " ms]");
            }

            // Let index build up a bit
            Thread.Sleep(100);

            DoSearching(es, stopTime);

            if (VERBOSE)
            {
                Console.WriteLine("TEST: all searching done [" + (Environment.TickCount - t0) + " ms]");
            }

            for (int thread = 0; thread < indexThreads.Length; thread++)
            {
                indexThreads[thread].Join();
            }

            if (VERBOSE)
            {
                Console.WriteLine("TEST: done join indexing threads [" + (Environment.TickCount - t0) + " ms]; addCount=" + addCount + " delCount=" + delCount);
            }

            IndexSearcher s = FinalSearcher;

            if (VERBOSE)
            {
                Console.WriteLine("TEST: finalSearcher=" + s);
            }

            assertFalse(failed.Get());

            bool doFail = false;

            // Verify: make sure delIDs are in fact deleted:
            foreach (string id in delIDs)
            {
                TopDocs hits = s.Search(new TermQuery(new Term("docid", id)), 1);
                if (hits.TotalHits != 0)
                {
                    Console.WriteLine("doc id=" + id + " is supposed to be deleted, but got " + hits.TotalHits + " hits; first docID=" + hits.ScoreDocs[0].Doc);
                    doFail = true;
                }
            }

            // Verify: make sure delPackIDs are in fact deleted:
            foreach (string id in delPackIDs)
            {
                TopDocs hits = s.Search(new TermQuery(new Term("packID", id)), 1);
                if (hits.TotalHits != 0)
                {
                    Console.WriteLine("packID=" + id + " is supposed to be deleted, but got " + hits.TotalHits + " matches");
                    doFail = true;
                }
            }

            // Verify: make sure each group of sub-docs are still in docID order:
            foreach (SubDocs subDocs in allSubDocs.ToList())
            {
                TopDocs hits = s.Search(new TermQuery(new Term("packID", subDocs.packID)), 20);
                if (!subDocs.deleted)
                {
                    // We sort by relevance but the scores should be identical so sort falls back to by docID:
                    if (hits.TotalHits != subDocs.subIDs.Count)
                    {
                        Console.WriteLine("packID=" + subDocs.packID + ": expected " + subDocs.subIDs.Count + " hits but got " + hits.TotalHits);
                        doFail = true;
                    }
                    else
                    {
                        int lastDocID  = -1;
                        int startDocID = -1;
                        foreach (ScoreDoc scoreDoc in hits.ScoreDocs)
                        {
                            int docID = scoreDoc.Doc;
                            if (lastDocID != -1)
                            {
                                assertEquals(1 + lastDocID, docID);
                            }
                            else
                            {
                                startDocID = docID;
                            }
                            lastDocID = docID;
                            Document doc = s.Doc(docID);
                            assertEquals(subDocs.packID, doc.Get("packID"));
                        }

                        lastDocID = startDocID - 1;
                        foreach (string subID in subDocs.subIDs)
                        {
                            hits = s.Search(new TermQuery(new Term("docid", subID)), 1);
                            assertEquals(1, hits.TotalHits);
                            int docID = hits.ScoreDocs[0].Doc;
                            if (lastDocID != -1)
                            {
                                assertEquals(1 + lastDocID, docID);
                            }
                            lastDocID = docID;
                        }
                    }
                }
                else
                {
                    // Pack was deleted -- make sure its docs are
                    // deleted.  We can't verify packID is deleted
                    // because we can re-use packID for update:
                    foreach (string subID in subDocs.subIDs)
                    {
                        assertEquals(0, s.Search(new TermQuery(new Term("docid", subID)), 1).TotalHits);
                    }
                }
            }

            // Verify: make sure all not-deleted docs are in fact
            // not deleted:
            int endID = Convert.ToInt32(docs.NextDoc().Get("docid"), CultureInfo.InvariantCulture);

            docs.Dispose();

            for (int id = 0; id < endID; id++)
            {
                string stringID = id.ToString(CultureInfo.InvariantCulture);
                if (!delIDs.Contains(stringID))
                {
                    TopDocs hits = s.Search(new TermQuery(new Term("docid", stringID)), 1);
                    if (hits.TotalHits != 1)
                    {
                        Console.WriteLine("doc id=" + stringID + " is not supposed to be deleted, but got hitCount=" + hits.TotalHits + "; delIDs=" + string.Join(",", delIDs.ToArray()));
                        doFail = true;
                    }
                }
            }
            assertFalse(doFail);

            assertEquals("index=" + writer.SegString() + " addCount=" + addCount + " delCount=" + delCount, addCount.Get() - delCount.Get(), s.IndexReader.NumDocs);
            ReleaseSearcher(s);

            writer.Commit();

            assertEquals("index=" + writer.SegString() + " addCount=" + addCount + " delCount=" + delCount, addCount.Get() - delCount.Get(), writer.NumDocs);

            DoClose();
            writer.Dispose(false);

            // Cannot shutdown until after writer is closed because
            // writer has merged segment warmer that uses IS to run
            // searches, and that IS may be using this es!

            /*if (es != null)
             * {
             * es.shutdown();
             * es.awaitTermination(1, TimeUnit.SECONDS);
             * }*/

            TestUtil.CheckIndex(dir);
            dir.Dispose();
            //System.IO.Directory.Delete(tempDir.FullName, true);
            TestUtil.Rm(tempDir);

            if (VERBOSE)
            {
                Console.WriteLine("TEST: done [" + (Environment.TickCount - t0) + " ms]");
            }
        }
 private void Read(object state)
 {
     this.state.Set(state);
     _read.Set(true);
 }
        public void TestInvalidationDistortionSequenceAndGuid()
        {
            var mapName  = "nearCachedMapDistortion";
            var mapSize  = 100000;
            var stopTest = new AtomicBoolean(false);

            Assert.True(PopulateMapFromServer(mapName, mapSize).Success);
            var clientMap = Client.GetMap <int, int>(mapName);

            var populateNearCache = new Thread(() =>
            {
                while (!stopTest.Get())
                {
                    for (int i = 0; i < mapSize; i++)
                    {
                        clientMap.Get(i);
                    }
                }
            });

            var distortSequence = new Thread(() =>
            {
                while (!stopTest.Get())
                {
                    var response = DistortRandomPartitionSequence(mapName);
                    Assert.True(response.Success, response.Message);
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            });

            var distortUuid = new Thread(() =>
            {
                while (!stopTest.Get())
                {
                    var response = DistortRandomPartitionUuid();
                    Assert.True(response.Success, response.Message);
                    Thread.Sleep(TimeSpan.FromSeconds(5));
                }
            });

            var putOnMember = new Thread(() =>
            {
                var random = new Random();
                // change some data
                while (!stopTest.Get())
                {
                    var key   = random.Next(mapSize);
                    var value = random.Next(int.MaxValue);
                    Assert.True(PutOnMember(key, value, mapName).Success);
                    Thread.Sleep(100);
                }
            });

            // start threads
            putOnMember.Start();
            populateNearCache.Start();
            distortSequence.Start();
            distortUuid.Start();

            Thread.Sleep(TimeSpan.FromSeconds(60));

            // stop threads
            stopTest.Set(true);
            distortUuid.Join();
            distortSequence.Join();
            populateNearCache.Join();
            putOnMember.Join();

            TestSupport.AssertTrueEventually(() =>
            {
                var allValueFromMember = GetAllValueFromMember(mapSize, mapName);
                for (int i = 0; i < mapSize; i++)
                {
                    var valueSeenFromMember = allValueFromMember[i] as int?;
                    var valueSeenFromClient = clientMap.Get(i);
                    Assert.AreEqual(valueSeenFromMember, valueSeenFromClient);
                }
            });
        }
 public void Close()
 {
     _closed.Set(true);
     _executor.Shutdown();
 }
Beispiel #10
0
        public virtual void TestAccquireReleaseRace()
        {
            DocumentsWriterStallControl ctrl = new DocumentsWriterStallControl();

            ctrl.UpdateStalled(false);
            AtomicBoolean stop       = new AtomicBoolean(false);
            AtomicBoolean checkPoint = new AtomicBoolean(true);

            int          numStallers  = AtLeast(1);
            int          numReleasers = AtLeast(1);
            int          numWaiters   = AtLeast(1);
            Synchronizer sync         = new Synchronizer(numStallers + numReleasers, numStallers + numReleasers + numWaiters);

            ThreadClass[]     threads    = new ThreadClass[numReleasers + numStallers + numWaiters];
            IList <Exception> exceptions = new ConcurrentList <Exception>(new List <Exception>());

            for (int i = 0; i < numReleasers; i++)
            {
                threads[i] = new Updater(stop, checkPoint, ctrl, sync, true, exceptions);
            }
            for (int i = numReleasers; i < numReleasers + numStallers; i++)
            {
                threads[i] = new Updater(stop, checkPoint, ctrl, sync, false, exceptions);
            }
            for (int i = numReleasers + numStallers; i < numReleasers + numStallers + numWaiters; i++)
            {
                threads[i] = new Waiter(stop, checkPoint, ctrl, sync, exceptions);
            }

            Start(threads);
            int   iters = AtLeast(10000);
            float checkPointProbability = TEST_NIGHTLY ? 0.5f : 0.1f;

            for (int i = 0; i < iters; i++)
            {
                if (checkPoint.Get())
                {
                    Assert.IsTrue(sync.UpdateJoin.@await(new TimeSpan(0, 0, 0, 10)), "timed out waiting for update threads - deadlock?");
                    if (exceptions.Count > 0)
                    {
                        foreach (Exception throwable in exceptions)
                        {
                            Console.WriteLine(throwable.ToString());
                            Console.Write(throwable.StackTrace);
                        }
                        Assert.Fail("got exceptions in threads");
                    }

                    if (ctrl.HasBlocked() && ctrl.Healthy)
                    {
                        AssertState(numReleasers, numStallers, numWaiters, threads, ctrl);
                    }

                    checkPoint.Set(false);
                    sync.Waiter.countDown();
                    sync.LeftCheckpoint.@await();
                }
                Assert.IsFalse(checkPoint.Get());
                Assert.AreEqual(0, sync.Waiter.Remaining);
                if (checkPointProbability >= (float)Random().NextDouble())
                {
                    sync.Reset(numStallers + numReleasers, numStallers + numReleasers + numWaiters);
                    checkPoint.Set(true);
                }
            }
            if (!checkPoint.Get())
            {
                sync.Reset(numStallers + numReleasers, numStallers + numReleasers + numWaiters);
                checkPoint.Set(true);
            }

            Assert.IsTrue(sync.UpdateJoin.@await(new TimeSpan(0, 0, 0, 10)));
            AssertState(numReleasers, numStallers, numWaiters, threads, ctrl);
            checkPoint.Set(false);
            stop.Set(true);
            sync.Waiter.countDown();
            sync.LeftCheckpoint.@await();

            for (int i = 0; i < threads.Length; i++)
            {
                ctrl.UpdateStalled(false);
                threads[i].Join(2000);
                if (threads[i].IsAlive && threads[i] is Waiter)
                {
                    if (threads[i].State == ThreadState.WaitSleepJoin)
                    {
                        Assert.Fail("waiter is not released - anyThreadsStalled: " + ctrl.AnyStalledThreads());
                    }
                }
            }
        }
        public void TestConcurrentAccess()
        {
            assertEquals(1, searchers.Count);
            using (IndexReader r = DirectoryReader.Open(userindex))
            {
                spellChecker.ClearIndex();
                assertEquals(2, searchers.Count);
                Addwords(r, spellChecker, "field1");
                assertEquals(3, searchers.Count);
                int num_field1 = this.NumDoc();
                Addwords(r, spellChecker, "field2");
                assertEquals(4, searchers.Count);
                int num_field2 = this.NumDoc();
                assertEquals(num_field2, num_field1 + 1);
                int numThreads = 5 + Random().nextInt(5);
                SpellCheckWorker[] workers = new SpellCheckWorker[numThreads];
                var stop = new AtomicBoolean(false);
                for (int i = 0; i < numThreads; i++)
                {
                    SpellCheckWorker spellCheckWorker = new SpellCheckWorker(this, r, stop);
                    workers[i] = spellCheckWorker;
                    spellCheckWorker.Start();
                }
                int iterations = 5 + Random().nextInt(5);
                for (int i = 0; i < iterations; i++)
                {
                    Thread.Sleep(100);
                    // concurrently reset the spell index
                    spellChecker.SpellIndex = (this.spellindex);
                    // for debug - prints the internal open searchers
                    // showSearchersOpen();
                }

                spellChecker.Dispose();
                stop.Set(true);

                // wait for 60 seconds - usually this is very fast but coverage runs could take quite long
                //executor.awaitTermination(60L, TimeUnit.SECONDS);
                foreach (SpellCheckWorker worker in workers)
                {
                    worker.Join((long)TimeSpan.FromSeconds(60).TotalMilliseconds);
                }

                for (int i = 0; i < workers.Length; i++)
                {
                    assertFalse(string.Format(CultureInfo.InvariantCulture, "worker thread {0} failed \n" + workers[i].Error, i), workers[i].Error != null);
                    assertTrue(string.Format(CultureInfo.InvariantCulture, "worker thread {0} is still running but should be terminated", i), workers[i].terminated);
                }
                // 4 searchers more than iterations
                // 1. at creation
                // 2. clearIndex()
                // 2. and 3. during addwords
                assertEquals(iterations + 4, searchers.Count);
                AssertSearchersClosed();
            }
        }
Beispiel #12
0
        public static void Main()
        {
            // Maximum number of message fragments to receive during a single 'poll' operation
            const int fragmentLimitCount = 10;

            // The channel (an endpoint identifier) to receive messages from
            const string channel = "udp://*****:*****@{offset:D})");

                // Received the intended message, time to exit the program
                running.Set(false);
            };

            // Create a context, needed for client connection to media driver
            // A separate media driver process need to run prior to running this application
            var ctx = new Aeron.Context();

            // Create an Aeron instance with client-provided context configuration, connect to the
            // media driver, and add a subscription for the given channel and stream using the supplied
            // dataHandler method, which will be called with new messages as they are received.
            // The Aeron and Subscription classes implement AutoCloseable, and will automatically
            // clean up resources when this try block is finished.
            using (var aeron = Aeron.Connect(ctx))
                using (var subscription = aeron.AddSubscription(channel, streamId))
                {
                    IIdleStrategy idleStrategy = new BusySpinIdleStrategy();

                    // Try to read the data from subscriber
                    while (running.Get())
                    {
                        // poll delivers messages to the dataHandler as they arrive
                        // and returns number of fragments read, or 0
                        // if no data is available.
                        var fragmentsRead = subscription.Poll(fragmentHandler, fragmentLimitCount);
                        // Give the IdleStrategy a chance to spin/yield/sleep to reduce CPU
                        // use if no messages were received.
                        idleStrategy.Idle(fragmentsRead);
                    }

                    Console.WriteLine("Press any key...");
                    Console.ReadLine();
                }
        }
Beispiel #13
0
        public static void Main()
        {
            ComputerSpecifications.Dump();


            var reporter            = new RateReporter(1000, PrintRate);
            var rateReporterHandler = SamplesUtil.RateReporterHandler(reporter);
            var context             = new Aeron.Context();

            var running = new AtomicBoolean(true);

            var reportThread    = new Thread(reporter.Run);
            var subscribeThread = new Thread(subscription => SamplesUtil.SubscriberLoop(rateReporterHandler, FragmentCountLimit, running)((Subscription)subscription));

            using (var aeron = Aeron.Connect(context))
                using (var publication = aeron.AddPublication(Channel, StreamID))
                    using (var subscription = aeron.AddSubscription(Channel, StreamID))
                        using (var buffer = new UnsafeBuffer(new byte[MessageLength]))
                        {
                            reportThread.Start();
                            subscribeThread.Start(subscription);

                            do
                            {
                                Console.WriteLine("Streaming {0:G} messages of size {1:G} bytes to {2} on stream Id {3}", NumberOfMessages, MessageLength, Channel, StreamID);

                                _printingActive = true;

                                long backPressureCount = 0;
                                for (long i = 0; i < NumberOfMessages; i++)
                                {
                                    buffer.PutLong(0, i);

                                    OfferIdleStrategy.Reset();
                                    while (publication.Offer(buffer, 0, buffer.Capacity) < 0)
                                    {
                                        OfferIdleStrategy.Idle();
                                        backPressureCount++;
                                    }
                                }

                                Console.WriteLine("Done streaming. backPressureRatio=" + (double)backPressureCount / NumberOfMessages);

                                if (0 < LingerTimeoutMs)
                                {
                                    Console.WriteLine("Lingering for " + LingerTimeoutMs + " milliseconds...");
                                    Thread.Sleep((int)LingerTimeoutMs);
                                }

                                _printingActive = false;
                            } while (Console.ReadLine() != "x");

                            reporter.Halt();
                            running.Set(false);

                            if (!subscribeThread.Join(5000))
                            {
                                Console.WriteLine("Warning: not all tasks completed promptly");
                            }
                        }
        }
Beispiel #14
0
 public void Close()
 {
     closed.Set(true);
 }
 public virtual void TestApplyDeletesOnFlush()
 {
     Directory dir = NewDirectory();
     // Cannot use RandomIndexWriter because we don't want to
     // ever call commit() for this test:
     AtomicInteger docsInSegment = new AtomicInteger();
     AtomicBoolean closing = new AtomicBoolean();
     AtomicBoolean sawAfterFlush = new AtomicBoolean();
     IndexWriter w = new IndexWriterAnonymousInnerClassHelper(this, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetRAMBufferSizeMB(0.5).SetMaxBufferedDocs(-1).SetMergePolicy(NoMergePolicy.NO_COMPOUND_FILES).SetReaderPooling(false), docsInSegment, closing, sawAfterFlush);
     int id = 0;
     while (true)
     {
         StringBuilder sb = new StringBuilder();
         for (int termIDX = 0; termIDX < 100; termIDX++)
         {
             sb.Append(' ').Append(TestUtil.RandomRealisticUnicodeString(Random()));
         }
         if (id == 500)
         {
             w.DeleteDocuments(new Term("id", "0"));
         }
         Document doc = new Document();
         doc.Add(NewStringField("id", "" + id, Field.Store.NO));
         doc.Add(NewTextField("body", sb.ToString(), Field.Store.NO));
         w.UpdateDocument(new Term("id", "" + id), doc);
         docsInSegment.IncrementAndGet();
         // TODO: fix this test
         if (SlowFileExists(dir, "_0_1.del") || SlowFileExists(dir, "_0_1.liv"))
         {
             if (VERBOSE)
             {
                 Console.WriteLine("TEST: deletes created @ id=" + id);
             }
             break;
         }
         id++;
     }
     closing.Set(true);
     Assert.IsTrue(sawAfterFlush.Get());
     w.Dispose();
     dir.Dispose();
 }
 private void Written() => _written.Set(true);
        private void AssertConsistentYoungestChild(FacetLabel abPath, int abOrd, int abYoungChildBase1, int abYoungChildBase2, int retry, int numCategories)
        {
            var indexDir = new SlowRAMDirectory(-1, null); // no slowness for intialization
            var tw = new DirectoryTaxonomyWriter(indexDir);
            tw.AddCategory(new FacetLabel("a", "0"));
            tw.AddCategory(abPath);
            tw.Commit();

            var tr = new DirectoryTaxonomyReader(indexDir);
            for (int i = 0; i < numCategories; i++)
            {
                var cp = new FacetLabel("a", "b", Convert.ToString(i));
                tw.AddCategory(cp);
                Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tr.GetOrdinal(cp), "Ordinal of " + cp + " must be invalid until Taxonomy Reader was refreshed");
            }
            tw.Dispose();

            var stop = new AtomicBoolean(false);
            Exception[] error = new Exception[] { null };
            int[] retrieval = new int[] { 0 };

            var thread = new ThreadAnonymousInnerClassHelper(this, abPath, abOrd, abYoungChildBase1, abYoungChildBase2, retry, tr, stop, error, retrieval);
            thread.Start();

            indexDir.SleepMillis = 1; // some delay for refresh
            var newTaxoReader = TaxonomyReader.OpenIfChanged(tr);
            if (newTaxoReader != null)
            {
                newTaxoReader.Dispose();
            }

            stop.Set(true);
            thread.Join();
            Assert.Null(error[0], "Unexpcted exception at retry " + retry + " retrieval " + retrieval[0] + ": \n" + stackTraceStr(error[0]));

            tr.Dispose();
        }
Beispiel #18
0
 internal void SetSecured()
 {
     secured.Set(true);
 }