예제 #1
0
        public void TestDocMakerLeak()
        {
            // DocMaker did not close its ContentSource if resetInputs was called twice,
            // leading to a file handle leak.
            FileInfo   f  = new FileInfo(Path.Combine(getWorkDir().FullName, "docMakerLeak.txt"));
            TextWriter ps = new StreamWriter(new FileStream(f.FullName, FileMode.Create, FileAccess.Write), Encoding.UTF8);

            ps.WriteLine("one title\t" + Time.CurrentTimeMilliseconds() + "\tsome content");
            ps.Dispose();

            Dictionary <string, string> props = new Dictionary <string, string>();

            props["docs.file"] = f.FullName;
            props["content.source.forever"] = "false";
            Config config = new Config(props);

            ContentSource source = new LineDocSource();

            source.SetConfig(config);

            DocMaker dm = new DocMaker();

            dm.SetConfig(config, source);
            dm.ResetInputs();
            dm.ResetInputs();
            dm.Dispose();
        }
예제 #2
0
        protected override Query[] PrepareQueries()
        {
            int    maxQueries = m_config.Get("query.file.maxQueries", 1000);
            Config srcConfig  = new Config(new Dictionary <string, string>());

            srcConfig.Set("docs.file", m_config.Get("query.file", null));
            srcConfig.Set("line.parser", m_config.Get("query.file.line.parser", null));
            srcConfig.Set("content.source.forever", "false");

            JCG.List <Query> queries = new JCG.List <Query>();
            LineDocSource    src     = new LineDocSource();

            try
            {
                src.SetConfig(srcConfig);
                src.ResetInputs();
                DocData docData = new DocData();
                for (int i = 0; i < maxQueries; i++)
                {
                    docData = src.GetNextDocData(docData);
                    IShape shape = SpatialDocMaker.MakeShapeFromString(m_strategy, docData.Name, docData.Body);
                    if (shape != null)
                    {
                        shape = m_shapeConverter.Convert(shape);
                        queries.Add(MakeQueryFromShape(shape));
                    }
                    else
                    {
                        i--;//skip
                    }
                }
            }
#pragma warning disable 168
            catch (NoMoreDataException e)
#pragma warning restore 168
            {
                //all-done
            }
            finally
            {
                src.Dispose();
            }
            return(queries.ToArray());
        }