示例#1
0
        private void SparqlQueryThreadSafeEvaluationActual()
        {
            String query1 = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/1> { ?s ?p ?o } }";
            String query2 = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/2> { ?s ?p ?o } }";

            SparqlQuery q1 = this._parser.ParseFromString(query1);
            SparqlQuery q2 = this._parser.ParseFromString(query2);

            Assert.False(q1.UsesDefaultDataset, "Query 1 should not be thread safe");
            Assert.False(q2.UsesDefaultDataset, "Query 2 should not be thread safe");

            InMemoryDataset dataset = new InMemoryDataset();
            Graph           g       = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = new Uri("http://example.org/1");
            Graph h = new Graph();

            h.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.LeviathanFunctionLibrary.ttl");
            h.BaseUri = new Uri("http://example.org/2");

            dataset.AddGraph(g);
            dataset.AddGraph(h);
            LeviathanQueryProcessor processor = new LeviathanQueryProcessor(dataset);

            QueryWithGraphDelegate d  = new QueryWithGraphDelegate(this.QueryWithGraph);
            IAsyncResult           r1 = d.BeginInvoke(q1, processor, null, null);
            IAsyncResult           r2 = d.BeginInvoke(q2, processor, null, null);

            WaitHandle.WaitAll(new WaitHandle[] { r1.AsyncWaitHandle, r2.AsyncWaitHandle });

            IGraph gQuery = d.EndInvoke(r1);

            Assert.Equal(g, gQuery);

            IGraph hQuery = d.EndInvoke(r2);

            Assert.Equal(h, hQuery);

            Assert.NotEqual(g, h);
        }
        private void SparqlQueryAndUpdateThreadSafeEvaluationActual()
        {
            String query1 = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/1> { ?s ?p ?o } }";
            String query2 = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/2> { ?s ?p ?o } }";
            String query3 = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/3> { ?s ?p ?o } }";
            String update1 = "INSERT DATA { GRAPH <http://example.org/3> { <ex:subj> <ex:pred> <ex:obj> } }";

            SparqlQuery q1 = this._parser.ParseFromString(query1);
            SparqlQuery q2 = this._parser.ParseFromString(query2);
            SparqlQuery q3 = this._parser.ParseFromString(query3);
            Assert.IsFalse(q1.UsesDefaultDataset, "Query 1 should not be thread safe");
            Assert.IsFalse(q2.UsesDefaultDataset, "Query 2 should not be thread safe");
            Assert.IsFalse(q3.UsesDefaultDataset, "Query 3 should not be thread safe");

            SparqlUpdateParser parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds = parser.ParseFromString(update1);

            InMemoryDataset dataset = new InMemoryDataset();
            Graph g = new Graph();
            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = new Uri("http://example.org/1");
            Graph h = new Graph();
            h.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.Functions.LeviathanFunctionLibrary.ttl");
            h.BaseUri = new Uri("http://example.org/2");
            Graph i = new Graph();
            i.BaseUri = new Uri("http://example.org/3");

            dataset.AddGraph(g);
            dataset.AddGraph(h);
            dataset.AddGraph(i);
            LeviathanQueryProcessor processor = new LeviathanQueryProcessor(dataset);
            LeviathanUpdateProcessor upProcessor = new LeviathanUpdateProcessor(dataset);

            QueryWithGraphDelegate d = new QueryWithGraphDelegate(this.QueryWithGraph);
            RunUpdateDelegate d2 = new RunUpdateDelegate(this.RunUpdate);
            IAsyncResult r1 = d.BeginInvoke(q1, processor, null, null);
            IAsyncResult r2 = d.BeginInvoke(q2, processor, null, null);
            IAsyncResult r3 = d.BeginInvoke(q3, processor, null, null);
            IAsyncResult r4 = d2.BeginInvoke(cmds, upProcessor, null, null);

            WaitHandle.WaitAll(new WaitHandle[] { r1.AsyncWaitHandle, r2.AsyncWaitHandle, r3.AsyncWaitHandle, r4.AsyncWaitHandle });

            IGraph gQuery = d.EndInvoke(r1);
            Assert.AreEqual(g, gQuery, "Query 1 Result not as expected");

            IGraph hQuery = d.EndInvoke(r2);
            Assert.AreEqual(h, hQuery, "Query 2 Result not as expected");

            IGraph iQuery = d.EndInvoke(r3);
            if (iQuery.IsEmpty)
            {
                Console.WriteLine("Query 3 executed before the INSERT DATA command - running again to get the resulting graph");
                iQuery = this.QueryWithGraph(q3, processor);
            }
            else
            {
                Console.WriteLine("Query 3 executed after the INSERT DATA command");
            }
            //Test iQuery against an empty Graph
            Assert.IsFalse(iQuery.IsEmpty, "Graph should not be empty as INSERT DATA should have inserted a Triple");
            Assert.AreNotEqual(new Graph(), iQuery, "Graphs should not be equal");

            Assert.AreNotEqual(g, h, "Graphs should not be different");
        }
        private void SparqlQueryThreadSafeEvaluationActual()
        {
            String query1 = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/1> { ?s ?p ?o } }";
            String query2 = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/2> { ?s ?p ?o } }";

            SparqlQuery q1 = this._parser.ParseFromString(query1);
            SparqlQuery q2 = this._parser.ParseFromString(query2);
            Assert.IsFalse(q1.UsesDefaultDataset, "Query 1 should not be thread safe");
            Assert.IsFalse(q2.UsesDefaultDataset, "Query 2 should not be thread safe");

            InMemoryDataset dataset = new InMemoryDataset();
            Graph g = new Graph();
            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = new Uri("http://example.org/1");
            Graph h = new Graph();
            h.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.Functions.LeviathanFunctionLibrary.ttl");
            h.BaseUri = new Uri("http://example.org/2");

            dataset.AddGraph(g);
            dataset.AddGraph(h);
            LeviathanQueryProcessor processor = new LeviathanQueryProcessor(dataset);

            QueryWithGraphDelegate d = new QueryWithGraphDelegate(this.QueryWithGraph);
            IAsyncResult r1 = d.BeginInvoke(q1, processor, null, null);
            IAsyncResult r2 = d.BeginInvoke(q2, processor, null, null);

            WaitHandle.WaitAll(new WaitHandle[] { r1.AsyncWaitHandle, r2.AsyncWaitHandle });

            IGraph gQuery = d.EndInvoke(r1);
            Assert.AreEqual(g, gQuery, "Query 1 Result not as expected");

            IGraph hQuery = d.EndInvoke(r2);
            Assert.AreEqual(h, hQuery, "Query 2 Result not as expected");

            Assert.AreNotEqual(g, h, "Graphs should not be different");
        }
示例#4
0
        private void SparqlQueryAndUpdateThreadSafeEvaluationActual()
        {
            String query1  = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/1> { ?s ?p ?o } }";
            String query2  = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/2> { ?s ?p ?o } }";
            String query3  = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/3> { ?s ?p ?o } }";
            String update1 = "INSERT DATA { GRAPH <http://example.org/3> { <ex:subj> <ex:pred> <ex:obj> } }";

            SparqlQuery q1 = this._parser.ParseFromString(query1);
            SparqlQuery q2 = this._parser.ParseFromString(query2);
            SparqlQuery q3 = this._parser.ParseFromString(query3);

            Assert.False(q1.UsesDefaultDataset, "Query 1 should not be thread safe");
            Assert.False(q2.UsesDefaultDataset, "Query 2 should not be thread safe");
            Assert.False(q3.UsesDefaultDataset, "Query 3 should not be thread safe");

            SparqlUpdateParser     parser = new SparqlUpdateParser();
            SparqlUpdateCommandSet cmds   = parser.ParseFromString(update1);

            InMemoryDataset dataset = new InMemoryDataset();
            Graph           g       = new Graph();

            g.LoadFromEmbeddedResource("VDS.RDF.Configuration.configuration.ttl");
            g.BaseUri = new Uri("http://example.org/1");
            Graph h = new Graph();

            h.LoadFromEmbeddedResource("VDS.RDF.Query.Expressions.LeviathanFunctionLibrary.ttl");
            h.BaseUri = new Uri("http://example.org/2");
            Graph i = new Graph();

            i.BaseUri = new Uri("http://example.org/3");

            dataset.AddGraph(g);
            dataset.AddGraph(h);
            dataset.AddGraph(i);
            LeviathanQueryProcessor  processor   = new LeviathanQueryProcessor(dataset);
            LeviathanUpdateProcessor upProcessor = new LeviathanUpdateProcessor(dataset);

            QueryWithGraphDelegate d  = new QueryWithGraphDelegate(this.QueryWithGraph);
            RunUpdateDelegate      d2 = new RunUpdateDelegate(this.RunUpdate);
            IAsyncResult           r1 = d.BeginInvoke(q1, processor, null, null);
            IAsyncResult           r2 = d.BeginInvoke(q2, processor, null, null);
            IAsyncResult           r3 = d.BeginInvoke(q3, processor, null, null);
            IAsyncResult           r4 = d2.BeginInvoke(cmds, upProcessor, null, null);

            WaitHandle.WaitAll(new WaitHandle[] { r1.AsyncWaitHandle, r2.AsyncWaitHandle, r3.AsyncWaitHandle, r4.AsyncWaitHandle });

            IGraph gQuery = d.EndInvoke(r1);

            Assert.Equal(g, gQuery);

            IGraph hQuery = d.EndInvoke(r2);

            Assert.Equal(h, hQuery);

            IGraph iQuery = d.EndInvoke(r3);

            if (iQuery.IsEmpty)
            {
                Console.WriteLine("Query 3 executed before the INSERT DATA command - running again to get the resulting graph");
                iQuery = this.QueryWithGraph(q3, processor);
            }
            else
            {
                Console.WriteLine("Query 3 executed after the INSERT DATA command");
            }
            //Test iQuery against an empty Graph
            Assert.False(iQuery.IsEmpty, "Graph should not be empty as INSERT DATA should have inserted a Triple");
            Assert.NotEqual(new Graph(), iQuery);

            Assert.NotEqual(g, h);
        }