Esempio n. 1
0
        public Benchmark(TextReader algReader)
        {
            // prepare run data
            try
            {
                runData = new PerfRunData(new Config(algReader));
            }
            catch (Exception e)
            {
                //e.printStackTrace();
                throw new Exception("Error: cannot init PerfRunData!", e);
            }

            // parse algorithm
            try
            {
                algorithm = new Algorithm(runData);
            }
            catch (Exception e)
            {
                throw new Exception("Error: cannot understand algorithm!", e);
            }
        }
Esempio n. 2
0
        public void TestParseExamples()
        {
            // LUCENENET specific
            // Rather than relying on a file path somewhere, we store the
            // files zipped in an embedded resource and unzip them to a
            // known temp directory for the test.
            DirectoryInfo examplesDir = CreateTempDir("test-parse-examples");

            using (var stream = GetType().getResourceAsStream("conf.zip"))
            {
                TestUtil.Unzip(stream, examplesDir);
            }

            // hackedy-hack-hack
            bool foundFiles = false;

            foreach (FileInfo algFile in examplesDir.EnumerateFiles("*.alg"))
            {
                try
                {
                    Config config        = new Config(new StreamReader(new FileStream(algFile.FullName, FileMode.Open, FileAccess.Read), Encoding.UTF8));
                    String contentSource = config.Get("content.source", null);
                    if (contentSource != null)
                    {
                        if (Type.GetType(contentSource) == null)
                        {
                            throw new TypeLoadException(contentSource);
                        }
                    }
                    config.Set("work.dir", CreateTempDir(LuceneTestCase.TestClass.Name).FullName);
                    config.Set("content.source", typeof(MockContentSource).AssemblyQualifiedName);
                    String dir = config.Get("content.source", null);
                    if (dir != null)
                    {
                        if (Type.GetType(dir) == null)
                        {
                            throw new TypeLoadException(dir);
                        }
                    }
                    config.Set("directory", typeof(RAMDirectory).AssemblyQualifiedName);
                    if (config.Get("line.file.out", null) != null)
                    {
                        config.Set("line.file.out", CreateTempFile("linefile", ".txt").FullName);
                    }
                    string queryMaker = config.Get("query.maker", null);
                    if (queryMaker != null)
                    {
                        if (Type.GetType(queryMaker) == null)
                        {
                            throw new TypeLoadException(queryMaker);
                        }

                        config.Set("query.maker", typeof(MockQueryMaker).AssemblyQualifiedName);
                    }
                    PerfRunData data = new PerfRunData(config);
                    new Algorithm(data);
                }
                catch (Exception t)
                {
                    throw new Exception("Could not parse sample file: " + algFile, t);
                }
                foundFiles = true;
            }
            if (!foundFiles)
            {
                fail("could not find any .alg files!");
            }
        }