コード例 #1
0
        public void TestConsolidateStore()
        {
            // create a store
            var sid = CreateStore();

            // initialise and start the store worker
            var storeWorker = new StoreWorker(Configuration.StoreLocation, sid);

            storeWorker.Start();

            // execute transactions
            var data =
                @"<http://www.networkedplanet.com/people/gra> <http://www.networkedplanet.com/types/worksfor> <http://www.networkedplanet.com/companies/np>";

            var jobId = storeWorker.ProcessTransaction("", "", "", data, Constants.DefaultGraphUri, "nt");
            JobExecutionStatus jobStatus = storeWorker.GetJobStatus(jobId.ToString());

            while (jobStatus.JobStatus != JobStatus.CompletedOk)
            {
                Thread.Sleep(1000);
                jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            }

            jobId = Guid.NewGuid();
            storeWorker.QueueJob(new ConsolidateJob(jobId, null, storeWorker));
            jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            while (jobStatus.JobStatus != JobStatus.CompletedOk && jobStatus.JobStatus != JobStatus.TransactionError)
            {
                Thread.Sleep(1000);
                jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            }

            Assert.AreEqual(JobStatus.CompletedOk, jobStatus.JobStatus);

            // open store and find all triples
            var        results  = storeWorker.Query("select * where { ?a ?b ?c }", SparqlResultsFormat.Xml, new[] { Constants.DefaultGraphUri });
            var        doc      = XDocument.Parse(results);
            XNamespace sparqlNs = "http://www.w3.org/2005/sparql-results#";

            Assert.AreEqual(1, doc.Descendants(sparqlNs + "result").Count());

            data =
                @"<http://www.networkedplanet.com/people/gra> <http://www.networkedplanet.com/types/worksfor> <http://www.networkedplanet.com/companies/np>";

            jobId     = storeWorker.ProcessTransaction("", "", data, "", Constants.DefaultGraphUri, "nt");
            jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            while (jobStatus.JobStatus != JobStatus.CompletedOk)
            {
                Thread.Sleep(1000);
                jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            }

            Assert.AreEqual(JobStatus.CompletedOk, jobStatus.JobStatus);

            // consolidate again
            jobId = Guid.NewGuid();
            storeWorker.QueueJob(new ConsolidateJob(jobId, null, storeWorker));
            jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            while (jobStatus.JobStatus != JobStatus.CompletedOk && jobStatus.JobStatus != JobStatus.TransactionError)
            {
                Thread.Sleep(1000);
                jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            }

            Assert.AreEqual(JobStatus.CompletedOk, jobStatus.JobStatus);

            results = storeWorker.Query("select * where { ?a ?b ?c }", SparqlResultsFormat.Xml, new[] { Constants.DefaultGraphUri });
            doc     = XDocument.Parse(results);
            Assert.AreEqual(0, doc.Descendants(sparqlNs + "result").Count());
        }