コード例 #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);
        }
コード例 #2
0
        private void SparqlQueryAndUpdateThreadSafeEvaluationActual()
        {
            var query1  = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/1> { ?s ?p ?o } }";
            var query2  = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/2> { ?s ?p ?o } }";
            var query3  = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/3> { ?s ?p ?o } }";
            var update1 = "INSERT DATA { GRAPH <http://example.org/3> { <ex:subj> <ex:pred> <ex:obj> } }";

            var q1 = _parser.ParseFromString(query1);
            var q2 = _parser.ParseFromString(query2);
            var q3 = _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");

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

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

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

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

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

            var d  = new QueryWithGraphDelegate(QueryWithGraph);
            var d2 = new RunUpdateDelegate(RunUpdate);
            var t1 = Task.Factory.StartNew(() => QueryWithGraph(q1, processor));
            var t2 = Task.Factory.StartNew(() => QueryWithGraph(q2, processor));
            var t3 = Task.Factory.StartNew(() => QueryWithGraph(q3, processor));
            var t4 = Task.Factory.StartNew(() => RunUpdate(cmds, upProcessor));

            Task.WaitAll(t1, t2, t3, t4);
            var gQuery = t1.Result;
            var hQuery = t2.Result;
            var iQuery = t3.Result;

            Assert.Equal(g, gQuery);
            Assert.Equal(h, hQuery);
            if (iQuery.IsEmpty)
            {
                _output.WriteLine("Query 3 executed before the INSERT DATA command - running again to get the resulting graph");
                iQuery = QueryWithGraph(q3, processor);
            }
            else
            {
                _output.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);
        }
コード例 #3
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.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");
        }
コード例 #4
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.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");
        }
コード例 #5
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);
        }