public override void Run()
            {
//#if FEATURE_THREAD_INTERRUPT
//                try
//                {
//#endif
                latch.Wait();
//#if FEATURE_THREAD_INTERRUPT
//                }
//                catch (ThreadInterruptedException e) // LUCENENET NOTE: Senseless to catch and rethrow the same exception type
//                {
//                    throw new ThreadInterruptedException("Thread Interrupted Exception", e);
//                }
//#endif

                int i = 0;

                while ((i = index.GetAndIncrement()) < ids.Length)
                {
                    Term term = new Term("id", ids[i].ToString());
                    queue.Add(term, slice);
                    Assert.IsTrue(slice.IsTailItem(term));
                    slice.Apply(deletes, BufferedUpdates.MAX_INT32);
                }
            }
示例#2
0
            public override void Run()
            {
//#if !NETSTANDARD1_6
//                try
//                {
//#endif
                Latch.Wait();
//#if !NETSTANDARD1_6
//                }
//                catch (ThreadInterruptedException e) // LUCENENET NOTE: Senseless to catch and rethrow the same exception type
//                {
//                    throw new ThreadInterruptedException("Thread Interrupted Exception", e);
//                }
//#endif

                int i = 0;

                while ((i = Index.GetAndIncrement()) < Ids.Length)
                {
                    Term term = new Term("id", Ids[i].ToString());
                    Queue.Add(term, Slice);
                    Assert.IsTrue(Slice.IsTailItem(term));
                    Slice.Apply(Deletes, BufferedUpdates.MAX_INT32);
                }
            }
示例#3
0
        /// <summary>
        /// Note: Document instance is re-used per-thread </summary>
        public virtual Document NextDoc()
        {
            string line;

            UninterruptableMonitor.Enter(syncLock);
            try
            {
                line = reader.ReadLine();
                if (line == null)
                {
                    // Always rewind at end:
                    if (LuceneTestCase.Verbose)
                    {
                        Console.WriteLine("TEST: LineFileDocs: now rewind file...");
                    }
                    Close();
                    Open(null);
                    line = reader.ReadLine();
                }
            }
            finally
            {
                UninterruptableMonitor.Exit(syncLock);
            }

            DocState docState = threadDocs.Value;

            if (docState == null)
            {
                docState         = new DocState(useDocValues);
                threadDocs.Value = docState;
            }

            int spot = line.IndexOf(SEP);

            if (spot == -1)
            {
                throw RuntimeException.Create("line: [" + line + "] is in an invalid format !");
            }
            int spot2 = line.IndexOf(SEP, 1 + spot);

            if (spot2 == -1)
            {
                throw RuntimeException.Create("line: [" + line + "] is in an invalid format !");
            }

            docState.Body.SetStringValue(line.Substring(1 + spot2, line.Length - (1 + spot2)));
            string title = line.Substring(0, spot);

            docState.Title.SetStringValue(title);
            if (docState.TitleDV != null)
            {
                docState.TitleDV.SetBytesValue(new BytesRef(title));
            }
            docState.TitleTokenized.SetStringValue(title);
            docState.Date.SetStringValue(line.Substring(1 + spot, spot2 - (1 + spot)));
            docState.Id.SetStringValue(Convert.ToString(id.GetAndIncrement(), CultureInfo.InvariantCulture));
            return(docState.Doc);
        }
示例#4
0
        /// <summary>
        /// Note: Document instance is re-used per-thread </summary>
        public virtual Document NextDoc()
        {
            string line;

            lock (this)
            {
                line = Reader.ReadLine();
                if (line == null)
                {
                    // Always rewind at end:
                    if (LuceneTestCase.VERBOSE)
                    {
                        Console.WriteLine("TEST: LineFileDocs: now rewind file...");
                    }
                    Dispose();
                    Open(null);
                    line = Reader.ReadLine();
                }
            }

            DocState docState = ThreadDocs.Value;

            if (docState == null)
            {
                docState         = new DocState(UseDocValues);
                ThreadDocs.Value = docState;
            }

            int spot = line.IndexOf(SEP);

            if (spot == -1)
            {
                throw new Exception("line: [" + line + "] is in an invalid format !");
            }
            int spot2 = line.IndexOf(SEP, 1 + spot);

            if (spot2 == -1)
            {
                throw new Exception("line: [" + line + "] is in an invalid format !");
            }

            docState.Body.SetStringValue(line.Substring(1 + spot2, line.Length - (1 + spot2)));
            string title = line.Substring(0, spot);

            docState.Title.SetStringValue(title);
            if (docState.TitleDV != null)
            {
                docState.TitleDV.SetBytesValue(new BytesRef(title));
            }
            docState.TitleTokenized.SetStringValue(title);
            docState.Date.SetStringValue(line.Substring(1 + spot, spot2 - (1 + spot)));
            docState.Id.SetStringValue(Convert.ToString(Id.GetAndIncrement(), CultureInfo.InvariantCulture));
            return(docState.Doc);
        }
示例#5
0
            public void OneTimeSetUpWrapper()
            {
                //var fixture = TestExecutionContext.CurrentContext.CurrentTest;
                if (stackCount.GetAndIncrement() == 0)
                {
                    // Set up for assembly

                    // This is where a global application setup can be done that includes a randomized context,
                    // therefore LuceneTestCase.Random calls are allowed here and are repeatable.
                    initializer.DoTestFrameworkSetUp();
                }
            }
示例#6
0
            public override void Run()
            {
                latch.Wait();
                // LUCENENET NOTE: No need to catch and rethrow same excepton type ThreadInterruptedException

                int i = 0;

                while ((i = index.GetAndIncrement()) < ids.Length)
                {
                    Term term = new Term("id", ids[i].ToString());
                    queue.Add(term, slice);
                    Assert.IsTrue(slice.IsTailItem(term));
                    slice.Apply(deletes, BufferedUpdates.MAX_INT32);
                }
            }
示例#7
0
            public override void Run()
            {
                try
                {
                    latch.Wait();
                }
                catch (Exception ie) when(ie.IsInterruptedException())
                {
                    throw new Util.ThreadInterruptedException(ie);
                }

                int i = 0;

                while ((i = index.GetAndIncrement()) < ids.Length)
                {
                    Term term = new Term("id", ids[i].ToString());
                    queue.Add(term, slice);
                    Assert.IsTrue(slice.IsTailItem(term));
                    slice.Apply(deletes, BufferedUpdates.MAX_INT32);
                }
            }
            public override void Run()
            {
#if !NETSTANDARD
                try
                {
#endif
                Latch.Wait();
#if !NETSTANDARD
            }
            catch (ThreadInterruptedException e)
            {
                throw new ThreadInterruptedException("Thread Interrupted Exception", e);
            }
#endif

                int i = 0;
                while ((i = Index.GetAndIncrement()) < Ids.Length)
                {
                    Term term = new Term("id", Ids[i].ToString());
                    Queue.Add(term, Slice);
                    Assert.IsTrue(Slice.IsTailItem(term));
                    Slice.Apply(Deletes, BufferedUpdates.MAX_INT32);
                }
            }
示例#9
0
        // create a doc
        // use only part of the body, modify it to keep the rest (or use all if size==0).
        // reset the docdata properties so they are not added more than once.
        private Document CreateDocument(DocData docData, int size, int cnt)
        {
            DocState ds  = GetDocState();
            Document doc = m_reuseFields ? ds.doc : new Document();

            doc.Fields.Clear();

            // Set ID_FIELD
            FieldType ft = new FieldType(m_valType);

            ft.IsIndexed = true;

            Field idField = ds.GetField(ID_FIELD, ft);
            int   id;

            if (r != null)
            {
                id = r.Next(updateDocIDLimit);
            }
            else
            {
                id = docData.ID;
                if (id == -1)
                {
                    id = numDocsCreated.GetAndIncrement();
                }
            }
            idField.SetStringValue(Convert.ToString(id, CultureInfo.InvariantCulture));
            doc.Add(idField);

            // Set NAME_FIELD
            string name = docData.Name;

            if (name == null)
            {
                name = "";
            }
            name = cnt < 0 ? name : name + "_" + cnt;
            Field nameField = ds.GetField(NAME_FIELD, m_valType);

            nameField.SetStringValue(name);
            doc.Add(nameField);

            // Set DATE_FIELD
            DateTime?date       = null;
            string   dateString = docData.Date;

            if (dateString != null)
            {
                // LUCENENET: TryParseExact needs a non-nullable DateTime to work.
                DateTime temp;
                if (DateTime.TryParseExact(dateString, new string[] {
                    // Original format from Java
                    "dd-MMM-yyyy HH:mm:ss",
                    // Actual format from the test files...
                    "yyyyMMddHHmmss"
                }, CultureInfo.InvariantCulture, DateTimeStyles.None, out temp))
                {
                    date = temp;
                }
                // LUCENENET: Hail Mary in case the formats above are not adequate
                else if (DateTime.TryParse(dateString, CultureInfo.InvariantCulture, DateTimeStyles.None, out temp))
                {
                    date = temp;
                }
            }
            else
            {
                dateString = "";
            }
            Field dateStringField = ds.GetField(DATE_FIELD, m_valType);

            dateStringField.SetStringValue(dateString);
            doc.Add(dateStringField);

            if (date == null)
            {
                // just set to right now
                date = DateTime.Now;
            }

            Field dateField = ds.GetNumericField(DATE_MSEC_FIELD, NumericType.INT64);

            dateField.SetInt64Value(date.Value.Ticks);
            doc.Add(dateField);

            //util.cal.setTime(date);
            //int sec = util.cal.get(Calendar.HOUR_OF_DAY) * 3600 + util.cal.get(Calendar.MINUTE) * 60 + util.cal.get(Calendar.SECOND);
            int sec = Convert.ToInt32(date.Value.ToUniversalTime().TimeOfDay.TotalSeconds);

            Field timeSecField = ds.GetNumericField(TIME_SEC_FIELD, NumericType.INT32);

            timeSecField.SetInt32Value(sec);
            doc.Add(timeSecField);

            // Set TITLE_FIELD
            string title      = docData.Title;
            Field  titleField = ds.GetField(TITLE_FIELD, m_valType);

            titleField.SetStringValue(title == null ? "" : title);
            doc.Add(titleField);

            string body = docData.Body;

            if (body != null && body.Length > 0)
            {
                string bdy;
                if (size <= 0 || size >= body.Length)
                {
                    bdy          = body; // use all
                    docData.Body = "";   // nothing left
                }
                else
                {
                    // attempt not to break words - if whitespace found within next 20 chars...
                    for (int n = size - 1; n < size + 20 && n < body.Length; n++)
                    {
                        if (char.IsWhiteSpace(body[n]))
                        {
                            size = n;
                            break;
                        }
                    }
                    bdy          = body.Substring(0, size - 0); // use part
                    docData.Body = body.Substring(size);        // some left
                }
                Field bodyField = ds.GetField(BODY_FIELD, m_bodyValType);
                bodyField.SetStringValue(bdy);
                doc.Add(bodyField);

                if (storeBytes)
                {
                    Field bytesField = ds.GetField(BYTES_FIELD, StringField.TYPE_STORED);
                    bytesField.SetBytesValue(Encoding.UTF8.GetBytes(bdy));
                    doc.Add(bytesField);
                }
            }

            if (m_indexProperties)
            {
                var props = docData.Props;
                if (props != null)
                {
                    foreach (var entry in props)
                    {
                        Field f = ds.GetField((string)entry.Key, m_valType);
                        f.SetStringValue((string)entry.Value);
                        doc.Add(f);
                    }
                    docData.Props = null;
                }
            }

            //System.out.println("============== Created doc "+numDocsCreated+" :\n"+doc+"\n==========");
            return(doc);
        }
示例#10
0
 public TextWriterInfoStream(TextWriter stream)
     : this(stream, MESSAGE_ID.GetAndIncrement())
 {
 }