use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestService method query_service_context_application_04.
@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_04() {
// This test requires us to set some timeouts 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 {
serviceContext.put(Service.queryTimeout, "10,20");
Query q = QueryFactory.create("ASK { }");
QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(SERVICE, q);
Assert.assertNotNull(engine);
// Check that no settings were changed
Assert.assertEquals(20, engine.getTimeout1());
Assert.assertEquals(10, engine.getTimeout2());
Assert.assertTrue(engine.getAllowCompression());
Assert.assertNull(engine.getClient());
} finally {
serviceContext.remove(Service.queryTimeout);
}
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestService method testStringTimeout.
@Test
public void testStringTimeout() {
BasicPattern basicPattern = new BasicPattern();
basicPattern.add(Triple.ANY);
Node serviceNode = NodeFactory.createURI(SERVICE);
OpService opService = new OpService(serviceNode, new OpBGP(basicPattern), false);
Context context = new Context();
ARQ.setNormalMode(context);
context.set(Service.queryTimeout, "10");
try {
Service.exec(opService, context);
Assert.fail("Expected QueryExceptionHTTP");
} catch (QueryExceptionHTTP expected) {
Throwable thrown = expected.getCause();
if (thrown instanceof SocketException || thrown instanceof ConnectTimeoutException) {
// expected
} else {
Assert.fail(String.format("Expected SocketException or ConnectTimeoutException, instead got: %s %s", thrown.getClass().getName(), thrown.getMessage()));
}
}
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestService method update_service_context_application_01.
@Test
public void update_service_context_application_01() {
// This test requires no service context to be set
@SuppressWarnings("unchecked") Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
if (serviceContextMap != null) {
serviceContextMap.remove(SERVICE);
}
UpdateRequest updates = UpdateFactory.create("CREATE GRAPH <http://example>");
UpdateProcessRemoteBase engine = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, SERVICE);
Assert.assertNotNull(engine);
// Check that no settings were changed
Assert.assertNull(engine.getClient());
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestService method query_service_context_application_01.
@Test
public void query_service_context_application_01() {
// This test requires no service context to be set
@SuppressWarnings("unchecked") Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
if (serviceContextMap != null) {
serviceContextMap.remove(SERVICE);
}
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.assertNull(engine.getClient());
}
use of org.apache.jena.sparql.util.Context in project jena by apache.
the class TestContext method testCxt6.
@Test
public void testCxt6() {
Context cxt = new Context();
cxt.setTrue(p1);
assertTrue("Not true", cxt.isTrue(p1));
String x = cxt.getAsString(p1);
assertEquals("Not string 'true'", "true", x);
}
Aggregations