/** * Runs two queries in parallel. * * @throws IOException I/O exception */ @Test public void queryParallel() throws IOException { final Query query1 = session.query("1 to 2"); final Query query2 = session.query("reverse(3 to 4)"); assertEqual("1", query1.next()); assertEqual("4", query2.next()); assertEqual("2", query1.next()); assertEqual("3", query2.next()); assertNull(query1.next()); assertNull(query2.next()); query1.close(); query2.close(); }
/** * Runs a query with an external variable declaration. * * @throws IOException I/O exception */ @Test public void queryBindEmptySequence() throws IOException { final Query query = session.query("declare variable $a external; $a"); query.bind("a", "()", "empty-sequence()"); assertNull(query.next()); query.close(); }
/** * Runs a query, omitting more(). * * @throws IOException I/O exception */ @Test public void queryNoMore() throws IOException { final Query query = session.query("1 to 2"); assertEqual("1", query.next()); assertEqual("2", query.next()); assertNull(query.next()); query.close(); }
/** * Queries empty content. * * @throws IOException I/O exception */ @Test public void queryEmptyString() throws IOException { final Query q = session.query("'',1"); assertTrue(q.more()); assertEqual("", q.next()); assertTrue(q.more()); assertEqual("1", q.next()); assertNull(q.next()); }
/** Test for method {@link IndexCache#delete(byte[])}. */ @Test public void testDelete() { final byte[] key = token("keyDelete"); final int size = 10; final long pointer = 12L; cache.add(key, size, pointer); cache.delete(key); assertNull(cache.get(key)); }
/** Test for method {@link IndexCache#get(byte[])}. */ @Test public void testGetNotExisting() { for (int i = 0; i < 4000; ++i) { final byte[] key = token("keyAdd" + i); final long pointer = i + 5000L; cache.add(key, i, pointer); assertCacheEntry(key, i, pointer); } assertNull(cache.get(token("keyAdd" + 4000))); }
/** * Queries empty content. * * @throws IOException I/O exception */ @Test public void queryEmptyBinary() throws IOException { session.execute("create db " + NAME); session.store("X", new ArrayInput("")); assertEqual("", session.execute("xquery " + RAW + _DB_RETRIEVE.args(NAME, "X"))); assertEqual("", session.query(RAW + _DB_RETRIEVE.args(NAME, "X")).execute()); final Query q = session.query(RAW + _DB_RETRIEVE.args(NAME, "X")); assertTrue(q.more()); assertEqual("", q.next()); assertNull(q.next()); }
/** * Queries binary content (works only if output stream is specified). * * @throws IOException I/O exception */ @Test public void queryBinary() throws IOException { if (out == null) return; session.execute("create db " + NAME); final byte[] tmp = {0, 1, 2, 127, 0, -1, -2, -128}; session.store("X", new ArrayInput(tmp)); final String retr = _DB_RETRIEVE.args(NAME, "X"); // check command session.execute("xquery " + RAW + retr + ',' + retr); assertTrue(eq(out.toArray(), concat(tmp, tmp))); out.reset(); // check query execution session.query(RAW + retr + ',' + retr).execute(); assertTrue(eq(out.toArray(), concat(tmp, tmp))); out.reset(); // check iterator final Query q = session.query(RAW + retr + ',' + retr); q.next(); assertTrue(eq(out.toArray(), tmp)); out.reset(); q.next(); assertTrue(eq(out.toArray(), tmp)); assertNull(q.next()); }