/** * Populates cache with test data. * * @param cache Cache. * @throws GridException In case of error. */ private static void populate(GridCache<Object, Object> cache) throws GridException { cache.put("o1", new Organization(1, "GridGain")); cache.put("o2", new Organization(2, "Other")); // Persons are collocated with their organizations to support joins. cache.put(new GridCacheAffinityKey<String>("p1", "o1"), new Person(1, "John White", 25, 1)); cache.put(new GridCacheAffinityKey<String>("p2", "o1"), new Person(2, "Joe Black", 35, 1)); cache.put(new GridCacheAffinityKey<String>("p3", "o2"), new Person(3, "Mike Green", 40, 2)); }
/** * JUnit. * * @throws Exception In case of error. */ @SuppressWarnings({"TooBroadScope"}) public void testH2Text() throws Exception { int duration = 60 * 1000; final int keyCnt = 5000; final int logFreq = 50; final String txt = "Value"; final GridCache<Integer, H2TextValue> c = grid(0).cache(null); GridFuture<?> fut1 = multithreadedAsync( new Callable() { @Override public Object call() throws Exception { for (int i = 0; i < keyCnt; i++) { c.putx(i, new H2TextValue(txt)); if (i % logFreq == 0) X.println("Stored values: " + i); } return null; } }, 1); // Create query. final GridCacheQuery<Map.Entry<Integer, H2TextValue>> qry = c.queries().createFullTextQuery(H2TextValue.class, txt); qry.enableDedup(false); qry.includeBackups(false); qry.timeout(TEST_TIMEOUT); final AtomicBoolean stop = new AtomicBoolean(); GridFuture<?> fut2 = multithreadedAsync( new Callable() { @Override public Object call() throws Exception { int cnt = 0; while (!stop.get()) { Collection<Map.Entry<Integer, H2TextValue>> res = qry.execute().get(); cnt++; if (cnt % logFreq == 0) { X.println("Result set: " + res.size()); X.println("Executed queries: " + cnt); } } return null; } }, 1); Thread.sleep(duration); fut1.get(); stop.set(true); fut2.get(); }