/** * Return a copy of this context. Modifications of the copy do not affect * the original context. */ public Context copy() { return new Context(this) ; }
public SDBRequest(Store store, Query query, Context context) { super(store) ; this.query = query ; this.prefixMapping = null ; if ( query != null ) prefixMapping = query.getPrefixMapping() ; if ( context == null ) context = SDB.getContext() ; this.context = new Context(context) ; }
@Test public void testCxt1() { Context cxt = new Context() ; }
private static Context context(StreamManager streamMgr) { Context context = new Context() ; context.put(SysRIOT.sysStreamManager, streamMgr) ; return context ; }
@Override protected QueryIterator createQueryIter(List<Binding> data) { QueryIterator qIter = new QueryIterPlainWrapper(data.iterator()) ; return new QueryIterDistinctMem(qIter, new ExecutionContext(new Context(), null, null, null)) ; }
private static Plan makePlan(Query query, DatasetGraph dataset, Binding input, Context context) { if ( context == null ) context = new Context(ARQ.getContext()) ; if ( input == null ) input = BindingRoot.create() ; QueryEngineFactory f = findFactory(query, dataset, context) ; if ( f == null ) return null ; return f.create(query, dataset, input, context) ; } // ---------------- Internal routines
@Override protected QueryIterator createQueryIter(List<Binding> data) { QueryIterator qIter = new QueryIterPlainWrapper(data.iterator()) ; Context cxt = new Context() ; cxt.set(ARQ.spillToDiskThreshold, 2L); return new QueryIterDistinct(qIter, new ExecutionContext(cxt, null, null, null)) ; }
@Test public void testCxt3() { Context cxt = new Context() ; cxt.set(p1, "v") ; cxt.setIfUndef(p1, "w") ; Object v = cxt.get(p1) ; assertSame("Not as first set", "v", v) ; }
@Test(expected=ARQException.class) public void testCxt9() { Context cxt = new Context() ; assertEquals(-1L, cxt.getLong(p1, -1L)) ; cxt.set(p1, 1L) ; // Bad. Long for Integer. cxt.getInt(p1, -2) ; } }
@Test public void testCxt5() { Context cxt = new Context() ; cxt.set(p1, "false") ; assertTrue("Not false", cxt.isFalse(p1)) ; assertTrue("Not false or undef", cxt.isFalseOrUndef(p1)) ; }
@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) ; }
@Test public void testCxt7() { Context cxt = new Context() ; assertEquals(-1, cxt.getInt(p1, -1)) ; cxt.set(p1, 1) ; int x = cxt.getInt(p1, -1) ; assertEquals(1, x) ; }
@Test public void testCxt8() { Context cxt = new Context() ; assertEquals(-1L, cxt.getLong(p1, -1L)) ; cxt.set(p1, 1L) ; long x = cxt.getLong(p1, -2L) ; assertEquals(1L, x) ; }
@Test public void testCloseClosesSourceIterator() { Context context = new Context() ; ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null); QueryIterSort qis = new QueryIterSort(iterator, comparator, ec); qis.close(); assertTrue("source iterator should have been closed", iterator.isClosed()); }
@Test public void testTopNCloseClosesSource() { 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); tn.close(); assertTrue(iterator.isClosed()); }
@Test public void testCancelClosesSourceIterator() { Context context = new Context() ; ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null); QueryIterSort qis = new QueryIterSort(iterator, comparator, ec); try { while (qis.hasNext()) qis.next(); fail("query should have been cancelled by trigger"); } catch (QueryCancelledException q) { assertTrue("source iterator should have been closed", iterator.isClosed()); } }
@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()); }
@Test public void testCxt2() { Context cxt = new Context() ; assertTrue("Defined in empty context", !cxt.isDefined(p1)) ; cxt.set(p1, "v") ; assertTrue("Not defined after .set", cxt.isDefined(p1)) ; Object v = cxt.get(p1) ; assertSame("Not the same", "v", v) ; }
@Test public void testExhaustionClosesSourceIterator() { iterator.setCallback(() -> {}); Context context = new Context() ; ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null); QueryIterSort qis = new QueryIterSort(iterator, comparator, ec); while (qis.hasNext()) qis.next(); assertTrue("source iterator should have been closed", iterator.isClosed()); }
@Test public void testCxt4() { Context cxt = new Context() ; cxt.set(p1, "true") ; assertTrue("Not true", cxt.isTrue(p1)) ; assertTrue("Not true or undef", cxt.isTrueOrUndef(p1)) ; assertTrue("Not false or undef", cxt.isFalseOrUndef(p2)) ; assertTrue("False when undef", !cxt.isFalse(p2)) ; }