use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestQueryIterSort method testTopNExhaustionClosesSource.
@Test
public void testTopNExhaustionClosesSource() {
iterator.setCallback(() -> {
});
long numItems = 3;
boolean distinct = false;
Context context = new Context();
ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
QueryIterTopN tn = new QueryIterTopN(iterator, comparator, numItems, distinct, ec);
while (tn.hasNext()) tn.next();
assertTrue(iterator.isClosed());
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TextDatasetFactory method create.
/** Create a text-indexed DatasetGraph, optionally allowing the text index to be closed if the DatasetGraph is */
public static DatasetGraph create(DatasetGraph dsg, TextIndex textIndex, boolean closeIndexOnDSGClose, TextDocProducer producer) {
if (producer == null)
producer = new TextDocProducerTriples(textIndex);
DatasetGraph dsgt = new DatasetGraphText(dsg, textIndex, producer, closeIndexOnDSGClose);
// Also set on dsg
Context c = dsgt.getContext();
c.set(TextQuery.textIndex, textIndex);
return dsgt;
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestService method query_service_context_application_02.
@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_02() {
// This test requires us to set some authentication credentials for the
// service
Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
if (serviceContextMap == null) {
ARQ.getContext().put(Service.serviceContext, new HashMap<String, Context>());
serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
}
if (serviceContextMap.get(SERVICE) == null) {
serviceContextMap.put(SERVICE, new Context(ARQ.getContext()));
}
Context serviceContext = serviceContextMap.get(SERVICE);
try {
HttpClient testClient = HttpClients.custom().build();
serviceContext.put(Service.queryClient, testClient);
Query q = QueryFactory.create("ASK { }");
QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(SERVICE, q);
Assert.assertNotNull(engine);
// Check that no settings were changed
Assert.assertEquals(-1, engine.getTimeout1());
Assert.assertEquals(-1, engine.getTimeout2());
Assert.assertTrue(engine.getAllowCompression());
Assert.assertEquals(testClient, engine.getClient());
} finally {
serviceContext.remove(Service.queryClient);
}
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestService method update_service_context_application_02.
@SuppressWarnings("unchecked")
@Test
public void update_service_context_application_02() {
// This test requires no service context to be set
Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
if (serviceContextMap == null) {
ARQ.getContext().put(Service.serviceContext, new HashMap<String, Context>());
serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
}
if (serviceContextMap.get(SERVICE) == null) {
serviceContextMap.put(SERVICE, new Context(ARQ.getContext()));
}
Context serviceContext = serviceContextMap.get(SERVICE);
try {
HttpClient testClient = HttpClients.custom().build();
serviceContext.put(Service.queryClient, testClient);
UpdateRequest updates = UpdateFactory.create("CREATE GRAPH <http://example>");
UpdateProcessRemoteBase engine = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, SERVICE);
Assert.assertNotNull(engine);
// Check that client settings were changed
Assert.assertEquals(testClient, engine.getClient());
} finally {
serviceContext.remove(Service.queryClient);
}
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestService method query_service_context_application_05.
@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_05() {
// This test requires us to set that GZip and Deflate are permitted
Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
if (serviceContextMap == null) {
ARQ.getContext().put(Service.serviceContext, new HashMap<String, Context>());
serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
}
if (serviceContextMap.get(SERVICE) == null) {
serviceContextMap.put(SERVICE, new Context(ARQ.getContext()));
}
Context serviceContext = serviceContextMap.get(SERVICE);
try {
serviceContext.put(Service.queryCompression, false);
Query q = QueryFactory.create("ASK { }");
QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(SERVICE, q);
Assert.assertNotNull(engine);
// Check that no settings were changed
Assert.assertEquals(-1, engine.getTimeout1());
Assert.assertEquals(-1, engine.getTimeout2());
Assert.assertFalse(engine.getAllowCompression());
Assert.assertNull(engine.getClient());
} finally {
serviceContext.remove(Service.queryCompression);
}
}
Aggregations