/** * Test metrics for Sql queries. */ @Test public void testTextQueryMetrics() { TextQuery qry = new TextQuery<>("String", "1"); checkNoQueryMetrics(qry); }
@Override public void applyx() throws IgniteCheckedException { while (!done.get()) { QueryCursor<Cache.Entry<UUID, PersonObj>> master = cache0.query(new TextQuery(PersonObj.class, "Master")); Collection<Cache.Entry<UUID, PersonObj>> entries = master.getAll(); checkResult(entries, p1, p2); long cnt = luceneCnt.incrementAndGet(); if (cnt % logMod == 0) info("Executed LUCENE queries: " + cnt); } } }, luceneThreads, "LUCENE-THREAD");
/** * Reads text query. * * @param reader Binary reader. * @return Query. */ private Query readTextQuery(BinaryRawReader reader) { boolean loc = reader.readBoolean(); String txt = reader.readString(); String typ = reader.readString(); final int pageSize = reader.readInt(); return new TextQuery(typ, txt).setPageSize(pageSize).setLocal(loc); }
/** * Test metrics for Sql queries. * * @throws Exception In case of error. */ @Test public void testTextQueryHistoryNotFullyFetched() throws Exception { TextQuery qry = new TextQuery<>("String", "1"); qry.setPageSize(10); checkQueryNotFullyFetchedMetrics(qry, true); }
@Override public Object call() throws IgniteCheckedException { return jcache().query(new TextQuery<>(String.class, "text")).getAll(); } }, "Indexing is disabled for cache: default");
/** * Clear cache with check. */ private static void clearCache(IgniteEx ignite) { IgniteCache<Integer, Person> cache = ignite.cache(PERSON_CACHE); cache.clear(); List all = cache.query(new TextQuery<>(Person.class, "1*")).getAll(); assertTrue(all.isEmpty()); }
/** * @throws Exception If failed. */ @Test public void testFullTextQuery() throws Exception { IgniteCache<Integer, String> cache = grid().getOrCreateCache(String.class.getSimpleName()); try { cache.query(new TextQuery<Integer, String>(String.class, "text")).getAll(); assert false; } catch (CacheException e) { X.println("Caught expected exception: " + e); } catch (Exception ignored) { assert false; } }
/** * Test metrics for Sql queries. * * @throws Exception In case of error. */ @Test public void testTextQueryMetrics() throws Exception { IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A"); TextQuery qry = new TextQuery<>("String", "1"); checkQueryMetrics(cache, qry); }
/** * Test metrics for Sql queries. * * @throws Exception In case of error. */ @Test public void testTextQueryMetrics() throws Exception { IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A"); TextQuery qry = new TextQuery<>("String", "1"); checkQueryMetrics(cache, qry); }
/** * Test metrics for failed Scan queries. * * @throws Exception In case of error. */ @Test public void testTextQueryFailedMetrics() throws Exception { IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A"); TextQuery qry = new TextQuery<>("Unknown", "zzz"); checkQueryFailedMetrics(cache, qry); }
/** * Test metrics for failed Scan queries. * * @throws Exception In case of error. */ @Test public void testTextQueryFailedMetrics() throws Exception { IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A"); TextQuery qry = new TextQuery<>("Unknown", "zzz"); checkQueryFailedMetrics(cache, qry); }
/** * @throws Exception If failed. */ @Test public void testFullTextLocalQuery() throws Exception { IgniteCache<Integer, String> cache = grid().getOrCreateCache(String.class.getSimpleName()); try { cache.query(new TextQuery<Integer, String>(String.class, "text").setLocal(true)).getAll(); assert false; } catch (CacheException e) { X.println("Caught expected exception: " + e); } catch (Exception ignored) { assert false; } }
/** * Test metrics if queries executed from several threads. * * @throws Exception In case of error. */ @Test public void testQueryMetricsMultithreaded() throws Exception { IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A"); Collection<CacheAbstractQueryMetricsSelfTest.Worker> workers = new ArrayList<>(); int repeat = 100; for (int i = 0; i < repeat; i++) { workers.add(new CacheAbstractQueryMetricsSelfTest.Worker(cache, new SqlFieldsQuery("select * from String limit " + i))); workers.add(new CacheAbstractQueryMetricsSelfTest.Worker(cache, new SqlQuery("String", "from String"))); workers.add(new CacheAbstractQueryMetricsSelfTest.Worker(cache, new ScanQuery())); workers.add(new CacheAbstractQueryMetricsSelfTest.Worker(cache, new TextQuery("String", "1"))); } for (CacheAbstractQueryMetricsSelfTest.Worker worker : workers) worker.start(); for (CacheAbstractQueryMetricsSelfTest.Worker worker : workers) worker.join(); checkMetrics(cache, repeat * 4, repeat * 4, 0, false); }
/** * @throws IgniteCheckedException if failed. */ @Test public void testTextIndexedKey() throws IgniteCheckedException { IgniteCache<ObjectValue, Long> cache = jcache(ObjectValue.class, Long.class); cache.put(new ObjectValue("test_key1", 10), 19L); cache.put(new ObjectValue("test_key0", 11), 11005L); cache.put(new ObjectValue("test_key1", 12), 17L); assertEquals(11005L, cache.query(new TextQuery<ObjectValue, Long>(Long.class, "test_key0")) .getAll().get(0).getValue().intValue()); }
/** * JUnit. */ @Test public void testTwoObjectsTextSearch() { CacheConfiguration<Object, Object> conf = new CacheConfiguration<>(cacheConfiguration()); conf.setQueryEntities(Arrays.asList( new QueryEntity(Integer.class, ObjectValue.class), new QueryEntity(String.class, ObjectValueOther.class) )); IgniteCache<Object, Object> c = jcache(ignite(), conf, Object.class, Object.class); c.put(1, new ObjectValue("ObjectValue str", 1)); c.put("key", new ObjectValueOther("ObjectValueOther str")); Collection<Cache.Entry<Object, Object>> res = c.query(new TextQuery<>(ObjectValue.class, "str")).getAll(); assert res != null; int expCnt = 1; assert res.size() == expCnt; assert F.first(res).getValue().getClass() == ObjectValue.class; res = c.query(new TextQuery<>(ObjectValueOther.class, "str")).getAll(); assert res != null; assert res.size() == expCnt; assert F.first(res).getValue().getClass() == ObjectValueOther.class; }
/** * Test metrics for Sql queries. * * @throws Exception In case of error. */ @Test public void testTextQueryNotFullyFetchedMetrics() throws Exception { IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A"); TextQuery qry = new TextQuery<>("String", "1"); qry.setPageSize(10); checkQueryNotFullyFetchedMetrics(cache, qry, true); }
/** * Test metrics for Sql queries. * * @throws Exception In case of error. */ @Test public void testTextQueryNotFullyFetchedMetrics() throws Exception { IgniteCache<Integer, String> cache = grid(0).context().cache().jcache("A"); TextQuery qry = new TextQuery<>("String", "1"); qry.setPageSize(10); checkQueryNotFullyFetchedMetrics(cache, qry, true); }
/** * @param clause Query clause. * @param loc local query flag. * @param keepBinary keep binary flag. */ private void checkTextQuery(String clause, boolean loc, boolean keepBinary) throws Exception { final IgniteEx ignite = grid(0); if (F.isEmpty(clause)) clause = "1*"; // 1. Populate cache with data, calculating expected count in parallel. Set<Integer> exp = populateCache(ignite, loc, MAX_ITEM_COUNT, new IgnitePredicate<Integer>() { @Override public boolean apply(Integer x) { return String.valueOf(x).startsWith("1"); } }); // 2. Validate results. TextQuery qry = new TextQuery<>(Person.class, clause).setLocal(loc); validateQueryResults(ignite, qry, exp, keepBinary); clearCache(ignite); }
/** * JUnit. * * @throws Exception In case of error. */ @Test public void testObjectWithString() throws Exception { IgniteCache<Integer, ObjectValue2> cache = jcache(Integer.class, ObjectValue2.class); cache.put(1, new ObjectValue2("value 1")); cache.put(2, new ObjectValue2("value 2")); cache.put(3, new ObjectValue2("value 3")); QueryCursor<Cache.Entry<Integer, ObjectValue2>> qry = cache.query(new SqlQuery<Integer, ObjectValue2>(ObjectValue2.class, "strVal like ?").setArgs("value%")); int expCnt = 3; List<Cache.Entry<Integer, ObjectValue2>> results = qry.getAll(); assertEquals(expCnt, results.size()); qry = cache.query(new SqlQuery<Integer, ObjectValue2>(ObjectValue2.class, "strVal > ?").setArgs("value 1")); results = qry.getAll(); assertEquals(expCnt - 1, results.size()); qry = cache.query(new TextQuery<Integer, ObjectValue2>(ObjectValue2.class, "value")); results = qry.getAll(); assertEquals(0, results.size()); //Should fail for FULL_TEXT index, but SORTED }
/** * @throws Exception If failed. */ @Test public void testFullTextQueryNodeJoin() throws Exception { for (int r = 0; r < 5; r++) { startGrids(GRID_CNT); try { for (int i = 0; i < 1000; i++) { IndexedEntity entity = new IndexedEntity("indexed " + i); grid(0).cache(DEFAULT_CACHE_NAME).put(new AffinityKey<>(i, i), entity); } Ignite started = startGrid(GRID_CNT); for (int i = 0; i < 100; i++) { QueryCursor<Cache.Entry<AffinityKey<Integer>, IndexedEntity>> res = started.cache(DEFAULT_CACHE_NAME) .query(new TextQuery<AffinityKey<Integer>, IndexedEntity>(IndexedEntity.class, "indexed")); assertEquals("Failed iteration: " + i, 1000, res.getAll().size()); } } finally { stopAllGrids(); } } }